private void CreateConstraint_Click(object sender, RoutedEventArgs e) { var item = new ConstraintItem(); item.Elements = this.GetElements(); item.ObjectType = this.objType; if (!string.IsNullOrEmpty(this.amountBox.Text)) { try { item.Amount = Convert.ToInt32(this.amountBox.Text); if (item.Amount < 0) { throw new Exception("The number can not be less than zero."); } if (item.Elements.Item1 == string.Empty) { throw new Exception("Please, choose element type."); } } catch (Exception ex) { this.errorLabel.Visibility = Visibility.Visible; this.errorLabel.Foreground = Brushes.Red; this.errorLabel.Text = ex.Message; return; } } if (this.model.Constraints.Add(item.Elements, item.Amount)) { this.constraintsList.Add(item); } else { foreach (var listItem in this.constraintsList) { if ((listItem.Elements.Item1 == item.Elements.Item1) && (listItem.Elements.Item2 == item.Elements.Item2)) { listItem.Amount = item.Amount; } } } this.ConstraintsPanel.ItemsSource = null; this.ConstraintsPanel.ItemsSource = this.constraintsList; }
private void DeleteItem_Click(object sender, RoutedEventArgs e) { var button = sender as Button; var item = button.DataContext as ConstraintItem; var removingElement = new ConstraintItem(); foreach (var listItem in this.constraintsList) { if ((listItem.Elements.Item1 == item.Elements.Item1) && (listItem.Elements.Item2 == item.Elements.Item2) && (listItem.Elements.Item3 == item.Elements.Item3)) { removingElement = listItem; } } this.constraintsList.Remove(removingElement); this.ConstraintsPanel.ItemsSource = null; this.ConstraintsPanel.ItemsSource = this.constraintsList; }
public frmAddConstraint(List <string> TheAggregates, TAIObjectCanvas2.CanvasObject obj) { InitializeComponent(); taig.Cols = 1; taig.set_HeaderLabel(0, "Aggregation to constrain"); taig.Rows = 0; foreach (string s in TheAggregates) { taig.Rows += 1; taig.set_item(taig.Rows - 1, 0, s); } if (obj.MetaData2 != string.Empty) { ConstraintItem ci = new ConstraintItem(); List <string> constraintValues = new List <string>(); //parse through the meta info to papulate the ConstraintItem object string[] meta = obj.MetaData2.Split('|'); string[] values = meta[2].Split(','); taig.AutoSizeCellsToContents = true; taig.Refresh(); ci.ConstraintType = meta[0]; ci.ConstraintField = meta[1]; for (int i = 0; i < values.Length; i++) { constraintValues.Add(values[i]); } ci.ConstraintValues = constraintValues; //Populate the appropriate text box according to the constraint type switch (ci.ConstraintType) { case "EQUAL": txtNumEqual.Text = ci.ConstraintValues[0]; break; case "NOTEQUAL": txtNumNotEqual.Text = ci.ConstraintValues[0]; break; case "GREATERTHAN": txtNumGreaterThan.Text = ci.ConstraintValues[0]; break; case "LESSTHAN": txtNumLessThan.Text = ci.ConstraintValues[0]; break; case "BETWEEN": txtNumBetweenLower.Text = ci.ConstraintValues[0]; txtNumBetweenUpper.Text = ci.ConstraintValues[1]; break; } //Find the corresponding row id and select the row (if a row was found) int row = taig.FindInColumn(ci.ConstraintField, taig.GetColumnIDByName("Aggregation to constrain"), false); if (row != -1) { taig.SelectedRow = row; } //generate the SQL clause GenerateClause(); } else { showError("Unable to load object data"); } }
private void GenerateClause() { try { string sql = ""; ConstraintItem ci = new ConstraintItem(); List <string> ciValues = new List <string>(); if (taig.SelectedRow != -1) { string isn = "YES"; //string isd = taig.get_item(taig.SelectedRow, "DATE"); //string isa = taig.get_item(taig.SelectedRow, "ALPHA"); if (isn == "YES") { sql = taig.get_item(taig.SelectedRow, "Aggregation to constrain") + " "; ci.ConstraintField = taig.get_item(taig.SelectedRow, "Aggregation to constrain"); if (txtNumEqual.Text != "") { sql += "= " + txtNumEqual.Text + ""; ci.ConstraintType = "EQUAL"; ciValues.Add(txtNumEqual.Text); ci.ConstraintValues = ciValues; } if (txtNumNotEqual.Text != "") { sql += "<> " + txtNumNotEqual.Text + ""; ci.ConstraintType = "NOTEQUAL"; ciValues.Add(txtNumNotEqual.Text); ci.ConstraintValues = ciValues; } if (txtNumGreaterThan.Text != "") { sql += "> " + txtNumGreaterThan.Text + ""; ci.ConstraintType = "GREATERTHAN"; ciValues.Add(txtNumGreaterThan.Text); ci.ConstraintValues = ciValues; } if (txtNumLessThan.Text != "") { sql += "< " + txtNumLessThan.Text + ""; ci.ConstraintType = "LESSTHAN"; ciValues.Add(txtNumLessThan.Text); ci.ConstraintValues = ciValues; } if (txtNumBetweenLower.Text != "" && txtNumBetweenUpper.Text != "") { sql += "BETWEEN " + txtNumBetweenLower.Text + " AND " + txtNumBetweenUpper.Text + ""; ci.ConstraintType = "BETWEEN"; ciValues.Add(txtNumBetweenLower.Text); ciValues.Add(txtNumBetweenUpper.Text); ci.ConstraintValues = ciValues; } } } Constraint = ci; Clause = sql; txtClause.Text = sql; } catch (Exception ex) { showError("An error occurred while generating the query clause" + System.Environment.NewLine + ex.ToString()); } }