private void btnUpdate_Click(object sender, EventArgs e) { ListOfWork low = new ListOfWork(); try { low.no = Convert.ToInt32(this.listLOW.SelectedItems[0].SubItems[0].Text); low.job = this.rtJob.Text; low.status = this.cbbStatus.Text; low.Projects = new List <Project>(); foreach (Project pro in lstpro.Items) { low.Projects.Add(pro); } LOWController.UpdateLOW(low); this.listLOW.SelectedItems[0].Remove(); } catch { MessageBox.Show("Vui lòng chọn công việc cần sửa!", "", MessageBoxButtons.OKCancel); } displayLOWs(); this.rtJob.Text = ""; }
public static bool UpdateLOW(ListOfWork low) { try { DeleteLOW(low.no); AddLOW(low); return(true); } catch { return(false); } }
public static bool AddLOW(ListOfWork lows) { using (var _context = new LabMangementEntities()) { foreach (var pro in lows.Projects) { var prodb = (from u in _context.Projects where u.procode == pro.procode select u).Single(); prodb.ListOfWorks.Add(lows); } lows.Projects.Clear(); _context.ListOfWorks.AddOrUpdate(lows); _context.SaveChanges(); return(true); } }
private void btnAdd_Click(object sender, EventArgs e) { ListOfWork lows = new ListOfWork(); this.no = LOWController.getNofromDB(); lows.no = this.no; lows.job = this.rtJob.Text; lows.status = this.cbbStatus.Text; lows.Projects = new List <Project>(); string displaypros = ""; for (int i = 0; i < lstpro.Items.Count; i++) { displaypros = displaypros + this.lstpro.Items[i] + " "; lows.Projects.Add(this.lstpro.Items[i] as Project); } LOWController.AddLOW(lows); ListViewItem lOw = new ListViewItem(lows.no.ToString()); lOw.SubItems.Add(new ListViewItem.ListViewSubItem(lOw, displaypros)); lOw.SubItems.Add(new ListViewItem.ListViewSubItem(lOw, lows.job)); lOw.SubItems.Add(new ListViewItem.ListViewSubItem(lOw, lows.status)); this.listLOW.Items.Add(lOw); lows.job = ""; lows.status = ""; }