C#机房重构-优化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/TheBestAge/article/details/82562175
一、基本限制
  //限制只能输入汉字,正则表达式
  if(!Regex.IsMatch(this.txtdepartment.Text.Trim(),"[\u4e00-\u9fa5]")&& this.txtdepartment.Text.Length >= 4)
  {
       MessageBox.Show("请输入汉字,且汉字个数不超过4个");
       txtdepartment.Text = "";
       txtdepartment.Focus();
       return;
  }
  
//只能输入数字
   private void txtcardno_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((int)e.KeyChar >= 48 & (int)e.KeyChar <= 57 | (int)e.KeyChar == 8)
        {
            e.Handled = false;
        }
        else
        {
            MessageBox.Show("请输入数字");
            e.Handled = true;
        }
     }
 //建立一个函数,用来调用判断是否为数字
 public bool IsNumber(string text)//判断是否为数字的函数
    {
        try
        {
            int var = Convert.ToInt32(text);
            return true;
        }
        catch
        {
            return false;
        }
    }
二、获取服务器时间
获取服务器时间使用SQL函数GetDate(),写入的便是服务器时间。
Select convert(varchar(10),getdate(),120)  //yyyy-mm-dd
Select convert(varchar(10),getdate(),108)  //hh-mm-ss

猜你喜欢

转载自blog.csdn.net/TheBestAge/article/details/82562175