Esempio n. 1
0
        private void dgvBaseUnitList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa đơn vị tính này?",
                                                          "Xoá đơn vị tính này",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgvBaseUnitList.Rows[e.RowIndex];

                        MeasurementUnitService measurementUnitService = new MeasurementUnitService();
                        int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id");
                        ProductLogService productLogService = new ProductLogService();
                        ProductLog        log = productLogService.GetProductLogs().Where(p => p.UnitId == id && p.Status == BHConstant.ACTIVE_STATUS).FirstOrDefault();
                        if (log == null)
                        {
                            if (!measurementUnitService.DeleteMeasurementUnit(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            loadMeasurementUnitList();
                        }
                        else
                        {
                            MessageBox.Show("Đơn vị tính này đang được sử dụng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
        }
        public void ensureFromEntityWithUnitConvertsContinuousDimensionInterval()
        {
            double minValue  = 20;
            double maxValue  = 60;
            double increment = 2;

            Dimension continuousDimensionInterval = new ContinuousDimensionInterval(minValue, maxValue, increment);

            string unit = "dm";

            GetDimensionModelView getDimensionModelView = DimensionModelViewService.fromEntity(continuousDimensionInterval, unit);

            GetContinuousDimensionIntervalModelView result = (GetContinuousDimensionIntervalModelView)getDimensionModelView;

            GetContinuousDimensionIntervalModelView expected = new GetContinuousDimensionIntervalModelView();

            expected.minValue  = MeasurementUnitService.convertToUnit(minValue, unit);
            expected.maxValue  = MeasurementUnitService.convertToUnit(maxValue, unit);
            expected.increment = MeasurementUnitService.convertToUnit(increment, unit);
            expected.unit      = unit;

            Assert.Equal(expected.minValue, result.minValue);
            Assert.Equal(expected.maxValue, result.maxValue);
            Assert.Equal(expected.increment, result.increment);
            Assert.Equal(expected.unit, result.unit);
        }
        public void ensureFromModelViewCreatesContinuousDimensionIntervalWithExpectedData()
        {
            double minValue  = 20;
            double maxValue  = 120;
            double increment = 5;

            string unit = "m";

            AddContinuousDimensionIntervalModelView continuousDimensionIntervalModelView = new AddContinuousDimensionIntervalModelView()
            {
                minValue  = minValue,
                maxValue  = maxValue,
                increment = increment,
                unit      = unit
            };


            ContinuousDimensionInterval continuousDimensionInterval = (ContinuousDimensionInterval)DimensionModelViewService.fromModelView(continuousDimensionIntervalModelView);

            double expectedMinValue  = MeasurementUnitService.convertFromUnit(minValue, unit);
            double expectedMaxvalue  = MeasurementUnitService.convertFromUnit(maxValue, unit);
            double expectedIncrement = MeasurementUnitService.convertFromUnit(increment, unit);


            Assert.Equal(expectedMinValue, continuousDimensionInterval.minValue);
            Assert.Equal(expectedMaxvalue, continuousDimensionInterval.maxValue);
            Assert.Equal(expectedIncrement, continuousDimensionInterval.increment);
        }
Esempio n. 4
0
        public void ensureConvertFromUnitUsesMinimumUnitIfArgumentIsNull()
        {
            Console.WriteLine("ensureConvertFromUnitUsesMinimumUnitIfArgumentIsNull");
            double value = 100;

            Assert.Equal(100, MeasurementUnitService.convertFromUnit(value, null), 1);
        }
        public void ensureFromModelViewCreatesInstance()
        {
            double minWidth         = 25;
            double maxWidth         = 50;
            double recommendedWidth = 35;

            string unit = "cm";

            AddProductSlotWidthsModelView productSlotWidthsModelView = new AddProductSlotWidthsModelView();

            productSlotWidthsModelView.minWidth         = minWidth;
            productSlotWidthsModelView.maxWidth         = maxWidth;
            productSlotWidthsModelView.recommendedWidth = recommendedWidth;
            productSlotWidthsModelView.unit             = unit;

            ProductSlotWidths slotWidths = ProductSlotWidthsModelViewService.fromModelView(productSlotWidthsModelView);

            double expectedMinWidth         = MeasurementUnitService.convertFromUnit(minWidth, unit);
            double expectedMaxWidth         = MeasurementUnitService.convertFromUnit(maxWidth, unit);
            double expectedRecommendedWidth = MeasurementUnitService.convertFromUnit(recommendedWidth, unit);

            Assert.Equal(expectedMinWidth, slotWidths.minWidth);
            Assert.Equal(expectedMaxWidth, slotWidths.maxWidth);
            Assert.Equal(expectedRecommendedWidth, slotWidths.recommendedWidth);
        }
        public void ensureFromEntityWithUnitConvertsDiscreteDimensionInterval()
        {
            List <double> values = new List <double>()
            {
                21, 35, 42
            };

            Dimension discreteDimensionInterval = new DiscreteDimensionInterval(values);

            string unit = "dm";

            GetDimensionModelView getDimensionModelView = DimensionModelViewService.fromEntity(discreteDimensionInterval, unit);

            GetDiscreteDimensionIntervalModelView result = (GetDiscreteDimensionIntervalModelView)getDimensionModelView;

            GetDiscreteDimensionIntervalModelView expected = new GetDiscreteDimensionIntervalModelView();
            List <double> expectedValues = new List <double>();

            foreach (double dimensionValue in values)
            {
                double convertedValue = MeasurementUnitService.convertToUnit(dimensionValue, unit);
                expectedValues.Add(convertedValue);
            }

            expected.values = expectedValues;
            expected.unit   = unit;

            Assert.Equal(expected.values, result.values);
            Assert.Equal(expected.unit, result.unit);
        }
        private void LoadUnits(int productId, int attrId)
        {
            if (attrId == 0)
            {
                cbmUnits.Enabled       = false;
                cbmUnits.SelectedValue = 0;
            }
            else
            {
                cbmUnits.Enabled = true;
                MeasurementUnitService unitService = new MeasurementUnitService();
                MeasurementUnit        u           = new MeasurementUnit
                {
                    Name = "Tất cả",
                    Id   = 0
                };

                units = productLogService.GetUnitsOfProductAttribute(productId, attrId);
                units.Add(u);
                units = units.OrderBy(a => a.Id).ToList();
                if (units != null)
                {
                    cbmUnits.DataSource    = units;
                    cbmUnits.DisplayMember = "Name";
                    cbmUnits.ValueMember   = "Id";
                }
            }
        }
Esempio n. 8
0
 private void EntranceStock_Load(object sender, EventArgs e)
 {
     productLogService = new ProductLogService();
     unitService       = new MeasurementUnitService();
     loadSomeData();
     SetupColumns();
     updateProductionRequestDetailCells();
 }
Esempio n. 9
0
        public void ensureConvertFromUnitSucceeds()
        {
            Console.WriteLine("ensureConvertFromUnitSucceds");
            double value = 100;
            string unit  = "dm";

            Assert.Equal(10000, MeasurementUnitService.convertFromUnit(value, unit), 1);
        }
Esempio n. 10
0
        public void ensureConvertFromUnitThrowsArgumentException()
        {
            Console.WriteLine("ensureConvertToUnitThrowsArgumentException");
            double value  = 1;
            Action action = () => MeasurementUnitService.convertFromUnit(value, "der alte würfelt nicht");

            Assert.Throws <ArgumentException>(action);
        }
 private void EntranceStock_Load(object sender, EventArgs e)
 {
     productLogService = new ProductLogService();
     unitService = new MeasurementUnitService();
     loadSomeData();
     SetupColumns();
     updateProductionRequestDetailCells();
 }
        /// <summary>
        /// Creates a model view with a dimension information
        /// </summary>
        /// <param name="dimension">Dimension with the dimension being created the model view</param>
        /// <param name="unit">Unit to which the values will be converted</param>
        /// <returns>GetDimensionModelView with the dimension information model view</returns>
        /// <exception cref="System.ArgumentNullException">Throw when the provided Dimension is null.</exception>
        public static GetDimensionModelView fromEntity(Dimension dimension, string unit)
        {
            if (dimension == null)
            {
                throw new ArgumentNullException(ERROR_NULL_DIMENSION);
            }
            //if no unit is provided, use the default implementation
            if (Strings.isNullOrEmpty(unit))
            {
                return(fromEntity(dimension));
            }

            Type dimensionType = dimension.GetType();

            if (dimensionType == typeof(SingleValueDimension))
            {
                SingleValueDimension             singleValueDimension = (SingleValueDimension)dimension;
                GetSingleValueDimensionModelView singleMV             = new GetSingleValueDimensionModelView();
                singleMV.id    = singleValueDimension.Id;
                singleMV.unit  = unit;
                singleMV.value = MeasurementUnitService.convertToUnit(singleValueDimension.value, unit);

                return(singleMV);
            }
            else if (dimensionType == typeof(DiscreteDimensionInterval))
            {
                DiscreteDimensionInterval             discreteDimension = (DiscreteDimensionInterval)dimension;
                GetDiscreteDimensionIntervalModelView discreteMV        = new GetDiscreteDimensionIntervalModelView();
                discreteMV.id   = discreteDimension.Id;
                discreteMV.unit = unit;

                List <double> values = new List <double>();
                foreach (double value in discreteDimension.values)
                {
                    values.Add(MeasurementUnitService.convertToUnit(value, unit));
                }
                discreteMV.values = values;

                return(discreteMV);
            }
            else if (dimensionType == typeof(ContinuousDimensionInterval))
            {
                ContinuousDimensionInterval             continuousDimension = (ContinuousDimensionInterval)dimension;
                GetContinuousDimensionIntervalModelView continuousMV        = new GetContinuousDimensionIntervalModelView();
                continuousMV.id        = continuousDimension.Id;
                continuousMV.unit      = unit;
                continuousMV.minValue  = MeasurementUnitService.convertToUnit(continuousDimension.minValue, unit);
                continuousMV.maxValue  = MeasurementUnitService.convertToUnit(continuousDimension.maxValue, unit);
                continuousMV.increment = MeasurementUnitService.convertToUnit(continuousDimension.increment, unit);

                return(continuousMV);
            }
            else
            {
                throw new NotImplementedException(ERROR_NO_IMPLEMENTATION_UNKNOWN_DIMENSION);
            }
        }
 public void loadMeasurementUnitList()
 {
     MeasurementUnitService measurementUnitService = new MeasurementUnitService();
     List<MeasurementUnit> measurementUnits = measurementUnitService.GetMeasurementUnits();
     if (measurementUnits != null)
     {
         setUpDataGrid(measurementUnits);
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Converts the value from a unit to another unit.
        /// </summary>
        /// <param name="convertUnitMV">ConvertUnitModelView containing unit conversion data.</param>
        /// <returns>ConvertUnitModelView with converted value.</returns>
        public ConvertUnitModelView convertValue(ConvertUnitModelView convertUnitMV)
        {
            double valueInMM = MeasurementUnitService.convertFromUnit(convertUnitMV.value, convertUnitMV.fromUnit);

            double newValue = MeasurementUnitService.convertToUnit(valueInMM, convertUnitMV.toUnit);

            convertUnitMV.value = newValue;

            return(convertUnitMV);
        }
Esempio n. 15
0
        /// <summary>
        /// Builds a DimensionDTO out of a SingleValueDimension instance
        /// </summary>
        /// <returns>DimensionDTO instance</returns>
        public override DimensionDTO toDTO()
        {
            SingleValueDimensionDTO dto = new SingleValueDimensionDTO();

            dto.id    = Id;
            dto.value = value;
            dto.unit  = MeasurementUnitService.getMinimumUnit();

            return(dto);
        }
        /// <summary>
        /// Builds a SingleValueDimension instance from a SingleValueDimensionDTO
        /// </summary>
        /// <returns>SingleValueDimension instance</returns>
        public override Dimension toEntity()
        {
            double value = MeasurementUnitService.convertFromUnit(this.value, unit);

            SingleValueDimension instanceFromDTO = new SingleValueDimension(value);

            instanceFromDTO.Id = id;

            return(instanceFromDTO);
        }
Esempio n. 17
0
        public void loadMeasurementUnitList()
        {
            MeasurementUnitService measurementUnitService = new MeasurementUnitService();
            List <MeasurementUnit> measurementUnits       = measurementUnitService.GetMeasurementUnits();

            if (measurementUnits != null)
            {
                setUpDataGrid(measurementUnits);
            }
        }
        public void ensureFromCollectionWithEmptyUnitUsesMinimumUnit()
        {
            double    minValue  = 20;
            double    maxValue  = 60;
            double    increment = 2;
            Dimension continuousDimensionInterval = new ContinuousDimensionInterval(minValue, maxValue, increment);

            List <double> values = new List <double>()
            {
                21, 35, 42
            };
            Dimension discreteDimensionInterval = new DiscreteDimensionInterval(values);

            double    value = 72;
            Dimension singleValueDimension = new SingleValueDimension(value);

            IEnumerable <Dimension> dimensions = new List <Dimension>()
            {
                continuousDimensionInterval, discreteDimensionInterval, singleValueDimension
            };

            GetAllDimensionsModelView getAllDimensionsModelView = DimensionModelViewService.fromCollection(dimensions, "");

            string minimumUnit = MeasurementUnitService.getMinimumUnit();

            GetContinuousDimensionIntervalModelView continuousDimensionIntervalModelView = new GetContinuousDimensionIntervalModelView();

            continuousDimensionIntervalModelView.minValue  = minValue;
            continuousDimensionIntervalModelView.maxValue  = maxValue;
            continuousDimensionIntervalModelView.increment = increment;
            continuousDimensionIntervalModelView.unit      = minimumUnit;


            GetDiscreteDimensionIntervalModelView discreteDimensionIntervalModelView = new GetDiscreteDimensionIntervalModelView();

            discreteDimensionIntervalModelView.values = values;
            discreteDimensionIntervalModelView.unit   = minimumUnit;


            GetSingleValueDimensionModelView singleValueDimensionModelView = new GetSingleValueDimensionModelView();

            singleValueDimensionModelView.value = value;
            singleValueDimensionModelView.unit  = minimumUnit;

            GetAllDimensionsModelView expected = new GetAllDimensionsModelView()
            {
                continuousDimensionIntervalModelView, discreteDimensionIntervalModelView, singleValueDimensionModelView
            };

            for (int i = 0; i < 3; i++)
            {
                Assert.True(equalModelViews(getAllDimensionsModelView[i], expected[i]));
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Builds a CustomizedDimensionsDTO out of a CustomizedDimensions instance
        /// </summary>
        /// <returns>CustomizedDimensionsDTO instance</returns>
        public CustomizedDimensionsDTO toDTO()
        {
            CustomizedDimensionsDTO customizedDimensionsDTO = new CustomizedDimensionsDTO();

            customizedDimensionsDTO.Id     = this.Id;
            customizedDimensionsDTO.width  = width;
            customizedDimensionsDTO.depth  = depth;
            customizedDimensionsDTO.height = height;
            customizedDimensionsDTO.unit   = MeasurementUnitService.getMinimumUnit();
            return(customizedDimensionsDTO);
        }
Esempio n. 20
0
        /// <summary>
        /// Builds a DimensionDTO out of a ContinuousDimensionInterval instance
        /// </summary>
        /// <returns>DimensionDTO instance</returns>
        public override DimensionDTO toDTO()
        {
            ContinuousDimensionIntervalDTO dto = new ContinuousDimensionIntervalDTO();

            dto.id        = Id;
            dto.unit      = MeasurementUnitService.getMinimumUnit();
            dto.minValue  = minValue;
            dto.maxValue  = maxValue;
            dto.increment = increment;

            return(dto);
        }
        /// <summary>
        /// Builds a ContinuousDimensionInterval instance from a ContinuousDimensionIntervalDTO
        /// </summary>
        /// <returns>ContinuousDimensionInterval instance</returns>
        public override Dimension toEntity()
        {
            double minValue  = MeasurementUnitService.convertFromUnit(this.minValue, unit);
            double maxValue  = MeasurementUnitService.convertFromUnit(this.maxValue, unit);
            double increment = MeasurementUnitService.convertFromUnit(this.increment, unit);

            ContinuousDimensionInterval instanceFromDTO = new ContinuousDimensionInterval(minValue, maxValue, increment);

            instanceFromDTO.Id = id;

            return(instanceFromDTO);
        }
        /// <summary>
        /// Converts an instance of AddCustomizedDimensionsModelView into an instance of CustomizedDimensions.
        /// </summary>
        /// <param name="modelView">Instance of AddCustomizedDimensionsModelView.</param>
        /// <returns>The created instance of CustomizedDimensions</returns>
        /// <exception cref="System.ArgumentException">Thrown when the provided AddCustomizedDimensionsModelView is null.</exception>
        public static CustomizedDimensions fromModelView(AddCustomizedDimensionsModelView modelView)
        {
            if (modelView == null)
            {
                throw new ArgumentException(ERROR_NULL_MODEL_VIEW);
            }

            double height = MeasurementUnitService.convertFromUnit(modelView.height, modelView.unit);
            double width  = MeasurementUnitService.convertFromUnit(modelView.width, modelView.unit);
            double depth  = MeasurementUnitService.convertFromUnit(modelView.depth, modelView.unit);

            return(CustomizedDimensions.valueOf(height, width, depth));
        }
        public void ensureFromEntityWithEmptyUnitUsesMinimumUnit()
        {
            double minWidth         = 25;
            double maxWidth         = 50;
            double recommendedWidth = 35;

            ProductSlotWidths slotWidths = ProductSlotWidths.valueOf(minWidth, maxWidth, recommendedWidth);

            GetProductSlotWidthsModelView result = ProductSlotWidthsModelViewService.fromEntity(slotWidths, "");

            string expectedUnit = MeasurementUnitService.getMinimumUnit();

            Assert.Equal(expectedUnit, result.unit);
        }
Esempio n. 24
0
        /// <summary>
        /// Retrieves all the available units.
        /// </summary>
        /// <returns>GetUnitsModelView with data from all the available units.</returns>
        public GetUnitsModelView getAllAvailableUnits()
        {
            IEnumerable <string> availableUnits = MeasurementUnitService.getAvailableUnits();
            GetUnitsModelView    unitsModelView = new GetUnitsModelView();

            foreach (string unit in availableUnits)
            {
                GetUnitModelView unitModelView = new GetUnitModelView();
                unitModelView.unit = unit;
                unitsModelView.Add(unitModelView);
            }

            return(unitsModelView);
        }
Esempio n. 25
0
        public override DimensionDTO toDTO(string unit)
        {
            if (unit == null)
            {
                return(this.toDTO());
            }
            SingleValueDimensionDTO dto = new SingleValueDimensionDTO();

            dto.id    = Id;
            dto.value = MeasurementUnitService.convertToUnit(value, unit);
            dto.unit  = unit;

            return(dto);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (validator1.Validate())
            {
                if (measurementUnit != null && measurementUnit.Id > 0)
                {
                    measurementUnit.Description = txtDescription.Text;
                    measurementUnit.Name = txtName.Text;
                    measurementUnit.UnitCode = txtCode.Text;

                    MeasurementUnitService measurementUnitService = new MeasurementUnitService();
                    bool result = measurementUnitService.UpdateMeasurementUnit(measurementUnit);
                    if (result)
                    {
                        MessageBox.Show("Loại đơn vị đã được cập nhật vào hệ thống");
                        ((BaseUnitList)this.CallFromUserControll).loadMeasurementUnitList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    measurementUnit = new MeasurementUnit
                    {

                        Description = txtDescription.Text,
                        Name = txtName.Text,
                        UnitCode = txtCode.Text
                    };
                    MeasurementUnitService measurementUnitService = new MeasurementUnitService();
                    bool result = measurementUnitService.AddMeasurementUnit(measurementUnit);
                    if (result)
                    {
                        MessageBox.Show("Đơn vị tính đã được thêm mới vào hệ thống");
                        ((BaseUnitList)this.CallFromUserControll).loadMeasurementUnitList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            
            
        }
        private bool modelViewEqualsDimension(AddDimensionModelView modelView, Dimension dimension)
        {
            if (modelView.GetType() == typeof(AddDiscreteDimensionIntervalModelView) && dimension.GetType() == typeof(DiscreteDimensionInterval))
            {
                DiscreteDimensionInterval             discreteDimension = (DiscreteDimensionInterval)dimension;
                AddDiscreteDimensionIntervalModelView discreteModelView = (AddDiscreteDimensionIntervalModelView)modelView;

                List <double> expectedValues = new List <double>();

                foreach (double modelViewValue in discreteModelView.values)
                {
                    double expectedValue = MeasurementUnitService.convertFromUnit(modelViewValue, discreteModelView.unit);
                    expectedValues.Add(expectedValue);
                }

                var firstNotSecond = expectedValues.Except(discreteDimension.values.Select(dv => dv.value)).ToList();
                var secondNotFirst = discreteDimension.values.Select(dv => dv.value).Except(expectedValues).ToList();

                bool equalLists = !firstNotSecond.Any() && !secondNotFirst.Any();

                return(equalLists);
            }
            else if (modelView.GetType() == typeof(AddSingleValueDimensionModelView) && dimension.GetType() == typeof(SingleValueDimension))
            {
                SingleValueDimension             singleValueDimension = (SingleValueDimension)dimension;
                AddSingleValueDimensionModelView singleValueModelView = (AddSingleValueDimensionModelView)modelView;

                double expectedValue = MeasurementUnitService.convertFromUnit(singleValueModelView.value, singleValueModelView.unit);

                return(expectedValue.Equals(singleValueDimension.value));
            }
            else if (modelView.GetType() == typeof(AddContinuousDimensionIntervalModelView) && dimension.GetType() == typeof(ContinuousDimensionInterval))
            {
                ContinuousDimensionInterval             continuousDimension = (ContinuousDimensionInterval)dimension;
                AddContinuousDimensionIntervalModelView continuousModelView = (AddContinuousDimensionIntervalModelView)modelView;

                double expectedMinValue  = MeasurementUnitService.convertFromUnit(continuousModelView.minValue, continuousModelView.unit);
                double expectedMaxValue  = MeasurementUnitService.convertFromUnit(continuousModelView.maxValue, continuousModelView.unit);
                double expectedIncrement = MeasurementUnitService.convertFromUnit(continuousModelView.increment, continuousModelView.unit);

                return(expectedMinValue.Equals(continuousDimension.minValue) &&
                       expectedMaxValue.Equals(continuousDimension.maxValue) &&
                       expectedIncrement.Equals(continuousDimension.increment));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Converts an instance of AddProductSlotWidthsModelView into an instance of ProductSlotWidths.
        /// </summary>
        /// <param name="modelView">Instance of AddProductSlotWidthsModelView.</param>
        /// <returns>The created instance of ProductSlotWidths.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of AddProductSlotWidthsModelView is null.</exception>
        public static ProductSlotWidths fromModelView(AddProductSlotWidthsModelView modelView)
        {
            if (modelView == null)
            {
                throw new ArgumentNullException(ERROR_NULL_MODEL_VIEW);
            }

            double minWidth = MeasurementUnitService.convertFromUnit(modelView.minWidth, modelView.unit);

            double maxWidth = MeasurementUnitService.convertFromUnit(modelView.maxWidth, modelView.unit);

            double recommendedWidth = MeasurementUnitService.convertFromUnit(modelView.recommendedWidth, modelView.unit);

            return(ProductSlotWidths.valueOf(minWidth, maxWidth, recommendedWidth));
        }
        public void loadDataForEditMeasurementUnit(int measurementUnitId)
        {
            this.Text         = "Chỉnh sửa đơn vị này phẩm này";
            this.btnSave.Text = "Cập nhật";

            MeasurementUnitService measurementUnitService = new MeasurementUnitService();

            measurementUnit = measurementUnitService.GetMeasurementUnit(measurementUnitId);
            if (measurementUnit != null)
            {
                txtDescription.Text = measurementUnit.Description;
                txtCode.Text        = measurementUnit.UnitCode;
                txtName.Text        = measurementUnit.Name;
            }
        }
 public CustomizedDimensions toEntity()
 {
     if (unit == null)
     {
         CustomizedDimensions custDimensions = CustomizedDimensions.valueOf(height, width, depth);
         custDimensions.Id = this.Id;
         return(custDimensions);
     }
     else
     {
         return(CustomizedDimensions.valueOf(MeasurementUnitService.convertFromUnit(this.height, unit)
                                             , MeasurementUnitService.convertFromUnit(this.width, unit)
                                             , MeasurementUnitService.convertFromUnit(this.depth, unit)));
     }
 }
        /// <summary>
        /// Builds a DiscreteDimensionInterval instance from a DiscreteDimensionIntervalDTO
        /// </summary>
        /// <returns>DiscreteDimensionInterval instance</returns>
        public override Dimension toEntity()
        {
            List <double> valuesInMilimetres = new List <double>();

            foreach (double value in values)
            {
                valuesInMilimetres.Add(MeasurementUnitService.convertFromUnit(value, unit));
            }

            DiscreteDimensionInterval instanceFromDTO = new DiscreteDimensionInterval(valuesInMilimetres);

            instanceFromDTO.Id = id;

            return(instanceFromDTO);
        }
        public void loadDataForEditMeasurementUnit(int measurementUnitId)
        {
            this.Text = "Chỉnh sửa đơn vị này phẩm này";
            this.btnSave.Text = "Cập nhật";

            MeasurementUnitService measurementUnitService = new MeasurementUnitService();

            measurementUnit = measurementUnitService.GetMeasurementUnit(measurementUnitId);
            if (measurementUnit != null)
            {
                txtDescription.Text = measurementUnit.Description;
                txtCode.Text = measurementUnit.UnitCode;
                txtName.Text = measurementUnit.Name;
            }
        }
        /// <summary>
        /// Creates an instance of Dimension from an AddDimensionModelView instance.
        /// </summary>
        /// <param name="addDimensionModelView">AddDimensionModelView instance.</param>
        /// <returns>Created Dimension.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided AddDimensionModelView is null.</exception>
        public static Dimension fromModelView(AddDimensionModelView addDimensionModelView)
        {
            if (addDimensionModelView == null)
            {
                throw new ArgumentNullException(ERROR_NULL_DIMENSION_VIEW);
            }

            string unit = addDimensionModelView.unit;

            Type modelViewType = addDimensionModelView.GetType();

            if (modelViewType == typeof(AddSingleValueDimensionModelView))
            {
                AddSingleValueDimensionModelView singleValueMV = (AddSingleValueDimensionModelView)addDimensionModelView;

                double dimensionValue = MeasurementUnitService.convertFromUnit(singleValueMV.value, unit);

                return(new SingleValueDimension(dimensionValue));
            }
            else if (modelViewType == typeof(AddDiscreteDimensionIntervalModelView))
            {
                AddDiscreteDimensionIntervalModelView discreteMV = (AddDiscreteDimensionIntervalModelView)addDimensionModelView;

                List <double> dimensionValues = new List <double>();

                foreach (double value in discreteMV.values)
                {
                    double dimensionValue = MeasurementUnitService.convertFromUnit(value, unit);
                    dimensionValues.Add(dimensionValue);
                }

                return(new DiscreteDimensionInterval(dimensionValues));
            }
            else if (modelViewType == typeof(AddContinuousDimensionIntervalModelView))
            {
                AddContinuousDimensionIntervalModelView continuousMV = (AddContinuousDimensionIntervalModelView)addDimensionModelView;

                double minValue  = MeasurementUnitService.convertFromUnit(continuousMV.minValue, unit);
                double maxValue  = MeasurementUnitService.convertFromUnit(continuousMV.maxValue, unit);
                double increment = MeasurementUnitService.convertFromUnit(continuousMV.increment, unit);

                return(new ContinuousDimensionInterval(minValue, maxValue, increment));
            }
            else
            {
                throw new NotImplementedException(ERROR_NO_IMPLEMENTATION_UNKNOWN_VIEW);
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Builds a CustomizedDimensionsDTO out of a CustomizedDimensions instance
        /// </summary>
        /// <param name="unit">Desired unit</param>
        /// <returns>DimensionDTO instance</returns>
        public CustomizedDimensionsDTO toDTO(string unit)
        {
            if (unit == null)
            {
                return(this.toDTO());
            }

            CustomizedDimensionsDTO customizedDimensionsDTO = new CustomizedDimensionsDTO();

            customizedDimensionsDTO.Id     = this.Id;
            customizedDimensionsDTO.width  = MeasurementUnitService.convertToUnit(width, unit);
            customizedDimensionsDTO.depth  = MeasurementUnitService.convertToUnit(depth, unit);
            customizedDimensionsDTO.height = MeasurementUnitService.convertToUnit(height, unit);
            customizedDimensionsDTO.unit   = unit;
            return(customizedDimensionsDTO);
        }
        private void LoadUnits(int productId, int attrId)
        {
            if (attrId == 0)
            {
                cbmUnits.Enabled = false;
                cbmUnits.SelectedValue = 0;
            }
            else
            {
                cbmUnits.Enabled = true;
                MeasurementUnitService unitService = new MeasurementUnitService();
                MeasurementUnit u = new MeasurementUnit
                {
                    Name = "Tất cả",
                    Id = 0
                };

                units = productLogService.GetUnitsOfProductAttribute(productId, attrId);
                units.Add(u);
                units = units.OrderBy(a => a.Id).ToList();
                if (units != null)
                {
                    cbmUnits.DataSource = units;
                    cbmUnits.DisplayMember = "Name";
                    cbmUnits.ValueMember = "Id";
                }
            }
        }
        private void dgvBaseUnitList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa đơn vị tính này?",
                    "Xoá đơn vị tính này",
                     MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgvBaseUnitList.Rows[e.RowIndex];

                        MeasurementUnitService measurementUnitService = new MeasurementUnitService();
                        int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id");
                        ProductLogService productLogService = new ProductLogService();
                        ProductLog log = productLogService.GetProductLogs().Where(p => p.UnitId == id && p.Status == BHConstant.ACTIVE_STATUS).FirstOrDefault();
                        if (log == null)
                        {
                            if (!measurementUnitService.DeleteMeasurementUnit(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            loadMeasurementUnitList();
                        }
                        else
                        {
                            MessageBox.Show("Đơn vị tính này đang được sử dụng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                }

            }
        }
 private void AddOrder_Load(object sender, EventArgs e)
 {
     unitService = new MeasurementUnitService();
     productLogService = new ProductLogService();
     loadSomeData();
     SetupColumns();
     updateProductionRequestDetailCells();
     calculateTotal();
     loadOther();
 }
 private void AddProductionRequest_Load(object sender, EventArgs e)
 {
     unitService = new MeasurementUnitService();
     productLogService = new ProductLogService();
     loadSomeData();
     SetupColumnsForMaterial();
     SetupColumnsForProductRequest();
     updateProductionRequestDetailCells();
 }