private void BtnYingZheng_Click(object sender, EventArgs e) { //使用try catch 判断年龄不能为字符 try { double mn = Convert.ToDouble(this.txtMoney.Text); //判断成功执行SQL语句 string sql = "insert into bingkuang values ('" + this.txtnum.Text.Trim() + "','" + this.txtName.Text.Trim() + "','" + this.txtSex.Text.Trim() + "','" + this.txtage.Text.Trim() + "','" + this.txtBlood.Text.Trim() + "','" + this.txtPhone.Text.Trim() + "','" + this.txtBingKuang.Text.Trim() + "'," + mn + ",'" + this.txtAdds.Text.Trim() + "')"; if (Mindoc.Getzsgc(sql)) { MessageBox.Show("操作成功"); this.Hide(); //本窗体隐藏 } else { MessageBox.Show("操作失败"); } } catch (Exception) { MessageBox.Show("年龄格式不正确", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Show(); this.txtMoney.Focus();//如果输入不是数字返回到txtMoney文本框 } }
private void btnTiJiao_Load(object sender, EventArgs e) { //查询医生姓名和科室的SQL语句 string sql = "select uname,office from dbo.login where uid='" + Login.denglu + "'"; DataSet ds = Mindoc.Getds(sql); //创建ds对象 lblDocName1.Text = ds.Tables[0].Rows[0][0].ToString(); lblKemuName1.Text = ds.Tables[0].Rows[0][1].ToString(); //查询新挂号病人的SQL语句 sql = "select psfz,pname,page,psex,blood,phone,adds,data from [user] where pid='" + Mindoc.name1 + "'"; ds = Mindoc.Getds(sql); //创建ds对象 this.txtnum.Text = ds.Tables[0].Rows[0][0].ToString(); this.txtName.Text = ds.Tables[0].Rows[0][1].ToString(); this.txtSex.Text = ds.Tables[0].Rows[0][2].ToString(); this.txtage.Text = ds.Tables[0].Rows[0][3].ToString(); this.txtBlood.Text = ds.Tables[0].Rows[0][4].ToString(); this.txtPhone.Text = ds.Tables[0].Rows[0][5].ToString(); this.txtAdds.Text = ds.Tables[0].Rows[0][6].ToString(); this.txtTime.Text = ds.Tables[0].Rows[0][7].ToString(); }
private void save_Click(object sender, EventArgs e) { int accounts = 0; string sex = "男"; //默认性别为男 if (this.radiogirl.Checked == true) { sex = "女"; } string type = "挂号台"; if (this.DrRadio.Checked == true) { type = "医生"; } //判断用户名,密码,科室,年龄不能为空 if (this.trueName.Text.Trim() == "") { MessageBox.Show("用户名不能为空"); this.Focus(); return; } if (this.code.Text.Trim() == "") { MessageBox.Show("密码不能为空"); this.Focus(); return; } if (this.DrRadio.Checked == true && this.comboBox1.Text == "") { MessageBox.Show("科室不能为空"); this.Focus(); return; } if (this.ageAasked.Text.Trim() == "") { MessageBox.Show("年龄不能为空"); this.Focus(); return; } //向数据库插入注册的SQL语句 string sql = "insert into dbo.login values ('" + this.code.Text.Trim() + "','" + this.trueName.Text.Trim() + "','" + sex + "','" + this.ageAasked.Text.Trim() + "','" + type + "','" + this.comboBox1.Text.Trim() + "',0)"; SqlConnection con = DBhelper.Gethelper(); //调用DBhelp类中的方法,连接数据库 SqlCommand com = new SqlCommand(sql, con); //创建command对象执行SQL语句 con.Open(); int count = com.ExecuteNonQuery(); con.Close(); if (count > 0) //判断数据库中受影响的行数 { con.Open(); string sql1 = "select top 1 uid from dbo.login order by uid desc"; //将数据库中的数据按降序排列并查找出第一个 com.CommandText = sql1; accounts = Convert.ToInt32(com.ExecuteScalar()); //生成帐号 string Message = string.Format("注册成功!您的帐号是{0}", accounts); MessageBox.Show(Message, "注册成功", MessageBoxButtons.OK, MessageBoxIcon.Information); con.Close(); } sql = "insert into dbo.Friend(id,kemu,name) values(" + accounts + ",'" + this.comboBox1.Text + "','" + this.trueName.Text + "')"; Mindoc.Getzsgc(sql); }
private void land_Click(object sender, EventArgs e) { try { //判断用户名,密码,登陆类型不能为空 if (this.num.Text.Trim() == "") { MessageBox.Show("请输入用户名"); this.Focus(); return; } else if (this.pwdText.Text.Trim() == "") { MessageBox.Show("请输入密码"); this.Focus(); return; } else if (this.userType.Text.Trim() == "") { MessageBox.Show("用户类型不能为空"); this.Focus(); return; } } catch { throw; } denglu = Convert.ToInt32(this.num.Text.Trim()); //将文本框的值付给静态变量 //当登陆类型为挂号台时并且获取正确的帐号与密码就跳转挂号台窗体 if (this.userType.Text == "挂号") { string sql = "select count(*) from dbo.login where uid='" + this.num.Text.Trim().ToString() + "'and pwd='" + this.pwdText.Text.Trim().ToString() + "' and type='挂号台'"; bool yn = loginType(sql);//调用loginType方法 if (yn == true) { uc objreg = new uc(); objreg.Show(); } else { MessageBox.Show("帐号或密码错误!"); return; } } //当登陆类型为医生时并且获取正确的帐号与密码就跳转到医生窗体 if (this.userType.Text == "医生") { string sql = "select count(*) from dbo.login where uid='" + this.num.Text.Trim().ToString() + "'and pwd='" + this.pwdText.Text.Trim().ToString() + "'and type='医生'"; bool yn = loginType(sql);//调用loginType方法 if (yn == true) { sql = "update [login] set stata=0 where uid='" + denglu + "'"; if (Mindoc.Getzsgc(sql))//调用方法执行SQL语句 { Mindoc objmin = new Mindoc(); objmin.Show();//打开医生窗体 } } else { MessageBox.Show("帐号或密码错误!"); return; } } this.Hide();//本窗体隐藏 }