/// <summary> /// Init the column control list to contain 32 controls with CfColCtl1 & CfColCtl2 first /// </summary> /// <returns></returns> List <CalcFieldColumnControl> AddAdditionalCfColCtls() { List <CalcFieldColumnControl> cfcc = new List <CalcFieldColumnControl>(); cfcc.Add(CfColCtl1); cfcc.Add(CfColCtl2); //ScrollableColumnList.Controls.Clear(); // (any reason we need to do this?) //ScrollableColumnList.Controls.Add(CfColCtl1); //if (label1.Parent == null) // be sure operation control and parent are present // ScrollableColumnList.Controls.Add(label1); //if (Operation.Parent == null) // ScrollableColumnList.Controls.Add(Operation); //ScrollableColumnList.Controls.Add(CfColCtl2); CalcFieldColumnControl prevCtl = CfColCtl2; for (int ci = 2; ci < 32; ci++) { CalcFieldColumnControl cc = new Mobius.ClientComponents.CalcFieldColumnControl(); string cis = (ci + 1).ToString(); cc.FieldLabel = "Data Field " + cis; int dy = prevCtl.Size.Height + 6; cc.Size = new System.Drawing.Size(prevCtl.Size.Width, prevCtl.Size.Height); cc.Location = new System.Drawing.Point(prevCtl.Location.X, prevCtl.Location.Y + dy); cc.Name = "CfColCtl" + cis; //cc.TabIndex = 21; cfcc.Add(cc); ScrollableColumnList.Controls.Add(cc); prevCtl = cc; } return(cfcc); }
/// <summary> /// See if valid basic calculated field /// </summary> /// <returns></returns> private bool IsValidBasicCalcField() { for (int cfcci = 0; cfcci < CfColCtls.Count; cfcci++) { CalcFieldColumnControl cfcc = CfColCtls[cfcci]; bool validate = false; // decide if we should validate this field if (cfcci == 0) { validate = true; // always validate 1st field } else if (cfcci == 1 && !Lex.StartsWith(Operation.Text, "none")) { validate = true; // validate 2nd field if operator is not "none" } else if (cfcc.FieldSelectorControl.MetaColumn != null) { validate = true; } if (validate && !ValidateField(cfcc)) { return(false); } } if (!CondFormatRulesCtl.AreValid()) // are any rules valid { Tabs.SelectedTabPageIndex = 1; return(false); } CondFormatRules rules = CondFormatRulesCtl.GetRules(); if (CalcField.SourceColumnType == MetaColumnType.Structure && rules.Count == 0) { Tabs.SelectedTabPageIndex = 1; MessageBoxMx.Show( "Calculated fields on chemical structures must use classification\r\n" + "for the calculated field value", UmlautMobius.String); return(false); } if (rules.Count > 0) // must have at least one rule { foreach (CondFormatRule rule in rules) // must have name for each rule { if (String.IsNullOrEmpty(rule.Name)) { Tabs.SelectedTabPageIndex = 1; MessageBoxMx.Show("A name must be defined for each rule if using rule names the as calculated value", UmlautMobius.String); return(false); } } } return(true); }
void EnableSecondaryFields(bool enable) { for (int cci = 1; cci < CfColCtls.Count; cci++) { CalcFieldColumnControl cc = CfColCtls[cci]; cc.Enabled = enable; } return; }
/// <summary> /// First field changed, adjust source type /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CfColCtl1_ColumnChanged(object sender, EventArgs e) { CalcFieldColumnControl cfcc = sender as CalcFieldColumnControl; if (cfcc == null || cfcc.FieldSelectorControl == null || cfcc.FieldSelectorControl.MetaColumn == null) { return; } MetaColumn mc = cfcc.FieldSelectorControl.MetaColumn; if (mc != null) // reset form for type { SetSourceColumnType((int)mc.DataType); } }
/// <summary> /// Check column control for validity /// </summary> /// <param name="cfcc"></param> /// <returns></returns> private bool ValidateField( CalcFieldColumnControl cfcc) { string table = cfcc.FieldSelectorControl.TableName.Text; //cfcc.CfCol.TableName.Text; string field = cfcc.FieldSelectorControl.FieldName.Text; // cfcc.CfCol.FieldName.Text; string function = cfcc.Function.Text; string constant = cfcc.Constant.Text; string label = cfcc.FieldLabel; if (table == "" || field == "") { MessageBoxMx.Show("You must define the " + label + " data field"); return(false); } if (function.ToLower().IndexOf("constant") >= 0) // do we have a constant? { if (constant == "") { MessageBoxMx.Show("You must define the " + label + " data field"); return(false); } try { Double.Parse(constant); } catch (Exception ex) { MessageBoxMx.Show("The constant " + constant + " for the " + label + " data field is not valid"); return(false); } } if (function == "" || function.ToLower().StartsWith("---")) // valid function? { MessageBoxMx.Show("Invalid function for the " + label + " data field"); return(false); } return(true); }