public void updateUShop(SUPPLIER obj) { getUShop(); SUPPLIER ushop = UShopDB.SUPPLIERs.Where(o => o.RECORD_STATUS.Equals("U")).First(); ushop.TAX_CODE = obj.TAX_CODE; ushop.ADDRESS = obj.ADDRESS; ushop.SUPPLIER_NAME = obj.SUPPLIER_NAME; ushop.PHONE = obj.PHONE; UShopDB.SubmitChanges(); }
public void updateSupplier(SUPPLIER supplier) { SUPPLIER obj = UShopDB.SUPPLIERs.Where(o => o.SUPPLIER_ID == Convert.ToInt32(supplier.SUPPLIER_ID)).SingleOrDefault(); obj.SUPPLIER_NAME = supplier.SUPPLIER_NAME; obj.TAX_CODE = supplier.TAX_CODE; obj.PHONE = supplier.PHONE; obj.ADDRESS = supplier.ADDRESS; 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 addAccount(ACCOUNT obj) { try { UShopDB.ACCOUNTs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); } catch (Exception ex) { throw new Exception(); } }
public void addReceiptNote(RECEIPT_NOTE obj) { try { UShopDB.RECEIPT_NOTEs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); } catch (Exception ex) { throw new Exception(); } }
public void deleteProduct(string id) { PRODUCT obj = UShopDB.PRODUCTs.Where(o => o.PRODUCT_ID == Convert.ToInt32(id)).SingleOrDefault(); obj.RECORD_STATUS = "D"; foreach (PRODUCT_SIZE z in UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID == Convert.ToInt32(id))) { UShopDB.PRODUCT_SIZEs.DeleteOnSubmit(z); } UShopDB.SubmitChanges(); }
public void addProduct(PRODUCT obj) { try { UShopDB.PRODUCTs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); obj.PRODUCT_CODE = getCODE("PRO", obj.PRODUCT_ID); UShopDB.SubmitChanges(); } catch (Exception ex) { throw new Exception(); } }
public void addSupplier(SUPPLIER obj) { try { UShopDB.SUPPLIERs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); obj.SUPPLIER_CODE = getCODE("SUP", obj.SUPPLIER_ID); UShopDB.SubmitChanges(); } catch (Exception ex) { throw new Exception(); } }
public void addCategory(CATEGORY obj) { try { UShopDB.CATEGORies.InsertOnSubmit(obj); UShopDB.SubmitChanges(); obj.CATEGORY_CODE = getCODE("CAT", obj.CATEGORY_ID); UShopDB.SubmitChanges(); } catch (Exception ex) { throw new Exception(); } }
public void updateProduct(PRODUCT product) { PRODUCT obj = UShopDB.PRODUCTs.Where(o => o.PRODUCT_ID == Convert.ToInt32(product.PRODUCT_ID)).SingleOrDefault(); obj.CATEGORY_ID = product.CATEGORY_ID; obj.PRODUCT_NAME = product.PRODUCT_NAME; obj.UNIT = product.UNIT; obj.SELLING_PRICE = product.SELLING_PRICE; obj.COST_PRICE = product.COST_PRICE; obj.SALE_AMOUNT = product.SALE_AMOUNT; obj.DESCRIPTION = product.DESCRIPTION; obj.PRODUCER = product.PRODUCER; obj.ORIGIN = product.ORIGIN; UShopDB.SubmitChanges(); }
public bool deleteEmployee(string code) { bool ret = false; try { var result = UShopDB.EMPLOYEEs.Where(o => o.EMP_CODE.Equals(code)); EMPLOYEE emp = result.SingleOrDefault(); emp.RECORD_STATUS = ((char)RECORD_STATUS.INACTIVE) + ""; UShopDB.SubmitChanges(); ret = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(ret); }
public bool addEmployee(EMPLOYEE emp) { try { UShopDB.EMPLOYEEs.InsertOnSubmit(emp); UShopDB.SubmitChanges(); emp.EMP_CODE = getCODE("EMP", emp.EMP_ID); UShopDB.SubmitChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
bool IAccount.deleteAccount(string code) { bool ret = false; try { var result = UShopDB.ACCOUNTs.Where(o => o.ACC_CODE.Equals(code)); ACCOUNT acc = result.SingleOrDefault(); acc.RECORD_STATUS = ((char)RECORD_STATUS.INACTIVE) + ""; UShopDB.SubmitChanges(); ret = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(ret); }
public bool addCustomer(CUSTOMER cus) { try { UShopDB.CUSTOMERs.InsertOnSubmit(cus); UShopDB.SubmitChanges(); cus.CUS_CODE = getCODE("CUS", cus.CUS_ID); UShopDB.SubmitChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public bool deleteCustomer(string code) { bool ret = false; try { var result = UShopDB.CUSTOMERs.Where(o => o.CUS_CODE.Equals(code)); CUSTOMER cus = result.SingleOrDefault(); cus.RECORD_STATUS = ((char)RECORD_STATUS.INACTIVE) + ""; UShopDB.SubmitChanges(); ret = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(ret); }
public bool addAppointment(APPOINTMENT app) { try { UShopDB.APPOINTMENTs.InsertOnSubmit(app); UShopDB.SubmitChanges(); app.APP_CODE = getCODE("APP", app.APP_ID); UShopDB.SubmitChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public bool deleteAppointment(string code) { bool ret = false; try { var result = UShopDB.APPOINTMENTs.Where(o => o.APP_CODE.Equals(code)); APPOINTMENT app = result.SingleOrDefault(); app.RECORD_STATUS = ((char)RECORD_STATUS.INACTIVE) + ""; UShopDB.SubmitChanges(); ret = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(ret); }
private bool updateProductSize(int productId, string size, int deltaQuantity) { PRODUCT_SIZE prosize = UShopDB.PRODUCT_SIZEs.Where(o => o.PRODUCT_ID == productId && o.SIZE.Equals(size)).SingleOrDefault(); if (prosize != null) { if (prosize.IN_STOCK_QUANTITY == 0) { throw new Exception("instock quantity is zero but still has an invoice item "); } prosize.IN_STOCK_QUANTITY = prosize.IN_STOCK_QUANTITY + deltaQuantity; UShopDB.SubmitChanges(); return(true); } return(false); }
public bool addAccount(ACCOUNT obj) { try { UShopDB.ACCOUNTs.InsertOnSubmit(obj); UShopDB.SubmitChanges(); return(true); } catch (Exception ex) { //wtf ??? //throw new Exception(); Console.WriteLine(ex.Message); } return(false); }
public SUPPLIER getUShop() { int count = UShopDB.SUPPLIERs.Where(o => o.RECORD_STATUS.Equals("U")).Count(); if (count == 0) { SUPPLIER ushop = new SUPPLIER(); ushop.TAX_CODE = "0000"; ushop.ADDRESS = "Quận 3, TP HCM"; ushop.SUPPLIER_NAME = "UShop"; ushop.RECORD_STATUS = "U"; ushop.PHONE = "0975862516"; UShopDB.SUPPLIERs.InsertOnSubmit(ushop); UShopDB.SubmitChanges(); ushop.SUPPLIER_CODE = getCODE("SUP", ushop.SUPPLIER_ID); UShopDB.SubmitChanges(); } return(UShopDB.SUPPLIERs.Where(o => o.RECORD_STATUS.Equals("U")).First()); }
public bool deleteInvoice(string code) { try { var item = UShopDB.INVOICEs.Where(o => o.INVOICE_CODE == code).SingleOrDefault(); item.RECORD_STATUS = ((char)RECORD_STATUS.INACTIVE) + ""; UShopDB.SubmitChanges(); return(true); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } return(false); }
bool IAccount.updateAccount(ACCOUNT updateAcc) { bool ret = false; try { var result = UShopDB.ACCOUNTs.Where(o => o.ACC_ID == updateAcc.ACC_ID); ACCOUNT acc = result.SingleOrDefault(); acc.ACC_CODE = updateAcc.ACC_CODE; acc.PASSWORD = updateAcc.PASSWORD; acc.RECORD_STATUS = updateAcc.RECORD_STATUS; UShopDB.SubmitChanges(); ret = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(ret); }
public bool deleteInvoice(int id) { int queryid = id; if (queryid > 0) { try { var item = UShopDB.INVOICEs.Where(o => o.INVOICE_ID == queryid).SingleOrDefault(); item.RECORD_STATUS = ((char)RECORD_STATUS.INACTIVE) + ""; UShopDB.SubmitChanges(); return(true); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } } return(false); }
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(""); }
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 bool updateInvoice(INVOICE updated, List <INVOICE_ITEM> itemList) { int queryid = updated.INVOICE_ID; if (queryid > 0) { try { var invoice = UShopDB.INVOICEs.Where(o => o.INVOICE_ID == queryid).SingleOrDefault(); //invoice.INVOICE_CODE = updated.INVOICE_CODE; invoice.BUYER_ID = updated.BUYER_ID; invoice.DATE = updated.DATE; invoice.NOTE = updated.NOTE; invoice.PAYMENT_METHOD = updated.PAYMENT_METHOD; invoice.TOTAL_AMOUNT = updated.TOTAL_AMOUNT; invoice.TOTAL_PAYMENT = updated.TOTAL_PAYMENT; invoice.VAT_AMOUNT = updated.VAT_AMOUNT; invoice.VAT_RATE = updated.VAT_RATE; invoice.SELLER_ID = updated.SELLER_ID; UShopDB.SubmitChanges(); invoice.INVOICE_CODE = getCODE("INV", invoice.INVOICE_ID); UShopDB.SubmitChanges(); if (itemList != null && itemList.Count > 0) { double totalDiscount = 0; //double totalAmount = 0; //double totalPayment = 0; List <INVOICE_ITEM> invoiceItemList = UShopDB.INVOICE_ITEMs.Where(o => o.INVOICE_ID == queryid).DefaultIfEmpty().ToList(); if (invoiceItemList != null && invoiceItemList.Count > 0) { foreach (var item in invoiceItemList) { //tra lai so luong cho product size //updateProductSize((int)item.PRODUCT_ID, item.SIZE,(int)item.QUANTITY - 0); // xoa di item nay UShopDB.INVOICE_ITEMs.DeleteOnSubmit(item); ////update invoice item data //bool isExisted = false; //foreach (var updateItem in itemList) //{ // if (item.INVOICE_ITEM_ID == updateItem.INVOICE_ITEM_ID) // { // isExisted = true; // item.NOTE = updateItem.NOTE; // item.PRICE = updateItem.PRICE; // item.RECORD_STATUS = updateItem.RECORD_STATUS; // if( !item.SIZE.Equals(updateItem.SIZE) // || !item.PRODUCT_ID.Equals(updateItem.PRODUCT_ID) // || !item.QUANTITY.Equals(updateItem.QUANTITY)) // { // //UPDATE product size // updateProductSize((int)updateItem.PRODUCT_ID, updateItem.SIZE, (int)( item.QUANTITY - updateItem.QUANTITY )); // } // item.SIZE = updateItem.SIZE; // item.PRODUCT_ID = updateItem.PRODUCT_ID; // item.QUANTITY = updateItem.QUANTITY; // UShopDB.SubmitChanges(); // break; // } //} //UShopDB.INVOICE_ITEMs.DeleteOnSubmit(item); } UShopDB.SubmitChanges(); } //add lai UShopDB.INVOICE_ITEMs.InsertAllOnSubmit(itemList); UShopDB.SubmitChanges(); foreach (var update in itemList) { totalDiscount += (double)update.DISCOUNT; // totalAmount += (double)update.AMOUNT; update.INVOICE_ITEM_CODE = getCODE("INVI", update.INVOICE_ITEM_ID); update.INVOICE_ID = invoice.INVOICE_ID; //tru lai trong bang product size //updateProductSize((int)update.PRODUCT_ID, update.SIZE, (int)(0 - update.QUANTITY)); } UShopDB.SubmitChanges(); invoice.TOTAL_SALE = totalDiscount; } UShopDB.SubmitChanges(); return(true); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } } return(false); }