示例#1
0
        private void OnSuppAttrChanged(object sender, TSuppAttrArgs e)
        {
            int attr = e.attr;

            if (attr == -2)
            {
                supplement[suppIdx].IsRoughage = e.attrVal != 0.0;
            }
            else if (attr == -1)
            {
                supplement[suppIdx].Amount = e.attrVal;
            }
            else if (attr >= 0)
            {
                TSupplement.TSuppAttribute tagEnum = (TSupplement.TSuppAttribute)e.attr;
                switch (tagEnum)
                {
                case TSupplement.TSuppAttribute.spaDMP:
                    supplement[suppIdx].DM_Propn = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaDMD:
                    supplement[suppIdx].DM_Digestibility = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaMEDM:
                    supplement[suppIdx].ME_2_DM = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaEE:
                    supplement[suppIdx].EtherExtract = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaCP:
                    supplement[suppIdx].CrudeProt = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaDG:
                    supplement[suppIdx].DgProt = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaADIP:
                    supplement[suppIdx].ADIP_2_CP = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaPH:
                    supplement[suppIdx].Phosphorus = e.attrVal;
                    break;

                case TSupplement.TSuppAttribute.spaSU:
                    supplement[suppIdx].Sulphur = e.attrVal;
                    break;

                default:
                    break;
                }
            }
        }
示例#2
0
        private void RealEditValidator(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;

            if (tb != null)
            {
                TSupplement.TSuppAttribute tagEnum = (TSupplement.TSuppAttribute)tb.Tag;
                double maxVal = 0.0;
                double scale  = 1.0;
                switch (tagEnum)
                {
                case TSupplement.TSuppAttribute.spaDMP:
                case TSupplement.TSuppAttribute.spaDMD:
                case TSupplement.TSuppAttribute.spaEE:
                case TSupplement.TSuppAttribute.spaDG:
                    maxVal = 100.0;
                    scale  = 0.01;
                    break;

                case TSupplement.TSuppAttribute.spaMEDM:
                    maxVal = 20.0;
                    break;

                case TSupplement.TSuppAttribute.spaCP:
                    maxVal = 300.0;
                    scale  = 0.01;
                    break;

                case TSupplement.TSuppAttribute.spaPH:
                case TSupplement.TSuppAttribute.spaSU:
                case TSupplement.TSuppAttribute.spaADIP:
                    maxVal = 200.0;      // Why 200?
                    scale  = 0.01;
                    break;

                default:
                    maxVal = 100.0;
                    break;
                }
                double value;
                if (string.IsNullOrWhiteSpace(tbAmount.Text)) // Treat blank as a value of 0.
                {
                    value = 0.0;
                }
                else if (!Double.TryParse(tb.Text, out value) || value < 0.0 || value > maxVal)
                {
                    e.Cancel = true;
                    MessageBox.Show(String.Format("Value should be a number in the range 0 to {0:F2}", maxVal));
                }
                if (!e.Cancel && tb.Modified)
                {
                    if (SuppAttrChanged != null)
                    {
                        TSuppAttrArgs args = new TSuppAttrArgs();
                        args.attr    = (int)tagEnum;
                        args.attrVal = value * scale;
                        SuppAttrChanged.Invoke(sender, args);
                        tb.Modified = false;
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// The supplement attribute has changed
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The arguments</param>
        private void OnSuppAttrChanged(object sender, TSuppAttrArgs e)
        {
            int attr = e.attr;

            if (attr == -2)
            {
                this.explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(supplement[supplement.curIndex], "IsRoughage", e.attrVal != 0.0));
            }
            else if (attr == -1)
            {
                this.explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(supplement[supplement.curIndex], "Amount", e.attrVal));
            }
            else if (attr >= 0)
            {
                string propName = null;
                TSupplement.TSuppAttribute tagEnum = (TSupplement.TSuppAttribute)e.attr;
                switch (tagEnum)
                {
                case TSupplement.TSuppAttribute.spaDMP:
                    propName = "DM_Propn";
                    break;

                case TSupplement.TSuppAttribute.spaDMD:
                    propName = "DM_Digestibility";
                    break;

                case TSupplement.TSuppAttribute.spaMEDM:
                    propName = "ME_2_DM";
                    break;

                case TSupplement.TSuppAttribute.spaEE:
                    propName = "EtherExtract";
                    break;

                case TSupplement.TSuppAttribute.spaCP:
                    propName = "CrudeProt";
                    break;

                case TSupplement.TSuppAttribute.spaDG:
                    propName = "DgProt";
                    break;

                case TSupplement.TSuppAttribute.spaADIP:
                    propName = "ADIP_2_CP";
                    break;

                case TSupplement.TSuppAttribute.spaPH:
                    propName = "Phosphorus";
                    break;

                case TSupplement.TSuppAttribute.spaSU:
                    propName = "Sulphur";
                    break;

                default:
                    break;
                }
                if (propName != null)
                {
                    this.explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(supplement[supplement.curIndex], propName, e.attrVal));
                }
            }
        }