private void onePanelChanged(object sender, EventArgs e) { if (this.locked) { return; } try { string test = ""; foreach (Control ct in panel1.Controls) { if (ct is OperationArithmetic) { test += ((OperationArithmetic)ct).toString(); } if (ct is OperationCondition) { test += ((OperationCondition)ct).toString(); } } test = Regex.Replace(test, @"\s+", "").Replace(',', '.'); string s = ConditionTranslator.TranslateCondition(test); if (s.Length == 0) { MessageBox.Show("Error: " + ConditionTranslator.GetLastError()); } if (s == null) { //if (MessageBox.Show("Error: " + ConditionTranslator.GetLastError(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand) != DialogResult.Cancel) return; } else { Condition condition = new Condition().GetCondition(new CharStream(s)); if (condition == null) { //if (MessageBox.Show("Error parsing text.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand) != DialogResult.Cancel) return; } else { this.Result = condition; } } this.ConditionTB.Text = this.Result.GetRepresentation(); } catch { } }
public void SingleCondition() { var builder = new StringBuilder(); var translator = new ConditionTranslator(builder); var condition = new Condition { AttributeName = "Название империи", Operation = Operation.NotEqual, Value = "Империя 1" }; translator.Translate(condition); Assert.Equal("\n\"empires\".\"name\" <> @0", builder.ToString()); Assert.Single(translator.Parameters); Assert.Equal("Империя 1", translator.Parameters["@0"]); }
private void ConditionVisual_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; string test = ""; foreach (Control ct in panel1.Controls) { if (ct is OperationArithmetic) { test += ((OperationArithmetic)ct).toString(); } if (ct is OperationCondition) { test += ((OperationCondition)ct).toString(); } } /// MessageBox.Show(test); string s = ConditionTranslator.TranslateCondition(string.Join("", test.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries))); if (s == null) { if (MessageBox.Show("Error: " + ConditionTranslator.GetLastError(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand) != DialogResult.Cancel) { return; } e.Cancel = false; } else { Condition condition = new Condition().GetCondition(new CharStream(s)); if (condition == null) { if (MessageBox.Show("Error parsing text.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand) != DialogResult.Cancel) { return; } e.Cancel = false; } else { this.Result = condition; this.DialogResult = DialogResult.OK; e.Cancel = false; } } }
public void SeveralCondition() { var builder = new StringBuilder(); var translator = new ConditionTranslator(builder); translator.Translate(new Condition { AttributeName = "Название империи", Operation = Operation.Equal, Value = "Империя 1", Link = LinkMethod.And }); translator.Translate(new Condition { AttributeName = "Название планеты", Operation = Operation.LessEqual, Value = "Планета 1", Link = LinkMethod.Or }); translator.Translate(new Condition { AttributeName = "Мощь империи", Operation = Operation.More, Value = 50, }); Assert.Equal("\n\"empires\".\"name\" = @0 and" + "\n\"planets\".\"name\" <= @1 or" + "\n\"empires\".\"power\" > @2", builder.ToString()); Assert.Equal(3, translator.Parameters.Count); Assert.Equal("Империя 1", translator.Parameters["@0"]); Assert.Equal("Планета 1", translator.Parameters["@1"]); Assert.Equal(50, translator.Parameters["@2"]); }