public List <IssueDetail> GetAll(int sellerId, DateTime dateOfIssue) { using (DistributorEntities ent = new DistributorEntities()) { return(ent.IssueDetails.Include("Product").Where(c => c.SellerId == sellerId && c.DateOfIssue == dateOfIssue).ToList()); } }
public void AutoAdd() { using (DistributorEntities ent = new DistributorEntities()) { int curYear = DateTime.Today.Year; int curMonth = DateTime.Today.Month; var lstProc = ent.Products.ToList(); foreach (var proc in lstProc) { var curSale = ent.Sales.Where(c => c.ProId == proc.Id && c.Month == curMonth && c.Year == curYear).FirstOrDefault(); var lstSellerSale = ent.SellerSales.Where(c => c.ProId == proc.Id && c.Month == curMonth && c.Year == curYear).ToList(); int totalQuantity = lstSellerSale.Sum(c => c.Quantity.Value); decimal totalSale = lstSellerSale.Sum(c => c.Sales.Value); if (curSale != null) { curSale.Quantity = totalQuantity; curSale.Sales = totalSale; } else { curSale = new Sale { ProId = proc.Id, Year = curYear, Month = curMonth, Quantity = totalQuantity, Sales = totalSale }; ent.Sales.Add(curSale); } ent.SaveChanges(); } } }
public bool Update(Category cat) { bool flag = true; if (IsExistedName(cat) == true) { flag = false; } else { using (DistributorEntities entity = new DistributorEntities()) { var catData = entity.Categories.Where(i => i.Id == cat.Id).FirstOrDefault(); if (catData != null) { catData.Name = cat.Name; entity.SaveChanges(); } else { flag = false; } } } return(flag); }
public bool Add(Category cat) { bool flag = true; if (IsExistedName(cat) == true) { flag = false; } else { try { using (DistributorEntities entity = new DistributorEntities()) { entity.Categories.Add(cat); entity.SaveChanges(); } } catch (System.Exception ex) { ex.Message.ToString(); flag = false; } } return(flag); }
public bool Remove(int id) { bool flag = true; using (DistributorEntities entity = new DistributorEntities()) { var pro = entity.Products.Where(p => p.Id == id).FirstOrDefault(); if (pro != null) { try { entity.Products.Remove(pro); entity.SaveChanges(); } catch (System.Exception ex) { ex.Message.ToString(); return(false); } } else { flag = false; } } return(flag); }
public bool Remove(int id) { bool flag = true; using (DistributorEntities entity = new DistributorEntities()) { var staff = entity.Staffs.Where(c => c.Id == id).FirstOrDefault(); if (staff != null) { if (staff.Permission != 0) { flag = false; } else { entity.Staffs.Remove(staff); entity.SaveChanges(); } } else { flag = false; } } return(flag); }
public void AutoAdd() { int curYear = DateTime.Now.Year; using (DistributorEntities ent = new DistributorEntities()) { var lstSel = ent.Sellers.ToList(); foreach (var sel in lstSel) { if (!sel.Debts.Where(c => c.Year == curYear).Any()) { Debt debt = new Debt { SellerId = sel.Id, Year = curYear }; ent.Debts.Add(debt); } else { } } ent.SaveChanges(); } }
public Boolean UpdateMonth(int sellerId, int year, decimal debtVal, int month) { Boolean success = true; using (DistributorEntities ent = new DistributorEntities()) { var debt = ent.Debts.Where(c => c.SellerId == sellerId && c.Year == year).First(); if (debt != null) { switch (month) { case 1: debt.Month1 = debtVal; break; case 2: debt.Month2 = debtVal; break; case 3: debt.Month3 = debtVal; break; case 4: debt.Month4 = debtVal; break; case 5: debt.Month5 = debtVal; break; case 6: debt.Month6 = debtVal; break; case 7: debt.Month7 = debtVal; break; case 8: debt.Month8 = debtVal; break; case 9: debt.Month9 = debtVal; break; case 10: debt.Month10 = debtVal; break; case 11: debt.Month11 = debtVal; break; case 12: debt.Month12 = debtVal; break; } } else { success = false; } ent.SaveChanges(); } return(success); }
public bool UpdateInfo(Product pro) { bool flag = true; using (DistributorEntities entity = new DistributorEntities()) { var proData = entity.Products.Where(p => p.Id == pro.Id).FirstOrDefault(); if (proData != null) { proData.Name = pro.Name; proData.Price = pro.Price; proData.Quantity = pro.Quantity; proData.Sale = pro.Sale; proData.Description = pro.Description; proData.CatId = pro.CatId; entity.SaveChanges(); } else { flag = false; } } return(flag); }
public void AutoAdd() { int curMonth = DateTime.Today.Month; int curYear = DateTime.Today.Year; using (DistributorEntities ent = new DistributorEntities()) { var lstProcs = ent.Products.ToList(); foreach (var proc in lstProcs) { int totalSales = 0; totalSales += ent.Sales.Where(c => c.ProId == proc.Id && c.Year == curYear && c.Month == curMonth).Sum(c => c.Quantity.Value); Stock stk = ent.Stocks.Where(c => c.ProId == proc.Id && c.Month == curMonth && c.Year == curYear).FirstOrDefault(); if (stk == null) { stk = new Stock { ProId = proc.Id, Month = curMonth, Year = curYear, Quantity = proc.Quantity.Value - totalSales }; ent.Stocks.Add(stk); } else { stk.Quantity = proc.Quantity.Value - totalSales; } ent.SaveChanges(); } } }
public List <Category> GetAll() { using (DistributorEntities entity = new DistributorEntities()) { return(entity.Categories.ToList()); } }
public List <Stock> GetAll() { using (DistributorEntities entity = new DistributorEntities()) { return(entity.Stocks.ToList()); } }
public bool Remove(int distributorId, int proId, int year, int month) { bool flag = true; using (DistributorEntities entity = new DistributorEntities()) { var st = entity.Stocks.Where(s => s.ProId == proId && s.Year == year && s.Month == month) .FirstOrDefault(); if (st != null) { try { entity.Stocks.Remove(st); entity.SaveChanges(); } catch (System.Exception ex) { ex.Message.ToString(); return(false); } } else { flag = false; } } return(flag); }
public Boolean IsExist(Issue iss) { using (DistributorEntities ent = new DistributorEntities()) { return(ent.Issues.Where(c => c.SellerId == iss.SellerId && c.DateOfIssue == iss.DateOfIssue).Any()); } }
public List <Product> GetAll() { using (DistributorEntities entity = new DistributorEntities()) { return(entity.Products.ToList()); } }
private void btnOpenReportBySeller_Click(object sender, RoutedEventArgs e) { DateTime date = txtDate.DateTime; using (DistributorEntities ent = new DistributorEntities()) { var lstSale = (from c in ent.SellerSales where c.Month == date.Month && c.Year == date.Year select new { SellerId = c.SellerId, SellerName = c.Seller.Name, ProId = c.ProId, ProName = c.Product.Name, c.Year, c.Month, Quantity = c.Quantity.Value, Sales = c.Sales.Value }).ToList(); if (lstSale.Count == 0) { DXMessageBox.Show("Không có dữ liệu thống kê"); return; } ReportDocument report = new ReportDocument(); report.Load("./Views/CrystalReport/SellerSaleReport.rpt"); report.SetDataSource(lstSale); crystalReportsViewer1.ViewerCore.ReportSource = report; } }
public Product GetById(int Id) { using (DistributorEntities entity = new DistributorEntities()) { return(entity.Products.Include("Category").Where(p => p.Id == Id).FirstOrDefault()); } }
public Staff GetByUsername(string username, string password) { string encPassword = MD5Encrypt.Encrypt(password); using (DistributorEntities entity = new DistributorEntities()) { return(entity.Staffs.Where(s => s.Username == username && s.Password == encPassword).FirstOrDefault()); } }
public bool Add(Seller sel) { using (DistributorEntities entity = new DistributorEntities()) { entity.Sellers.Add(sel); entity.SaveChanges(); return(true); } }
public Issue GetById(int sellerId, DateTime doi) { Issue iss = null; using (DistributorEntities ent = new DistributorEntities()) { iss = ent.Issues.Where(c => c.SellerId == sellerId && c.DateOfIssue == doi).FirstOrDefault(); } return(iss); }
public List <Debt> GetAll(int SellerId) { List <Debt> lst = new List <Debt>(); using (DistributorEntities ent = new DistributorEntities()) { lst = ent.Debts.Where(c => c.SellerId == SellerId).ToList(); } return(lst); }
public bool Add(Staff staff) { using (DistributorEntities entity = new DistributorEntities()) { staff.Password = MD5Encrypt.Encrypt(staff.Password); entity.Staffs.Add(staff); entity.SaveChanges(); return(true); } }
public List <Issue> GetAll() { List <Issue> lst = new List <Issue>(); using (DistributorEntities ent = new DistributorEntities()) { lst = ent.Issues.Include("Seller").ToList(); } return(lst); }
public Debt Get(int distrId, int year) { Debt debt = null; using (DistributorEntities ent = new DistributorEntities()) { debt = ent.Debts.Where(c => c.SellerId == distrId && c.Year == year).FirstOrDefault(); } return(debt); }
public bool IsExistAccount(String username) { using (DistributorEntities entity = new DistributorEntities()) { if (entity.Staffs.Where(c => c.Username.Equals(username)).Any()) { return(true); } } return(false); }
public bool Login(String username, String password) { using (DistributorEntities entity = new DistributorEntities()) { String encryptedPwd = MD5Encrypt.Encrypt(password); if (entity.Staffs.Where(c => c.Username.Equals(username) && c.Password.Equals(encryptedPwd)).Any()) { return(true); } } return(false); }
public void Update(int distrId, int year, int month, decimal debtValue) { using (DistributorEntities ent = new DistributorEntities()) { var debt = ent.Debts.Where(c => c.Year == year && c.SellerId == distrId).FirstOrDefault(); switch (month) { case 1: debt.Month1 = debtValue; break; case 2: debt.Month2 = debtValue; break; case 3: debt.Month3 = debtValue; break; case 4: debt.Month4 = debtValue; break; case 5: debt.Month5 = debtValue; break; case 6: debt.Month6 = debtValue; break; case 7: debt.Month7 = debtValue; break; case 8: debt.Month8 = debtValue; break; case 9: debt.Month9 = debtValue; break; case 10: debt.Month10 = debtValue; break; case 11: debt.Month11 = debtValue; break; case 12: debt.Month12 = debtValue; break; default: break; } ent.SaveChanges(); } }
public void Add(Issue iss, List <IssueDetail> lstIssD) { using (DistributorEntities ent = new DistributorEntities()) { ent.Issues.Add(iss); ent.SaveChanges(); var lstRemainIssue = ent.IssueDetails.Where(c => c.SellerId == iss.SellerId && c.Remainder != 0).ToList(); foreach (IssueDetail issD in lstIssD) { issD.SellerId = iss.SellerId; issD.DateOfIssue = iss.DateOfIssue; ent.IssueDetails.Add(issD); Product proc = ent.Products.Where(c => c.Id == issD.ProId).FirstOrDefault(); proc.Quantity -= issD.Quantity; ent.SaveChanges(); } foreach (IssueDetail issD in lstRemainIssue) { var tempIss = ent.IssueDetails.Where(c => c.SellerId == iss.SellerId && c.ProId == issD.ProId && c.DateOfIssue == iss.DateOfIssue).FirstOrDefault(); if (tempIss != null) { tempIss.Quantity += issD.Remainder.Value; tempIss.Remainder += issD.Remainder.Value; tempIss.Amount += issD.Remainder.Value * issD.Product.Price.Value; ent.SaveChanges(); } else { IssueDetail newIssue = new IssueDetail { SellerId = iss.SellerId, ProId = issD.ProId, DateOfIssue = iss.DateOfIssue, Quantity = issD.Remainder, Remainder = issD.Remainder, Amount = issD.Remainder.Value * issD.Product.Price.Value }; ent.IssueDetails.Add(newIssue); ent.SaveChanges(); } } } }
public void ReturnToStock(IssueDetail issDetail) { using (DistributorEntities ent = new DistributorEntities()) { var issCurDetail = ent.IssueDetails.Where(c => c.SellerId == issDetail.SellerId && c.ProId == issDetail.ProId && c.DateOfIssue == issDetail.DateOfIssue).FirstOrDefault(); var product = ent.Products.Where(c => c.Id == issCurDetail.ProId).FirstOrDefault(); var issCur = ent.Issues.Where(c => c.SellerId == issCurDetail.SellerId && c.DateOfIssue == issCurDetail.DateOfIssue).FirstOrDefault(); issCur.Debt -= issCurDetail.Remainder.Value * issCurDetail.Product.Price.Value; product.Quantity += issCurDetail.Remainder.Value; issCurDetail.Remainder = 0; ent.SaveChanges(); } }
public void Remove(Issue iss) { using (DistributorEntities ent = new DistributorEntities()) { var curIss = ent.Issues.Where(c => c.SellerId == iss.SellerId && c.DateOfIssue == iss.DateOfIssue).FirstOrDefault(); var lstCurIssDe = ent.IssueDetails.Where(c => c.SellerId == iss.SellerId && c.DateOfIssue == iss.DateOfIssue).ToList(); foreach (var curIssD in lstCurIssDe) { ent.IssueDetails.Remove(curIssD); } ent.Issues.Remove(curIss); ent.SaveChanges(); } }