zoukankan      html  css  js  c++  java
  • c# 整理一

    1.将DataTable中的某列转换成数组或者List

    string[] arrRate = dtRate.AsEnumerable().Select(d => d.Field<string>("列名")).ToArray();
    	
    List<string> litRate = dtRate.AsEnumerable().Select(d => d.Field<string>("列名")).ToList();
    

    2.使用事务  

    using (SqlConnection conn = new SqlConnection(DBObject.DBConnectionString))
    {
    conn.Open();
    SqlTransaction tran = conn.BeginTransaction();
    //此处省略将tran当做参数传入到SQLHelper函数文件
    tran.commit
    若异常
    tran.rollback

     3.同一程序,禁止重复开启,在Program.cs中设置

      Mutex mutex = new System.Threading.Mutex(true, "OnlyRun");
                if (mutex.WaitOne(0, false))
                {
                    Application.Run(new Form2());
                }
                else
                {
                    MessageBox.Show("程序已经在运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Application.Exit();
                }

     4.写日志方法

     static void WriteLog(string logmsg)
            {
                DateTime now = DateTime.Now;
                string rootdir = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"DCFileLogs";
                DirectoryInfo di = new DirectoryInfo(rootdir);
                if (!System.IO.Directory.Exists(rootdir))
                {
                    Directory.CreateDirectory(rootdir);
                }
                string path = string.Format(@"{0}{1}", rootdir, DateTime.Now.ToString("yyyy-MM-dd"));
                StreamWriter sw = new StreamWriter(path + ".txt", true);
                sw.WriteLine(now.ToString() + "	" + logmsg);
                sw.Close();
            } 

     5,通过数据库表名生成Model类

    SELECT  a.name TableName,CONCAT('public class ', a.name, N'{', CHAR(9), ( SELECT CONCAT(CHAR(10), 'public ', CASE b.user_type_id
                                                                                                  WHEN 61 THEN 'DateTime?'
                                                                                                  WHEN 56 THEN 'int?'
                                                                                                  WHEN 231 THEN 'string '
                                                                                                  WHEN 167 THEN 'string'
                                                                                                  WHEN 104 THEN 'bool?'
                                                                                                  WHEN 106 THEN 'decimal'
                                                                                                  ELSE 'UNKOWN'
                                                                                                END, ' ', b.name, '{get;set;}' + char(10))
                                                             FROM   sys.columns b
                                                             WHERE  b.object_id = a.object_id
                                                           FOR
                                                             XML PATH('')
                                                           ), CHAR(10), '}') TextSql
    FROM    sys.tables a
    WHERE   name IN( '表名')

    SQL语句生成结果复制出来如下:

    public class OABasicData{    
    public int? FID{get;set;}
    
    public string FName{get;set;}
    
    public string  FDepart{get;set;}
    
    public bool? IsEnable{get;set;}
    
    public string FType{get;set;}
    
    public string FMark{get;set;}
    
    }

     6.asp.testbox限制只能输入大写字母

    <asp:TextBox runat="server" ID="txtProjectName" Style="margin-left: 0px; text-transform:uppercase " Width="350px"
    TabIndex="1"></asp:TextBox>

    7.清空网页上asp:textbox值,(winform界面原理相同)

        public void ControlValueClear(System.Web.UI.Control page)
        {
            int count = page.Controls.Count;
            for (int i = 0; i < count; i++)
            {
                foreach (System.Web.UI.Control control in page.Controls[i].Controls)
                {
                    if (control is TextBox)
                    {
                        (control as TextBox).Text = string.Empty;
    
                    }
    
                }
            }
        }
    
    调用时,参数传入this,表示当前界面

     8.获取界面按钮post产生的数据,(做公司派车申请单,派车明细校验时使用到)

      private static string PostInput(System.Web.UI.Page page)
            {
                try
                {
    
                    System.IO.Stream s = page.Request.InputStream;
    
                    int count = 0;
    
                    byte[] buffer = new byte[1024];
    
                    StringBuilder builder = new StringBuilder();
    
                    while ((count = s.Read(buffer, 0, 1024)) > 0)
                    {
    
                        builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
    
                    }
    
                    s.Flush();
    
                    s.Close();
    
                    s.Dispose();
    
                    return builder.ToString();
    
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

    调用:
    PostInput(this.page)
     

     C#继承中的override(重写)与new(覆盖)用法

      https://www.cnblogs.com/vsSure/p/7816639.html

    委托与事件应用场景: https://www.cnblogs.com/guoqiang1/p/8138889.html

  • 相关阅读:
    SQL基本操作(工作中够用了)
    用Ajax爬取今日头条图片集
    (完整)爬取数据存储之TXT、JSON、CSV存储
    (最全)Xpath、Beautiful Soup、Pyquery三种解析库解析html 功能概括
    基础爬虫,谁学谁会,用requests、正则表达式爬取豆瓣Top250电影数据!
    正则表达式功能概括
    常用的os库笔记
    软件测试阶段
    Python接口自动化测试(一)什么是接口?
    界面和易用性测试
  • 原文地址:https://www.cnblogs.com/gudaozi/p/10376586.html
Copyright © 2011-2022 走看看