private void button1_Click(object sender, EventArgs e) { try { List <ClassCongViec> lstcv = new List <ClassCongViec>(); this.listsearchG.DataSource = null; this.listsearchG.Items.Clear(); foreach (var item in this.checkedListBox1.CheckedItems) { ClassDuAn da = DAController.GetDuAn(item.ToString()); //lay danh sach cong viec cua du an vao listsearchG foreach (var i in da.listCV) { lstcv.Add(i); } //MessageBox.Show(item.ToString()); } listsearchG.DataSource = lstcv; } catch { } }
public static bool UpdatelistCV(ClassDuAn da) { try { using (var _context = new DBManageContext()) { var dbda = (from d in _context.tbDuAn where d.MaDA == da.MaDA select d).Single(); foreach (ClassCongViec cv in dbda.listCV.ToList()) { dbda.listCV.Remove(cv); } foreach (var cv in da.listCV) { var dbcv = (from c in _context.tbCongViec where c.MaCV == cv.MaCV select c).Single(); dbda.listCV.Add(dbcv); } _context.tbDuAn.AddOrUpdate(dbda); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool UpdateDA(ClassDuAn da) { try { using (var _context = new DBManageContext()) { _context.tbDuAn.AddOrUpdate(da); _context.SaveChanges(); return(true); } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); return(false); } }
private void addbt_Click(object sender, EventArgs e) { //Kiem tra MaDA da ton tai hay khong if (DAController.GetDuAn(txtMaDA.Text.Trim()) != null) { return; } //kiem tra hop le bool check = false; if (KiemTra(check) == true) { return; } ClassDuAn da = new ClassDuAn(); da.MaDA = txtMaDA.Text.Trim(); da.TenDA = txtTenDA.Text.Trim(); da.fromDate = fromDatePicker.Value; da.toDate = toDatePicker.Value; da.ChiTiet = txtChitiet.Text; //them vao csdl if (DAController.AddDuAn(da) == false) { MessageBox.Show("Loi khi them du an", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //hien thi du lieu ShowData(); ClearControls(); }
public static bool AddDuAn(ClassDuAn da) { try { using (var _context = new DBManageContext()) { _context.tbDuAn.Add(da); _context.SaveChanges(); return(true); } //using (var _context = new DBManageContext()) //{ // //lay du an // var dbda = (from proj in _context.tbDuAn // where proj.MaDA == da.MaDA // select proj).Single(); // foreach (ClassCongViec cv in da.listCV) // { // //lay congviec tu sql // var dbcv = (from d in _context.tbCongViec // where d.MaCV == cv.MaCV // select d).Single(); // //them vao listcv cua dbda // dbda.listCV.Add(dbcv); // } // _context.tbDuAn.AddOrUpdate(dbda); // _context.SaveChanges(); // return true; //} } catch { return(false); } }
private void editbt_Click(object sender, EventArgs e) { bool check = false; if (KiemTra(check) == true) { return; } ClassDuAn da = new ClassDuAn(); da.MaDA = txtMaDA.Text.Trim(); da.TenDA = txtTenDA.Text.Trim(); da.fromDate = fromDatePicker.Value; da.toDate = toDatePicker.Value; da.ChiTiet = txtChitiet.Text; //Kiem tra congviec thuoc du an khac hay khong khi ADD //if(selectedMaDA!=this.txtMaDA.Text.Trim()) //{ // List<ClassCongViec> congViecs = new List<ClassCongViec>(); // foreach (var i in CongViecController.GetListCV()) // { // if (i.listDA.Count != 0) // congViecs.Add(i); // } // foreach (var j in congViecs) // { // foreach (var z in da.listCV) // { // if (j.MaCV == z.MaCV) // { // MessageBox.Show("Cong viec da thuoc du an khac", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; // } // } // } //} //kiem tra cong viec thuoc du an khac hay khong Update //foreach(var i in da.listCV) //{ // if(i.listDA.Count!=0) // foreach(var j in i.listDA) // { // if (j.MaDA != da.MaDA) // { // MessageBox.Show("Cong viec da thuoc du an khac", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; // } // } //} if (DAController.UpdateDA(da) == false) { MessageBox.Show("Loi khi sua du an", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ShowData(); ClearControls(); }