Exemplo n.º 1
0
 private void btnregito_Click_2(object sender, EventArgs e)            //挂号按钮
 {
     if (this.txtsfz1.Text.Trim() == "")                               //判断身份证号文本框为空否
     {
         MessageBox.Show("输入身份证号或填写新病历");
         return;
     }
     else
     {
         string        sql = "select psfz from [user] where psfz='" + txtsfz1.Text.Trim() + "'";
         SqlConnection con = DBhelper.Gethelper();                    //验证该身份证有否病史
         SqlCommand    com = new SqlCommand(sql, con);
         con.Open();
         try
         {
             string idcard = com.ExecuteScalar().ToString();              //声明变量查询返回第一行第一列的值
             if (idcard == txtsfz1.Text.Trim())                           //找到记录的记录是否与文本框一致
             {
                 sql = "insert into [user](pname,psex,page,blood,phone,psfz,[money],adds) values('" + this.txtname1.Text.Trim() + "','" + txtsex1.Text.Trim() + "','" + this.txtage1.Text.Trim() + "','" + txtblood.Text + "','" + this.txtphone1.Text.Trim() + "','" + this.txtsfz1.Text.Trim() + "','0','" + this.txtadd1.Text.Trim() + "') ";
                 com = new SqlCommand(sql, con);                           //将有病史的病人的资料重新插入数据库一次
                 int temp = com.ExecuteNonQuery();                         //声明变量获取插入成功的行数,只要不为0就成功
                 if (temp != 0)
                 {
                     sql             = "select top 1 [pid] from [user] order by [pid] desc"; //找到此人本次看病的编号
                     com.CommandText = sql;
                     Num             = Convert.ToInt32(com.ExecuteScalar().ToString());
                     string aa = string.Format("您本次挂号临时编号为{0}", Num);
                     MessageBox.Show(aa, "领取成功!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     con.Close();
                     Relook obj = new Relook();                                          //挂号窗口打开,此窗体隐藏
                     obj.Show();
                     this.Hide();
                 }
             }
         }
         catch (Exception)
         {
             this.txtsfz1.Clear();
             MessageBox.Show("输入有错,请输入正确的身份证号查询或注册新病历!");
         }
     }
 }
Exemplo n.º 2
0
 private void btnUp_Click_1(object sender, EventArgs e)      //提交按钮
 {
     sfz = this.txtsfz.Text;                                 //给变量赋值
     if (this.txtsfz.Text.Trim() == "")                      //判断身份证为不为空
     {
         MessageBox.Show("请输入身份证");
         this.txtsfz.Focus();
     }
     else if (this.txtage.Text.Trim() == "")
     {
         MessageBox.Show("请输入年龄");
         this.txtage.Focus();
     }
     else if (this.txtname.Text.Trim() == "")
     {
         MessageBox.Show("请输入真实姓名");
         this.txtname.Focus();
     }
     else if (this.txtphone.Text.Trim() == "")
     {
         MessageBox.Show("请输入联系方式");
         this.txtphone.Focus();
     }
     else if (this.txtadd.Text.Trim() == "")
     {
         MessageBox.Show("请输入住址");
         this.txtadd.Focus();
     }
     else
     {
         try
         {
             long sfz1 = Convert.ToInt64(this.txtsfz.Text);              //声明身份证的变量接受强转INT型的身份证文本框的值
             int  age7 = Convert.ToInt32(this.txtage.Text);              //声明年龄的变量接受强转INT型的年龄文本框的值
             if (age7 >= 1 && age7 <= 130)                               //判断年龄规范
             {
                 SqlConnection con = DBhelper.Gethelper();               //声明SqlConnection对象
                 string        sex = "男";                                //给变量附初始值=男
                 if (this.radioButton2.Checked == true)                  //用户选择的按钮2被选中的话,变量为 女
                 {
                     sex = "女";
                 }
                 string     sql = "insert into [user](pname,psex,page,blood,phone,psfz,[money],adds) values('" + this.txtname.Text.Trim() + "','" + sex + "','" + this.txtage.Text.Trim() + "','" + this.cbxblood.SelectedItem.ToString() + "','" + this.txtphone.Text.Trim() + "','" + this.txtsfz.Text.Trim() + "','0','" + this.txtadd.Text.Trim() + "') ";
                 SqlCommand com = new SqlCommand(sql, con);              //往[user]表里添加病人信息,声明SqlCommand对象
                 con.Open();                                             //打开连接
                 int temp = com.ExecuteNonQuery();                       //声明变量接收SqlCommand对象的ExecuteNonQuery方法
                 if (temp != 0)
                 {
                     sql             = "select top 1 [pid] from [user] order by [pid] desc"; //降序排列得到[user]表中新注册用户的自动增长列
                     com.CommandText = sql;                                                  //获取SQL语句
                     Num             = Convert.ToInt32(com.ExecuteScalar().ToString());      //用静态变量接收强转INT型的查询所返回的1行1列的值即ID
                     string aa = string.Format("您的电子病历号是{0}", Num);
                     MessageBox.Show(aa, "电子病历注册成功!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     con.Close();                                                    //声明aa变量接收格式化后的字符串用消息框弹出成功信息
                     Relook obj1 = new Relook();                                     //病历注册后即进入挂号窗口
                     obj1.Show();
                     this.Hide();                                                    //此窗体隐藏
                 }
             }
             else
             {
                 MessageBox.Show("年龄格式不正确", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.txtage.Focus();
             }
         }
         catch (Exception)
         {
             MessageBox.Show("请输入数字", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }