public void DeleteSupplyCategory(int id) { SupplyCategory supplyCategory = this._context.SupplyCategories.FirstOrDefault(w => w.Id == id); this._context.SupplyCategories.Remove(supplyCategory); this._context.SaveChangesAsync(); }
public SupplyCategory UpdateSupplyCategory(ref SupplyCategory supplyCategory) { this._context.Entry(supplyCategory).State = EntityState.Modified; this._context.Entry(supplyCategory).Property("LastUpdate").CurrentValue = DateTime.Now; this._context.SaveChangesAsync(); return(supplyCategory); }
public void AddSupplyCategory(SupplyCategory supplyCategory) { using (SalesDB db = new SalesDB()) { db.SuppliesCategories.Add(supplyCategory); db.SaveChanges(); } }
private void PopulateCatTree(String Type) { if (Type == "Drug") { Category cat = new Category(); treeCategory.DataSource = cat.GetCategoryTree(); } else { SupplyCategory subCat = new SupplyCategory(); treeCategory.DataSource = subCat.GetAllSupplyCategories(); } }
private void PopulateCatTree() { ProductTree.Nodes.Clear(); if (Convert.ToInt32(lkCommodityTypes.EditValue) == BLL.Type.Constants.Pharmacuticals) { Category cat = new Category(); SubCategory subCat = new SubCategory(); Product prod = new Product(); cat.LoadAll(); cat.Sort = "CategoryName"; ProductTree.Nodes.Add("All0", "All"); foreach (DataRowView dv in cat.DefaultView) { TreeNode nodes = new TreeNode(); nodes.Name = "cat" + dv["ID"].ToString(); nodes.Text = dv["CategoryName"].ToString() + " (" + dv["CategoryCode"].ToString() + ")"; nodes.ToolTipText = "Double Click to List"; subCat.GetSubCategory(Convert.ToInt32(dv["ID"])); subCat.Sort = "SubCategoryName"; foreach (DataRowView subDv in subCat.DefaultView) { TreeNode subNodes = new TreeNode(); subNodes.Name = "sub" + subDv["ID"].ToString(); subNodes.Text = subDv["SubCategoryName"].ToString() + " (" + subDv["SubCategoryCode"].ToString() + ")"; subNodes.ToolTipText = "Double Click to List"; nodes.Nodes.Add(subNodes); } ProductTree.Nodes[0].Nodes.Add(nodes); } ProductTree.Nodes[0].Expand(); } else { SupplyCategory scat = new SupplyCategory(); scat.LoadAll(); scat.Sort = "Name"; ProductTree.Nodes.Add("Als0", "All"); foreach (DataRowView dv in scat.DefaultView) { TreeNode nodes = new TreeNode(); nodes.Name = "sup" + dv["ID"].ToString(); nodes.Text = dv["Name"].ToString(); nodes.ToolTipText = "Double Click to List"; ProductTree.Nodes[0].Nodes.Add(nodes); } ProductTree.Nodes[0].Expand(); } }
/// <summary> /// Handles the saving of supply category /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveSupCat_Click(object sender, EventArgs e) { if (txtSupCat.Text != "") { SupplyCategory supCat = new SupplyCategory(); if (_supCatId == 0) { supCat.AddNew(); } else { supCat.LoadByPrimaryKey(_supCatId); } supCat.Name = txtSupCat.Text; supCat.Code = txtSupCode.Text; supCat.ParentId = ((cboSupCat.Visible) ? Convert.ToInt32(cboSupCat.SelectedValue) : 0); supCat.Save(); PopulateSupplyCatTree(); } }
/// <summary> /// Handles the treeSupCategory focused node changed and updates the form accordingly /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeSupCategory_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { SupplyCategory supCat = new SupplyCategory(); string value = treeSupCategory.Selection[0].GetValue("ID").ToString(); int categoryId = Convert.ToInt32(value.Substring(1)); supCat.LoadByPrimaryKey(categoryId); if (supCat.ParentId != 0) { cboSupCat.Visible = true; lblSupCat.Text = "Sub Category"; cboSupCat.SelectedValue = Convert.ToInt32(supCat.ParentId); } else { cboSupCat.Visible = false; lblSupCat.Text = "Main Category"; } txtSupCat.Text = supCat.Name; txtSupCode.Text = supCat.Code; _supCatId = supCat.ID; btnSave.Text = "Update"; }
/// <summary> /// Populates the supply category tree /// </summary> private void PopulateSupplyCatTree() { SupplyCategory subCat = new SupplyCategory(); treeSupCategory.DataSource = subCat.GetAllSupplyCategories(); }
private void ExecuteSave() { try { DateTime _dt = DateTime.Now; _newSupply.RegistrationDate = _dt; _supplyServ.AddSupply(_newSupply); int _supplyID = _supplyServ.GetLastSupplyID(); foreach (var item in _supplyCategories) { SupplyCategory _supplyCategory = new SupplyCategory { CategoryID = item.CategoryID, Cost = item.Cost, CostTotal = item.CostTotal, SupplyID = _supplyID, Qty = item.Qty, Price = item.Price }; _supplyCategoryServ.AddSupplyCategory(_supplyCategory); Category cat = _categoryServ.GetCategory(item.CategoryID); if (cat.Qty + item.Qty != 0) { cat.Cost = (item.CostTotal + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty); } cat.Qty = cat.Qty + item.Qty; cat.Price = item.Price; _categoryServ.UpdateCategory(cat); } ClientAccount _account = new ClientAccount { ClientID = _newSupply.ClientID, Date = _newSupply.Date, RegistrationDate = _dt, Statement = "فاتورة مشتريات رقم " + _supplyID, Credit = _newSupply.Cost, Debit = _newSupply.CashPaid + _newSupply.DiscountPaid }; _clientAccountServ.AddAccount(_account); if (_newSupply.CashPaid > 0) { Safe _safe = new Safe { Date = _newSupply.Date, RegistrationDate = _dt, Statement = "فاتورة مشتريات رقم " + _supplyID + " من العميل : " + _selectedClient.Name, Amount = -_newSupply.CashPaid, Source = 3 }; _safeServ.AddSafe(_safe); } NewSupply = new Supply(); NewSupplyCategory = new SupplyCategoryVM(); SupplyCategories = new ObservableCollection <SupplyCategoryVM>(); NewSupply.Date = DateTime.Now; OldCosts = new ObservableCollection <SupplyCategory>(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void CreateSupplyCategory(ref SupplyCategory supplyCategory) { this._context.SupplyCategories.Add(supplyCategory); this._context.SaveChangesAsync(); }
private void ExecuteSave() { try { _supplyServ.UpdateSupply(_selectedSupply); _safeServ.DeleteSafe(_selectedSupply.RegistrationDate); _clientAccountServ.DeleteAccount(_selectedSupply.RegistrationDate); var supplyCategories = _supplyCategoryServ.GetSupplyCategories(_selectedSupply.ID); foreach (var item in supplyCategories) { Category cat = _categoryServ.GetCategory(item.CategoryID); if (cat.Qty - item.Qty != 0) { cat.Cost = ((cat.Cost * cat.Qty) - item.CostTotal) / (cat.Qty - item.Qty); } if (cat.Cost < 0) { cat.Cost = 0; } cat.Qty = cat.Qty - item.Qty; _categoryServ.UpdateCategory(cat); } _supplyCategoryServ.DeleteSupplyCategories(ID); foreach (var item in _supplyCategories) { SupplyCategory _supplyCategory = new SupplyCategory { CategoryID = item.CategoryID, Cost = item.Cost, CostTotal = item.CostTotal, SupplyID = ID, Qty = item.Qty, Price = item.Price }; _supplyCategoryServ.AddSupplyCategory(_supplyCategory); Category cat = _categoryServ.GetCategory(item.CategoryID); if (cat.Qty + item.Qty != 0) { cat.Cost = (item.CostTotal + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty); } cat.Qty = cat.Qty + item.Qty; cat.Price = item.Price; _categoryServ.UpdateCategory(cat); } ClientAccount _account = new ClientAccount { ClientID = _selectedSupply.ClientID, Date = _selectedSupply.Date, RegistrationDate = _selectedSupply.RegistrationDate, Statement = "فاتورة مشتريات رقم " + ID, Credit = _selectedSupply.Cost, Debit = _selectedSupply.CashPaid + _selectedSupply.DiscountPaid }; _clientAccountServ.AddAccount(_account); if (_selectedSupply.CashPaid > 0) { Safe _safe = new Safe { Date = _selectedSupply.Date, RegistrationDate = _selectedSupply.RegistrationDate, Statement = "فاتورة مشتريات رقم " + ID + " من العميل : " + _selectedSupply.Client.Name, Amount = -_selectedSupply.CashPaid, Source = 3 }; _safeServ.AddSafe(_safe); } _currentWindow.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private async void ExecuteSaveAsync() { if (NewSupply.Future == true && NewSupplyFuture.Place == null) { await _currentWindow.ShowMessageAsync("فشل الإضافة", "يجب كتابة مكان الدفع", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "موافق", DialogMessageFontSize = 25, DialogTitleFontSize = 30 }); return; } Mouse.OverrideCursor = Cursors.Wait; DateTime _dt = DateTime.Now; _newSupply.RegistrationDate = _dt; _supplyServ.AddSupply(_newSupply); int _supplyID = _supplyServ.GetLastSupplyID(); foreach (var item in _supplyCategories) { SupplyCategory _supplyCategory = new SupplyCategory { CategoryID = item.CategoryID, Cost = item.Cost, CostAfterDiscount = item.CostAfterDiscount, CostAfterTax = item.CostAfterTax, CostTotal = item.CostTotal, CostTotalAfterDiscount = item.CostTotalAfterDiscount, CostTotalAfterTax = item.CostTotalAfterTax, Discount = item.Discount, DiscountValue = item.DiscountValue, DiscountValueTotal = item.DiscountValueTotal, SupplyID = _supplyID, Qty = item.Qty, Tax = item.Tax, TaxValue = item.TaxValue, TaxValueTotal = item.TaxValueTotal, Price = item.Price }; _supplyCategoryServ.AddSupplyCategory(_supplyCategory); Category cat = _categoryServ.GetCategory(item.CategoryID); if (cat.Qty + item.Qty != 0) { cat.Cost = (item.CostTotalAfterDiscount + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty); } cat.Qty = cat.Qty + item.Qty; cat.Price = item.Price; _categoryServ.UpdateCategory(cat); } if (_newSupply.Future == true) { _newSupplyFuture.Change = _newSupply.Change; _newSupplyFuture.SupplyID = _supplyID; if (_newSupplyFuture.Cheque == false) { _newSupplyFuture.ChequeNumber = null; } _supplyFutureServ.AddSupplyFuture(_newSupplyFuture); _placesSuggestions.Add(_newSupplyFuture.Place); } ClientAccount _account = new ClientAccount { ClientID = _newSupply.ClientID, Date = _newSupply.Date, RegistrationDate = _dt, Statement = "فاتورة مشتريات رقم " + _supplyID, Credit = _newSupply.CostAfterTax, Debit = _newSupply.CashPaid }; _clientAccountServ.AddAccount(_account); if (_newSupply.DiscountPaid != 0 || _newSupply.TotalDiscount != 0) { _account = new ClientAccount { ClientID = _newSupply.ClientID, Date = _newSupply.Date, RegistrationDate = _dt, Statement = "خصومات فاتورة مشتريات رقم " + _supplyID, Credit = _newSupply.DiscountPaid, Debit = _newSupply.TotalDiscount }; _clientAccountServ.AddAccount(_account); } if (_newSupply.CashPaid > 0) { Safe _safe = new Safe { Date = _newSupply.Date, RegistrationDate = _dt, Statement = "فاتورة مشتريات رقم " + _supplyID + " من العميل : " + _selectedClient.Name, Amount = -_newSupply.CashPaid, Source = 3 }; _safeServ.AddSafe(_safe); } DS ds = new DS(); ds.Sale.Rows.Clear(); int i = 0; foreach (var item in _supplyCategories) { ds.Sale.Rows.Add(); ds.Sale[i]["ID"] = _supplyID; ds.Sale[i]["Date"] = _newSupply.Date; ds.Sale[i]["Client"] = _selectedClient.Name; ds.Sale[i]["Serial"] = i + 1; ds.Sale[i]["Category"] = item.Category + " " + item.Company; ds.Sale[i]["Qty"] = item.Qty; ds.Sale[i]["Price"] = Math.Round(Convert.ToDecimal(item.CostAfterTax), 2); ds.Sale[i]["TotalPrice"] = Math.Round(Convert.ToDecimal(item.CostTotalAfterTax), 2); ds.Sale[i]["BillPrice"] = Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2); ds.Sale[i]["OldDebt"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2)); ds.Sale[i]["Paid"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.CashPaid + _newSupply.DiscountPaid), 2)); ds.Sale[i]["NewDebt"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.NewDebt), 2)); if (_newSupply.NewDebt > 0) { ds.Sale[i]["PrintingMan"] = "له"; } else if (_newSupply.NewDebt < 0) { ds.Sale[i]["PrintingMan"] = "عليه"; } if (_newSupply.OldDebt > 0) { ds.Sale[i]["Type"] = "له"; } else if (_newSupply.OldDebt < 0) { ds.Sale[i]["Type"] = "عليه"; } ds.Sale[i]["BillTotal"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2)); if (Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2) > 0) { ds.Sale[i]["Type2"] = "له"; } else if (Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2) < 0) { ds.Sale[i]["Type2"] = "عليه"; } i++; } ReportWindow rpt = new ReportWindow(); SupplyReport supplyRPT = new SupplyReport(); supplyRPT.SetDataSource(ds.Tables["Sale"]); rpt.crv.ViewerCore.ReportSource = supplyRPT; Mouse.OverrideCursor = null; _currentWindow.Hide(); rpt.ShowDialog(); NewSupply = new Supply(); NewSupplyCategory = new SupplyCategoryVM(); NewSupplyFuture = new SupplyFuture(); SupplyCategories = new ObservableCollection <SupplyCategoryVM>(); NewSupply.Date = DateTime.Now; NewSupplyFuture.Date = DateTime.Now; OldCosts = new ObservableCollection <SupplyCategory>(); _currentWindow.ShowDialog(); }
public ActionResult <SupplyCategory> UpdateSupplyCategory(SupplyCategory supplyCategory) { this._serviceSupplyCategory.UpdateSupplyCategory(ref supplyCategory); return(Ok(supplyCategory)); }
public ActionResult <SupplyCategory> CreateSupplyCategory(SupplyCategory supplyCategory) { this._serviceSupplyCategory.CreateSupplyCategory(ref supplyCategory); return(new CreatedAtRouteResult("GetSupplyCategory", new { id = supplyCategory.Id }, supplyCategory)); }