//xóa ca public void XoaCa(int id) { CaLam ca = (from l in db.CaLams where l.IDCa == id select l).SingleOrDefault(); db.CaLams.DeleteOnSubmit(ca); db.SubmitChanges(); }
//Thêm ca public bool ThemCa(CaLam ca) { try { db.CaLams.InsertOnSubmit(ca); db.SubmitChanges(); return(true); } catch { return(false); } }
public CaLam LayCaLamByMa(int maCa) { CaLam CaLam = null; string query = "SELECT * FROM dbo.CaLamViec WHERE MaCa =" + maCa; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { CaLam = new CaLam(item); return(CaLam); } return(CaLam); }
public List <CaLam> CaLam() { List <CaLam> listCaLam = new List <CaLam>(); string query = "SELECT * FROM dbo.CaLamViec"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { CaLam caLam = new CaLam(item); listCaLam.Add(caLam); } return(listCaLam); }
//sửa ca public bool SuaCa(CaLam ca) { try { CaLam cl = (from c in db.CaLams where c.IDCa == ca.IDCa select c).SingleOrDefault(); cl.GioBDCa = ca.GioBDCa; cl.GioHetCa = ca.GioHetCa; cl.TenCa = ca.TenCa; cl.TienCong = ca.TienCong; db.SubmitChanges(); return(true); } catch { return(false); } }
private void btn_ThemLoaiNV_Click(object sender, EventArgs e) { if (them == 0) { txt_MaCa.Text = ""; txt_TenCa.Text = ""; txt_MaCa.Text = ""; txt_GioBD.Text = ""; txt_GioKT.Text = ""; txt_TenCa.Enabled = true; txt_TienCong.Enabled = true; txt_GioBD.Enabled = true; txt_GioKT.Enabled = true; btn_ThemCa.Text = "Lưu"; btn_SuaCa.Enabled = false; btn_XoaCa.Enabled = false; them = 1; return; } if (them == 1) { TimeSpan gioBD, gioKT; String tenCa = txt_TenCa.Text; try { gioBD = TimeSpan.Parse(txt_GioBD.Text); } catch { MessageBox.Show("Thêm không thành công !"); them = 0; btn_ThemCa.Text = "Thêm"; return; } try { gioKT = TimeSpan.Parse(txt_GioBD.Text); } catch { MessageBox.Show("Thêm không thành công !"); them = 0; btn_ThemCa.Text = "Thêm"; return; } int tienCong; if (txt_TienCong.Text == "") { tienCong = 0; } tienCong = Int32.Parse(txt_TienCong.Text); if (tienCong < 0) { tienCong = 0; } CaLam cl = new CaLam() { TenCa = tenCa, GioBDCa = gioBD, GioHetCa = gioKT, TienCong = tienCong }; if (linqToSql.Instance.ThemCa(cl)) { MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Thêm thất bại"); } them = 0; btn_ThemCa.Text = "Thêm"; btn_XoaCa.Enabled = true; btn_SuaCa.Enabled = true; loadData(); return; } }