//public bool deleteBill(string id) //{ // db = new CMART1Entities1(); // try // { // Bill bill = db.Bills.Single(st => st.IDBill.Equals(id)); // Bill_List bill_list; // db.Bills.Remove(bill); // db.SaveChanges(); // return true; // } // catch (Exception) // { // return false; // } //} public float countMoney(int id, int number) { db = new CMART1Entities1(); List <PriceHistory> price1 = db.PriceHistories.Where(st => st.IDProduct == id).ToList(); foreach (PriceHistory addPrice in price1) { priceProduct = (float)addPrice.Price * number; } try { Promotion addPromo = new Promotion(); List <Promotion> proList = db.Promotions.Where(st => st.IDProduct == id).ToList(); foreach (Promotion promo in proList) { addPromo = promo; } if (DateTime.Now <= addPromo.EndDate && DateTime.Now >= addPromo.StartDate) { priceProduct = (float)addPromo.Price * number; return(priceProduct); } else { return(priceProduct); } } catch (Exception) { return(0); } }
public bool editBill(string id, DateTime date, string totalAmount, string Recieved, string returned, int totalQuantity, string POS, string IDAcc, int[] idpro, string[] quantity, string[] unitprice) { db = new CMART1Entities1(); Bill bill = db.Bills.Single(st => st.IDBill.Equals(id)); List <Bill_List> bill_list = bill.Bill_List.ToList(); foreach (Bill_List bi in bill_list) { db.Bill_List.Remove(bi); db.SaveChanges(); } try { bill.BillDate = date; bill.TotalAmount = totalAmount; bill.TotalQuantity = totalQuantity; bill.Recieved = Recieved; bill.Returned = returned; bill.POS = POS; bill.IDAcc = IDAcc; db.SaveChanges(); addBillList(id, idpro, quantity, unitprice); return(true); } catch (Exception) { return(false); } }
public bool addPromotion(string a, int idProduct, float price, string image, DateTime start, DateTime end, string content) { db = new CMART1Entities1(); Promotion promotion = new Promotion(); promotion = new Promotion(); Promotion promotion1 = db.Promotions.Single(st => st.IDPromotion.Equals(a)); string idold = promotion1.IDPromotion; int changeID = int.Parse(idold.Substring(1, 6)) + 1; string idnew = "P"; for (int i = changeID.ToString().Length; i < 6; i++) { idnew = idnew + "0"; } idnew = idnew + changeID.ToString(); try { promotion.IDPromotion = idnew; promotion.IDProduct = idProduct; promotion.Price = price; promotion.Image = image; promotion.Contents = content; promotion.StartDate = start; promotion.EndDate = end; db.Promotions.Add(promotion); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool addProduct(int id, string Name, string image, string IDSupplier, string IDType) { db = new CMART1Entities1(); Product pro = db.Products.Single(st => st.IDProduct.Equals(id)); int a = pro.IDProduct; Product product = new Product(); ProductType type = db.ProductTypes.Single(st => st.IDType.Equals(IDType)); try { product.IDProduct = a + 1; product.Name = Name; product.Image = image; product.IDSupplier = IDSupplier; product.IDType = IDType; type.Quantity = type.Quantity + 1; db.Products.Add(product); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool editProduct(int id, string Name, string image, string IDSupplier, string IDType) { db = new CMART1Entities1(); try { Product product = db.Products.Single(st => st.IDProduct.Equals(id)); if (IDType != product.IDType) { ProductType type1 = db.ProductTypes.Single(st => st.IDType.Equals(IDType)); ProductType type2 = db.ProductTypes.Single(st => st.IDType.Equals(product.IDType)); product.Image = image; product.Name = Name; product.IDSupplier = IDSupplier; product.IDType = IDType; type2.Quantity = type2.Quantity - 1; type1.Quantity = type1.Quantity + 1; db.SaveChanges(); } else { product.Name = Name; product.Image = image; product.IDSupplier = IDSupplier; db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public bool editHeadImport(string idHI, DateTime date, float Total, string IDAcc, int[] idpro, int[] quantity, double[] price, DateTime[] dateti, string[] status) { db = new CMART1Entities1(); HeadImport head = db.HeadImports.Single(st => st.IDHeadImport.Equals(idHI)); List <HeadImport_List> headlist = head.HeadImport_List.ToList(); try { head.IDAcc = IDAcc; head.TotalAmount = Total; db.SaveChanges(); foreach (HeadImport_List he in headlist) { db.HeadImport_List.Remove(he); db.SaveChanges(); } for (int i = 0; i < idpro.Length; i++) { HeadImport_List headli = new HeadImport_List(); headli.IDHeadImport = idHI; headli.IDProduct = idpro[i]; headli.Quantity = quantity[i]; headli.Status = status[i]; headli.Price = price[i]; headli.Expiration = dateti[i]; db.HeadImport_List.Add(headli); db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public bool checkexistIDreandIDPro(string idRe, string idPro) { db = new CMART1Entities1(); bool flag = false; try { int idPr = int.Parse(idPro); requestImport re = db.requestImports.Single(st => st.IDRequestImport.Equals(idRe)); List <requestImport_List> relist = re.requestImport_List.ToList(); foreach (requestImport_List pro in relist) { if (idPr == pro.IDProduct) { flag = true; break; } } return(flag); } catch (Exception) { return(false); } }
public bool editBranchImport(string idBranch, DateTime date, int branch, string IDAcc, int[] idpro, int[] quantity, string[] status) { db = new CMART1Entities1(); BranchImport branchImport = db.BranchImports.Single(st => st.IDBranchImport.Equals(idBranch)); List <BranchImport_List> branchList = branchImport.BranchImport_List.ToList(); try { branchImport.BranchDate = date; branchImport.Branch = branch; branchImport.IDAcc = IDAcc; db.SaveChanges(); foreach (BranchImport_List br in branchList) { db.BranchImport_List.Remove(br); db.SaveChanges(); } addBranchList(idBranch, idpro, quantity, status); return(true); } catch (Exception) { return(false); } }
private void btnEdit_Click(object sender, EventArgs e) { if (lstBill.SelectedRows.Count == 1) { //btnEdit.Enabled = false; i = 1; btnEdit.Enabled = false; btnCancel.Text = "Cancel"; tabAdd.Text = "Edit"; string id = (string)lstBill.SelectedRows[0].Cells[0].Value; CMART1Entities1 db = new CMART1Entities1(); Bill bill = db.Bills.Single(s => s.IDBill.Equals(id)); dateTime.Value = bill.BillDate; lblTotalQuantity.Text = bill.TotalQuantity.ToString(); txtReceived.Text = bill.Recieved.ToString(); lblTotalAmount.Text = bill.TotalAmount.ToString(); lblReturned.Text = bill.Returned; Total = float.Parse(bill.TotalAmount); List <Bill_List> bill_list = bill.Bill_List.ToList(); foreach (Bill_List bi in bill_list) { Product pro = db.Products.Single(st => st.IDProduct.Equals(bi.IDProduct)); lstPro.Rows.Add(bi.IDProduct, pro.Name, bi.Quantity, float.Parse(bi.unitPrice) * int.Parse(bi.Quantity)); } tabList.SelectedIndex = 1; } }
private void C04_Print_Load(object sender, EventArgs e) { CMART1Entities1 db = new CMART1Entities1(); cmb.DataSource = db.HeadImports.ToList(); cmb.ValueMember = "IDHeadImport"; cmb.ValueMember = "IDHeadImport"; }
private void btnPrint_Click(object sender, EventArgs e) { CMART1Entities1 db = new CMART1Entities1(); XtraReport4 rpt = new XtraReport4(); ReportPrintTool tool = new ReportPrintTool(rpt); rpt.ShowPreviewDialog(); }
private void C03_Print_Load(object sender, EventArgs e) { //throw new NotImplementedException(); CMART1Entities1 db = new CMART1Entities1(); cmb.DataSource = db.Bills.ToList(); cmb.ValueMember = "IDBill"; cmb.ValueMember = "IDBill"; }
public void loadIDPro() { CMART1Entities1 db = new CMART1Entities1(); List <requestImport_List> re = db.requestImport_List.Where(st => st.IDRequestImport.Equals(txtIDRequest.Text)).ToList(); foreach (requestImport_List idpro in re) { txtIDProduct.Items.Add(idpro.IDProduct); } }
public void loadIDHI() { CMART1Entities1 db = new CMART1Entities1(); List <HeadImport> re = db.HeadImports.ToList(); foreach (HeadImport ri in re) { txtIDHead.Items.Add(ri.IDHeadImport); } txtIDHead.DropDownStyle = ComboBoxStyle.DropDownList; }
public bool addProduct(string Name, string image, string IDSupplier, string IDType) { db = new CMART1Entities1(); Product pro = null; List <Product> lst = db.Products.ToList(); foreach (Product pri in lst) { pro = pri; } if (pro != null) { int a = pro.IDProduct; Product product = new Product(); ProductType type = db.ProductTypes.Single(st => st.IDType.Equals(IDType)); try { product.IDProduct = a + 1; product.Name = Name; product.Image = image; product.IDSupplier = IDSupplier; product.IDType = IDType; type.Quantity = type.Quantity + 1; db.Products.Add(product); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } else { Product product = new Product(); ProductType type = db.ProductTypes.Single(st => st.IDType.Equals(IDType)); try { product.IDProduct = 1; product.Name = Name; product.Image = image; product.IDSupplier = IDSupplier; product.IDType = IDType; type.Quantity = type.Quantity + 1; db.Products.Add(product); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool checkExistedProduct(string stm) { db = new CMART1Entities1(); Product product = db.Products.FirstOrDefault(st => st.Name.Equals(stm)); if (product == null) { return(true); } return(false); }
public bool addBill(string id, DateTime date, string totalAmount, string Recieved, string returned, int totalQuantity, string POS, string IDAcc, int[] idpro, string[] quantity, string[] unitprice) { db = new CMART1Entities1(); int t = int.Parse(id.Substring(6, 6)) + 1; string Month = date.Month.ToString(); string Date = date.Day.ToString(); if (Month.Length < 2) { Month = "0" + Month; } if (Date.Length < 2) { Date = "0" + Date; } string idnew = date.Year.ToString() + Month + Date; idnew = idnew.Substring(2, 6); if (idnew == id.Substring(0, 6)) { for (int i = t.ToString().Length; i < 6; i++) { idnew = idnew + "0"; } idnew = idnew + t; } else { idnew = idnew + "000001"; } Bill bill = new Bill(); try { bill.IDBill = idnew; bill.BillDate = date; bill.TotalAmount = totalAmount; bill.TotalQuantity = totalQuantity; bill.Recieved = Recieved; bill.Returned = returned; bill.POS = POS; bill.IDAcc = IDAcc; db.Bills.Add(bill); db.SaveChanges(); addBillList(idnew, idpro, quantity, unitprice); return(true); } catch (Exception) { return(false); } }
public Account FindAcc() { db = new CMART1Entities1(); try { acc = db.Accounts.Single(x => x.Username == userName); return(acc); } catch (Exception) { return(null); } }
public void loadIDRe() { CMART1Entities1 db = new CMART1Entities1(); List <requestImport> re = db.requestImports.ToList(); requestImport h = null; foreach (requestImport ri in re) { txtIDRequest.Items.Add(ri.IDRequestImport); h = ri; } txtIDRequest.DropDownStyle = ComboBoxStyle.DropDownList; txtIDRequest.DisplayMember = h.IDRequestImport; }
public bool addProductList(int idPro) { db = new CMART1Entities1(); try { Product pro = db.Products.Single(st => st.IDProduct.Equals(idPro)); nameProduct = pro.Name; return(true); } catch (Exception) { return(false); } }
public bool deletePriceHT(int id, DateTime date) { db = new CMART1Entities1(); try { PriceHistory priceht = db.PriceHistories.Single(st => st.IDProduct.Equals(id) && st.Date.Equals(date)); db.PriceHistories.Remove(priceht); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public List <PriceHistory> searchListHistory(string mp) { db = new CMART1Entities1(); int i; try { i = int.Parse(mp); return(db.PriceHistories.Where(st => st.IDProduct.Equals(i)).ToList()); } catch (Exception) { return(null); } }
public bool deleteProduct(int id) { try { db = new CMART1Entities1(); Product product = db.Products.Single(st => st.IDProduct.Equals(id)); ProductType type = db.ProductTypes.Single(st => st.IDType.Equals(product.IDType)); db.Products.Remove(product); type.Quantity = type.Quantity - 1; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
private void btnEdit_Click(object sender, EventArgs e) { if (list.SelectedRows.Count == 1) { i = 1; CMART1Entities1 db = new CMART1Entities1(); int id = (int)list.SelectedRows[0].Cells[0].Value; Product product = db.Products.Single(st => st.IDProduct.Equals(id)); txtName.Text = product.Name; image = product.Image; img.ImageLocation = image; cbbTypes.Text = product.ProductType.Name; cbbSupplier.Text = product.Supplier.Name; btnClear.Text = "Cancel"; this.tabPage2.Text = "Edit"; tabControl1.SelectedIndex = 1; } }
private void btnEdit_Click(object sender, EventArgs e) { if (list.SelectedRows.Count == 1) { i = 1; tabAdd.Text = "Edit"; this.id = (int)list.SelectedRows[0].Cells[0].Value; string price = list.SelectedRows[0].Cells["Price"].Value.ToString(); DateTime date = (DateTime)list.SelectedRows[0].Cells["Date"].Value; CMART1Entities1 db = new CMART1Entities1(); txtID.Text = id.ToString(); txtPrice.Text = price; dateTime.Value = date; btnCancel.Text = "Cancel"; tabControl1.SelectedIndex = 1; txtID.Enabled = false; } }
public bool addBillList(string idBill, int[] idpro, string[] quantity, string[] unitprice) { db = new CMART1Entities1(); try { //for (int i = 0; i < list.Rows.Count; i++) //{ // Bill_List billlist; // billlist = new Bill_List(); // billlist.IDBill = idBill; // billlist.IDProduct = i++; // billlist.Quantity = list.Rows[i].Cells[2].Value.ToString(); // billlist.unitPrice = (float.Parse(list.Rows[i].Cells[3].Value.ToString()) / int.Parse(list.Rows[i].Cells[2].Value.ToString())).ToString(); // db.Bill_List.Add(billlist); // db.SaveChanges(); //} //for (int i = 0; i < idpro.Length; i++) //{ // billlist = new Bill_List(); // billlist.IDBill = idBill; // billlist.IDProduct = idpro[i]; // billlist.Quantity = quantity[i]; // billlist.unitPrice = unitprice[i]; // db.Bill_List.Add(billlist); // db.SaveChanges(); //} for (int i = 0; i <= quantity.Length; i++) { Bill_List billlist; billlist = new Bill_List(); billlist.IDBill = idBill; billlist.IDProduct = idpro[i]; billlist.Quantity = quantity[i]; billlist.unitPrice = unitprice[i]; db.Bill_List.Add(billlist); db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public bool addPriceHistory(string id, string price, DateTime date) { db = new CMART1Entities1(); PriceHistory priceht = new PriceHistory(); try { priceht.IDProduct = int.Parse(id); priceht.Price = float.Parse(price); priceht.Date = date; db.PriceHistories.Add(priceht); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
private void btnEdit_Click(object sender, EventArgs e) { if (list.SelectedRows.Count == 1) { i = 1; CMART1Entities1 db = new CMART1Entities1(); string id = (string)list.SelectedRows[0].Cells[0].Value; promotion = db.Promotions.Single(st => st.IDPromotion.Equals(id)); txtID.Text = promotion.IDProduct.ToString(); txtPrice.Text = promotion.Price.ToString(); image = promotion.Image; img.ImageLocation = image; txtContent.Text = promotion.Contents; this.tabAdd.Text = "Edit"; btnEdit.Enabled = false; btnCancel.Text = "Cancel"; tabControl1.SelectedIndex = 1; } }
public bool deleteBranchImport(string id) { db = new CMART1Entities1(); try { BranchImport branchImport = db.BranchImports.Single(st => st.IDBranchImport.Equals(id)); List <BranchImport_List> branchlist = branchImport.BranchImport_List.ToList(); foreach (BranchImport_List a in branchlist) { db.BranchImport_List.Remove(a); } db.BranchImports.Remove(branchImport); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool deleteHeadImport(string id) { db = new CMART1Entities1(); try { HeadImport headimport = db.HeadImports.Single(st => st.IDHeadImport.Equals(id)); List <HeadImport_List> headlist = headimport.HeadImport_List.ToList(); foreach (HeadImport_List a in headlist) { db.HeadImport_List.Remove(a); } db.HeadImports.Remove(headimport); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }