public void updateReceiptNote(RECEIPT_NOTE receipt_note) { /* * Category obj = UShopDB.Categories.Where(o => o.CategoryID == Convert.ToInt32(category.CategoryID)).SingleOrDefault(); * obj.CategoryName = category.CategoryName; * obj.CategoryDescription = category.CategoryDescription; * UShopDB.SubmitChanges(); * */ }
public void add(RECEIPT_NOTE obj, DataTable dtItems) { UShopDB.RECEIPT_NOTEs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); obj.RN_CODE = getCODE("RCN", obj.RN_ID); List <RECEIPT_NOTE_ITEM> lst = new List <RECEIPT_NOTE_ITEM>(); foreach (DataRow r in dtItems.Rows) { RECEIPT_NOTE_ITEM item = new RECEIPT_NOTE_ITEM(); item.RN_ID = obj.RN_ID; item.PRODUCT_ID = Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), r[0].ToString().Length - r[0].ToString().IndexOf('0'))); item.QUANTITY_STOCK_S = Int32.Parse(r[2].ToString()); item.QUANTITY_VOUCHER_S = Int32.Parse(r[3].ToString()); item.SIZE = r[4].ToString(); item.PRICE = Int32.Parse(r[5].ToString()); item.AMOUNT = Int32.Parse(r[6].ToString()); item.RECORD_STATUS = "A"; lst.Add(item); // foreach (RECEIPT_NOTE_ITEM i in lst) { if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(i.PRODUCT_ID) && o.SIZE.Equals(i.SIZE)).Count() > 0) { PRODUCT_SIZE p = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(i.PRODUCT_ID) && o.SIZE.Equals(i.SIZE)).First(); p.IN_STOCK_QUANTITY += item.QUANTITY_STOCK_S; } else { PRODUCT_SIZE p = new PRODUCT_SIZE(); p.PRODUCT_ID = i.PRODUCT_ID ?? 1; p.SIZE = i.SIZE; p.IN_STOCK_QUANTITY = item.QUANTITY_STOCK_S; UShopDB.PRODUCT_SIZEs.InsertOnSubmit(p); } } } UShopDB.RECEIPT_NOTE_ITEMs.InsertAllOnSubmit(lst); UShopDB.SubmitChanges(); foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID == obj.RN_ID)) { i.RN_ITEM_CODE = getCODE("RIT", i.RN_ITEM_ID); } UShopDB.SubmitChanges(); }
public void add(RECEIPT_NOTE obj, DataTable dtItems) { UShopDB.RECEIPT_NOTEs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); obj.RN_CODE = getCODE("RCN", obj.RN_ID); List <RECEIPT_NOTE_ITEM> lst = new List <RECEIPT_NOTE_ITEM>(); foreach (DataRow r in dtItems.Rows) { RECEIPT_NOTE_ITEM item = new RECEIPT_NOTE_ITEM(); item.RN_ID = obj.RN_ID; item.PRODUCT_ID = Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), 5)); item.QUANTITY_STOCK_S = Int32.Parse(r[2].ToString()); item.QUANTITY_VOUCHER_S = Int32.Parse(r[3].ToString()); item.QUANTITY_STOCK_M = Int32.Parse(r[4].ToString()); item.QUANTITY_VOUCHER_M = Int32.Parse(r[5].ToString()); item.QUANTITY_STOCK_L = Int32.Parse(r[6].ToString()); item.QUANTITY_VOUCHER_L = Int32.Parse(r[7].ToString()); item.QUANTITY_STOCK_XL = Int32.Parse(r[8].ToString()); item.QUANTITY_VOUCHER_XL = Int32.Parse(r[9].ToString()); item.QUANTITY_STOCK_XXL = Int32.Parse(r[10].ToString()); item.QUANTITY_VOUCHER_XXL = Int32.Parse(r[11].ToString()); item.TOTAL_STOCK = Int32.Parse(r[12].ToString()); item.TOTAL_VOUCHER = Int32.Parse(r[13].ToString()); item.PRICE = Int32.Parse(r[14].ToString()); item.AMOUNT = Int32.Parse(r[15].ToString()); item.RECORD_STATUS = "A"; lst.Add(item); foreach (PRODUCT p in UShopDB.PRODUCTs.Where(o => o.PRODUCT_ID == item.PRODUCT_ID)) { p.SIZE_S += item.QUANTITY_STOCK_S; p.SIZE_M += item.QUANTITY_STOCK_M; p.SIZE_L += item.QUANTITY_STOCK_L; p.SIZE_XL += item.QUANTITY_STOCK_XL; p.SIZE_XXL += item.QUANTITY_STOCK_XXL; } } UShopDB.RECEIPT_NOTE_ITEMs.InsertAllOnSubmit(lst); UShopDB.SubmitChanges(); foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID == obj.RN_ID)) { i.RN_ITEM_CODE = getCODE("RIT", i.RN_ITEM_ID); } UShopDB.SubmitChanges(); }
public void addReceiptNote(RECEIPT_NOTE obj) { try { UShopDB.RECEIPT_NOTEs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); } catch (Exception ex) { throw new Exception(); } }
public RECEIPT_NOTE getReceiptNoteByCODE(string code) { RECEIPT_NOTE r = new RECEIPT_NOTE(); foreach (RECEIPT_NOTE item in UShopDB.RECEIPT_NOTEs) { if (item.RN_CODE.Equals(code)) { r = item; break; } } return(r); }
public string update(RECEIPT_NOTE obj, DataTable dtItems) { _model.update(obj, dtItems); return(_model.update(obj, dtItems)); }
public void add(RECEIPT_NOTE obj, DataTable dtItems) { _model.add(obj, dtItems); }
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { String strError = ""; if (cboxSupplier.Text.Equals("")) { strError += "\nSuppiler is null"; } else { bool checkExist = false; foreach (DataRow d in preReceiptNote.loadSupplierDT(true).Rows) { if (cboxSupplier.Text.Equals(d[0].ToString() + " - " + d[1].ToString())) { checkExist = true; break; } } if (!checkExist) { strError += "\nDidn't see any supplier like " + cboxSupplier.Text; } } bool checkItem = true; if (gridItems.DataSource == null || ((DataTable)gridItems.DataSource).Rows.Count == 0) { checkItem = false; } else { foreach (DataRow r in ((DataTable)gridItems.DataSource).Rows) { if (Int32.Parse(r[13].ToString()) == 0) { checkItem = false; } } } if (!checkItem /*lbTotal.Text.Equals("")*/) { strError += "\nSome product hasn't amount, check again"; } else { if (float.Parse(tboxAccounted.Text).CompareTo(float.Parse(lbTotal.Text)) > 0) { strError += "\nAccounted is not rather than total"; } } if (dpickIssued.Value > dpickAccounting.Value) { strError += "\nIssued date is not rather than accounting date"; } if (!strError.Equals("")) { MessageBox.Show(strError); return; } // if (obj != null) { //chua get data obj obj.SUPPLIER_ID = Int32.Parse(cboxSupplier.Text.Substring(cboxSupplier.Text.IndexOf('0'), 5)); obj.ACCOUNTED = Int32.Parse(tboxAccounted.Text); obj.TOTAL = Int32.Parse(lbTotal.Text); obj.ISSUED_DATE = dpickIssued.Value; obj.ACCOUNTING_DATE = dpickAccounting.Value; obj.NOTE = tboxNote.Text; String strEr = preReceiptNote.update(obj, dtItems); if (strEr.Equals("")) { preReceiptNote.loadReceiptNotesDB(); Close(); } else { MessageBox.Show(strEr); } return; } // if (receipt_note == null) { receipt_note = new RECEIPT_NOTE(); } receipt_note.SUPPLIER_ID = Int32.Parse(cboxSupplier.Text.Substring(cboxSupplier.Text.IndexOf('0'), cboxSupplier.Text.IndexOf(' ') - cboxSupplier.Text.IndexOf('0'))); receipt_note.ACCOUNTED = Int32.Parse(tboxAccounted.Text); receipt_note.ISSUED_DATE = DateTime.Parse(dpickIssued.Text); receipt_note.ACCOUNTING_DATE = DateTime.Parse(dpickAccounting.Text); receipt_note.NOTE = tboxNote.Text; receipt_note.PREPARER_ID = 1; receipt_note.RECORD_STATUS = "A"; //receipt_note.RN_CODE = "aaaa"; receipt_note.TOTAL = float.Parse(lbTotal.Text); //receipt_note.RN_ID = 1; preReceiptNote.add(receipt_note, dtItems); preReceiptNote.loadReceiptNotesDB(); Close(); }
public string update(RECEIPT_NOTE obj, DataTable dtItems) { String strError = ""; List <RECEIPT_NOTE_ITEM> lstDeleted = new List <RECEIPT_NOTE_ITEM>(); List <RECEIPT_NOTE_ITEM> lstUpdated = new List <RECEIPT_NOTE_ITEM>(); List <RECEIPT_NOTE_ITEM> lstInserted = new List <RECEIPT_NOTE_ITEM>(); //update foreach (DataRow r in dtItems.Rows) { foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID.Equals(obj.RN_ID))) { if (Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), 5)).Equals(i.PRODUCT_ID) && i.RN_ID.Equals(obj.RN_ID) && i.RECORD_STATUS.Equals("A")) { lstUpdated.Add(i); break; } } } //insert foreach (DataRow r in dtItems.Rows) { bool isFounded = false; foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID.Equals(obj.RN_ID))) { if (Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), 5)).Equals(i.PRODUCT_ID) && i.RECORD_STATUS.Equals("A")) { isFounded = true; break; } } if (!isFounded) { RECEIPT_NOTE_ITEM re_i = new RECEIPT_NOTE_ITEM(); re_i.RN_ID = obj.RN_ID; re_i.PRODUCT_ID = getProductByCODE(r[0].ToString()).PRODUCT_ID; re_i.QUANTITY_STOCK_S = Int32.Parse(r[2].ToString()); re_i.QUANTITY_VOUCHER_S = Int32.Parse(r[3].ToString()); re_i.QUANTITY_STOCK_M = Int32.Parse(r[4].ToString()); re_i.QUANTITY_VOUCHER_M = Int32.Parse(r[5].ToString()); re_i.QUANTITY_STOCK_L = Int32.Parse(r[6].ToString()); re_i.QUANTITY_VOUCHER_L = Int32.Parse(r[7].ToString()); re_i.QUANTITY_STOCK_XL = Int32.Parse(r[8].ToString()); re_i.QUANTITY_VOUCHER_XL = Int32.Parse(r[9].ToString()); re_i.QUANTITY_STOCK_XXL = Int32.Parse(r[10].ToString()); re_i.QUANTITY_VOUCHER_XXL = Int32.Parse(r[11].ToString()); re_i.TOTAL_STOCK = Int32.Parse(r[12].ToString()); re_i.TOTAL_VOUCHER = Int32.Parse(r[13].ToString()); re_i.PRICE = Int32.Parse(r[14].ToString()); re_i.AMOUNT = Int32.Parse(r[15].ToString()); lstInserted.Add(re_i); } } //delete foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID.Equals(obj.RN_ID))) { bool isFounded = false; foreach (DataRow r in dtItems.Rows) { if (Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), 5)).Equals(i.PRODUCT_ID) && i.RN_ID.Equals(obj.RN_ID) && i.RECORD_STATUS.Equals("A")) { isFounded = true; break; } } if (!isFounded) { lstDeleted.Add(i); } } // Sau khi tim duoc lstInsert-Delete-Update, tien hanh kiem tra co loi hay khong //kiem tra delete foreach (RECEIPT_NOTE_ITEM r in lstDeleted) { foreach (PRODUCT p in UShopDB.PRODUCTs) { if (p.PRODUCT_ID.Equals(r.PRODUCT_ID) && (p.SIZE_S < r.QUANTITY_STOCK_S || p.SIZE_M < r.QUANTITY_STOCK_M || p.SIZE_L < r.QUANTITY_STOCK_L || p.SIZE_XL < r.QUANTITY_STOCK_XL || p.SIZE_XXL < r.QUANTITY_STOCK_XXL)) { strError += "\nSo luong " + p.PRODUCT_NAME + "khong du de delete."; break; } } } //kiem tra update foreach (RECEIPT_NOTE_ITEM i in lstUpdated) { //DataRow rForCheck = new DataRow(); foreach (DataRow r in dtItems.Rows) { if (i.PRODUCT_ID.Equals(Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), 5)))) { //rForCheck = r; //i.RN_ID = obj.RN_ID; //i.PRODUCT_ID = getProductByCODE(r[0].ToString()).PRODUCT_ID; int sTotal = Int32.Parse(r[2].ToString()); int mTotal = Int32.Parse(r[4].ToString()); int lTotal = Int32.Parse(r[6].ToString()); int xlTotal = Int32.Parse(r[8].ToString()); int xxlTotal = Int32.Parse(r[10].ToString()); foreach (PRODUCT p in UShopDB.PRODUCTs) { if (p.PRODUCT_ID.Equals(i.PRODUCT_ID) && (p.SIZE_S + (sTotal - i.QUANTITY_STOCK_S) < 0 || p.SIZE_M + (mTotal - i.QUANTITY_STOCK_M) < 0 || p.SIZE_L + (lTotal - i.QUANTITY_STOCK_L) < 0 || p.SIZE_XL + (xlTotal - i.QUANTITY_STOCK_XL) < 0 || p.SIZE_XXL + (xxlTotal - i.QUANTITY_STOCK_XXL) < 0)) { strError += "\nSo luong " + p.PRODUCT_NAME + "khong du de update."; break; } } break; } } } //insert khong can quan tam so luong luc truoc nen khong can kiem tra // if (!strError.Equals("")) { Console.WriteLine("loi roi hixx " + strError); return(strError); } // if (dtItems.Rows.Count == 0) //chuc nang xoa RECEIPT_NOTE { obj.RECORD_STATUS = "D"; } // //delete foreach (RECEIPT_NOTE_ITEM r in lstDeleted) { UShopDB.RECEIPT_NOTE_ITEMs.DeleteOnSubmit(r); //cap nhat PRODUCT table foreach (PRODUCT p in UShopDB.PRODUCTs) { if (p.PRODUCT_ID.Equals(r.PRODUCT_ID)) { p.SIZE_S -= r.QUANTITY_STOCK_S; p.SIZE_M -= r.QUANTITY_STOCK_M; p.SIZE_L -= r.QUANTITY_STOCK_L; p.SIZE_XL -= r.QUANTITY_STOCK_XL; p.SIZE_XXL -= r.QUANTITY_STOCK_XXL; break; } } } //update foreach (RECEIPT_NOTE_ITEM i in lstUpdated) { foreach (DataRow r in dtItems.Rows) { if (i.PRODUCT_ID.Equals(Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), 5)))) { int sTotal = Int32.Parse(r[2].ToString()); int mTotal = Int32.Parse(r[4].ToString()); int lTotal = Int32.Parse(r[6].ToString()); Console.WriteLine("lTotal aaa: " + lTotal); int xlTotal = Int32.Parse(r[8].ToString()); int xxlTotal = Int32.Parse(r[10].ToString()); foreach (PRODUCT p in UShopDB.PRODUCTs) { Console.WriteLine("chay ko du"); if (p.PRODUCT_ID.Equals(i.PRODUCT_ID)) { p.SIZE_S += (sTotal - i.QUANTITY_STOCK_S); p.SIZE_M += (mTotal - i.QUANTITY_STOCK_M); Console.WriteLine("QUANTITY_STOCK_L aaa: " + i.QUANTITY_STOCK_L); p.SIZE_L += (lTotal - i.QUANTITY_STOCK_L); Console.WriteLine("Tang " + (lTotal - i.QUANTITY_STOCK_L)); p.SIZE_XL += (xlTotal - i.QUANTITY_STOCK_XL); p.SIZE_XXL += (xxlTotal - i.QUANTITY_STOCK_XXL); break; } } i.RN_ID = obj.RN_ID; i.PRODUCT_ID = getProductByCODE(r[0].ToString()).PRODUCT_ID; i.QUANTITY_STOCK_S = Int32.Parse(r[2].ToString()); i.QUANTITY_VOUCHER_S = Int32.Parse(r[3].ToString()); i.QUANTITY_STOCK_M = Int32.Parse(r[4].ToString()); i.QUANTITY_VOUCHER_M = Int32.Parse(r[5].ToString()); i.QUANTITY_STOCK_L = Int32.Parse(r[6].ToString()); i.QUANTITY_VOUCHER_L = Int32.Parse(r[7].ToString()); i.QUANTITY_STOCK_XL = Int32.Parse(r[8].ToString()); i.QUANTITY_VOUCHER_XL = Int32.Parse(r[9].ToString()); i.QUANTITY_STOCK_XXL = Int32.Parse(r[10].ToString()); i.QUANTITY_VOUCHER_XXL = Int32.Parse(r[11].ToString()); i.TOTAL_STOCK = Int32.Parse(r[12].ToString()); i.TOTAL_VOUCHER = Int32.Parse(r[13].ToString()); i.PRICE = Int32.Parse(r[14].ToString()); i.AMOUNT = Int32.Parse(r[15].ToString()); break; } } } //insert foreach (RECEIPT_NOTE_ITEM r in lstInserted) { r.RECORD_STATUS = "A"; UShopDB.RECEIPT_NOTE_ITEMs.InsertOnSubmit(r); foreach (PRODUCT p in UShopDB.PRODUCTs) { if (p.PRODUCT_ID.Equals(r.PRODUCT_ID)) { p.SIZE_S += r.QUANTITY_STOCK_S; p.SIZE_M += r.QUANTITY_STOCK_M; p.SIZE_L += r.QUANTITY_STOCK_L; p.SIZE_XL += r.QUANTITY_STOCK_XL; p.SIZE_XXL += r.QUANTITY_STOCK_XXL; } break; } } UShopDB.SubmitChanges(); return(""); }
public string update(RECEIPT_NOTE obj, DataTable dtItems) { String strError = ""; List <RECEIPT_NOTE_ITEM> lstDeleted = new List <RECEIPT_NOTE_ITEM>(); List <RECEIPT_NOTE_ITEM> lstUpdated = new List <RECEIPT_NOTE_ITEM>(); List <RECEIPT_NOTE_ITEM> lstInserted = new List <RECEIPT_NOTE_ITEM>(); //list update foreach (DataRow r in dtItems.Rows) { int id = Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), r[0].ToString().Length - r[0].ToString().IndexOf('0'))); string size = r[4].ToString(); foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID.Equals(obj.RN_ID) && o.RECORD_STATUS.Equals("A"))) { if (id.Equals(i.PRODUCT_ID) && i.RN_ID.Equals(obj.RN_ID) && i.SIZE.Equals(size)) { lstUpdated.Add(i); break; } } } //list insert foreach (DataRow r in dtItems.Rows) { int id = Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), r[0].ToString().Length - r[0].ToString().IndexOf('0'))); string size = r[4].ToString(); bool isFounded = false; foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID.Equals(obj.RN_ID) && o.RECORD_STATUS.Equals("A"))) { if (id.Equals(i.PRODUCT_ID) && i.RN_ID.Equals(obj.RN_ID) && i.SIZE.Equals(size)) { isFounded = true; break; } } if (!isFounded) { RECEIPT_NOTE_ITEM re_i = new RECEIPT_NOTE_ITEM(); re_i.RN_ID = obj.RN_ID; re_i.PRODUCT_ID = getProductByCODE(r[0].ToString()).PRODUCT_ID; re_i.QUANTITY_STOCK_S = Int32.Parse(r[2].ToString()); re_i.QUANTITY_VOUCHER_S = Int32.Parse(r[3].ToString()); re_i.SIZE = r[4].ToString(); re_i.PRICE = Int32.Parse(r[5].ToString()); re_i.AMOUNT = Int32.Parse(r[6].ToString()); lstInserted.Add(re_i); } } //list delete foreach (RECEIPT_NOTE_ITEM i in UShopDB.RECEIPT_NOTE_ITEMs.Where(o => o.RN_ID.Equals(obj.RN_ID) && o.RECORD_STATUS.Equals("A"))) { bool isFounded = false; foreach (DataRow r in dtItems.Rows) { int id = Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), r[0].ToString().Length - r[0].ToString().IndexOf('0'))); string size = r[4].ToString(); if (id.Equals(i.PRODUCT_ID) && i.RN_ID.Equals(obj.RN_ID) && i.SIZE.Equals(size)) { isFounded = true; break; } } if (!isFounded) { lstDeleted.Add(i); } } // Sau khi tim duoc lstInsert-Delete-Update, tien hanh kiem tra co loi hay khong //kiem tra delete foreach (RECEIPT_NOTE_ITEM re in lstDeleted) { int count = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID == re.PRODUCT_ID && o.SIZE.Equals(re.SIZE)).Count(); if (count > 0) { PRODUCT_SIZE p = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID == re.PRODUCT_ID && o.SIZE.Equals(re.SIZE)).First(); if (p.IN_STOCK_QUANTITY - re.QUANTITY_STOCK_S < 0) { PRODUCT pro = null; pro = UShopDB.PRODUCTs.Where(o => o.PRODUCT_ID == p.PRODUCT_ID).SingleOrDefault(); strError += "\nSo luong " + pro.PRODUCT_NAME + "khong du de delete."; } break; } else { //ko co thi sao? } } //kiem tra update foreach (DataRow r in dtItems.Rows) { int id = Int32.Parse(r[0].ToString().Substring(r[0].ToString().IndexOf('0'), r[0].ToString().Length - r[0].ToString().IndexOf('0'))); string size = r[4].ToString(); string name = r[1].ToString(); foreach (RECEIPT_NOTE_ITEM re in lstUpdated) { if (re.PRODUCT_ID == id) { int sub = Int32.Parse(r[2].ToString()); RECEIPT_NOTE_ITEM i = new RECEIPT_NOTE_ITEM(); foreach (RECEIPT_NOTE_ITEM rr in lstUpdated) { if (rr.PRODUCT_ID == id) { i = rr; break; } } int count = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID == id && o.SIZE.Equals(size)).Count(); if (count > 0) { PRODUCT_SIZE p = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID == id && o.SIZE.Equals(size)).First(); if (p.IN_STOCK_QUANTITY + (sub - i.QUANTITY_STOCK_S) < 0) { strError += "\nSo luong " + name + "khong du de delete."; } break; } else { //ko co thi sao? } } } } //insert khong can quan tam so luong luc truoc nen khong can kiem tra // if (!strError.Equals("")) { return(strError); } // if (dtItems.Rows.Count == 0) //chuc nang xoa RECEIPT_NOTE { obj.RECORD_STATUS = "D"; } // //delete foreach (RECEIPT_NOTE_ITEM r in lstDeleted) { int count = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).Count(); if (count > 0) { /* * int sub = 0; * foreach (DataRow ro in dtItems.Rows) * { * int id = Int32.Parse(ro[0].ToString().Substring(ro[0].ToString().IndexOf('0'), ro[0].ToString().Length - ro[0].ToString().IndexOf('0'))); * string size = ro[4].ToString(); * string name = ro[1].ToString(); * * if (id.Equals(r.PRODUCT_ID) && size.Equals(r.SIZE) && r.RN_ID.Equals(obj.RN_ID) && r.RECORD_STATUS.Equals("A")) * { * sub = Int32.Parse(ro[2].ToString()); * } * } * Console.WriteLine("sub = "+sub); * */ if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).Count() > 0) { UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).First().IN_STOCK_QUANTITY -= r.QUANTITY_STOCK_S; } } r.RECORD_STATUS = "D"; } //update foreach (RECEIPT_NOTE_ITEM r in lstUpdated) { foreach (DataRow ro in dtItems.Rows) { int id = Int32.Parse(ro[0].ToString().Substring(ro[0].ToString().IndexOf('0'), ro[0].ToString().Length - ro[0].ToString().IndexOf('0'))); string size = ro[4].ToString(); string name = ro[1].ToString(); int sub = Int32.Parse(ro[2].ToString()); if (id == r.PRODUCT_ID) { int count = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).Count(); if (count > 0) { UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).First().IN_STOCK_QUANTITY += (sub - r.QUANTITY_STOCK_S); } r.QUANTITY_STOCK_S += (sub - r.QUANTITY_STOCK_S); break; } } } //insert foreach (RECEIPT_NOTE_ITEM r in lstInserted) { int count = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).Count(); if (count > 0) { UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(r.PRODUCT_ID) && o.SIZE.Equals(r.SIZE)).First().IN_STOCK_QUANTITY += r.QUANTITY_STOCK_S; } else { PRODUCT_SIZE pro = new PRODUCT_SIZE(); pro.PRODUCT_ID = r.PRODUCT_ID ?? 1; pro.SIZE = r.SIZE; pro.IN_STOCK_QUANTITY = r.QUANTITY_STOCK_S; UShopDB.PRODUCT_SIZEs.InsertOnSubmit(pro); } r.RECORD_STATUS = "A"; UShopDB.RECEIPT_NOTE_ITEMs.InsertOnSubmit(r); } /* * foreach (RECEIPT_NOTE_ITEM r in lstInserted) * { * * r.RECORD_STATUS = "A"; * UShopDB.RECEIPT_NOTE_ITEMs.InsertOnSubmit(r); * * foreach (PRODUCT p in UShopDB.PRODUCTs) * { * if (p.PRODUCT_ID.Equals(r.PRODUCT_ID)) * { * // * if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("S")).Count() > 0) * UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("S")).First().IN_STOCK_QUANTITY += r.QUANTITY_STOCK_S; * else * { * if (r.QUANTITY_STOCK_S>0) * UShopDB.PRODUCT_SIZEs.InsertOnSubmit(new PRODUCT_SIZE { PRODUCT_ID = p.PRODUCT_ID, SIZE = "S", IN_STOCK_QUANTITY = r.QUANTITY_STOCK_S }); * } * * if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("M")).Count() > 0) * UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("M")).First().IN_STOCK_QUANTITY += r.QUANTITY_STOCK_M; * else * { * if (r.QUANTITY_STOCK_M > 0) * UShopDB.PRODUCT_SIZEs.InsertOnSubmit(new PRODUCT_SIZE { PRODUCT_ID = p.PRODUCT_ID, SIZE = "M", IN_STOCK_QUANTITY = r.QUANTITY_STOCK_M }); * } * * if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("L")).Count() > 0) * UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("L")).First().IN_STOCK_QUANTITY += r.QUANTITY_STOCK_L; * else * { * if (r.QUANTITY_STOCK_L > 0) * UShopDB.PRODUCT_SIZEs.InsertOnSubmit(new PRODUCT_SIZE { PRODUCT_ID = p.PRODUCT_ID, SIZE = "L", IN_STOCK_QUANTITY = r.QUANTITY_STOCK_L }); * } * * if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("XL")).Count() > 0) * UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("XL")).First().IN_STOCK_QUANTITY += r.QUANTITY_STOCK_XL; * else * { * if (r.QUANTITY_STOCK_XL > 0) * UShopDB.PRODUCT_SIZEs.InsertOnSubmit(new PRODUCT_SIZE { PRODUCT_ID = p.PRODUCT_ID, SIZE = "XL", IN_STOCK_QUANTITY = r.QUANTITY_STOCK_XL }); * } * * if (UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("XXL")).Count() > 0) * UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID.Equals(p.PRODUCT_ID) && o.SIZE.Equals("XXL")).First().IN_STOCK_QUANTITY += r.QUANTITY_STOCK_XXL; * else * { * if (r.QUANTITY_STOCK_XXL > 0) * UShopDB.PRODUCT_SIZEs.InsertOnSubmit(new PRODUCT_SIZE { PRODUCT_ID = p.PRODUCT_ID, SIZE = "XXL", IN_STOCK_QUANTITY = r.QUANTITY_STOCK_XXL }); * } * // * * } * break; * } * } */ UShopDB.SubmitChanges(); return(""); }
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { String strError = ""; if (cboxSupplier.Text.Equals("")) { strError += "\nNhà cung cấp trống"; } else { bool checkExist = false; foreach (DataRow d in preReceiptNote.loadSupplierDT(true).Rows) { if (cboxSupplier.Text.Equals(d[0].ToString() + " - " + d[1].ToString())) { checkExist = true; break; } } if (!checkExist) { strError += "\nKhông tìm thấy " + cboxSupplier.Text; } } bool checkItem = true; if (gridItems.DataSource == null || ((DataTable)gridItems.DataSource).Rows.Count == 0) { checkItem = false; } else { foreach (DataRow r in ((DataTable)gridItems.DataSource).Rows) { if (Int32.Parse(r[3].ToString()) == 0) { checkItem = false; } } } if (!checkItem) { strError += "\nHàng hóa phải có số lượng"; } else { if (float.Parse(tboxAccounted.Text).CompareTo(float.Parse(lbTotal.Text)) > 0) { strError += "\nTiền thanh toán không được lớn hơn tổng tiền"; } } if (!strError.Equals("")) { MessageBox.Show(strError); return; } // if (obj != null) { //chua get data obj obj.SUPPLIER_ID = Int32.Parse(cboxSupplier.Text.Substring(cboxSupplier.Text.IndexOf('0'), cboxSupplier.Text.IndexOf(' ') - cboxSupplier.Text.IndexOf('0') + 1)); obj.ACCOUNTED = Int32.Parse(tboxAccounted.Text); obj.TOTAL = Int32.Parse(lbTotal.Text); obj.ISSUED_DATE = dpickIssued.Value; obj.ACCOUNTING_DATE = dpickAccounting.Value; obj.NOTE = tboxNote.Text; obj.STATUS = "Chưa thanh toán"; if (lbTotal.Text.Equals(tboxAccounted.Text)) { obj.STATUS = "Đã thanh toán"; } String strEr = preReceiptNote.update(obj, dtItems); if (strEr.Equals("")) { preReceiptNote.loadReceiptNotesDB(); Close(); beforeForm.WindowState = FormWindowState.Maximized; beforeForm.Activate(); } else { MessageBox.Show(strEr); } return; } // if (receipt_note == null) { receipt_note = new RECEIPT_NOTE(); } receipt_note.SUPPLIER_ID = Int32.Parse(cboxSupplier.Text.Substring(cboxSupplier.Text.IndexOf('0'), cboxSupplier.Text.IndexOf(' ') - cboxSupplier.Text.IndexOf('0'))); receipt_note.ACCOUNTED = Int32.Parse(tboxAccounted.Text); receipt_note.ISSUED_DATE = dpickIssued.Value; receipt_note.ACCOUNTING_DATE = dpickAccounting.Value; receipt_note.NOTE = tboxNote.Text; receipt_note.STATUS = "Chưa thanh toán"; if (lbTotal.Text.Equals(tboxAccounted.Text)) { receipt_note.STATUS = "Đã thanh toán"; } if (AccountPresenter.currentEmployee == null) { receipt_note.PREPARER_ID = 1; } else { receipt_note.PREPARER_ID = AccountPresenter.currentEmployee.EMP_ID; } receipt_note.RECORD_STATUS = "A"; receipt_note.TOTAL = float.Parse(lbTotal.Text); preReceiptNote.add(receipt_note, dtItems); preReceiptNote.loadReceiptNotesDB(); beforeForm.WindowState = FormWindowState.Maximized; beforeForm.Activate(); //Close(); }