Пример #1
0
        public override void UserControlLoad()
        {
            SetEmptyValues();
            base.ClearResultContext(this.lbResultContext);

            if (this.ownerPage == null)
            {
                throw new UMSException("Current Page is null or is not inheritor of BasicPage.");
            }

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

            InitLoadControls();

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

            if (this.currentEntity != null)
            {
                this.SetHdnField(this.currentEntity.idProductivityAndScrapDetail.ToString());

                this.tbxDateFrom.SetTxbDateTimeValue(this.currentEntity.ProductivityAndScrap.DateFrom);
                this.tbxDateTo.SetTxbDateTimeValue(this.currentEntity.ProductivityAndScrap.DateTo);
                this.tbxStatus.Text = this.currentEntity.ProductivityAndScrap.Status;

                BaseHelper.CheckAndSetSelectedValue(this.ddlCostCenter.DropDownListCTRL, this.currentEntity.idCostCenter.ToString(), false);
                BaseHelper.CheckAndSetSelectedValue(this.ddlProfileSetting.DropDownListCTRL, this.currentEntity.idProfileSetting.ToString(), false);

                this.tbxSumOfHours.Text       = this.currentEntity.SumOfHours_RoundString;
                this.tbxSumOfConsumption.Text = this.currentEntity.SumOfConsumption_RoundString;
                this.tbxSumOfProduction.Text  = this.currentEntity.SumOfProduction_RoundString;

                this.tbxProductivityKGh.Text = this.currentEntity.ProductivityKGh_RoundString;
                this.tbxScrapRate.Text       = this.currentEntity.ScrapRatePercent_RoundString;

                base.ClearResultContext(this.lbResultContext);
            }
            else
            {
                SetEmptyValues();
            }

            this.pnlFormData.Visible = true;
            this.pnlFormData.Focus();
        }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ownerPage.CheckUserActionPermission(ETEMEnums.SecuritySettings.ProductivityAndScrapSave, false))
            {
                return;
            }

            bool isNew = true;

            if (string.IsNullOrEmpty(this.hdnRowMasterKey.Value) || this.hdnRowMasterKey.Value == Constants.INVALID_ID_STRING)
            {
                this.currentEntity = new ProductivityAndScrapDetail();
            }
            else
            {
                this.currentEntity = this.ownerPage.CostCalculationRef.GetProductivityAndScrapDetailById(this.hdnRowMasterKey.Value);

                if (this.currentEntity == null)
                {
                    this.ownerPage.CallContext.ResultCode = ETEMEnums.ResultEnum.Error;

                    base.AddMessage(this.lbResultContext, string.Format("Entity `ProductivityAndScrapDetail` not found by ID ({0})!", this.hdnRowMasterKey.Value));

                    return;
                }

                isNew = false;
            }

            this.currentEntity.idCostCenter     = this.ddlCostCenter.SelectedValueINT;
            this.currentEntity.idProfileSetting = this.ddlProfileSetting.SelectedValueINT;
            this.currentEntity.SumOfHours       = BaseHelper.ConvertToDecimalOrMinValue(this.tbxSumOfHours.Text.Trim());
            this.currentEntity.SumOfConsumption = BaseHelper.ConvertToDecimalOrMinValue(this.tbxSumOfConsumption.Text.Trim());
            this.currentEntity.SumOfProduction  = BaseHelper.ConvertToDecimalOrMinValue(this.tbxSumOfProduction.Text.Trim());

            decimal productivityKGh = decimal.Zero;
            decimal scrapRate       = decimal.Zero;

            if (this.currentEntity.SumOfHours.HasValue && this.currentEntity.SumOfHours.Value != 0 &&
                this.currentEntity.SumOfProduction.HasValue)
            {
                productivityKGh = Math.Round((this.currentEntity.SumOfProduction.Value / this.currentEntity.SumOfHours.Value), 9, MidpointRounding.AwayFromZero);

                this.currentEntity.ProductivityKGh = productivityKGh;

                this.tbxProductivityKGh.Text = this.currentEntity.ProductivityKGh_RoundString;
            }
            if (this.currentEntity.SumOfConsumption.HasValue && this.currentEntity.SumOfConsumption.Value != 0 &&
                this.currentEntity.SumOfProduction.HasValue)
            {
                scrapRate = Math.Round(((this.currentEntity.SumOfConsumption.Value - this.currentEntity.SumOfProduction.Value) / this.currentEntity.SumOfConsumption.Value), 9, MidpointRounding.AwayFromZero);

                this.currentEntity.ScrapRate = scrapRate;

                this.tbxScrapRate.Text = this.currentEntity.ScrapRate_RoundString;
            }

            this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.ProductivityAndScrapDetailSave(new List <ProductivityAndScrapDetail>()
            {
                this.currentEntity
            }, this.ownerPage.CallContext);

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

                base.AddMessage(this.lbResultContext, this.ownerPage.CallContext.Message);
            }
            else
            {
                if (!ShowErrors(new List <CallContext>()
                {
                    this.ownerPage.CallContext
                }))
                {
                    return;
                }
            }

            if (this.ownerPage is ProductivityAndScrapDetailList)
            {
                ((ProductivityAndScrapDetailList)this.ownerPage).LoadFilteredList();
            }
        }
Пример #3
0
        public CallContext ImportProductivityAndScrapCostData(string fileFullName, int idEntity, CallContext resultContext)
        {
            try
            {
                resultContext.ResultCode = ETEMEnums.ResultEnum.Error;

                FileInfo excelFile = new FileInfo(fileFullName);

                using (ExcelPackage package = new ExcelPackage(excelFile))
                {
                    int currRow = 1;
                    int currCol = 0;

                    bool    res;
                    decimal resultParseDecimal;
                    int     resultParseInt;

                    ExcelWorksheet workSheet = package.Workbook.Worksheets[1];

                    if (workSheet == null)
                    {
                        resultContext.Message = "Error! No Excel work sheet with `Productivity and Scrap` data!";
                        return(resultContext);
                    }

                    ProductivityAndScrap productivityAndScrap = this.GetEntityById(idEntity);

                    if (productivityAndScrap == null)
                    {
                        resultContext.Message = "Entity `ProductivityAndScrap` not found by ID (`" + idEntity + "`)!";
                        return(resultContext);
                    }

                    List <KeyValue>       listKeyValuesToCostCenterPresses = new List <KeyValue>();
                    List <ProfileSetting> listProfileSettings = new List <ProfileSetting>();

                    List <string> listKeyTypeIntCodes = new List <string>()
                    {
                        ETEMEnums.KeyTypeEnum.CostCenter.ToString()
                    };

                    listKeyValuesToCostCenterPresses = (from kv in this.dbContext.KeyValues
                                                        join kt in this.dbContext.KeyTypes on kv.idKeyType equals kt.idKeyType
                                                        where listKeyTypeIntCodes.Contains(kt.KeyTypeIntCode)
                                                        select kv).ToList <KeyValue>();

                    listProfileSettings = (from ps in this.dbContext.ProfileSettings
                                           select ps).ToList();

                    List <ProductivityAndScrapDetail> listProductivityAndScrapDetailOld = new List <ProductivityAndScrapDetail>();
                    List <ProductivityAndScrapDetail> listProductivityAndScrapDetailNew = new List <ProductivityAndScrapDetail>();

                    listProductivityAndScrapDetailOld = (from psd in this.dbContext.ProductivityAndScrapDetails
                                                         where psd.idProductivityAndScrap == productivityAndScrap.idProductivityAndScrap
                                                         select psd).ToList <ProductivityAndScrapDetail>();

                    Dictionary <string, string> dictErrorsProductivityAndScrapDetails = new Dictionary <string, string>();

                    ProductivityAndScrapDetail newProductivityAndScrapDetail = new ProductivityAndScrapDetail();

                    bool hasNotErrorInRow = true;

                    string rangeValueStr = string.Empty;

                    ExcelRange range;

                    for (; ;)
                    {
                        currRow++;

                        hasNotErrorInRow = true;

                        if (string.IsNullOrWhiteSpace(workSheet.Cells[currRow, 1].Text) &&
                            string.IsNullOrWhiteSpace(workSheet.Cells[currRow, 2].Text) &&
                            string.IsNullOrWhiteSpace(workSheet.Cells[currRow, 3].Text) &&
                            string.IsNullOrWhiteSpace(workSheet.Cells[currRow, 4].Text) &&
                            string.IsNullOrWhiteSpace(workSheet.Cells[currRow, 5].Text) &&
                            string.IsNullOrWhiteSpace(workSheet.Cells[currRow, 6].Text))
                        {
                            break;
                        }

                        newProductivityAndScrapDetail = new ProductivityAndScrapDetail();

                        newProductivityAndScrapDetail.idProductivityAndScrap = idEntity;

                        currCol       = 1;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString().Replace(" ", "") : string.Empty);

                        var kvPress = listKeyValuesToCostCenterPresses.Where(w => w.DefaultValue4 != null && w.DefaultValue4.Replace(" ", "").Trim().ToUpper() == rangeValueStr.Trim().ToUpper()).FirstOrDefault();

                        if (kvPress != null)
                        {
                            newProductivityAndScrapDetail.idCostCenter = kvPress.idKeyValue;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            //if (dictErrorsProductivityAndScrapDetails.ContainsKey("CostCenterPresses"))
                            //{
                            //    dictErrorsProductivityAndScrapDetails["CostCenterPresses"] += "," + currRow;
                            //}
                            //else
                            //{
                            //    dictErrorsProductivityAndScrapDetails.Add("CostCenterPresses", currRow.ToString());
                            //}
                        }

                        currCol       = 2;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString().Replace(" ", "") : string.Empty);

                        var profileSetting = listProfileSettings.Where(w => w.ProfileNameSAP != null && w.ProfileNameSAP.Replace(" ", "").Trim().ToUpper() == rangeValueStr.Trim().ToUpper()).FirstOrDefault();

                        if (profileSetting != null)
                        {
                            newProductivityAndScrapDetail.idProfileSetting = profileSetting.idProfileSetting;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            //if (dictErrorsProductivityAndScrapDetails.ContainsKey("ProfileSetting"))
                            //{
                            //    dictErrorsProductivityAndScrapDetails["ProfileSetting"] += "," + currRow;
                            //}
                            //else
                            //{
                            //    dictErrorsProductivityAndScrapDetails.Add("ProfileSetting", currRow.ToString());
                            //}
                        }

                        currCol       = 3;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Decimal.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 9), out resultParseDecimal);
                        if (res)
                        {
                            newProductivityAndScrapDetail.SumOfHours = resultParseDecimal;
                        }
                        else
                        {
                            newProductivityAndScrapDetail.SumOfHours = decimal.Zero;
                        }

                        currCol       = 4;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Decimal.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 9), out resultParseDecimal);
                        if (res)
                        {
                            newProductivityAndScrapDetail.SumOfConsumption = resultParseDecimal;
                        }
                        else
                        {
                            newProductivityAndScrapDetail.SumOfConsumption = decimal.Zero;
                        }

                        currCol       = 5;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Decimal.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 9), out resultParseDecimal);
                        if (res)
                        {
                            newProductivityAndScrapDetail.SumOfProduction = resultParseDecimal;
                        }
                        else
                        {
                            newProductivityAndScrapDetail.SumOfProduction = decimal.Zero;
                        }

                        currCol       = 7;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Decimal.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 9), out resultParseDecimal);
                        if (res)
                        {
                            newProductivityAndScrapDetail.ProductivityKGh = resultParseDecimal;
                        }
                        else
                        {
                            newProductivityAndScrapDetail.ProductivityKGh = decimal.Zero;
                        }

                        currCol       = 8;
                        range         = workSheet.Cells[currRow, currCol];
                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Decimal.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 9), out resultParseDecimal);
                        if (res)
                        {
                            newProductivityAndScrapDetail.ScrapRate = resultParseDecimal;
                        }
                        else
                        {
                            newProductivityAndScrapDetail.ScrapRate = decimal.Zero;
                        }

                        var checkProductivityAndScrapDetail = listProductivityAndScrapDetailOld.Where(w => w.idCostCenter == newProductivityAndScrapDetail.idCostCenter &&
                                                                                                      w.idProfileSetting == newProductivityAndScrapDetail.idProfileSetting).ToList();

                        if (checkProductivityAndScrapDetail.Count > 0)
                        {
                            hasNotErrorInRow = false;
                            if (dictErrorsProductivityAndScrapDetails.ContainsKey("DuplicateProductivityAndScrapDetail"))
                            {
                                dictErrorsProductivityAndScrapDetails["DuplicateProductivityAndScrapDetail"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsProductivityAndScrapDetails.Add("DuplicateProductivityAndScrapDetail", currRow.ToString());
                            }
                        }

                        if (hasNotErrorInRow)
                        {
                            listProductivityAndScrapDetailNew.Add(newProductivityAndScrapDetail);
                        }
                    }

                    if (dictErrorsProductivityAndScrapDetails.Count == 0)
                    {
                        resultContext = new ProductivityAndScrapDetailBL().EntitySave <ProductivityAndScrapDetail>(listProductivityAndScrapDetailNew, resultContext);
                        if (resultContext.ResultCode == ETEMEnums.ResultEnum.Success)
                        {
                            resultContext.ResultCode = ETEMEnums.ResultEnum.Success;
                            resultContext.Message    = "The productivity and scrap cost data have been imported successfully!";
                        }
                        else
                        {
                            resultContext.ResultCode = ETEMEnums.ResultEnum.Error;
                            resultContext.Message    = "Error import the productivity and scrap cost data!";
                        }
                    }
                    else
                    {
                        List <string> listErrors = new List <string>();

                        if (dictErrorsProductivityAndScrapDetails.ContainsKey("CostCenterPresses"))
                        {
                            listErrors.Add("Error! The field `PRESS - Short Text` is missing or in wrong format, Rows (" + dictErrorsProductivityAndScrapDetails["CostCenterPresses"] + ")!");
                        }
                        if (dictErrorsProductivityAndScrapDetails.ContainsKey("ProfileSetting"))
                        {
                            listErrors.Add("Error! The field `SHAPE` is missing or in wrong format, Rows (" + dictErrorsProductivityAndScrapDetails["ProfileSetting"] + ")!");
                        }
                        if (dictErrorsProductivityAndScrapDetails.ContainsKey("DuplicateProductivityAndScrapDetail"))
                        {
                            listErrors.Add("Error! The selected file includes productivity and scrap cost data with duplicate data in the database, Rows (" + dictErrorsProductivityAndScrapDetails["DuplicateProductivityAndScrapDetail"] + ")!");
                        }

                        resultContext.Message = string.Join(Constants.ERROR_MESSAGES_SEPARATOR, listErrors);
                    }
                }
            }
            catch (Exception ex)
            {
                resultContext.Message = "Error import the productivity and scrap cost data!";

                BaseHelper.Log("Error import entities `ProductivityAndScrapDetail`!");
                BaseHelper.Log(ex.Message);
                BaseHelper.Log(ex.StackTrace);
            }

            return(resultContext);
        }