コード例 #1
0
ファイル: EntityBinder.cs プロジェクト: orbea/Mesen
        public void AddBinding(string fieldName, Control bindedField, eNumberFormat format = eNumberFormat.Default)
        {
            if (BindedType == null)
            {
                throw new Exception("Need to override BindedType to use bindings");
            }

            if (_fieldInfo == null)
            {
                _fieldInfo = new Dictionary <string, FieldInfo>();
                FieldInfo[] members = BindedType.GetFields();
                foreach (FieldInfo info in members)
                {
                    _fieldInfo[info.Name] = info;
                }
            }

            if (_fieldInfo.ContainsKey(fieldName))
            {
                Type fieldType = _fieldInfo[fieldName].FieldType;
                if (fieldType.IsSubclassOf(typeof(Enum)) && bindedField is ComboBox)
                {
                    BaseConfigForm.InitializeComboBox(((ComboBox)bindedField), fieldType);
                }
                _bindings[fieldName]    = bindedField;
                _fieldFormat[fieldName] = format;
            }
            else
            {
                throw new Exception("Invalid field name");
            }
        }
コード例 #2
0
        public void UpdateUI()
        {
            this.Updating = true;

            foreach (KeyValuePair <string, Control> kvp in _bindings)
            {
                if (!_fieldInfo.ContainsKey(kvp.Key))
                {
                    throw new Exception("Invalid binding key");
                }
                else
                {
                    FieldInfoWrapper field  = _fieldInfo[kvp.Key];
                    eNumberFormat    format = _fieldFormat[kvp.Key];
                    object           value  = field.GetValue(this.Entity);
                    if (kvp.Value is TextBox)
                    {
                        if (value is IFormattable)
                        {
                            kvp.Value.Text = ((IFormattable)value).ToString(format == eNumberFormat.Decimal ? "" : "X", System.Globalization.CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            kvp.Value.Text = value == null ? "" : ((string)value).Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine);
                        }
                    }
                    else if (kvp.Value is ctrlPathSelection)
                    {
                        kvp.Value.Text = (string)value;
                    }
                    else if (kvp.Value is CheckBox)
                    {
                        ((CheckBox)kvp.Value).Checked = Convert.ToBoolean(value);
                    }
                    else if (kvp.Value is ctrlRiskyOption)
                    {
                        ((ctrlRiskyOption)kvp.Value).Checked = Convert.ToBoolean(value);
                    }
                    else if (kvp.Value is RadioButton)
                    {
                        ((RadioButton)kvp.Value).Checked = (bool)value;
                    }
                    else if (kvp.Value is Panel)
                    {
                        RadioButton radio = kvp.Value.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
                        if (radio != null)
                        {
                            radio.Checked = true;
                        }
                        else
                        {
                            throw new Exception("No radio button matching value found");
                        }
                    }
                    else if (kvp.Value is ctrlTrackbar)
                    {
                        if (field.FieldType == typeof(Int32))
                        {
                            ((ctrlTrackbar)kvp.Value).Value = (int)value;
                        }
                        else
                        {
                            ((ctrlTrackbar)kvp.Value).Value = (int)(uint)value;
                        }
                    }
                    else if (kvp.Value is ctrlHorizontalTrackbar)
                    {
                        ((ctrlHorizontalTrackbar)kvp.Value).Value = (int)value;
                    }
                    else if (kvp.Value is TrackBar)
                    {
                        if (field.FieldType == typeof(Int32))
                        {
                            ((TrackBar)kvp.Value).Value = (int)value;
                        }
                        else
                        {
                            ((TrackBar)kvp.Value).Value = (int)(uint)value;
                        }
                    }
                    else if (kvp.Value is MesenNumericUpDown)
                    {
                        MesenNumericUpDown nud = kvp.Value as MesenNumericUpDown;
                        decimal            val;
                        if (field.FieldType == typeof(UInt32))
                        {
                            val = (UInt32)value;
                        }
                        else if (field.FieldType == typeof(Int32))
                        {
                            val = (Int32)value;
                        }
                        else
                        {
                            val = (decimal)(double)value;
                        }
                        val       = Math.Min(Math.Max(val, nud.Minimum), nud.Maximum);
                        nud.Value = val;
                    }
                    else if (kvp.Value is ComboBox)
                    {
                        ComboBox combo = kvp.Value as ComboBox;
                        if (value is Enum)
                        {
                            combo.SelectedItem = ResourceHelper.GetEnumText((Enum)value);
                        }
                        else if (field.FieldType == typeof(UInt32))
                        {
                            for (int i = 0, len = combo.Items.Count; i < len; i++)
                            {
                                UInt32 numericValue;
                                string item = Regex.Replace(combo.Items[i].ToString(), "[^0-9]", "");
                                if (UInt32.TryParse(item, out numericValue))
                                {
                                    if (numericValue == (UInt32)value)
                                    {
                                        combo.SelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                        else if (field.FieldType == typeof(string))
                        {
                            combo.SelectedItem = value;
                            if (combo.SelectedIndex < 0 && combo.Items.Count > 0)
                            {
                                combo.SelectedIndex = 0;
                            }
                        }
                    }
                }
            }

            this.Updating = false;
        }
コード例 #3
0
 public void UpdateObject()
 {
     foreach (KeyValuePair <string, Control> kvp in _bindings)
     {
         if (!_fieldInfo.ContainsKey(kvp.Key))
         {
             throw new Exception("Invalid binding key");
         }
         else
         {
             try {
                 FieldInfoWrapper field  = _fieldInfo[kvp.Key];
                 eNumberFormat    format = _fieldFormat[kvp.Key];
                 if (kvp.Value is TextBox)
                 {
                     object       value       = kvp.Value.Text;
                     NumberStyles numberStyle = format == eNumberFormat.Decimal ? NumberStyles.Integer : NumberStyles.HexNumber;
                     if (field.FieldType != typeof(string))
                     {
                         value = ((string)value).Trim().Replace("$", "").Replace("0x", "");
                         if (string.IsNullOrWhiteSpace((string)value))
                         {
                             value = "0";
                         }
                     }
                     if (field.FieldType == typeof(UInt32))
                     {
                         UInt32 result;
                         if (!UInt32.TryParse((string)value, numberStyle, null, out result))
                         {
                             continue;                                     //Invalid value, ignore it
                         }
                         value = result;
                     }
                     else if (field.FieldType == typeof(Int32))
                     {
                         Int32 result;
                         if (!Int32.TryParse((string)value, numberStyle, null, out result))
                         {
                             continue;                                     //Invalid value, ignore it
                         }
                         value = result;
                     }
                     else if (field.FieldType == typeof(Byte))
                     {
                         Byte result;
                         if (!Byte.TryParse((string)value, numberStyle, null, out result))
                         {
                             continue;                                     //Invalid value, ignore it
                         }
                         value = result;
                     }
                     else if (field.FieldType == typeof(UInt16))
                     {
                         UInt16 result;
                         if (!UInt16.TryParse((string)value, numberStyle, null, out result))
                         {
                             continue;                                     //Invalid value, ignore it
                         }
                         value = result;
                     }
                     else if (field.FieldType == typeof(UInt64))
                     {
                         UInt64 result;
                         if (!UInt64.TryParse((string)value, numberStyle, null, out result))
                         {
                             continue;                                     //Invalid value, ignore it
                         }
                         value = result;
                     }
                     else if (field.FieldType == typeof(Int64))
                     {
                         Int64 result;
                         if (!Int64.TryParse((string)value, numberStyle, null, out result))
                         {
                             continue;                                     //Invalid value, ignore it
                         }
                         value = result;
                     }
                     field.SetValue(Entity, value);
                 }
                 else if (kvp.Value is ctrlPathSelection)
                 {
                     field.SetValue(Entity, ((ctrlPathSelection)kvp.Value).Text);
                 }
                 else if (kvp.Value is CheckBox)
                 {
                     if (field.FieldType == typeof(bool))
                     {
                         field.SetValue(Entity, ((CheckBox)kvp.Value).Checked);
                     }
                     else if (field.FieldType == typeof(byte))
                     {
                         field.SetValue(Entity, ((CheckBox)kvp.Value).Checked ? (byte)1 : (byte)0);
                     }
                 }
                 else if (kvp.Value is ctrlRiskyOption)
                 {
                     if (field.FieldType == typeof(bool))
                     {
                         field.SetValue(Entity, ((ctrlRiskyOption)kvp.Value).Checked);
                     }
                     else if (field.FieldType == typeof(byte))
                     {
                         field.SetValue(Entity, ((ctrlRiskyOption)kvp.Value).Checked ? (byte)1 : (byte)0);
                     }
                 }
                 else if (kvp.Value is RadioButton)
                 {
                     field.SetValue(Entity, ((RadioButton)kvp.Value).Checked);
                 }
                 else if (kvp.Value is Panel)
                 {
                     field.SetValue(Entity, kvp.Value.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked).Tag);
                 }
                 else if (kvp.Value is ctrlTrackbar)
                 {
                     if (field.FieldType == typeof(Int32))
                     {
                         field.SetValue(Entity, (Int32)((ctrlTrackbar)kvp.Value).Value);
                     }
                     else
                     {
                         field.SetValue(Entity, (UInt32)((ctrlTrackbar)kvp.Value).Value);
                     }
                 }
                 else if (kvp.Value is ctrlHorizontalTrackbar)
                 {
                     field.SetValue(Entity, (Int32)((ctrlHorizontalTrackbar)kvp.Value).Value);
                 }
                 else if (kvp.Value is TrackBar)
                 {
                     if (field.FieldType == typeof(Int32))
                     {
                         field.SetValue(Entity, ((TrackBar)kvp.Value).Value);
                     }
                     else
                     {
                         field.SetValue(Entity, (UInt32)((TrackBar)kvp.Value).Value);
                     }
                 }
                 else if (kvp.Value is MesenNumericUpDown)
                 {
                     if (field.FieldType == typeof(UInt32))
                     {
                         field.SetValue(Entity, (UInt32)((MesenNumericUpDown)kvp.Value).Value);
                     }
                     else if (field.FieldType == typeof(Int32))
                     {
                         field.SetValue(Entity, (Int32)((MesenNumericUpDown)kvp.Value).Value);
                     }
                     else
                     {
                         field.SetValue(Entity, (double)((MesenNumericUpDown)kvp.Value).Value);
                     }
                 }
                 else if (kvp.Value is ComboBox)
                 {
                     if (field.FieldType.IsSubclassOf(typeof(Enum)))
                     {
                         Enum enumValue = ((ComboBox)kvp.Value).GetEnumValue(field.FieldType);
                         if (enumValue != null)
                         {
                             field.SetValue(Entity, enumValue);
                         }
                     }
                     else if (field.FieldType == typeof(UInt32))
                     {
                         UInt32 numericValue;
                         string item = Regex.Replace(((ComboBox)kvp.Value).SelectedItem.ToString(), "[^0-9]", "");
                         if (UInt32.TryParse(item, out numericValue))
                         {
                             field.SetValue(Entity, numericValue);
                         }
                     }
                     else if (field.FieldType == typeof(string))
                     {
                         field.SetValue(Entity, ((ComboBox)kvp.Value).SelectedItem);
                     }
                 }
             } catch {
                 //Ignore exceptions caused by bad user input
             }
         }
     }
 }
コード例 #4
0
 protected void AddBinding(string fieldName, Control bindedField, eNumberFormat format = eNumberFormat.Default)
 {
     _binder.AddBinding(fieldName, bindedField, format);
 }
コード例 #5
0
        public void AddBinding(string fieldName, object bindedField, eNumberFormat format = eNumberFormat.Default, EventHandler onEditHandler = null)
        {
            if (BindedType == null)
            {
                throw new Exception("Need to override BindedType to use bindings");
            }

            if (_fieldInfo == null)
            {
                _fieldInfo = new Dictionary <string, FieldInfoWrapper>();
                PropertyInfo[] properties = BindedType.GetProperties();
                foreach (PropertyInfo info in properties)
                {
                    _fieldInfo[info.Name] = new FieldInfoWrapper(info);
                }

                FieldInfo[] members = BindedType.GetFields();
                foreach (FieldInfo info in members)
                {
                    _fieldInfo[info.Name] = new FieldInfoWrapper(info);
                }
            }

            if (_fieldInfo.ContainsKey(fieldName))
            {
                Type fieldType = _fieldInfo[fieldName].FieldType;
                if (fieldType.IsSubclassOf(typeof(Enum)) && bindedField is ComboBox)
                {
                    BaseConfigForm.InitializeComboBox(((ComboBox)bindedField), fieldType);
                }
                _bindings[fieldName]       = bindedField;
                _bindedHandlers[fieldName] = onEditHandler;

                if (bindedField is TextBox)
                {
                    ((TextBox)bindedField).Leave += onEditHandler;
                }
                else if (bindedField is ctrlPathSelection)
                {
                    ((ctrlPathSelection)bindedField).Leave += onEditHandler;
                }
                else if (bindedField is CheckBox)
                {
                    ((CheckBox)bindedField).CheckedChanged += onEditHandler;
                }
                else if (bindedField is ToolStripMenuItem)
                {
                    ((ToolStripMenuItem)bindedField).CheckedChanged += onEditHandler;
                }
                else if (bindedField is ctrlRiskyOption)
                {
                    ((ctrlRiskyOption)bindedField).Click += onEditHandler;
                }
                else if (bindedField is RadioButton)
                {
                    ((RadioButton)bindedField).CheckedChanged += onEditHandler;
                }
                else if (bindedField is PictureBox)
                {
                    ((PictureBox)bindedField).BackColorChanged += onEditHandler;
                }
                else if (bindedField is Panel)
                {
                    FieldInfoWrapper field = _fieldInfo[fieldName];
                    object           value = field.GetValue(this.Entity);
                    RadioButton      radio = ((Panel)bindedField).Controls.OfType <RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
                    if (radio != null)
                    {
                        radio.CheckedChanged += onEditHandler;
                    }
                    else
                    {
                        throw new Exception("No radio button matching value found");
                    }
                }
                else if (bindedField is ctrlTrackbar)
                {
                    ((ctrlTrackbar)bindedField).ValueChanged += onEditHandler;
                }
                else if (bindedField is ctrlHorizontalTrackbar)
                {
                    ((ctrlHorizontalTrackbar)bindedField).ValueChanged += onEditHandler;
                }
                else if (bindedField is TrackBar)
                {
                    ((TrackBar)bindedField).ValueChanged += onEditHandler;
                }
                else if (bindedField is MesenNumericUpDown)
                {
                    ((MesenNumericUpDown)bindedField).ValueChanged += onEditHandler;
                }
                else if (bindedField is ComboBox)
                {
                    ((ComboBox)bindedField).SelectedIndexChanged += onEditHandler;
                }

                _fieldFormat[fieldName] = format;
            }
            else
            {
                throw new Exception("Invalid field name");
            }
        }
コード例 #6
0
        public static void SetNumberFormat(FarPoint.Win.Spread.Column col, eNumberFormat format)
        {
            FarPoint.Win.Spread.CellType.NumberCellType type = new FarPoint.Win.Spread.CellType.NumberCellType();

            type.ButtonAlign = FarPoint.Win.ButtonAlign.Right;

            col.HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Right;

            switch (format)
            {
            case eNumberFormat.Amount:
                type.DecimalPlaces    = 2;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MaximumValue     = (Math.Pow(10, 10 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Amount_THB:
                type.DecimalPlaces    = 2;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MaximumValue     = (Math.Pow(10, 10 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Qty_KG:
                type.DecimalPlaces    = 2;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 5 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Qty_Adjust_KG:
                type.DecimalPlaces    = 2;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 5 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Qty_Gram:
                type.DecimalPlaces    = 4;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 4 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Qty_PCS:
                type.DecimalPlaces    = 0;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 9 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Qty_Adjust_PCS:
                type.DecimalPlaces    = 0;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 12 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.UnitPrice:
                type.DecimalPlaces    = 4;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MaximumValue     = (Math.Pow(10, 5 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.ExchangeRate:
                type.DecimalPlaces    = 4;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MaximumValue     = (Math.Pow(10, 4 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.MasterNo:
                type.DecimalPlaces    = 0;
                type.DecimalSeparator = ".";
                type.Separator        = "";
                type.ShowSeparator    = false;
                type.MaximumValue     = (Math.Pow(10, 10 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Total_Qty_PCS:
                type.DecimalPlaces    = 0;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 8 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.Qty_Box:
                type.DecimalPlaces    = 0;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = true;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 4 /*จำนวนหลัก*/) - 1);
                break;

            case eNumberFormat.TagNo:
                type.DecimalPlaces    = 0;
                type.DecimalSeparator = ".";
                type.Separator        = ",";
                type.ShowSeparator    = false;
                type.MinimumValue     = 0;
                type.MaximumValue     = (Math.Pow(10, 5 /*จำนวนหลัก*/) - 1);
                break;

            default: break;
            }

            col.CellType = type;
        }
コード例 #7
0
        public static void SetNumberFormat(EVOFramework.Windows.Forms.EVONumericTextBox txtNumber, eNumberFormat format)
        {
            txtNumber.TextAlign          = System.Windows.Forms.HorizontalAlignment.Right;
            txtNumber.FixDecimalPosition = true;

            switch (format)
            {
            case eNumberFormat.Amount:
                txtNumber.MaxDecimalPlaces = 2;
                txtNumber.MaxWholeDigits   = 10;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Amount_THB:
                txtNumber.MaxDecimalPlaces = 2;
                txtNumber.MaxWholeDigits   = 10;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Qty_KG:
                txtNumber.MaxDecimalPlaces = 2;
                txtNumber.MaxWholeDigits   = 5;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Qty_Adjust_KG:
                txtNumber.MaxDecimalPlaces = 2;
                txtNumber.MaxWholeDigits   = 5;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Qty_Gram:
                txtNumber.MaxDecimalPlaces = 4;
                txtNumber.MaxWholeDigits   = 4;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Qty_PCS:
                txtNumber.MaxDecimalPlaces = 0;
                txtNumber.MaxWholeDigits   = 11;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Qty_Adjust_PCS:
                txtNumber.MaxDecimalPlaces = 0;
                txtNumber.MaxWholeDigits   = 12;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.UnitPrice:
                txtNumber.MaxDecimalPlaces = 4;
                txtNumber.MaxWholeDigits   = 5;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.ExchangeRate:
                txtNumber.MaxDecimalPlaces = 4;
                txtNumber.MaxWholeDigits   = 4;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.MasterNo:
                txtNumber.MaxDecimalPlaces = 0;
                txtNumber.MaxWholeDigits   = 10;
                txtNumber.RangeMin         = 0;
                txtNumber.DigitsInGroup    = 0;
                txtNumber.GroupSeparator   = ',';
                txtNumber.RangeMax         = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength        = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                             + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                             + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                             + txtNumber.MaxWholeDigits
                                             + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.Total_Qty_PCS:
                txtNumber.MaxDecimalPlaces = 0;
                txtNumber.MaxWholeDigits   = 8;
                if (txtNumber.AllowNegative)
                {
                    txtNumber.RangeMin     = (-1) * (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                    txtNumber.NegativeSign = '-';
                }
                else
                {
                    txtNumber.RangeMin = 0;
                }
                txtNumber.DigitsInGroup  = 3;
                txtNumber.GroupSeparator = ',';
                txtNumber.RangeMax       = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength      = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                           + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                           + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                           + txtNumber.MaxWholeDigits
                                           + txtNumber.MaxDecimalPlaces;
                break;

            case eNumberFormat.TagNo:
                txtNumber.MaxDecimalPlaces = 0;
                txtNumber.MaxWholeDigits   = 5;
                txtNumber.RangeMin         = 0;
                txtNumber.DigitsInGroup    = 0;
                txtNumber.GroupSeparator   = ',';
                txtNumber.RangeMax         = (Math.Pow(10, txtNumber.MaxWholeDigits) - 1);
                txtNumber.MaxLength        = (txtNumber.MaxDecimalPlaces > 0 ? ((txtNumber.MaxWholeDigits - 1) / 3) : 0) // คำนวณ ,
                                             + (txtNumber.MaxDecimalPlaces > 0 ? 1 : 0)                                  // คำนวณ .
                                             + (txtNumber.AllowNegative ? 1 : 0)                                         // คำนวณ -
                                             + txtNumber.MaxWholeDigits
                                             + txtNumber.MaxDecimalPlaces;
                break;

            default: break;
            }
        }