Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e) //添加用户
 {
     if (textBox_passwd.Text != textBox_rpasswd.Text)
     {
         MessageBox.Show("两次密码输入不一致!");
         textBox_passwd.Focus();
         return;
     }
     if (label_xm.Text != string.Empty && label_sfzhm.Text != string.Empty)
     {
         DataRow dr = ds.Tables[0].NewRow();
         dr["username"]     = label_xm.Text.Trim();
         dr["idcardnumber"] = MD5.md5(label_sfzhm.Text + "liuying");
         dr["password"]     = textBox_passwd.Text.Trim();
         dr["class"]        = Convert.ToInt16(domainUpDown_class.Text);
         if (textBox_nicheng.Text == string.Empty)
         {
             dr["nickname"] = label_xm.Text.Trim();
         }
         else
         {
             dr["nickname"] = textBox_nicheng.Text.Trim();
         }
         ds.Tables[0].Rows.Add(dr);
         ad.Update(ds);
         label_xm.Text        = string.Empty;
         label_sfzhm.Text     = string.Empty;
         textBox_passwd.Text  = string.Empty;
         textBox_rpasswd.Text = string.Empty;
     }
     else
     {
         DataRow dr = ds.Tables[0].NewRow();
         if (textBox_nicheng.Text == string.Empty)
         {
             MessageBox.Show("不用身份证登记,警号不能为空!");
             return;
         }
         else
         {
             for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
             {
                 if (ds.Tables[0].Rows[i]["nickname"].ToString().Trim() == textBox_nicheng.Text.Trim())
                 {
                     MessageBox.Show("数据库里已有此警号,请重新选择警号!");
                     textBox_nicheng.Focus();
                     return;
                 }
             }
             dr["nickname"] = textBox_nicheng.Text.Trim();
         }
         dr["password"] = textBox_passwd.Text.Trim();
         if (Convert.ToInt16(domainUpDown_class.Text) < 3)
         {
             MessageBox.Show("不用身份证登记,不能创建权限级别小于3的用户!");
             return;
         }
         else
         {
             dr["class"] = Convert.ToInt16(domainUpDown_class.Text);
         }
         ds.Tables[0].Rows.Add(dr);
         ad.Update(ds);
         textBox_nicheng.Text = string.Empty;
         label_xm.Text        = string.Empty;
         label_sfzhm.Text     = string.Empty;
         textBox_passwd.Text  = string.Empty;
         textBox_rpasswd.Text = string.Empty;
     }
 }