コード例 #1
0
 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 { }
 }
コード例 #2
0
        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"]);
        }
コード例 #3
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;
                }
            }
        }
コード例 #4
0
        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"]);
        }