public CashRegister() { _priceDataRepo = new PriceDataRepository(); _priceDataRepo.CalulateFinalPrices(); foreach (var price in _priceDataRepo.PriceData) { var pricingRecord = new PricingRecord { BasePrice = price, FinalPrice = _priceCalculator.CalculateFinalPrice(price, DateTime.Now) }; PriceResults.Add(pricingRecord); } }
private void AnalyzeExcelFile(HttpContext context) { string ProductsId = context.Request.Params["productsid"]; string PricingAction = context.Request.Params["pricingaction"]; if (!string.IsNullOrEmpty(ProductsId) && !string.IsNullOrEmpty(PricingAction)) { if (GetStreamFromFile(context)) { if (GetConfigurations()) { if (GetExcelSheet()) { if (ValidateSQHeader()) { //Get all the branches List<PricingIndexExcel> ListBranches = pricingReadExcel.GetValuesIndexExcel(PricingExcelStream, PricingSheetName, pricingConfig.ColumnBranch); if (ValidateDualBranch(ListBranches)) { ErrorCounter = 0; //Get start and end rows index int startInfoRow = int.Parse(pricingConfig.PricingHeader) + 1; int endInfRow = ListBranches[ListBranches.Count - 1].Position; //Validate the information List<PricingExcelObj> ListPricingExcelObj = new List<PricingExcelObj>(); for (int i = startInfoRow; i < endInfRow + 1; i++) { PricingExcelObj PEO = new PricingExcelObj(); PEO.Prices = new List<SQFT>(); ValidateBranch(i, ref PEO); ValidateAddINIFee(i, ref PEO); ValidateRNLMult(i, ref PEO); ValidateApps(i, ref PEO); ValidatePrices(i, ref PEO); ValidateExcessIncrement(i, ref PEO); ValidateExcessValuePerIncrement(i, ref PEO); ListPricingExcelObj.Add(PEO); } //Actions switch (PricingAction) { case "validate": if (ErrorCounter == 0) { if (ListPricingExcelObj.Count <= 250) { PricingResults.IsSuccess = true; PricingResults.NumberOfRows = ListPricingExcelObj.Count.ToString(); PricingResults.ExcelTabName = PricingSheetName; PricingResults.ExcelFileName = GlobalFileName; } else { PricingResults.IsSuccess = false; AddError("There are more that 250 rows in the excel file"); } } else { PricingResults.IsSuccess = false; } break; case "insert": int CounterUploadesPricingData = 0; int CounterRemovedPricingData = 0; if (ErrorCounter <= 0) { PricingResults.IsSuccess = true; SalesWebService SWS = new SalesWebService(); List<string> ListProducts = ProductsId.Split(',').ToList(); foreach (string prod in ListProducts) { int intProductID = int.Parse(prod); Product cProduct = SWS.GetProductByID(intProductID); CounterRemovedPricingData += SWS.DeletePricingDataByProductID(intProductID); List<PricingRecord> ListnewPrices = new List<PricingRecord>(); if (cProduct.IsOneTime)//OneTime = true { ListnewPrices.Clear(); foreach (PricingExcelObj cPEO in ListPricingExcelObj) { ListnewPrices.Clear(); foreach (SQFT cPrice in cPEO.Prices) { PricingRecord newPrice = new PricingRecord(); newPrice.ProductID = intProductID; newPrice.Branch = cPEO.BranchNumber; newPrice.INI_Amount = 0; newPrice.Reg_Amount = 0; newPrice.Renewal_Amount = 0; newPrice.OneTime_Amount = decimal.Parse(cPrice.Value); newPrice.SqFtFrom = cPrice.SqFtFrom; newPrice.SqFtTo = cPrice.SqTfTo; newPrice.IsMultiplier = false; newPrice.IsBaseRecord = false; newPrice.CreatedBy = SPContext.Current.Web.CurrentUser.Name; newPrice.DateCreated = DateTime.Now; newPrice.LastUpdatedBy = SPContext.Current.Web.CurrentUser.Name; newPrice.DateLastUpdated = DateTime.Now; newPrice.Brand = "TG"; newPrice.FlatCostPerSqFt = cPEO.ExcessIncrement; newPrice.FlatCostPerSqFtPrice = cPEO.ExcessValuePerIncrement; newPrice.SpcFlatCostPerSqFt = 0; newPrice.SpcFlatCostPerSqFtPrice = 0; ListnewPrices.Add(newPrice); } SalesWSResult resultws = SWS.SendPricingRecords(ListnewPrices, intProductID); CounterUploadesPricingData += resultws.CounterUpdated; if (!resultws.IsSuccess) { PricingResults.IsSuccess = false; AddError(resultws.Message); } SalesWSResult BPResult = SWS.UpdateBranchProduct(cPEO.BranchNumber, intProductID, int.Parse(cPEO.NumberAppas)); if (!BPResult.IsSuccess) { PricingResults.IsSuccess = false; AddError(BPResult.Message); } } //send to record } else { ListnewPrices.Clear(); foreach (PricingExcelObj cPEO in ListPricingExcelObj) { ListnewPrices.Clear(); foreach (SQFT cPrice in cPEO.Prices) { PricingRecord newPrice = new PricingRecord(); newPrice.ProductID = intProductID; newPrice.Branch = cPEO.BranchNumber; newPrice.INI_Amount = decimal.Parse(cPEO.AddINIFee); newPrice.Reg_Amount = decimal.Parse(cPrice.Value); newPrice.Renewal_Amount = decimal.Parse(cPrice.Value) * decimal.Parse(cPEO.RLNMult); newPrice.OneTime_Amount = 0; newPrice.SqFtFrom = cPrice.SqFtFrom; newPrice.SqFtTo = cPrice.SqTfTo; newPrice.IsMultiplier = false; newPrice.IsBaseRecord = false; newPrice.CreatedBy = SPContext.Current.Web.CurrentUser.Name; newPrice.DateCreated = DateTime.Now; newPrice.LastUpdatedBy = SPContext.Current.Web.CurrentUser.Name; newPrice.DateLastUpdated = DateTime.Now; newPrice.Brand = "TG"; newPrice.FlatCostPerSqFt = cPEO.ExcessIncrement; newPrice.FlatCostPerSqFtPrice = cPEO.ExcessValuePerIncrement; newPrice.SpcFlatCostPerSqFt = 0; newPrice.SpcFlatCostPerSqFtPrice = 0; ListnewPrices.Add(newPrice); } SalesWSResult resultws = SWS.SendPricingRecords(ListnewPrices, intProductID); CounterUploadesPricingData += resultws.CounterUpdated; if (!resultws.IsSuccess) { PricingResults.IsSuccess = false; AddError(resultws.Message); } SalesWSResult BPResult = SWS.UpdateBranchProduct(cPEO.BranchNumber, intProductID, int.Parse(cPEO.NumberAppas)); if (!BPResult.IsSuccess) { PricingResults.IsSuccess = false; AddError(BPResult.Message); } } //send to record } }//End for eahc PricingResults.NumberOfRows = ListPricingExcelObj.Count.ToString(); PricingResults.NumberofRemoved = CounterRemovedPricingData.ToString(); PricingResults.NumberofRowsPricingData = CounterUploadesPricingData.ToString(); } break; } } else//Fails validate branches dual { PricingResults.IsSuccess = false; } } else//Fails to validated the header prices { PricingResults.IsSuccess = false; } } else//Fails read sheets in file { PricingResults.IsSuccess = false; } } else//Fail to get cconfigurations { PricingResults.IsSuccess = false; } } else//Fails get stream { PricingResults.IsSuccess = false; } } else//Productid or action empty { PricingResults.IsSuccess = false; AddError("You need to select a action and products"); } }