コード例 #1
0
        private void tbAmount_Validating(object sender, EventArgs e)
        {
            double value;
            bool   cancel = false;

            if (string.IsNullOrWhiteSpace(tbAmount.Text)) // Treat blank as a value of 0.
            {
                value = 0.0;
            }
            else if (!Double.TryParse(tbAmount.Text, out value) || value < 0.0)
            {
                cancel = true;
                MessageDialog md = new MessageDialog(MainWidget.Toplevel as Window, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok,
                                                     "Value should be a non-negative number");
                md.Title = "Invalid entry";
                md.Run();
                md.Destroy();
            }
            if (!cancel)
            {
                if (SuppAttrChanged != null)
                {
                    TSuppAttrArgs args = new TSuppAttrArgs();
                    args.attr    = -1;
                    args.attrVal = value;
                    if (SuppAttrChanged != null)
                    {
                        SuppAttrChanged.Invoke(sender, args);
                    }
                }
            }
        }
コード例 #2
0
ファイル: SupplementView.cs プロジェクト: oseledets/ApsimX
        private void tbAmount_Validating(object sender, CancelEventArgs e)
        {
            double value;

            if (string.IsNullOrWhiteSpace(tbAmount.Text)) // Treat blank as a value of 0.
            {
                value = 0.0;
            }
            else if (!Double.TryParse(tbAmount.Text, out value) || value < 0.0)
            {
                e.Cancel = true;
                MessageBox.Show(String.Format("Value should be a non-negative number"));
            }
            if (!e.Cancel && tbAmount.Modified)
            {
                if (SuppAttrChanged != null)
                {
                    TSuppAttrArgs args = new TSuppAttrArgs();
                    args.attr    = -1;
                    args.attrVal = value;
                    SuppAttrChanged.Invoke(sender, args);
                    tbAmount.Modified = false;
                }
            }
        }
コード例 #3
0
        private void cbxRoughage_CheckedChanged(object sender, EventArgs e)
        {
            TSuppAttrArgs args = new TSuppAttrArgs();

            args.attr    = -2;
            args.attrVal = cbxRoughage.Active ? 1 : 0;
            SuppAttrChanged.Invoke(sender, args);
        }
コード例 #4
0
ファイル: SupplementView.cs プロジェクト: ver078/ApsimX
 private void CbxRoughage_CheckedChanged(object sender, EventArgs e)
 {
     try
     {
         TSuppAttrArgs args = new TSuppAttrArgs();
         args.Attr    = -2;
         args.AttrVal = cbxRoughage.Active ? 1 : 0;
         if (SuppAttrChanged != null)
         {
             SuppAttrChanged.Invoke(sender, args);
         }
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
コード例 #5
0
        private void RealEditValidator(object sender, EventArgs e)
        {
            Entry tb = sender as Entry;

            if (tb != null)
            {
                FoodSupplement.SuppAttribute tagEnum;
                if (entryLookup.TryGetValue(tb, out tagEnum))
                {
                    double maxVal = 0.0;
                    double scale  = 1.0;
                    switch (tagEnum)
                    {
                    case FoodSupplement.SuppAttribute.spaDMP:
                    case FoodSupplement.SuppAttribute.spaDMD:
                    case FoodSupplement.SuppAttribute.spaEE:
                    case FoodSupplement.SuppAttribute.spaDG:
                        maxVal = 100.0;
                        scale  = 0.01;
                        break;

                    case FoodSupplement.SuppAttribute.spaMEDM:
                        maxVal = 20.0;
                        break;

                    case FoodSupplement.SuppAttribute.spaCP:
                        maxVal = 300.0;
                        scale  = 0.01;
                        break;

                    case FoodSupplement.SuppAttribute.spaPH:
                    case FoodSupplement.SuppAttribute.spaSU:
                    case FoodSupplement.SuppAttribute.spaADIP:
                        maxVal = 100.0;
                        scale  = 0.01;
                        break;

                    default:
                        maxVal = 100.0;
                        break;
                    }
                    double value;
                    bool   cancel = false;
                    if (string.IsNullOrWhiteSpace(tb.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;
                        cancel = true;
                        MessageDialog md = new MessageDialog(MainWidget.Toplevel as Window, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok,
                                                             String.Format("Value should be a number in the range 0 to {0:F2}", maxVal));
                        md.Title = "Invalid entry";
                        md.Run();
                        md.Destroy();
                    }
                    if (!cancel)
                    {
                        if (SuppAttrChanged != null)
                        {
                            TSuppAttrArgs args = new TSuppAttrArgs();
                            args.attr    = (int)tagEnum;
                            args.attrVal = value * scale;
                            if (SuppAttrChanged != null)
                            {
                                SuppAttrChanged.Invoke(sender, args);
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: SupplementView.cs プロジェクト: oseledets/ApsimX
        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;
                    }
                }
            }
        }