Exemplo n.º 1
0
 public CallContext OfferProducitivitySave(OfferProducitivity offerProducitivity, CallContext callContext)
 {
    
    CallContext resContext = new OfferProducitivityBL().EntitySave<OfferProducitivity>(offerProducitivity, callContext);
    return resContext;
 }
Exemplo n.º 2
0
        public override void UserControlLoad()
        {
            if (this.ownerPage == null)
            {
                throw new UMSException("Current Page is null or is not inheritor of BasicPage.");
            }

            InitLoadControls();

            SetEmptyValues();

            if (!string.IsNullOrEmpty(this.hdnRowMasterKey.Value) && this.hdnRowMasterKey.Value != Constants.INVALID_ID_STRING)
            {
                this.CurrentEntityMasterID = this.hdnRowMasterKey.Value;
            }

            this.currentOffer = this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);

            this.currentOfferProducitivity = this.ownerPage.CostCalculationRef.GetOfferProducitivityByOfferID(this.CurrentEntityMasterID);



            if (this.currentOffer != null)
            {
                this.hdnRowMasterKey.Value = this.currentOffer.idOffer.ToString();

                ClearResultContext();
            }


            if (this.currentOfferProducitivity != null)
            {
                KeyValue kvPress    = this.ownerPage.GetKeyValueByID(this.currentOfferProducitivity.idPress);

                if (kvPress != null)
                {
                    this.lbPress.Text = kvPress.Name;
                }


                if (this.currentOfferProducitivity.idCOMetal.HasValue)
                {
                    KeyValue kvCOMetal = this.ownerPage.GetKeyValueByID(this.currentOfferProducitivity.idCOMetal.Value);

                    if (kvCOMetal != null)
                    {
                        this.lbCoMetal.Text = kvCOMetal.Name;
                    }
                   

                    foreach(TableRow row in this.gvProducitivity.Rows)
                    {
                        row.Cells[3].Visible = true;
                    }
                }
                else
                {
                    foreach(TableRow row in this.gvProducitivity.Rows)
                    {
                        row.Cells[3].Visible = false;
                    }
                }



                this.tbxPressProducitivity_KG_MH.Text       = this.currentOfferProducitivity.PressProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxPressProducitivity_TON_MH.Text      = this.currentOfferProducitivity.PressProducitivity_TON_MH.ToStringFormatted4();
                this.tbxQCProducitivity_KG_MH.Text          = this.currentOfferProducitivity.QCProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxQCProducitivity_TON_MH.Text         = this.currentOfferProducitivity.QCProducitivity_TON_MH.ToStringFormatted4();
                this.tbxCOMetalProducitivity_KG_MH.Text     = this.currentOfferProducitivity.COMetalProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxCOMetalProducitivity_TON_MH.Text    = this.currentOfferProducitivity.COMetalProducitivity_TON_MH.ToStringFormatted4();
                this.tbxPackagingProducitivity_KG_MH.Text   = this.currentOfferProducitivity.PackagingProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxPackagingProducitivity_TON_MH.Text  = this.currentOfferProducitivity.PackagingProducitivity_TON_MH.ToStringFormatted4();
                
                ClearResultContext();
            }
            else
            {
                SetEmptyValues();
            }
            
        }
Exemplo n.º 3
0
        public override void UserControlLoad()
        {
            if (this.ownerPage == null)
            {
                throw new UMSException("Current Page is null or is not inheritor of BasicPage.");
            }

            InitLoadControls();

            SetEmptyValues();

            if (!string.IsNullOrEmpty(this.hdnRowMasterKey.Value) && this.hdnRowMasterKey.Value != Constants.INVALID_ID_STRING)
            {
                this.CurrentEntityMasterID = this.hdnRowMasterKey.Value;
            }

            this.currentOffer = this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);

            this.currentOfferProducitivity = this.ownerPage.CostCalculationRef.GetOfferProducitivityByOfferID(this.CurrentEntityMasterID);



            if (this.currentOffer != null)
            {
                this.hdnRowMasterKey.Value = this.currentOffer.idOffer.ToString();

                ClearResultContext();
            }


            if (this.currentOfferProducitivity != null)
            {
                KeyValue kvPress = this.ownerPage.GetKeyValueByID(this.currentOfferProducitivity.idPress);

                if (kvPress != null)
                {
                    this.lbPress.Text = kvPress.Name;
                }


                if (this.currentOfferProducitivity.idCOMetal.HasValue)
                {
                    KeyValue kvCOMetal = this.ownerPage.GetKeyValueByID(this.currentOfferProducitivity.idCOMetal.Value);

                    if (kvCOMetal != null)
                    {
                        this.lbCoMetal.Text = kvCOMetal.Name;
                    }


                    foreach (TableRow row in this.gvProducitivity.Rows)
                    {
                        row.Cells[3].Visible = true;
                    }
                }
                else
                {
                    foreach (TableRow row in this.gvProducitivity.Rows)
                    {
                        row.Cells[3].Visible = false;
                    }
                }



                this.tbxPressProducitivity_KG_MH.Text      = this.currentOfferProducitivity.PressProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxPressProducitivity_TON_MH.Text     = this.currentOfferProducitivity.PressProducitivity_TON_MH.ToStringFormatted4();
                this.tbxQCProducitivity_KG_MH.Text         = this.currentOfferProducitivity.QCProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxQCProducitivity_TON_MH.Text        = this.currentOfferProducitivity.QCProducitivity_TON_MH.ToStringFormatted4();
                this.tbxCOMetalProducitivity_KG_MH.Text    = this.currentOfferProducitivity.COMetalProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxCOMetalProducitivity_TON_MH.Text   = this.currentOfferProducitivity.COMetalProducitivity_TON_MH.ToStringFormatted4();
                this.tbxPackagingProducitivity_KG_MH.Text  = this.currentOfferProducitivity.PackagingProducitivity_KG_MH.ToStringNotFormatted();
                this.tbxPackagingProducitivity_TON_MH.Text = this.currentOfferProducitivity.PackagingProducitivity_TON_MH.ToStringFormatted4();

                ClearResultContext();
            }
            else
            {
                SetEmptyValues();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the OfferProducitivities EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOfferProducitivities(OfferProducitivity offerProducitivity)
 {
     base.AddObject("OfferProducitivities", offerProducitivity);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Create a new OfferProducitivity object.
 /// </summary>
 /// <param name="idOfferProducitivity">Initial value of the idOfferProducitivity property.</param>
 /// <param name="idOffer">Initial value of the idOffer property.</param>
 /// <param name="idPress">Initial value of the idPress property.</param>
 /// <param name="pressProducitivity_KG_MH">Initial value of the PressProducitivity_KG_MH property.</param>
 /// <param name="pressProducitivity_TON_MH">Initial value of the PressProducitivity_TON_MH property.</param>
 /// <param name="qCProducitivity_KG_MH">Initial value of the QCProducitivity_KG_MH property.</param>
 /// <param name="qCProducitivity_TON_MH">Initial value of the QCProducitivity_TON_MH property.</param>
 /// <param name="cOMetalProducitivity_KG_MH">Initial value of the COMetalProducitivity_KG_MH property.</param>
 /// <param name="cOMetalProducitivity_TON_MH">Initial value of the COMetalProducitivity_TON_MH property.</param>
 /// <param name="packagingProducitivity_KG_MH">Initial value of the PackagingProducitivity_KG_MH property.</param>
 /// <param name="packagingProducitivity_TON_MH">Initial value of the PackagingProducitivity_TON_MH property.</param>
 public static OfferProducitivity CreateOfferProducitivity(global::System.Int32 idOfferProducitivity, global::System.Int32 idOffer, global::System.Int32 idPress, global::System.Decimal pressProducitivity_KG_MH, global::System.Decimal pressProducitivity_TON_MH, global::System.Decimal qCProducitivity_KG_MH, global::System.Decimal qCProducitivity_TON_MH, global::System.Decimal cOMetalProducitivity_KG_MH, global::System.Decimal cOMetalProducitivity_TON_MH, global::System.Decimal packagingProducitivity_KG_MH, global::System.Decimal packagingProducitivity_TON_MH)
 {
     OfferProducitivity offerProducitivity = new OfferProducitivity();
     offerProducitivity.idOfferProducitivity = idOfferProducitivity;
     offerProducitivity.idOffer = idOffer;
     offerProducitivity.idPress = idPress;
     offerProducitivity.PressProducitivity_KG_MH = pressProducitivity_KG_MH;
     offerProducitivity.PressProducitivity_TON_MH = pressProducitivity_TON_MH;
     offerProducitivity.QCProducitivity_KG_MH = qCProducitivity_KG_MH;
     offerProducitivity.QCProducitivity_TON_MH = qCProducitivity_TON_MH;
     offerProducitivity.COMetalProducitivity_KG_MH = cOMetalProducitivity_KG_MH;
     offerProducitivity.COMetalProducitivity_TON_MH = cOMetalProducitivity_TON_MH;
     offerProducitivity.PackagingProducitivity_KG_MH = packagingProducitivity_KG_MH;
     offerProducitivity.PackagingProducitivity_TON_MH = packagingProducitivity_TON_MH;
     return offerProducitivity;
 }
Exemplo n.º 6
0
        public override Tuple<CallContext, string> UserControlSave()
        {


            bool isNewOffer = false;

            if (string.IsNullOrEmpty(this.hdnRowMasterKey.Value) || this.hdnRowMasterKey.Value == Constants.INVALID_ID_STRING)
            {
                isNewOffer = true;
                this.currentEntity = new Offer();
                this.currentEntityBeforeSave = new Offer();
                this.currentEntity.idCreateUser = Int32.Parse(this.ownerPage.UserProps.IdUser);
                this.currentEntity.dCreate = DateTime.Now;
                
                this.NeedReCalculation = false;

                SetDefaultValues();
            }
            else
            {
                this.CurrentEntityMasterID = this.hdnRowMasterKey.Value;
                this.currentEntity =  this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);
                this.currentEntityBeforeSave = this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);
                
                if (this.currentEntity == null)
                {
                    string falseResult = string.Format(BaseHelper.GetCaptionString("Entity_is_not_update_in_tab"), BaseHelper.GetCaptionString("InquiryData_Data"));

                    this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                    this.ownerPage.CallContext.Message = falseResult;

                    return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
                }
             
            }

            
            this.currentEntity.idModifyUser = Int32.Parse(this.ownerPage.UserProps.IdUser);
            this.currentEntity.dModify = DateTime.Now;

            this.currentEntity.Customer = this.tbxCustomer.Text.Trim();
            this.currentEntity.InquiryNumber = this.tbxInquiryNumber.Text.Trim();

            if (this.tbxOfferDate.TextAsDateParseExact.HasValue)
            {
                this.currentEntity.OfferDate = this.tbxOfferDate.TextAsDateParseExact.Value;
            }
            else
            {
                this.currentEntity.OfferDate = DateTime.MinValue;
            }

          
            this.currentEntity.WeightPerMeter = BaseHelper.ConvertToDecimalOrZero(this.tbxWeightPerMeter.Text);

            SetOfferDataDependOnWeightPerMeter(this.currentEntity);
            

            if (!ValidateRequiredField())
            {   
                return new Tuple<CallContext, string>(this.ownerPage.CallContext, string.Empty);
            }


            


            GeneralPage.LogDebug("this.currentEntity.OfferDate = " + this.currentEntity.OfferDate);


            #region ProfileSetting

            if (this.hdnIdProfileSetting.Value.IsNotNullOrEmpty())
            {
                this.currentEntity.idProfileSetting = Int32.Parse(this.hdnIdProfileSetting.Value);
            }
            else
            {
                string falseResult = "The field `Profile` is required!";

                this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                this.ownerPage.CallContext.Message = falseResult;

                return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
            }

           



            if (this.currentEntity.idNumberOfCavities.HasValue)
            {
                //this.currentEntity.idNumberOfCavities = this.ddlNumberOfCavities.SelectedValueNullINT;
                this.ddlNumberOfCavities.SelectedValue = this.currentEntity.idNumberOfCavities.ToString();
            }
         
            

            if (this.tbxValueForA.Enabled && this.tbxValueForA.Text.IsNotNullOrEmpty())
            {
                this.currentEntity.ValueForA =  BaseHelper.ConvertToIntOrZero(this.tbxValueForA.Text.Trim());
            }

            if (this.tbxValueForB.Enabled && this.tbxValueForB.Text.IsNotNullOrEmpty())
            {
                this.currentEntity.ValueForB =  BaseHelper.ConvertToIntOrZero(this.tbxValueForB.Text.Trim());
            }

            if (this.tbxValueForC.Enabled && this.tbxValueForC.Text.IsNotNullOrEmpty())
            {
                this.currentEntity.ValueForC =  BaseHelper.ConvertToIntOrZero(this.tbxValueForC.Text.Trim());
            }

            if (this.tbxValueForD.Enabled && this.tbxValueForD.Text.IsNotNullOrEmpty())
            {
                this.currentEntity.ValueForD =  BaseHelper.ConvertToIntOrZero(this.tbxValueForD.Text.Trim());
            }

            if (this.tbxValueForS.Enabled && this.tbxValueForS.Text.IsNotNullOrEmpty())
            {
                this.currentEntity.ValueForS =  BaseHelper.ConvertToDecimalOrZero(this.tbxValueForS.Text.Trim());
            }

            this.currentEntity.Diameter = BaseHelper.ConvertToIntOrMinValue(this.tbxDiameter.Text.Trim());
            this.currentEntity.DieDiameter = BaseHelper.ConvertToIntOrMinValue(this.tbxDieDiameter.Text.Trim());

            

            this.profileSetting = this.ownerPage.CostCalculationRef.GetProfileSettingById(this.currentEntity.idProfileSetting.ToString());

            try
            {
                if (profileSetting != null)
                {

                     AddPrimitives();
                     this.tmpDiameter = Convert.ToDouble( evalHelper.EvalExpression(profileSetting.DiameterFormula, primitives) );

                     this.tbxDiameter.Text = this.tmpDiameter.ToStringNotFormatted();
                     this.currentEntity.Diameter = BaseHelper.ConvertToDecimalOrZero(this.tbxDiameter.Text);
                    
                }
            }
            catch (Exception ex)
            {
                string falseResult = ex.Message;

                this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                this.ownerPage.CallContext.Message = falseResult;

                return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
            } 
            #endregion

            #region DieFormula Die Dieamter

            if (this.currentEntity.idNumberOfCavities.HasValue)
            {
                DieFormula dieFormula = this.ownerPage.CostCalculationRef.GetDieFormulaParams(
                                    profileSetting.idProfileCategory,
                                    profileSetting.idProfileType,
                                    this.currentEntity.idNumberOfCavities.Value,
                                    this.ownerPage.CallContext);


                if (dieFormula != null)
                {
                    AddPrimitives();

                    this.tmpDieDiameter = Convert.ToDouble(evalHelper.EvalExpression(dieFormula.DieFormulaText, primitives));
                    this.tbxDieDiameter.Text = tmpDieDiameter.ToStringNotFormatted();                     
                    this.currentEntity.DieDiameter= BaseHelper.ConvertToDecimalOrZero(this.tbxDieDiameter.Text);
               
                    string result = ValidateFormulas();


                    if (result.IsNotNullOrEmpty())
                    {
                        string falseResult = "Is not met either of the following conditions: " + result;

                        this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                        this.ownerPage.CallContext.Message = falseResult;

                        return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
                    }

                    

                }
                else
                {

                    string falseResult = BaseHelper.GetCaptionString("InquiryData_DieFormula_not_found");

                    this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                    this.ownerPage.CallContext.Message = falseResult;

                    return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
                }
            }
            else
            {
                    string falseResult = "The field `Number of cavities` is required!";

                    this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                    this.ownerPage.CallContext.Message = falseResult;

                    return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
            }
            
            #endregion

            #region DiePrice
            ICollection<AbstractSearch> searchCriteria = new List<AbstractSearch>();
            AddCustomSearchCriterias(searchCriteria);

            GeneralPage.LogDebug("this.currentEntity.OfferDate = " + this.currentEntity.OfferDate.ToString());
            List<DiePriceListDetailDataView> listDiePrice = this.ownerPage
                                                                .CostCalculationRef
                                                                .GetAllDiePriceListDetails(
                                                                        searchCriteria,
                                                                        this.currentEntity.OfferDate, 
                                                                        "Price", 
                                                                        Constants.SORTING_ASC
                                                                        );


             GeneralPage.LogDebug("listDiePrice.count = " + listDiePrice.Count);

            listDiePrice = listDiePrice.OrderBy(s => s.DimensionA).ThenByDescending(s => s.Price).ToList();

            DiePriceListDetailDataView tmpDiePrice = listDiePrice.FirstOrDefault();



            if (tmpDiePrice != null)
            {
                this.tbxDieDimensions.Text = tmpDiePrice.DimensionA_String;
                this.tbxDiePrice.Text = tmpDiePrice.Price.ToStringNotFormatted();
                this.tbxVendor.Text = tmpDiePrice.VendorName;
                this.tbxPriceListStr.Text = tmpDiePrice.DateFromString + "-" + tmpDiePrice.DateToString;


                this.currentEntity.DiePrice = tmpDiePrice.Price;
                this.currentEntity.CostOfDie = tmpDiePrice.Price;
                
                this.currentEntity.DieDimensions = tmpDiePrice.DimensionA;
                this.currentEntity.idDiePriceListDetail = tmpDiePrice.idDiePriceListDetail;

            }
            else
            {
                string falseResult = "No die price is found. Please change your offer data..";

                this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                this.ownerPage.CallContext.Message = falseResult;

                return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
            } 
            #endregion

          
            
           
            
            this.currentEntity.ValueForPin = BaseHelper.ConvertToIntOrZero(this.tbxPin.Text.Trim());
            this.currentEntity.ValueForPout = BaseHelper.ConvertToIntOrZero(this.tbxPout.Text.Trim());
            this.currentEntity.SDI = 75;
            
            this.currentEntity.Lifespan = this.currentEntity.Lifespan_Computable; 

            this.currentEntity.LME = BaseHelper.ConvertToDecimalOrZero(this.tbxLME.Text);
            this.currentEntity.PREMIUM = BaseHelper.ConvertToDecimalOrZero(this.tbxPREMIUM.Text);

            this.currentEntity.LengthOfFinalPC = BaseHelper.ConvertToDecimalOrZero(this.tbxLengthOfFinalPC.Text);
            

            this.currentEntity.WeightPerPC = BaseHelper.ConvertToDecimalOrZero(this.tbxWeightPerPC.Text);

            if (this.currentEntity.WeightPerPC == Decimal.Zero)
            {
                this.currentEntity.WeightPerPC = this.currentEntity.WeightPerPCComputable;
                this.tbxWeightPerPC.Text = this.currentEntity.WeightPerPC.ToStringNotFormatted();
            }
            
            
            this.currentEntity.PcsForTheWholeProject = BaseHelper.ConvertToDecimalOrZero(this.tbxPcsForTheWholeProject.Text);
            
            this.currentEntity.Tonnage = this.currentEntity.TonnageComputable;          

            
            this.currentEntity.DaysOfCredit = BaseHelper.ConvertToIntOrMinValue(this.tbxDaysOfCredit.Text);
            this.currentEntity.GrossMargin = BaseHelper.ConvertToDecimalOrZero(this.tbxGrossMargin.Text);
            this.currentEntity.SavingsRate = BaseHelper.ConvertToDecimalOrZero(this.tbxSavingsRate.Text);

            this.currentEntity.idCommision = this.ddlCommision.SelectedValueNullINT;
            this.currentEntity.idAgent= this.ddlAgent.SelectedValueNullINT;
            this.currentEntity.idAging= this.ddlAging.SelectedValueINT;

            this.currentEntity.idHardness= this.ddlHardness.SelectedValueINT;
            this.currentEntity.idStandardPackaging = this.ddlStandardPackaging.SelectedValueINT;

            this.currentEntity.idCalculationCommission= this.ddlCalculationCommission.SelectedValueNullINT;

            
            this.currentEntity.CostOfScrap = this.currentEntity.NetConsumptionComputable - this.currentEntity.MaterialComputable;
            this.currentEntity.AdministrationExpenses = BaseHelper.ConvertToDecimalOrZero(this.tbxAdministrationExpenses.Text);
            this.currentEntity.SalesExpenses = BaseHelper.ConvertToDecimalOrZero(this.tbxSalesExpenses.Text);
            this.currentEntity.FinancialFixedExpenses = BaseHelper.ConvertToDecimalOrZero(this.tbxFinancialFixedExpenses.Text);

            this.currentEntity.FinancialVariableExpenses= BaseHelper.ConvertToDecimalOrZero(this.tbxFinancialVariableExpenses.Text);

            this.currentEntity.TransportationCost = BaseHelper.ConvertToDecimalOrZero(this.tbxTransportationCost.Text);

            this.currentEntity.ActualTotalSalesPriceToCustomer = BaseHelper.ConvertToDecimalOrZero(this.tbxActualTotalSalesPriceToCustomer.Text);

            this.currentEntity.TargetPrice_EUR_TON = BaseHelper.ConvertToDecimalOrZero(this.tbxTargetPrice.Text);

            

            this.ownerPage.CallContext.CurrentConsumerID = this.ownerPage.UserProps.IdUser;


            PresetData();


           

            

            if (!ValidateBeforeSave())
            {   
                return new Tuple<CallContext, string>(this.ownerPage.CallContext, string.Empty);
            }
        
            ProductivityAndScrap ps = this.ownerPage.CostCalculationRef.GetProductivityAndScrapByDateActiveTo(this.currentEntity.OfferDate);

            ProductivityAndScrapDataView psDataView = this.ownerPage.CostCalculationRef.GetProductivityAndScrapByDateActiveToWithAvgData(this.currentEntity.OfferDate);

            ProductivityAndScrapDetail productivityAndScrapDetail = this.ownerPage.CostCalculationRef.GetProductivityAndScrapDetailByDateActiveToAndPressAndProfile(this.currentEntity.OfferDate, this.currentEntity.idPress.Value, this.currentEntity.idProfileSetting.Value);

            if (productivityAndScrapDetail != null)
            {
                this.currentEntity.ConsumptionRatio = 1 +  productivityAndScrapDetail.ScrapRate;
            }
            

            this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.OfferSave(this.currentEntity, this.ownerPage.CallContext);


            this.lbResultContext.Text = this.ownerPage.CallContext.Message;

            if (isNewOffer)
            {
                this.hdnRowMasterKey.Value = this.ownerPage.CallContext.EntityID;
                this.CurrentEntityMasterID = this.ownerPage.CallContext.EntityID;
            }
           
            if (this.ownerPage.CallContext.ResultCode == ETEMEnums.ResultEnum.Success)
            {

                 if (this.currentEntity.idPress.HasValue)
                {
                    this.tbxPress.Text = this.ownerPage.GetKeyValueByID(this.currentEntity.idPress.Value).Name;
                    this.ddlPress.SelectedValue = this.currentEntity.idPress.ToString();
                }
               
                this.NeedReCalculation = !this.currentEntity.Equals(this.currentEntityBeforeSave);
                
                this.hdnRowMasterKey.Value = this.ownerPage.CallContext.EntityID;
                this.CurrentEntityMasterID = this.ownerPage.CallContext.EntityID;


                #region OfferDataExpenseGroup
                if (NeedReCalculation)
                {
                    List<Expense> listGroupExpense = this.ownerPage.CostCalculationRef.GetListGroupExpense(this.currentEntity, this.ownerPage.CallContext);

                    if (listGroupExpense == null || listGroupExpense.Count == 0)
                    {
                      

                        this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;
                        this.ownerPage.CallContext.Message = "No press is found. Please change your offer data.";

                        return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
                    }
                    List<OfferDataExpenseGroup> listOfferDataExpenseGroup = new List<OfferDataExpenseGroup>();

                    foreach (Expense expense in listGroupExpense)
                    {
                        OfferDataExpenseGroup odeg = new OfferDataExpenseGroup();

                        odeg.idOffer = Int32.Parse(this.ownerPage.CallContext.EntityID);
                        odeg.idSAPData = expense.IdSAPData;
                        odeg.idCostCenter = expense.CostCenter.idKeyValue;
                        odeg.idExpensesType = expense.ExpenseGroup.idKeyValue;
                        odeg.ValueData = expense.ExpenseValue_MH;
                        listOfferDataExpenseGroup.Add(odeg);
                    }


                    this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.OfferDataExpenseGroupDelete(this.currentEntity.idOffer, this.ownerPage.CallContext);
                    this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.OfferDataExpenseGroupSave(listOfferDataExpenseGroup, this.ownerPage.CallContext);
                } 
                #endregion

                #region OfferProducitivity
                OfferProducitivity offerProducitivity = this.ownerPage.CostCalculationRef.GetOfferProducitivityByOfferID(this.CurrentEntityMasterID);

                if (offerProducitivity == null)
                {
                    offerProducitivity = new OfferProducitivity();
                    offerProducitivity.idOffer = Int32.Parse(this.CurrentEntityMasterID);
                }



                KeyValue kvSelectPress, kvPackaging;
                List<KeyValue> listPress = this.ownerPage.GetAllKeyValueByKeyTypeIntCode("CostCenter").Where(p => p.DefaultValue1 == "Press").ToList();
                List<KeyValue> listCOMETAL = this.ownerPage.GetAllKeyValueByKeyTypeIntCode("CostCenter").Where(p => p.DefaultValue1 == "COMETAL").ToList();

                List<OfferDataExpenseGroupView> listOfferDataExpenseGroupView = this.ownerPage.CostCalculationRef.GetAllOfferDataExpenseGroupByOffer(offerProducitivity.idOffer);

                 kvPackaging = this.ownerPage.GetKeyValueByIntCode("CostCenter", "Packaging");

                if (listOfferDataExpenseGroupView.Count > 0)
                {

                    OfferDataExpenseGroupView odegvPress = (from e in listOfferDataExpenseGroupView
                                                            join p in listPress on e.idCostCenter equals p.idKeyValue
                                                            select e).FirstOrDefault();






                    offerProducitivity.idPress = odegvPress.idCostCenter;

                   
                    kvSelectPress = listPress.Where(p => p.idKeyValue == offerProducitivity.idPress).FirstOrDefault();


                    OfferDataExpenseGroupView odegvCOMETAL = (from e in listOfferDataExpenseGroupView
                                                              join p in listCOMETAL on e.idCostCenter equals p.idKeyValue
                                                              select e).FirstOrDefault();

                    if (odegvCOMETAL != null)
                    {
                        offerProducitivity.idCOMetal = odegvCOMETAL.idCostCenter;
                    }
                    else
                    {
                        offerProducitivity.idCOMetal = null;
                    }

                    if (productivityAndScrapDetail != null && productivityAndScrapDetail.ProductivityKGh.HasValue)
                    {
                        offerProducitivity.PressProducitivity_KG_MH = productivityAndScrapDetail.ProductivityKGh.Value;
                    }
                    else
                    {
                        offerProducitivity.PressProducitivity_KG_MH = Decimal.Zero;
                    }

                    



                    if (offerProducitivity.PressProducitivity_KG_MH > BaseHelper.ConvertToDecimalOrZero(kvSelectPress.DefaultValue3))
                    {
                        offerProducitivity.PressProducitivity_KG_MH = BaseHelper.ConvertToDecimalOrZero(kvSelectPress.DefaultValue3);
                    }


                    offerProducitivity.PressProducitivity_TON_MH = offerProducitivity.PressProducitivity_TON_MH_Computable;

                    offerProducitivity.COMetalProducitivity_KG_MH = offerProducitivity.PressProducitivity_KG_MH;//Productivity for QC and COMETAL is equal to productivity for press
                    offerProducitivity.COMetalProducitivity_TON_MH = offerProducitivity.COMetalProducitivity_TON_MH_Computable;

                    offerProducitivity.QCProducitivity_KG_MH = offerProducitivity.PressProducitivity_KG_MH;//Productivity for QC and COMETAL is equal to productivity for press
                    offerProducitivity.QCProducitivity_TON_MH = offerProducitivity.QCProducitivity_TON_MH_Computable;


                }


                if (NeedReCalculation)
                {


                    List<SAPDataQuantityDataView> listSAPDataQuantities = new List<SAPDataQuantityDataView>();


                    ICollection<AbstractSearch> searchCriteriaSAPDataQuantity = new List<AbstractSearch>();

                    searchCriteriaSAPDataQuantity.Add(
                      new NumericSearch
                      {
                          Comparator = NumericComparators.Equal,
                          Property = "idCostCenter",
                          SearchTerm = this.ownerPage.GetKeyValueByIntCode("CostCenter", "Packaging").idKeyValue
                      });


                    listSAPDataQuantities = base.CostCalculationRef.GetAllSAPDataQuantity(searchCriteriaSAPDataQuantity,
                                                                                          this.currentEntity.OfferDate,
                                                                                          base.GridViewSortExpression,
                                                                                          base.GridViewSortDirection);

                    KeyValue kvProductionQuantity = this.ownerPage.GetKeyValueByIntCode("QuantityType", "ProductionQuantity");
                    KeyValue kvMachineHours = this.ownerPage.GetKeyValueByIntCode("QuantityType", "MachineHours");

                    Decimal productionQuantity = listSAPDataQuantities.FirstOrDefault(q => q.idQuantityType == kvProductionQuantity.idKeyValue).ValueData;
                    Decimal machineHours = listSAPDataQuantities.FirstOrDefault(q => q.idQuantityType == kvMachineHours.idKeyValue).ValueData;



                    if (productionQuantity != Decimal.Zero && machineHours != Decimal.Zero)
                    {
                        offerProducitivity.PackagingProducitivity_KG_MH = productionQuantity / machineHours;

                        offerProducitivity.PackagingMachineHours = machineHours;
                        offerProducitivity.PackagingProductionQuantity = productionQuantity;
                    }
                    else
                    {
                        offerProducitivity.PackagingProducitivity_KG_MH = BaseHelper.ConvertToDecimalOrZero((BasicPage.GetSettingByCode(ETEMEnums.AppSettings.PackagingProducitivity_KG_MH).SettingValue));
                    }



                    if (offerProducitivity.PackagingProducitivity_KG_MH > BaseHelper.ConvertToDecimalOrZero(kvPackaging.DefaultValue3))
                    {
                        offerProducitivity.PackagingProducitivity_KG_MH = BaseHelper.ConvertToDecimalOrZero(kvPackaging.DefaultValue3);
                    }


                    offerProducitivity.PackagingProducitivity_TON_MH = offerProducitivity.PackagingProducitivity_TON_MH_Computable;


                    


                    this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.OfferProducitivitySave(offerProducitivity, this.ownerPage.CallContext);

                    ProducitivityData producitivityData = FindControlById(this.Page, "ProducitivityData") as ProducitivityData;

                    if (producitivityData != null)
                    {
                        producitivityData.CurrentEntityMasterID = this.CurrentEntityMasterID;
                        producitivityData.SetHdnField(this.CurrentEntityMasterID);
                        producitivityData.UserControlLoad();
                    }
                }

               
                
                #endregion

                ddlCommision_SelectedIndexChanged(null, null);
                ddlCalculationCommission_SelectedIndexChanged(null, null);

                this.currentEntity =  this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);

               

                this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.OfferSave(this.currentEntity, this.ownerPage.CallContext);
                
                this.currentEntity =  this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);

                
                this.currentEntity.LoadProductCostResult();
                this.currentEntity.LoadOfferOverviewResult();


                this.tbxSGAsAndFin_EUR_TON.Text = this.currentEntity.SGAsAndFin_EUR_TON_Computable.ToStringNotFormatted();
                this.tbxSGAsAndFin_EUR.Text = this.currentEntity.SGAsAndFin_EUR_Computable.ToStringNotFormatted();

                 this.tbxFinancialVariableExpenses.Text = this.currentEntity.Financial_variable_Computable.ToStringNotFormatted();
                this.currentEntity.FinancialVariableExpenses = this.currentEntity.Financial_variable_Computable;
                this.currentEntity.TotalSalesPrice = this.currentEntity.TotalSalesPrice_EUR_Computable;

                this.tbxExtrusion_EUR_TON.Text = currentEntity.Extrusion_EUR_TON_Computable.ToStringFormatted();
                this.tbxExtrusion_EUR.Text = currentEntity.Extrusion_EUR_Computable.ToStringFormatted();

                this.tbxPackaging_EUR_TON.Text = currentEntity.Packaging_EUR_TON_Computable.ToStringFormatted();
                this.tbxPackaging_EUR.Text = currentEntity.Packaging_EUR_Computable.ToStringFormatted();
                
                this.tbxTotalSalesPrice_EUR_TON.Text = this.currentEntity.TotalSalesPrice_EUR_TON_Computable.ToStringFormatted();
                this.tbxTotalSalesPrice_EUR.Text = this.currentEntity.TotalSalesPrice_EUR_Computable.ToStringFormatted();

                this.currentEntity.TotalSalesPrice = this.currentEntity.TotalSalesPrice_EUR_Computable;

                this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.OfferSave(this.currentEntity, this.ownerPage.CallContext);
                
                this.currentEntity =  this.ownerPage.CostCalculationRef.GetOfferByID(this.CurrentEntityMasterID);
                
                PresetData();


            }

           

            CheckIfResultIsSuccess();

            return new Tuple<CallContext, string>(this.ownerPage.CallContext, BaseHelper.GetCaptionString("InquiryData_Data"));
        }