private void btnyes_Click(object sender, EventArgs e) { string userName = txtName.Text; string password = txtPwd.Text; CommDB mydb = new CommDB(); string mystr; mystr = string.Format("select * from [User] where Username='******' and Password='******'", userName, password); try { int i = mydb.Rownum(mystr); if (i == 0) { MessageBox.Show("您输入的用户名或密码错误!请重试", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtPwd.Text = ""; return; } else { string mysql = string.Format("SELECT Level FROM [User] WHERE Username='******' AND Password='******'", userName, password); string level = mydb.Returnafield(mysql); this.Hide(); Form myform = new Main(level); myform.BackColor = System.Drawing.SystemColors.GradientInactiveCaption; myform.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = DialogResult.No; try { if (dgv_users.SelectedRows.Count > 0) { result = MessageBox.Show("是否删除选中项?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result == DialogResult.Yes) { CommDB mydb = new CommDB(); string mysql = "DELETE FROM [User] WHERE Username = '******'"; mydb.ExecuteNonQuery(mysql); MessageBox.Show("删除成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } cmbd.bind(dgv_users, "SELECT * FROM [User]", "User"); }
public void bind(DataGridView dgv, string mystr, string tb)//绑定数据的自定义方法 { CommDB mydb = new CommDB(); DataSet mydataset = mydb.ExecuteQuery(mystr, tb); dgv.DataSource = mydataset.Tables[tb]; }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = DialogResult.No; try { if (dgv_inquire.SelectedRows.Count > 0) { result = MessageBox.Show("是否删除选中项?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result == DialogResult.Yes) { CommDB mydb = new CommDB(); string mysql = "DELETE FROM [Parents] WHERE ID = '" + dgv_inquire.SelectedRows[0].Cells[1].Value.ToString() + "'"; mydb.ExecuteNonQuery(mysql); MessageBox.Show("删除成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } CmbDataGridview cmbd = new CmbDataGridview(); cmbd.bind(dgv_inquire, mystr, "Parents"); }
private void inquire() { if (txt_student_num.Text == "" && txt_tutors_name.Text == "" && txt_tutors_num.Text == "" && txt_phone.Text == "") { CmbDataGridview cmbd = new CmbDataGridview(); cmbd.bind(dgv_inquire, mystr, "Tutors"); return; } CommDB mydb = new CommDB(); string mysql = "", tempstr = ""; if (txt_tutors_num.Text != "") { tempstr = "教员编号 Like '%" + txt_tutors_num.Text.Trim() + "%'"; } if (txt_tutors_name.Text != "") { if (tempstr == "") { tempstr = "姓名 Like '%" + txt_tutors_name.Text.Trim() + "%'"; } else { tempstr += " AND 姓名 Like '%" + txt_tutors_name.Text.Trim() + "%'"; } } if (txt_student_num.Text != "") { if (tempstr == "") { tempstr = "学号 Like '%" + txt_student_num.Text.Trim() + "%'"; } else { tempstr += " AND 学号 Like '%" + txt_student_num.Text.Trim() + "%'"; } } if (txt_phone.Text != "") { if (tempstr == "") { tempstr = "联系方式 Like '%" + txt_phone.Text.Trim() + "%'"; } else { tempstr += " AND 联系方式 Like '%" + txt_phone.Text.Trim() + "%'"; } } if (tempstr == "") { mysql = "SELECT * FROM [Tutors] ORDER BY 教员编号"; } else { mysql += "SELECT * FROM [Tutors] WHERE " + tempstr + " ORDER BY 教员编号 DESC"; } DataSet mydataset = mydb.ExecuteQuery(mysql, "Tutors"); dgv_inquire.DataSource = mydataset.Tables["Tutors"]; }
private void 择此家教ToolStripMenuItem_Click(object sender, EventArgs e) { try { num1 = dgv_inquire.SelectedRows[0].Cells[2].Value.ToString(); string mysql = "SELECT 是否黑名单 FROM [Tutors] WHERE 教员编号='" + num1 + "'"; CommDB mydb = new CommDB(); string flag = mydb.Returnafield(mysql); if (flag == "是") { MessageBox.Show("此教员已被列入黑名单!请重新选择!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { name1 = dgv_inquire.SelectedRows[0].Cells[3].Value.ToString(); UpDate3(num1, name1); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } CmbDataGridview cmbd = new CmbDataGridview(); }
private void btn_prepared_Click(object sender, EventArgs e) { CommDB mydb = new CommDB(); string mysql = "SELECT ID,家长编号,打印编号,家长称呼,联系方式," + "年级科目,学员性别,家教状态,经办时间,家教价格,家教时间,家教地址详细,重要备注,缴费状态,缴费时间 FROM [Parents] WHERE 家教状态='待接' ORDER BY 经办时间 DESC"; DataSet mydataset = mydb.ExecuteQuery(mysql, "Parents"); dgv_track.DataSource = mydataset.Tables["Parents"]; }
public void cboDataBind(ComboBox cbo, string cmdText, string tb, string DisplayFied) { CommDB mydb = new CommDB(); DataSet mydataset; // string mystr = "SELECT distinct 接待人 FROM [Table]"; mydataset = mydb.ExecuteQuery(cmdText, tb); cbo.DataSource = mydataset.Tables[tb]; cbo.DisplayMember = DisplayFied; }
private void btn_delete_Click(object sender, EventArgs e) { CmbDataGridview cmbd = new CmbDataGridview(); DialogResult result = DialogResult.No; int n = 0; try { for (int i = 0; i < dgv_inquire.Rows.Count; i++) { if ((bool)dgv_inquire.Rows[i].Cells[0].EditedFormattedValue == true) //判断该复选框是否被选中 { n++; if (n == 1) { result = MessageBox.Show("是否删除勾选项?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); } if (result == DialogResult.Yes) { string mysql = "DELETE FROM [Parents] WHERE ID = '" + dgv_inquire.Rows[i].Cells[1].Value.ToString() + "'"; mydb.ExecuteNonQuery(mysql); } } } if (n != 0) { MessageBox.Show("删除成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); cmbd.bind(dgv_inquire, mystr, "Parents"); } if (dgv_inquire.SelectedRows.Count > 0 && n == 0) { result = MessageBox.Show("是否删除选中项?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result == DialogResult.Yes) { CommDB mydb = new CommDB(); string mysql = "DELETE FROM [Parents] WHERE ID = '" + dgv_inquire.SelectedRows[0].Cells[1].Value.ToString() + "'"; mydb.ExecuteNonQuery(mysql); MessageBox.Show("删除成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } cmbd.bind(dgv_inquire, mystr, "Parents"); }
public void Add(string reception, string state) { CommDB mydb = new CommDB(); string mysql = "SELECT 本月业务积分 FROM [Workers] WHERE 姓名='" + reception + "'"; float month = float.Parse(mydb.Returnafield(mysql)); month += standard(state); mysql = "SELECT 累计业务积分 FROM [Workers] WHERE 姓名='" + reception + "'"; float sum = float.Parse(mydb.Returnafield(mysql)); sum += standard(state); mysql = string.Format("UPDATE [Workers] SET 本月业务积分='{0}',累计业务积分='{1}' WHERE 姓名='{2}'", month, sum, reception); mydb.ExecuteNonQuery(mysql); }
private void inquire() { if (txt_parentnum.Text == "" && txt_printnum.Text == "" && txt_adr.Text == "" && txt_phone.Text == "") { CmbDataGridview cmbd = new CmbDataGridview(); cmbd.bind(dgv_inquire, mystr, "Parents"); return; } CommDB mydb = new CommDB(); string mysql = "", tempstr = ""; if (txt_parentnum.Text != "") { tempstr = "家长编号 Like '%" + txt_parentnum.Text.Trim() + "%'"; } if (txt_printnum.Text != "") { if (tempstr == "") { tempstr = "打印编号 Like '%" + txt_printnum.Text.Trim() + "%'"; } else { tempstr += " AND 打印编号 Like '%" + txt_printnum.Text.Trim() + "%'"; } } if (txt_adr.Text != "") { if (tempstr == "") { tempstr = "家教地址详细 Like '%" + txt_adr.Text.Trim() + "%'"; } else { tempstr += " AND 家教地址详细 Like '%" + txt_adr.Text.Trim() + "%'"; } } if (txt_phone.Text != "") { if (tempstr == "") { tempstr = "联系方式 Like '%" + txt_phone.Text.Trim() + "%'"; } else { tempstr += " AND 联系方式 Like '%" + txt_phone.Text.Trim() + "%'"; } } if (tempstr == "") { mysql = "SELECT ID,家长编号,打印编号,家长称呼,联系方式," + "年级科目,学员性别,家教状态,经办时间,家教价格,家教时间,家教地址详细,重要备注,缴费状态,缴费时间 FROM [Parents] ORDER BY 打印编号"; } else { mysql += "SELECT ID,家长编号,打印编号,家长称呼,联系方式," + "年级科目,学员性别,家教状态,经办时间,家教价格,家教时间,家教地址详细,重要备注,缴费状态,缴费时间 FROM [Parents] WHERE " + tempstr + " ORDER BY 打印编号 DESC"; } DataSet mydataset = mydb.ExecuteQuery(mysql, "Parents"); dgv_inquire.DataSource = mydataset.Tables["Parents"]; }