private void tsbSave_Click(object sender, EventArgs e) { //用户点击新建按钮 if (op == operation.insert) { DataClasses1DataContext db = new DataClasses1DataContext(connStr); Employeeinformation em = new Employeeinformation(); em.emp_id = txtId.Text; em.emp_name = txtName.Text; em.emp_sex = txtSex.Text; em.emp_phone = txtPhone.Text; em.emp_age = Convert.ToInt32(txtAge.Text); em.emp_position = txtPosition.Text; em.emp_address = txtAddress.Text; db.Employeeinformation.InsertOnSubmit(em); db.SubmitChanges(); MessageBox.Show("员工数据添加成功", "添加记录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); BindInfo(); } //用户点击编辑按钮 else if (op == operation.update) { DataClasses1DataContext db = new DataClasses1DataContext(connStr); Employeeinformation em = new Employeeinformation(); var result = from emp in db.Employeeinformation where emp.emp_id == txtId.Text select emp; foreach (Employeeinformation emp in result) { emp.emp_id = txtId.Text; emp.emp_name = txtName.Text; emp.emp_sex = txtSex.Text; emp.emp_phone = txtPhone.Text; emp.emp_age = Convert.ToInt32(txtAge.Text); emp.emp_position = txtPosition.Text; emp.emp_address = txtAddress.Text; db.SubmitChanges(); MessageBox.Show("数据修改成功", "修改记录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); BindInfo(); } } }
partial void DeleteEmployeeinformation(Employeeinformation instance);
partial void UpdateEmployeeinformation(Employeeinformation instance);
partial void InsertEmployeeinformation(Employeeinformation instance);