protected void btnSaveMaterial_Click(object sender, EventArgs e) { Material material = new Material(materialID); material.UnitID = Convert.ToInt32(ddlMaterialUnit.SelectedValue); material.Title = txtMaterialTitle.Text; material.CaseID = caseID; material.TypeID = Convert.ToInt32(ddlMaterialType.SelectedValue); material.CompanyID = Convert.ToInt64(ddlCompany.SelectedValue); material.MinStockOrder = Convert.ToDecimal(txtMinStockAmount.Text); material.Number = txtMaterialNumber.Text; if (material.Save()) { MaterialPrice price = new MaterialPrice(); price.Price = Convert.ToDecimal(txtMaterialPrice.Text); price.MaterialID = material.ID; price.CaseID = caseID; price.CurrencyISO = "DKK"; price.Save(); Response.Redirect(Request.RawUrl); } Response.Redirect(Request.RawUrl); }
public void Copy(int id) { //Base var material = _db.Materials.Find(id); var newMaterial = new SpecDomain.Model.Material(); MyReflection.Copy(material, newMaterial); newMaterial.Remark = "Copy -- " + newMaterial.Remark; _db.Materials.Add(newMaterial); _db.SaveChanges(); //Price var price = _db.MaterialPrices.Find(newMaterial.PriceID); var newPrice = new MaterialPrice(); MyReflection.Copy(price, newPrice); newPrice.MaterialID = newMaterial.MaterialID; _db.MaterialPrices.Add(newPrice); _db.SaveChanges(); //Update New Material Price newMaterial.PriceID = newPrice.PriceID; _db.Entry(newMaterial).State = EntityState.Modified; _db.SaveChanges(); }
public void Initialize(MaterialPrice price) { MyReflection.Copy(price, this); CurrentPrice = string.Format("{0:C2}", Price); InvoicingPrice = string.Format("{0:C2}", InvoicePrice); UnitName = price.MaterialPriceUnit.UnitName; UpdateDate = string.Format("{0:MMM dd, yyyy}", InputDate); }
public void Insert() { //Insert Categories if not exist var mc0 = new MyMaterialCategory0(); CategoryID0 = mc0.CreateCategoryID(CategoryID0, 0, CategoryName0); var mc1 = new MyMaterialCategory1(); CategoryID1 = mc1.CreateCategoryID(CategoryID1, CategoryID0, CategoryName1); var mc2 = new MyMaterialCategory2(); CategoryID2 = mc2.CreateCategoryID(CategoryID2, CategoryID1, CategoryName2); var mc3 = new MyMaterialCategory3(); CategoryID3 = mc3.CreateCategoryID(CategoryID3, CategoryID2, CategoryName3); var mc4 = new MyMaterialCategory4(); CategoryID4 = mc4.CreateCategoryID(CategoryID4, CategoryID3, CategoryName4); //1. Insert material var material = new SpecDomain.Model.Material(); MyReflection.Copy(this, material); _db.Materials.Add(material); _db.SaveChanges(); //2. Insert Price var price = new MaterialPrice { MaterialID = material.MaterialID, UnitID = UnitID, Price = Price, InvoicePriceUnitID = UnitID, VenderID = 0, Active = true }; _db.MaterialPrices.Add(price); _db.SaveChanges(); //3. Update Price material.PriceID = price.PriceID; material.UnitID = price.UnitID; material.Price = Price; _db.Entry(material).State = EntityState.Modified; _db.SaveChanges(); }
//2. Insert Price private void InsertPrice(int unitID, double unitPrice) { _myPrice = new MaterialPrice { MaterialID = _myMaterial.MaterialID, UnitID = unitID, Price = unitPrice, InvoicePriceUnitID = unitID, VenderID = 0, Active = true }; _db.MaterialPrices.Add(_myPrice); _db.SaveChanges(); }
public PlumResult DeleteMaterial(MaterialPrice material) { var result = new PlumResult(); try { db.Entry(material).State = EntityState.Deleted; result.Message = "کالا با موفقیت حذف شد"; return(result); } catch (Exception e) { result.IsChange = false; result.Message = e.Message; return(result); } }
public void Initialize(int parentID) { Value = new MaterialPrice(); Value.MaterialID = parentID; CalculatePriceByInvoice = true; Values = new List <MaterialPriceBase>(); var mps = _db.MaterialPrices.Where(x => x.MaterialID == parentID).OrderByDescending(x => x.InputDate).ThenByDescending(x => x.MaterialID).ToList(); if (mps.Count <= 0) { return; } foreach (var mp in mps) { var mpb = new MaterialPriceBase(); mpb.Initialize(mp); Values.Add(mpb); } }
public PlumResult InsertMaterial(MaterialPrice material) { var result = new PlumResult(); try { if (db.MaterialsPrice.Any(a => a.MaterialId == material.MaterialId && a.CompanyId == material.CompanyId && a.Active)) { result.IsChange = false; result.Message = "کالای وارد شده قبلا قیمت گذاری شده است"; return(result); } db.MaterialsPrice.Add(material); result.Message = "عملیات با موفقیت انجام شد"; return(result); } catch (Exception e) { result.IsChange = false; result.Message = e.Message; return(result); } }
/// <summary> /// /// </summary> /// <param name="material"></param> /// <param name="inHistory"></param> /// <returns></returns> public PlumResult UpdateMaterial(MaterialPrice material, bool inHistory) { var result = new PlumResult(); try { MaterialPrice materialModel = GetOne(material.Id); if (db.MaterialsPrice.Any(a => a.Id != material.Id && a.MaterialId == material.MaterialId && a.CompanyId == material.CompanyId && a.Active)) { result.IsChange = false; result.Message = "کالای وارد شده قبلا قیمت گذاری شده است"; return(result); } if (materialModel.UnitPrice != material.UnitPrice && inHistory) { var oldMaterial = new MaterialPrice() { MaterialId = materialModel.MaterialId, Active = false, CompanyId = materialModel.CompanyId, ParentId = materialModel.Id, UnitPrice = materialModel.UnitPrice, InsertTime = materialModel.InsertTime, MaterialTypeData = materialModel.MaterialTypeData }; db.MaterialsPrice.Add(oldMaterial); } materialModel.MaterialId = material.MaterialId; materialModel.UnitPrice = material.UnitPrice; materialModel.InsertTime = material.InsertTime; //تغییر قیمت یک در لیست مواد اولیه غذاها foreach (var item in materialModel.FoodMaterials.ToList()) { item.UnitPrice = material.UnitPrice; var unitPrice = material.UnitPrice / 1000; var quantity = item.Quantity; var totalPrice = unitPrice * quantity; item.MaterialTotalPrice = totalPrice; db.Entry(item).State = EntityState.Modified; var foodId = item.FoodId; //پس از تغییر قیمت کالا قیمت ناهایی کالا نیز تغییر میکند if (item.Food.FoodSurplusPrices.Any()) { var foodPRice = item.Food.FoodSurplusPrices.FirstOrDefault(a => a.AdjustKind == 8); var sumfoodMAterialPrice = 0.0; using (var unit = new UnitOfWork()) { var foodDetails = unit.FoodService.GetOne(foodId); foreach (var foodMaterial in foodDetails.FoodMaterials) { if (foodMaterial.Id == item.Id) { sumfoodMAterialPrice = sumfoodMAterialPrice + totalPrice; } else { sumfoodMAterialPrice = sumfoodMAterialPrice + foodMaterial.MaterialTotalPrice; } } var sumFoodPrice = unit.FoodSurplusPricService.CalculatorFinalPrice(foodId, sumfoodMAterialPrice, 1); if (foodPRice != null) { foodPRice.Price = sumFoodPrice; } } db.Entry(foodPRice).State = EntityState.Modified; } } result.Message = "عملیات با موفقیت انجام شد"; return(result); } catch (Exception e) { result.IsChange = false; result.Message = e.Message; return(result); } }