private void btnSeach_Click(object sender, EventArgs e) { dataAccess DataSelect = new dataAccess(); DataSelect.Datacon(); string condition = ""; if (txtSid.Text.Trim() != "") { condition += "and Sid = '" + txtSid.Text.Trim() + "'"; } if (txtSname.Text.Trim() != "") { condition += "and Sname LIKE '%" + txtSname.Text.Trim() + "%'"; } if (cboSex.Text != "") { condition += "and Sex = '" + cboSex.Text + "'"; } if (txtClass.Text.Trim() != "") { condition += "and Class = '" + txtClass.Text.Trim() + "'"; } try { string comStr = "select Sid as 学号, Sname as 姓名, Sex as 性别, Birthday as 生日, Class as 班级, Tel as 电话, Address as 家庭住址 from Studentinfo where 1=1 " + condition; DataSet ds = DataSelect.Data(comStr); dgvInfo.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//con 表 //conStr 定义连接表的参数 //com 对表操作的Command //comStr com的参数 //da DataAdapter缩写 为DataAdapter参数 //ds DataSet缩写 同上 private void button1_Click(object sender, EventArgs e) { //定义用户名密码 trim 删除前后空白 string userId = textId.Text.Trim(); string Pwd = textPwd.Text.Trim(); //链接数据库 dataAccess DataA = new dataAccess(); DataA.Datacon(); string comStr = "select * from Userinfo where Userid = '" + userId + "' and Userpwd = '" + Pwd + "'"; DataSet Login = DataA.Data(comStr); //ds集中第一个Tables,所有的行数 如果是对的择弹窗 if (Login.Tables[0].Rows.Count == 1) { if (Convert.ToString(Login.Tables[0].Rows[0][2]) == "教师") { power = 0; } else { power = 1; } frmMain fromM = new frmMain(); fromM.Show(); this.Hide(); } else { MessageBox.Show("登录失败"); } }
//点击删除以后删除该学生信息 private void btnDel_Click(object sender, EventArgs e) { if (dgvInfo.CurrentRow != null) { if (frmLogin.Power == 0) { dataAccess DataDel = new dataAccess(); DataDel.Datacon(); string comStr = "delete from Studentinfo where Sid = '" + dgvInfo.CurrentRow.Cells[0].Value.ToString() + "'"; if (DataDel.DataCom(comStr) == true) { MessageBox.Show("学生删除成功!"); } else { MessageBox.Show("学生删除失败!"); } } else { MessageBox.Show("权限不足!"); } } else { MessageBox.Show("请查询并选择你要删除的学生信息!"); } }
private void btnSeach_Click(object sender, EventArgs e) { dataAccess DataSelect = new dataAccess(); DataSelect.Datacon(); string condition = ""; if (txtCid.Text.Trim() != "") { condition += "and Cid = '" + txtCid.Text.Trim() + "'"; } if (txtCname.Text.Trim() != "") { condition += "and Cname = '" + txtCname.Text.Trim() + "'"; } try { string comStr = "select Cid as 课程编号, Cname as 课程名, Credit as 学分 from Courseinfo where 1=1 " + condition; DataSet ds = DataSelect.Data(comStr); dgvInfo.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void cboCname_SelectedIndexChanged(object sender, EventArgs e) { string Cname = Convert.ToString(cboCname.SelectedItem); dataAccess DataA = new dataAccess(); DataA.Datacon(); string comStr = "select * from Courseinfo where Cname = '" + Cname + "'"; DataSet name = DataA.Data(comStr); txtCid.Text = Convert.ToString(name.Tables[0].Rows[0][0]); }
private void frmEditCou_Load(object sender, EventArgs e) { txtCid.Text = frmManageCou.Cid; string Cid = Convert.ToString(txtCid.Text); string comStr; dataAccess DataB = new dataAccess(); DataB.Datacon(); comStr = "select * from Courseinfo where Cid = '" + Cid + "'"; DataSet cid = DataB.Data(comStr); txtCname.Text = Convert.ToString(cid.Tables[0].Rows[0][1]); }
private void btnEdit_Click(object sender, EventArgs e) { if (txtSname.Text == "") { txtSname.Text = frmManageStu.Sname; } if (cboSex.Text == "") { cboSex.Text = frmManageStu.Sex; } if (txtBirthday.Text == "") { txtBirthday.Text = frmManageStu.Birthday; } if (txtClass.Text == "") { txtClass.Text = frmManageStu.Class; } if (txtTel.Text == "") { txtTel.Text = frmManageStu.Tel; } if (txtAddress.Text == "") { txtAddress.Text = frmManageStu.Address; } if (txtSid.Text != "" && txtSname.Text != "" && cboSex.Text != "" && txtBirthday.Text != "" && txtClass.Text != "" && txtTel.Text != "" && txtAddress.Text != "") { dataAccess DataEdit = new dataAccess(); DataEdit.Datacon(); string comStr = "update Studentinfo set Sname = '" + txtSname.Text + "',Sex = '" + cboSex.Text + "', Birthday = '" + txtBirthday.Text + "', Class = '" + txtClass.Text + "', Tel = '" + txtTel.Text + "', Address = '" + txtAddress.Text + "' where Sid = '" + txtSid.Text.Trim() + "'"; if (DataEdit.DataCom(comStr) == true) { MessageBox.Show("学生修改成功!"); } else { MessageBox.Show("学生修改失败!"); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (frmLogin.Power == 0) { dataAccess DataAdd = new dataAccess(); DataAdd.Datacon(); string comStr = "insert into Courseinfo values ('" + txtCid.Text + "', '" + txtCname.Text + "', '" + txtCredit.Text + "')"; if (DataAdd.DataCom(comStr)) { MessageBox.Show("课程添加成功!"); } } else { MessageBox.Show("权限不足!"); } }
private void btnDel_Click(object sender, EventArgs e) { if (frmLogin.Power == 0) { dataAccess DataDel = new dataAccess(); DataDel.Datacon(); string comStr = "delete from Courseinfo where Cid = '" + dgvInfo.CurrentRow.Cells[0].Value.ToString() + "'"; if (DataDel.DataCom(comStr)) { MessageBox.Show("科目删除成功!"); } } else { MessageBox.Show("权限不足!"); } }
private void btnEdit_Click(object sender, EventArgs e) { if (txtCid.Text != "" && txtSid.Text != "" && txtScore.Text != "") { dataAccess DataEdit = new dataAccess(); DataEdit.Datacon(); string comStr = "update Scoreinfo set Score = '" + txtScore.Text + "' where Cid = '" + txtCid.Text.Trim() + "' and Sid = '" + txtSid.Text.Trim() + "'"; if (DataEdit.DataCom(comStr) == true) { MessageBox.Show("成绩修改成功!"); } else { MessageBox.Show("成绩修改失败!"); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (frmLogin.Power == 0) { dataAccess DataAdd = new dataAccess(); DataAdd.Datacon(); string comStr = "insert into Studentinfo(Sid,Sname,Sex,Birthday,Class,Tel,Address) values ('" + txtSid.Text + "', '" + txtSname.Text + "', '" + cboSex.Text + "', '" + txtBirthday.Text + "', '" + txtClass.Text + "', '" + txtTel.Text + "', '" + txtAddress.Text + "')"; if (DataAdd.DataCom(comStr)) { MessageBox.Show("学生添加成功!"); } else { MessageBox.Show("学生添加失败!"); } } else { MessageBox.Show("权限不足!"); } }