protected void btnDelete_Click(object sender, EventArgs e) { int fabricCode = int.Parse(this.hdnSelectedID.Value.Trim()); if (Page.IsValid) { try { List <PriceBO> lstPrices = (from o in (new PriceBO()).SearchObjects() where o.Pattern == int.Parse(this.hdnPattern.Value.Trim()) && o.FabricCode == fabricCode select o).ToList(); if (lstPrices.Count > 0) { using (TransactionScope ts = new TransactionScope()) { PriceBO objPrice = new PriceBO(this.ObjContext); objPrice.ID = lstPrices[0].ID; objPrice.GetObject(); foreach (PriceLevelCostBO itemPLC in objPrice.PriceLevelCostsWhereThisIsPrice) { PriceLevelCostBO objPLC = new PriceLevelCostBO(this.ObjContext); objPLC.ID = itemPLC.ID; objPLC.GetObject(); foreach (DistributorPriceLevelCostBO itemDPLC in objPLC.DistributorPriceLevelCostsWhereThisIsPriceLevelCost) { DistributorPriceLevelCostBO objDPLC = new DistributorPriceLevelCostBO(this.ObjContext); objDPLC.ID = itemDPLC.ID; objDPLC.GetObject(); objDPLC.Delete(); } objPLC.Delete(); } objPrice.Delete(); this.ObjContext.SaveChanges(); ts.Complete(); } } // Populate active pattern fabrics this.PopulatePatternFabrics(); } catch (Exception ex) { // Log the error IndicoLogging.log.Error("btnDelete_Click : Error occured while Adding the Item", ex); } } }
/// <summary> /// Process the page data. /// </summary> private void ProcessForm(int queryId, bool isDelete) { try { using (TransactionScope ts = new TransactionScope()) { PatternBO objPattern = new PatternBO(this.ObjContext); if (queryId > 0) { objPattern.ID = queryId; objPattern.GetObject(); } if (isDelete) { List <PriceBO> lstPrces = objPattern.PricesWhereThisIsPattern; foreach (PriceBO price in lstPrces) { PriceBO objPrice = new PriceBO(this.ObjContext); objPrice.ID = price.ID; objPrice.GetObject(); foreach (PriceLevelCostBO priceLevelCost in objPrice.PriceLevelCostsWhereThisIsPrice) { PriceLevelCostBO objPriceLevelCost = new PriceLevelCostBO(this.ObjContext); objPriceLevelCost.ID = priceLevelCost.ID; objPriceLevelCost.GetObject(); objPriceLevelCost.Delete(); } objPrice.Delete(); } } this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { // Log the error //IndicoLogging.log("Error occured while Adding the Item", ex); } }
/// <summary> /// Process the page data. /// </summary> private void ProcessForm(Repeater dataRepeater, int fabricCode) { try { using (TransactionScope ts = new TransactionScope()) { this.ActivePattern.ConvertionFactor = Convert.ToDecimal(decimal.Parse(this.txtConvertionFactor.Text.Trim()).ToString("0.00")); this.ActivePattern.PriceRemarks = this.txtRemarks.Text.Trim(); List <PriceBO> lstPrices = (from o in (new PriceBO()).SearchObjects() where o.Pattern == this.ActivePattern.ID && o.FabricCode == fabricCode select o).ToList(); PriceBO objPrice = new PriceBO(this.ObjContext); if (lstPrices.Count > 0) { objPrice.ID = lstPrices[0].ID; objPrice.GetObject(); } else { objPrice.Pattern = int.Parse(this.hdnPattern.Value.Trim()); objPrice.FabricCode = fabricCode; objPrice.Creator = this.LoggedUser.ID; objPrice.CreatedDate = Convert.ToDateTime(DateTime.Now.ToString("g")); } objPrice.Modifier = this.LoggedUser.ID; objPrice.ModifiedDate = Convert.ToDateTime(DateTime.Now.ToString("g")); foreach (RepeaterItem item in dataRepeater.Items) { HiddenField hdnCellID = (HiddenField)item.FindControl("hdnCellID"); TextBox txtCIFPrice = (TextBox)item.FindControl("txtCIFPrice"); int priceLevel = int.Parse(txtCIFPrice.Attributes["level"].ToString().Trim()); int priceLevelCost = int.Parse(hdnCellID.Value.Trim()); PriceLevelCostBO objPriceLevelCost = new PriceLevelCostBO(this.ObjContext); if (priceLevelCost > 0) { objPriceLevelCost.ID = priceLevelCost; objPriceLevelCost.GetObject(); } else { objPriceLevelCost.PriceLevel = priceLevel; objPrice.PriceLevelCostsWhereThisIsPrice.Add(objPriceLevelCost); } objPriceLevelCost.IndimanCost = Convert.ToDecimal(decimal.Parse(txtCIFPrice.Text.Trim()).ToString("0.00")); } this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { // Log the error IndicoLogging.log.Error("Error occured while Adding the Item", ex); } }