private void GrvSanPham_DoubleClick(object sender, EventArgs e) { GridView view = (GridView)sender; eSanPham sp = (eSanPham)view.GetFocusedRow(); if (sp != null) { int index = lstDetail.FindIndex(x => x.IDSanPham == sp.KeyID); if (index != -1) { grvChiTiet.FocusedRowHandle = index; } else { eNhapHangNhaCungCapChiTiet iDT = new eNhapHangNhaCungCapChiTiet(); iDT.IDSanPham = sp.KeyID; iDT.MaSanPham = sp.Ma; iDT.TenSanPham = sp.Ten; iDT.IDDonViTinh = sp.IDDonViTinh; iDT.MaDonViTinh = sp.MaDonViTinh; iDT.TenDonViTinh = sp.TenDonViTinh; iDT.SoLuongLe = 1; iDT.SoLuong = 1; lstDetail.Add(iDT); } } }
private void GrvChiTiet_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { GridView view = (GridView)sender; eNhapHangNhaCungCapChiTiet item = (eNhapHangNhaCungCapChiTiet)view.GetFocusedRow(); if (item == null) { return; } view.CellValueChanged -= GrvChiTiet_CellValueChanged; if (e.Column.FieldName.Equals("SoLuongSi") || e.Column.FieldName.Equals("SoLuongLe")) { item.SoLuong = item.SoLuongSi + item.SoLuongLe; item.ThanhTien = item.SoLuong * item.DonGia; item.TongTien = item.ThanhTien * ((100 - item.ChietKhau) / 100); CapNhatSoTien(); } if (e.Column.FieldName.Equals("DonGia")) { item.ThanhTien = item.SoLuong * item.DonGia; item.TongTien = item.ThanhTien * ((100 - item.ChietKhau) / 100); CapNhatSoTien(); } if (e.Column.FieldName.Equals("ChietKhau")) { item.TongTien = item.ThanhTien * ((100 - item.ChietKhau) / 100); CapNhatSoTien(); } view.CellValueChanged += GrvChiTiet_CellValueChanged; }
private void GrvChiTiet_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { GridView view = (GridView)sender; eNhapHangNhaCungCapChiTiet item = (eNhapHangNhaCungCapChiTiet)e.Row; if (!lstDetail_Edited.Any(x => x.KeyID == item.KeyID)) { lstDetail_Edited.Add(item); } }
private void RbtnXoa_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { eNhapHangNhaCungCapChiTiet item = (eNhapHangNhaCungCapChiTiet)grvChiTiet.GetFocusedRow(); if (item != null) { lstDetail.Remove(item); CapNhatSoTien(); } }
public async override Task <ActionResult> UpdateEntries(eNhapHangNhaCungCap[] Items) { aModel db = new aModel(); try { db.BeginTransaction(); db.eNhapHangNhaCungCap.AddOrUpdate(Items); Items.ToList().ForEach(async x => { IEnumerable <eNhapHangNhaCungCapChiTiet> lstDetail = await db.eNhapHangNhaCungCapChiTiet.Where(y => y.IDNhapHangNhaCungCap == x.KeyID).ToListAsync(); lstDetail.ToList().ForEach(y => { eNhapHangNhaCungCapChiTiet obj = x.eNhapHangNhaCungCapChiTiet.FirstOrDefault(z => z.KeyID == y.KeyID); if (obj == null) { db.eNhapHangNhaCungCapChiTiet.Remove(y); } else { db.Entry(y).CurrentValues.SetValues(obj); } }); x.eNhapHangNhaCungCapChiTiet.ToList().ForEach(y => { if (y.KeyID <= 0) { y.IDNhapHangNhaCungCap = x.KeyID; db.eNhapHangNhaCungCapChiTiet.Add(y); } }); }); await CapNhatCongNo(db, Items); await CapNhatTonKho(db, Items); await db.SaveChangesAsync(); db.CommitTransaction(); return(Ok(Items)); } catch (Exception ex) { db.RollbackTransaction(); return(BadRequest(ex)); } }
public async override Task <IActionResult> UpdateEntries([FromBody] eNhapHangNhaCungCap[] Items) { try { Instance.Context = new Model.aModel(); await Instance.BeginTransaction(); Instance.Context.eNhapHangNhaCungCap.UpdateRange(Items); Items.ToList().ForEach(x => { IEnumerable <eNhapHangNhaCungCapChiTiet> lstDetail = Instance.Context.eNhapHangNhaCungCapChiTiet.Where(y => y.IDNhapHangNhaCungCap == x.KeyID).ToList(); lstDetail.ToList().ForEach(y => { eNhapHangNhaCungCapChiTiet obj = x.eNhapHangNhaCungCapChiTiet.FirstOrDefault(z => z.KeyID == y.KeyID); if (obj == null) { Instance.Context.eNhapHangNhaCungCapChiTiet.Remove(y); } else { Instance.Context.Entry(y).CurrentValues.SetValues(obj); } }); x.eNhapHangNhaCungCapChiTiet.ToList().ForEach(y => { if (y.KeyID <= 0) { y.KeyID = 0; y.IDNhapHangNhaCungCap = x.KeyID; Instance.Context.eNhapHangNhaCungCapChiTiet.Add(y); } }); }); CapNhatCongNo(Items); await Instance.SaveChanges(); Instance.CommitTransaction(); return(Ok(Items)); } catch { Instance.RollbackTransaction(); return(BadRequest()); } }
private void RbtnXoa_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { eNhapHangNhaCungCapChiTiet item = (eNhapHangNhaCungCapChiTiet)grvChiTiet.GetFocusedRow(); if (item != null) { lstDetail.Remove(item); if (lstDetail_Edited.Any(x => x.KeyID == item.KeyID)) { lstDetail_Edited.Remove(item); } if (lstDetail_Deleted.Any(x => x.KeyID == item.KeyID)) { lstDetail_Deleted.Remove(item); } } }