Exemplo n.º 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.GetDiePriceListDetailById(this.CurrentEntityMasterID);

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

                BaseHelper.CheckAndSetSelectedValue(this.ddlVendor.DropDownListCTRL, this.currentEntity.idDiePriceList.ToString(), false);
                BaseHelper.CheckAndSetSelectedValue(this.ddlNumberOfCavities.DropDownListCTRL, this.currentEntity.idNumberOfCavities.ToString(), false);
                BaseHelper.CheckAndSetSelectedValue(this.ddlProfileCategory.DropDownListCTRL, this.currentEntity.idProfileCategory.ToString(), false);
                BaseHelper.CheckAndSetSelectedValue(this.ddlProfileComplexity.DropDownListCTRL, this.currentEntity.idProfileComplexity.ToString(), false);
                this.tbxDimensionA.Text = this.currentEntity.DimensionA_String;
                this.tbxDimensionB.Text = this.currentEntity.DimensionB_String;
                this.tbxDiePrice.Text   = this.currentEntity.PriceRoundString;
                this.tbxLifespan.Text   = this.currentEntity.LifespanRoundString;

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

            this.pnlFormData.Visible = true;
            this.pnlFormData.Focus();
        }
Exemplo n.º 2
0
        public CallContext ImportDiePriceListDetails(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.FirstOrDefault();

                    if (workSheet == null)
                    {
                        resultContext.Message = "Error! No Excel work sheet!";
                        return(resultContext);
                    }

                    DiePriceList diePriceList = this.GetEntityById(idEntity);

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

                    List <string> listKeyTypeIntCodes = new List <string>()
                    {
                        ETEMEnums.KeyTypeEnum.NumberOfCavities.ToString(),
                                  ETEMEnums.KeyTypeEnum.ProfileCategory.ToString(),
                                  ETEMEnums.KeyTypeEnum.ProfileComplexity.ToString()
                    };

                    List <KeyValueDataView> listKeyValuesToDiePriceListDetail = new List <KeyValueDataView>();
                    List <KeyValueDataView> listKeyValueNumberOfCavities      = new List <KeyValueDataView>();
                    List <KeyValueDataView> listKeyValueProfileCategory       = new List <KeyValueDataView>();
                    List <KeyValueDataView> listKeyValueProfileComplexity     = new List <KeyValueDataView>();

                    listKeyValuesToDiePriceListDetail = (from kv in this.dbContext.KeyValues
                                                         join kt in this.dbContext.KeyTypes on kv.idKeyType equals kt.idKeyType
                                                         where listKeyTypeIntCodes.Contains(kt.KeyTypeIntCode)
                                                         select new KeyValueDataView
                    {
                        idKeyValue = kv.idKeyValue,
                        Name = kv.Name,
                        NameEN = kv.NameEN,
                        DefaultValue1 = kv.DefaultValue1,
                        KeyValueIntCode = kv.KeyValueIntCode,
                        KeyTypeIntCode = kt.KeyTypeIntCode
                    }
                                                         ).ToList <KeyValueDataView>();

                    listKeyValueNumberOfCavities  = listKeyValuesToDiePriceListDetail.Where(w => w.KeyTypeIntCode == ETEMEnums.KeyTypeEnum.NumberOfCavities.ToString()).ToList();
                    listKeyValueProfileCategory   = listKeyValuesToDiePriceListDetail.Where(w => w.KeyTypeIntCode == ETEMEnums.KeyTypeEnum.ProfileCategory.ToString()).ToList();
                    listKeyValueProfileComplexity = listKeyValuesToDiePriceListDetail.Where(w => w.KeyTypeIntCode == ETEMEnums.KeyTypeEnum.ProfileComplexity.ToString()).ToList();

                    List <DiePriceListDetail> listDiePriceListDetailsOld = new List <DiePriceListDetail>();
                    List <DiePriceListDetail> listDiePriceListDetailsNew = new List <DiePriceListDetail>();

                    listDiePriceListDetailsOld = (from dpld in this.dbContext.DiePriceListDetails
                                                  where dpld.idDiePriceList == diePriceList.idDiePriceList
                                                  select dpld).ToList <DiePriceListDetail>();

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

                    DiePriceListDetail newDiePriceListDetail = new DiePriceListDetail();

                    bool hasNotErrorInRow = true;

                    string rangeValueStr = string.Empty;

                    ExcelRange range;

                    for (; ;)
                    {
                        currRow++;

                        hasNotErrorInRow = true;

                        currCol = 1;
                        range   = workSheet.Cells[currRow, currCol];
                        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;
                        }

                        newDiePriceListDetail = new DiePriceListDetail();

                        newDiePriceListDetail.idDiePriceList = idEntity;

                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        var numberOfCavities = listKeyValueNumberOfCavities.Where(w => w.DefaultValue1.Trim().ToUpper() == rangeValueStr.Trim().ToUpper()).FirstOrDefault();

                        if (numberOfCavities != null)
                        {
                            newDiePriceListDetail.idNumberOfCavities = numberOfCavities.idKeyValue;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            if (dictErrorsRows.ContainsKey("NumberOfCavities"))
                            {
                                dictErrorsRows["NumberOfCavities"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("NumberOfCavities", currRow.ToString());
                            }
                        }

                        currCol++;
                        range = workSheet.Cells[currRow, currCol];

                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        string[] arrRangeValue = rangeValueStr.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);

                        string profileComplexityVal = (arrRangeValue.Length > 0 ? arrRangeValue[0] : string.Empty);
                        string profileCategoryVal   = (arrRangeValue.Length > 1 ? arrRangeValue[1] : string.Empty);

                        var profileComplexity = listKeyValueProfileComplexity.Where(w => w.Name.Trim().ToUpper() == profileComplexityVal.Trim().ToUpper()).FirstOrDefault();

                        if (profileComplexity != null)
                        {
                            newDiePriceListDetail.idProfileComplexity = profileComplexity.idKeyValue;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            if (dictErrorsRows.ContainsKey("ProfileComplexity"))
                            {
                                dictErrorsRows["ProfileComplexity"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("ProfileComplexity", currRow.ToString());
                            }
                        }

                        var profileCategory = listKeyValueProfileCategory.Where(w => w.Name.Trim().ToUpper() == profileCategoryVal.Trim().ToUpper()).FirstOrDefault();

                        if (profileCategory != null)
                        {
                            newDiePriceListDetail.idProfileCategory = profileCategory.idKeyValue;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            if (dictErrorsRows.ContainsKey("ProfileCategory"))
                            {
                                dictErrorsRows["ProfileCategory"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("ProfileCategory", currRow.ToString());
                            }
                        }

                        currCol++;

                        currCol++;
                        range = workSheet.Cells[currRow, currCol];

                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Decimal.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 2), out resultParseDecimal);
                        if (res)
                        {
                            newDiePriceListDetail.Price = resultParseDecimal;
                        }
                        else
                        {
                            hasNotErrorInRow            = false;
                            newDiePriceListDetail.Price = decimal.MinValue;

                            if (dictErrorsRows.ContainsKey("Price"))
                            {
                                dictErrorsRows["Price"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("Price", currRow.ToString());
                            }
                        }

                        currCol++;
                        range = workSheet.Cells[currRow, currCol];

                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Int32.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 0), out resultParseInt);
                        if (res)
                        {
                            newDiePriceListDetail.DimensionA = resultParseInt;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            newDiePriceListDetail.DimensionA = int.MinValue;

                            if (dictErrorsRows.ContainsKey("DimensionA"))
                            {
                                dictErrorsRows["DimensionA"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("DimensionA", currRow.ToString());
                            }
                        }

                        currCol++;
                        range = workSheet.Cells[currRow, currCol];

                        rangeValueStr = (range.Value != null ? range.Value.ToString() : string.Empty);

                        res = Int32.TryParse(rangeValueStr, NumberStyles.Any, BaseHelper.GetNumberFormatInfo("", ".", 0), out resultParseInt);
                        if (res)
                        {
                            newDiePriceListDetail.DimensionB = resultParseInt;
                        }
                        else
                        {
                            hasNotErrorInRow = false;
                            newDiePriceListDetail.DimensionB = int.MinValue;

                            if (dictErrorsRows.ContainsKey("DimensionB"))
                            {
                                dictErrorsRows["DimensionB"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("DimensionB", currRow.ToString());
                            }
                        }

                        newDiePriceListDetail.Lifespan = decimal.Zero;

                        var checkDiePriceListDetail = listDiePriceListDetailsOld.Where(w => w.idNumberOfCavities == newDiePriceListDetail.idNumberOfCavities &&
                                                                                       w.idProfileComplexity == newDiePriceListDetail.idProfileComplexity &&
                                                                                       w.idProfileCategory == newDiePriceListDetail.idProfileCategory &&
                                                                                       w.Price == newDiePriceListDetail.Price &&
                                                                                       w.DimensionA == newDiePriceListDetail.DimensionA &&
                                                                                       w.DimensionB == newDiePriceListDetail.DimensionB).ToList();

                        if (checkDiePriceListDetail.Count > 0)
                        {
                            hasNotErrorInRow = false;
                            if (dictErrorsRows.ContainsKey("DuplicateOld"))
                            {
                                dictErrorsRows["DuplicateOld"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("DuplicateOld", currRow.ToString());
                            }
                        }

                        checkDiePriceListDetail = listDiePriceListDetailsNew.Where(w => w.idNumberOfCavities == newDiePriceListDetail.idNumberOfCavities &&
                                                                                   w.idProfileComplexity == newDiePriceListDetail.idProfileComplexity &&
                                                                                   w.idProfileCategory == newDiePriceListDetail.idProfileCategory &&
                                                                                   w.Price == newDiePriceListDetail.Price &&
                                                                                   w.DimensionA == newDiePriceListDetail.DimensionA &&
                                                                                   w.DimensionB == newDiePriceListDetail.DimensionB).ToList();

                        if (checkDiePriceListDetail.Count > 0)
                        {
                            hasNotErrorInRow = false;
                            if (dictErrorsRows.ContainsKey("DuplicateNew"))
                            {
                                dictErrorsRows["DuplicateNew"] += "," + currRow;
                            }
                            else
                            {
                                dictErrorsRows.Add("DuplicateNew", currRow.ToString());
                            }
                        }

                        if (hasNotErrorInRow)
                        {
                            listDiePriceListDetailsNew.Add(newDiePriceListDetail);
//                            this.dbContext.DiePriceListDetails.AddObject(newDiePriceListDetail);
                        }
                    }

                    if (dictErrorsRows.Count == 0)
                    {
                        resultContext = new DiePriceListDetailBL().EntitySave <DiePriceListDetail>(listDiePriceListDetailsNew, resultContext);

                        if (resultContext.ResultCode == ETEMEnums.ResultEnum.Success)
                        {
                            resultContext.ResultCode = ETEMEnums.ResultEnum.Success;
                            resultContext.Message    = "The details for current `Die Price List by Vendor` have been imported successfully!";
                        }
                        else
                        {
                            resultContext.ResultCode = ETEMEnums.ResultEnum.Error;
                            resultContext.Message    = "Error import details for current `Die Price List by Vendor`!";
                        }
                    }
                    else
                    {
                        List <string> listErrors = new List <string>();

                        if (dictErrorsRows.ContainsKey("NumberOfCavities"))
                        {
                            listErrors.Add("Error! The field `cavities` is missing or in wrong format, Rows (" + dictErrorsRows["NumberOfCavities"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("ProfileComplexity"))
                        {
                            listErrors.Add("Error! The field `complexity` is missing or in wrong format, Rows (" + dictErrorsRows["ProfileComplexity"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("ProfileCategory"))
                        {
                            listErrors.Add("Error! The field `category` is missing or in wrong format, Rows (" + dictErrorsRows["ProfileCategory"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("Price"))
                        {
                            listErrors.Add("Error! The field `price` is missing or in wrong NUMBER format, Rows (" + dictErrorsRows["Price"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("DimensionA"))
                        {
                            listErrors.Add("Error! The field `dimensiona` is missing or in wrong INTEGER NUMBER format, Rows (" + dictErrorsRows["DimensionA"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("DimensionB"))
                        {
                            listErrors.Add("Error! The field `dimensionb` is missing or in wrong INTEGER NUMBER format, Rows (" + dictErrorsRows["DimensionB"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("DuplicateNew"))
                        {
                            listErrors.Add("Error! The selected file includes die price list details with duplicate values, Rows (" + dictErrorsRows["DuplicateNew"] + ")!");
                        }
                        if (dictErrorsRows.ContainsKey("DuplicateOld"))
                        {
                            listErrors.Add("Error! The selected file includes die price list details with duplicate values in the database, Rows (" + dictErrorsRows["DuplicateOld"] + ")!");
                        }

                        resultContext.Message = string.Join(Constants.ERROR_MESSAGES_SEPARATOR, listErrors);
                    }
                }
            }
            catch (Exception ex)
            {
                resultContext.Message = "Error import details for current `Die Price List by Vendor`!";

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

            return(resultContext);
        }
Exemplo n.º 3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ownerPage.CheckUserActionPermission(ETEMEnums.SecuritySettings.DiePriceListDetailsSave, false))
            {
                return;
            }


            if (string.IsNullOrEmpty(this.hdnRowMasterKey.Value) || this.hdnRowMasterKey.Value == Constants.INVALID_ID_STRING)
            {
                this.currentEntity = new DiePriceListDetail();

                this.currentEntity.idDiePriceList = this.ddlVendor.SelectedValueINT;
            }
            else
            {
                this.currentEntity = this.ownerPage.CostCalculationRef.GetDiePriceListDetailById(this.hdnRowMasterKey.Value);

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

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

                    return;
                }
            }

            this.currentEntity.idNumberOfCavities  = this.ddlNumberOfCavities.SelectedValueINT;
            this.currentEntity.idProfileCategory   = this.ddlProfileCategory.SelectedValueINT;
            this.currentEntity.idProfileComplexity = this.ddlProfileComplexity.SelectedValueINT;
            this.currentEntity.DimensionA          = BaseHelper.ConvertToIntOrMinValue(this.tbxDimensionA.Text.Trim());
            this.currentEntity.DimensionB          = BaseHelper.ConvertToIntOrMinValue(this.tbxDimensionB.Text.Trim());
            this.currentEntity.Price    = BaseHelper.ConvertToDecimalOrMinValue(this.tbxDiePrice.Text.Trim());
            this.currentEntity.Lifespan = BaseHelper.ConvertToDecimalOrMinValue(this.tbxLifespan.Text.Trim());

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

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

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

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

            if (this.ownerPage is DiePriceListDetailsList)
            {
                ((DiePriceListDetailsList)this.ownerPage).LoadFilteredList();
            }
        }