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; } } }
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); } } } }
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); }
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; } } }
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); } }
/// <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) { try { int attr = e.Attr; if (attr == -2) { explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(supplement[supplement.CurIndex], "IsRoughage", e.AttrVal != 0.0)); } else if (attr == -1) { explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(supplement[supplement.CurIndex], "Amount", e.AttrVal)); } else if (attr >= 0) { string propName = null; FoodSupplement.SuppAttribute tagEnum = (FoodSupplement.SuppAttribute)e.Attr; switch (tagEnum) { case FoodSupplement.SuppAttribute.spaDMP: propName = "DMPropn"; break; case FoodSupplement.SuppAttribute.spaDMD: propName = "DMDigestibility"; break; case FoodSupplement.SuppAttribute.spaMEDM: propName = "ME2DM"; break; case FoodSupplement.SuppAttribute.spaEE: propName = "EtherExtract"; break; case FoodSupplement.SuppAttribute.spaCP: propName = "CrudeProt"; break; case FoodSupplement.SuppAttribute.spaDG: propName = "DegProt"; break; case FoodSupplement.SuppAttribute.spaADIP: propName = "ADIP2CP"; break; case FoodSupplement.SuppAttribute.spaPH: propName = "Phosphorus"; break; case FoodSupplement.SuppAttribute.spaSU: propName = "Sulphur"; break; default: break; } if (propName != null) { explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(supplement[supplement.CurIndex], propName, e.AttrVal)); } } } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } }
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); } } } } } }
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; SuppAttrChanged.Invoke(sender, args); } } }
private void RealEditValidator(object sender, EventArgs e) { Entry tb = sender as Entry; if (tb != null) { TSupplement.TSuppAttribute tagEnum; if (entryLookup.TryGetValue(tb, out tagEnum)) { 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; 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; SuppAttrChanged.Invoke(sender, args); } } } } }
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; } } } }
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; } } }
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; } } } }
/// <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)); } } }