Example #1
0
        public void bigRangeDateTest()
        {
            DateTime dt1 = new DateTime(1, 1, 1);
            DateTime dt2 = new DateTime(9999, 12, 12);
            d = new FieldNode(2, "name", "DDMMYYYY", dt1, dt2);

            string sDate;

            for (int i = 0; i < 10000; i++)
            {
                sDate = d.getRndDate();
                DateTime dt = DateTime.Parse(sDate);
                Assert.Greater(dt, dt1);
                Assert.Greater(dt2, dt);
            }
        }
        private void saveField()
        {
            if (clickedBtnIndex != -1)
                FieldBtn[clickedBtnIndex].Text = nameTxt.Text;
            if (this.typeBox.SelectedIndex == 0)
            {
                int type = 0;
                string name = this.nameTxt.Text;
                string pathToFile;
                if (fd.FileName != "")
                {
                    pathToFile = fd.FileName;
                }
                else
                {
                    pathToFile = standartList.SelectedItem.ToString();
                }
                if (clickedBtnIndex == -1)
                    nodes.Add(new FieldNode(type, name, pathToFile));
                else
                    nodes[clickedBtnIndex] = new FieldNode(type, name, pathToFile);

            }
            else if (this.typeBox.SelectedIndex == 1)
            {
                int type = 1;
                string name = this.nameTxt.Text;
                long from = long.Parse(this.rangeFromTxt.Text.Trim());
                long to = long.Parse(this.rangeToTxt.Text.Trim());
                if (clickedBtnIndex == -1)
                    nodes.Add(new FieldNode(type, name, from, to));
                else
                    nodes[clickedBtnIndex] = new FieldNode(type, name, from, to);
            }
            else if (this.typeBox.SelectedIndex == 2)
            {
                int type = 2;
                string name = this.nameTxt.Text;
                string dateFormat = this.dateFormatCbox.SelectedItem.ToString();
                DateTime dfrom = this.datePickerFrom.Value;
                DateTime dto = this.datePickerTo.Value;
                if (clickedBtnIndex == -1)
                    nodes.Add(new FieldNode(type, name, dateFormat, dfrom, dto));
                else
                    nodes[clickedBtnIndex] = new FieldNode(type, name, dateFormat, dfrom, dto);
            }
            else if (this.typeBox.SelectedIndex == 3)
            {
                int type = 3;
                string name = this.nameTxt.Text;
                long start = long.Parse(this.seqFromTxt.Text.Trim());
                long step = long.Parse(this.seqStepTxt.Text.Trim());
                if (clickedBtnIndex == -1)
                    nodes.Add(new FieldNode(name, type, start, step));
                else
                    nodes[clickedBtnIndex] = new FieldNode(name, type, start, step);
            }
            else if (this.typeBox.SelectedIndex == 4)
            {

                int type = 4;
                string name = this.nameTxt.Text;
                string pathToFile;
                if (fd.FileName != "")
                {
                    pathToFile = fd.FileName;
                }
                else
                {
                    pathToFile = standartList.SelectedItem.ToString();
                }
                if (clickedBtnIndex == -1)
                    nodes.Add(new FieldNode(type, name, pathToFile));
                else
                    nodes[clickedBtnIndex] = new FieldNode(type, name, pathToFile);
            }
        }
 private void BtClick(object sender, System.EventArgs e)
 {
     nodes.Clear();
     foreach(Button b in FieldBtn)
         LeftPanel.Controls.Remove(b);
     foreach (Button b in ParametresBtn)
         LeftPanel.Controls.Remove(b);
     foreach (Button b in DeleteBtn)
         LeftPanel.Controls.Remove(b);
     FieldBtn.Clear();
     ParametresBtn.Clear();
     DeleteBtn.Clear();
     tBtn = 0;
     string f = (sender as Button).Name.ToString();
     using (var db = new MyDBContext())
     {
         var find = from templ in db.Templetes
                    where templ.Id.ToString() == f
                    select templ;
         if (find != null)
         {
             foreach (var t in find)
             {
                 string [] record = t.Tmp.Split(new Char [] { '_' });
                 foreach(var r in record)
                 {
                     FieldNode fn = null;
                     string[] pole = r.Split(new Char[] { ';' });
                     if(pole[0] == "0")
                     {
                         fn = new FieldNode(Int32.Parse(pole[0]), pole[1], pole[2].ToString());
                     }
                     if (pole[0] == "1")
                     {
                         fn = new FieldNode(Int32.Parse(pole[0]), pole[1], long.Parse(pole[2]), long.Parse(pole[3]));
                     }
                     if(pole[0] == "2")
                     {
                         DateTime from = new DateTime();
                         DateTime to = new DateTime();
                         DateTime.TryParse(pole[3],out from);
                         DateTime.TryParse(pole[4],out to);
                         fn = new FieldNode(Int32.Parse(pole[0]), pole[1], pole[2], from, to);
                     }
                     if(pole[0] == "3")
                     {
                         fn = new FieldNode(pole[1], Int32.Parse(pole[0]), long.Parse(pole[2]), long.Parse(pole[3]));
                     }
                     if(pole[0] == "4")
                     {
                         fn = new FieldNode(Int32.Parse(pole[0]), pole[1], pole[2]);
                     }
                     if(fn != null)
                     {
                         nodes.Add(fn);
                         nameTxt.Text = fn.name;
                         NewButton();
                     }
                 }
                 //foreach(var n in nodes)
                   //  MessageBox.Show(n.type.ToString() + " : " + n.name.ToString());
                 //MessageBox.Show(t.Tmp);
             }
         }
     }
 }
Example #4
0
        private void saveT_Click(object sender, EventArgs e)
        {
            if (clickedBtnIndexT == -1)
            {
                Message mess = new Message(this, "Oшибка", "Выберите шаблон!", MessageBoxIcon.Warning);
                mess.switchMessage();
                cancelT_Click(sender, e);
                return;
            }
            nodes.Clear();
            foreach (Button b in FieldBtn)
                LeftPanel.Controls.Remove(b);
            foreach (Button b in ParametresBtn)
                LeftPanel.Controls.Remove(b);
            foreach (Button b in DeleteBtn)
                LeftPanel.Controls.Remove(b);
            FieldBtn.Clear();
            ParametresBtn.Clear();
            DeleteBtn.Clear();
            tBtn = 0;
            if (tBtn == -1)
            {
                Message mess = new Message(this, "Oшибка", "Выберите шаблон!", MessageBoxIcon.Warning);
                mess.switchMessage();
                cancelT_Click(sender, e);
                return;
            }
            string f = "";
            try
            {

                 f = TemplateBtnArray[clickedBtnIndexT].Name.ToString();
            }
            catch (Exception)
            {
                Message mess = new Message(this, "Oшибка", "Выберите шаблон!", MessageBoxIcon.Warning);
                mess.switchMessage();
                cancelT_Click(sender, e);
            }
            using (var db = new MyDBContext())
            {
                var find = from templ in db.Templates
                           where templ.Id.ToString() == f
                           select templ;
                if (find != null)
                {
                    foreach (var t in find)
                    {
                        string[] record = t.Tmp.Split(new Char[] { '_' });
                        foreach (var r in record)
                        {
                            FieldNode fn = null;
                            string[] pole = r.Split(new Char[] { ';' });
                            if (pole[0] == "0")
                            {
                                fn = new FieldNode(Int32.Parse(pole[0]), pole[1], pole[2]);
                            }
                            if (pole[0] == "1")
                            {
                                fn = new FieldNode(Int32.Parse(pole[0]), pole[1], long.Parse(pole[2]), long.Parse(pole[3]));
                            }
                            if (pole[0] == "2")
                            {
                                DateTime from = new DateTime();
                                DateTime to = new DateTime();
                                DateTime.TryParse(pole[3], out from);
                                DateTime.TryParse(pole[4], out to);
                                fn = new FieldNode(Int32.Parse(pole[0]), pole[1], pole[2], from, to);
                            }
                            if (pole[0] == "3")
                            {
                                fn = new FieldNode(pole[1], Int32.Parse(pole[0]), long.Parse(pole[2]), long.Parse(pole[3]));
                            }
                            if (pole[0] == "4")
                            {
                                fn = new FieldNode(Int32.Parse(pole[0]), pole[1], pole[2]);
                            }
                            if (fn != null)
                            {
                                nodes.Add(fn);
                                nameTxt.Text = fn.name;
                                NewButton();
                            }
                        }
                        //foreach(var n in nodes)
                        //  MessageBox.Show(n.type.ToString() + " : " + n.name.ToString());
                        //MessageBox.Show(t.Tmp);
                    }
                }
            }

            f2.Close();
        }
Example #5
0
 public void standartDataTest()
 {
     d = new FieldNode(4, "name", "Фамилии");
     Assert.Contains("Ярцев ", d.data);
 }
Example #6
0
 public void wrongFormatDateTest()
 {
     DateTime dt1 = new DateTime(2014, 1, 1);
     DateTime dt2 = new DateTime(2015, 12, 12);
     d = new FieldNode(2, "name", "DDMMMYYYYYYY", dt1, dt2);
     string sDate = d.getRndDate();
     DateTime dt = DateTime.Parse(sDate);
     Assert.Greater(dt, dt1);
     Assert.Greater(dt2, dt);
 }
Example #7
0
        public void sequentialStringTest()
        {
            d = new FieldNode(1, "1", 1, 1);
            d.data.Add("1");
            d.data.Add("2");
            d.data.Add("3");

            Assert.AreEqual("1", d.getSequentialString(0));
            Assert.AreEqual("1", d.getSequentialString(3));
            Assert.AreNotEqual("1", d.getSequentialString(4));
        }
Example #8
0
 public void initFieldNodeString()
 {
     a = new FieldNode(0, "name", "Фамилии");
 }
Example #9
0
 public void initFieldNodeStep()
 {
     b = new FieldNode("name", 2, 1, 1);
 }
Example #10
0
 public void initFieldNodeRand()
 {
     c = new FieldNode( 1 ,"name", 5, 7);
 }
Example #11
0
 public void initFieldNodeDate()
 {
     d = new FieldNode(2, "name", "dd.MM.yyyy", new DateTime(2015, 5, 1), new DateTime(2015, 5, 2));
 }