Exemplo n.º 1
0
 public void connectionTest()
 {
     using (var db = new MyDBContext())
     {
         db.Templates.Add(new Template { Name = "name", Tmp = "string" });
         db.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public void wrongDeletionTest()
 {
     int id = 0;
     using (var db = new MyDBContext())
     {
         var del = db.Templates.SingleOrDefault(x => x.Id == id);
         db.Templates.Remove(del);
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void entryTest()
 {
     List<int> ids = new List<int>();
     Random r = new Random();
     int id = -1;
     using (var db = new MyDBContext())
     {
         db.Templates.Add(new Template { Name = "name", Tmp = "string" });
         db.SaveChanges();
         foreach (var templete in db.Templates)
         {
             if (templete.Name == "name" && templete.Tmp == "string")
                 id = templete.Id;
         }
     }
     Assert.AreNotEqual("-1", id);
 }
Exemplo n.º 4
0
        public void deletionTest()
        {
            int id = 0;
            using (var db = new MyDBContext())
            {
                db.Templates.Add(new Template { Name = "name", Tmp = "string" });
                db.SaveChanges();
                foreach (var templete in db.Templates)
                {
                    id = templete.Id;
                }

            }
            using (var db = new MyDBContext()) {
                var del = db.Templates.SingleOrDefault(x => x.Id == id);
                db.Templates.Remove(del);
                db.SaveChanges();
            }
        }
Exemplo n.º 5
0
 private void button2_Click(object sender, EventArgs e)
 {
     //обозреватель шаблонов
     Form f2 = new Form();
     int i = 0;
     using (var db = new MyDBContext())
     {
         Button[] bt = new Button[50];
         foreach (var templete in db.Templetes)
         {
                 bt[i] = new Button();
                 bt[i].Name = templete.Id.ToString();
                 bt[i].Text = templete.Name;
                 bt[i].Left = 10 + i * 50;
                 bt[i].Top = 10 + i * 50;
                 bt[i].Click += new EventHandler(BtClick);
                 f2.Controls.Add(bt[i]);
             i++;
         }
     }
     f2.Show();
 }
Exemplo n.º 6
0
 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);
             }
         }
     }
 }
Exemplo n.º 7
0
 private void button1_Click(object sender, EventArgs e)
 {
     //сохранение шаблона
     string result_str = "";
     foreach (FieldNode a in nodes)
     {
         result_str += a.type.ToString() + ";";
         if (a.type == 0)
         {
             result_str += a.name + ";";
             if (a.pathToFile != "")
             {
                 result_str += a.pathToFile.ToString() + ";";
             }
             else
             {
                 result_str += standartList.SelectedItem.ToString() + ";";
             }
         }
         if (a.type == 1)
         {
             result_str += a.name + ";";
             result_str += a.from.ToString() + ";";
             result_str += a.to.ToString() + ";";
         }
         if(a.type == 2)
         {
             result_str += a.name + ";";
             result_str += a.dateFormat + ";";
             //result_str += dateFormatCbox.SelectedItem.ToString() + ";";
             result_str += a.dfrom.ToString() + ";";
             result_str += a.dto.ToString() + ";";
         }
         if(a.type == 3)
         {
             result_str += a.name.ToString() + ";";
             result_str += long.Parse(this.seqFromTxt.Text.Trim()) + ";";
             result_str += long.Parse(this.seqStepTxt.Text.Trim()) + ";";
         }
         if (a.type == 4)
         {
             result_str += a.name + ";";
             if (a.pathToFile != "")
                 result_str += a.pathToFile.ToString() + ";";
             else
                 result_str += standartList.SelectedValue.ToString() + ";";
         }
         result_str += "_";
     }
     using (var db = new MyDBContext())
     {
         db.Templetes.Add(new Templete { Name = "Test111", Tmp = result_str });
         db.SaveChanges();
     }
     MessageBox.Show("Шаблон сохранен!");
 }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        private void deleteBtnT_Click(object sender, EventArgs e)
        {
            int id = int.Parse((sender as Button).Name.ToString());
            using (var db = new MyDBContext())
            {
                var del = db.Templates.SingleOrDefault(x => x.Id == id);
                if (del != null)
                {
                    db.Templates.Remove(del);
                    db.SaveChanges();
                }
            }
            int i = 0;
            foreach (Button b in DeleteBtnArray)
            {
                if (sender == b)
                {
                    leftPanelT.Controls.Remove(TemplateBtnArray[i]);
                    TemplateBtnArray[i].Dispose();
                    TemplateBtnArray.RemoveAt(i);

                    leftPanelT.Controls.Remove(DeleteBtnArray[i]);
                    DeleteBtnArray[i].Dispose();
                    DeleteBtnArray.RemoveAt(i);

                    for (int j = i; j < TemplateBtnArray.Count; j++)
                    {
                        TemplateBtnArray[j].Location = new Point(TemplateBtnArray[j].Location.X, TemplateBtnArray[j].Location.Y - deltaY);
                        DeleteBtnArray[j].Location = new Point(DeleteBtnArray[j].Location.X, DeleteBtnArray[j].Location.Y - deltaY);
                    }
                    break;
                }
                i++;
            }
        }
Exemplo n.º 10
0
        private void button2_Click(object sender, EventArgs e)
        {
            //обозреватель шаблонов
            int i = 0;
            TemplateBtnArray.Clear();
            DeleteBtnArray.Clear();
            f2 = new Form();
            f2.Text = "Шаблоны";
            f2.MinimizeBox = false;
            f2.MaximizeBox = false;
            f2.Size = new Size(260, 430);
            f2.FormBorderStyle = FormBorderStyle.FixedDialog;
            f2.StartPosition = FormStartPosition.Manual;
            f2.Location = new Point(this.Location.X + (this.Width - f2.Width) / 2, this.Location.Y + (this.Height - f2.Height) / 2);

            Label lblT = new Label();
            lblT.Location = new Point(25, 10);
            lblT.Size = new Size(198, 30);
            lblT.Text = "Список шаблонов :";
            lblT.Font = new Font("Segoe UI", 12);
            f2.Controls.Add(lblT);

            leftPanelT = new Panel();
            leftPanelT.AutoScroll = true;
            leftPanelT.Size = new Size(198, 300);
            leftPanelT.Location = new Point(25, 50);
            leftPanelT.BorderStyle = BorderStyle.FixedSingle;
            leftPanelT.Visible = true;
            f2.Controls.Add(leftPanelT);

            Button saveT = new Button();

            saveT.Location = new Point(23, 355);
            saveT.Size = new Size(98, 30);
            saveT.Font = new Font("Segoe UI", 8);
            saveT.Text = "Продолжить";
            saveT.Click += new System.EventHandler(this.saveT_Click);
            f2.Controls.Add(saveT);

            Button cancelT = new Button();
            cancelT.Location = new Point(127, 355);
            cancelT.Size = new Size(98, 30);
            cancelT.Font = new Font("Segoe UI", 8);
            cancelT.Text = "Отмена";
            cancelT.Click += new System.EventHandler(this.cancelT_Click);
            f2.Controls.Add(cancelT);

            using (var db = new MyDBContext())
            {
                foreach (var templete in db.Templates)
                {
                    Button TemplateBtnT = new Button();
                    TemplateBtnT.Size = new Size(164, 32);

                    Button deleteBtnT = new Button();
                    deleteBtnT.Size = new Size(32, 32);

                    int newLocationY;
                    if (TemplateBtnArray.Count == 0)
                        newLocationY = locationYT;
                    else
                    {

                        int maxY = TemplateBtnArray[TemplateBtnArray.Count - 1].Location.Y;
                        newLocationY = maxY + deltaYT;
                    }

                    TemplateBtnT.Location = new Point(locationXT, newLocationY);
                    TemplateBtnT.Visible = true;
                    TemplateBtnT.Text = templete.Name;
                    TemplateBtnT.Font = new Font("Segoe UI", 8);
                    TemplateBtnT.BackColor = defaultColor;
                    TemplateBtnT.Name = templete.Id.ToString();

                    deleteBtnT.Location = new Point(locationXT + 164, newLocationY);
                    deleteBtnT.Visible = true;
                    deleteBtnT.Font = new Font("Segoe UI", 8);
                    deleteBtnT.BackgroundImage = Properties.Resources._1435861214_remove_sign;
                    deleteBtnT.BackgroundImageLayout = ImageLayout.Center;
                    deleteBtnT.Name = templete.Id.ToString();

                    TemplateBtnT.Click += new System.EventHandler(this.TemplateBtnT_Click);
                    deleteBtnT.Click += new System.EventHandler(this.deleteBtnT_Click);

                    TemplateBtnArray.Add(TemplateBtnT);
                    DeleteBtnArray.Add(deleteBtnT);

                    leftPanelT.Controls.Add(TemplateBtnT);
                    leftPanelT.Controls.Add(deleteBtnT);
                    i++;
                }
            }
            f2.Show();
        }
Exemplo n.º 11
0
        // End Drag and Drop functions
        private void button1_Click(object sender, EventArgs e)
        {
            //сохранение шаблона
            //StreamWriter sr = new StreamWriter(@"test.txt");
            if (nodes.Count == 0)
            {
                Message mess = new Message(this, "Ошибка", "Добавьте хотя бы одно поле", MessageBoxIcon.Warning);
                mess.switchMessage();
                return;
            }

            MessageDialog md = new MessageDialog(0);
            md.StartPosition = FormStartPosition.Manual;
            md.Location = new Point(this.Location.X + (this.Width - md.Width) / 2, this.Location.Y + (this.Height - md.Height) / 2);
            md.ShowDialog();
            string nameT = md.NameT;
            string result_str = "";
            if(md.btn_continuy & !md.cancel & md.closing ){
                if (nameT.Trim() == "")// исправлен баг  с некорректным именем
                {
                    Message mess = new Message(this, "Oшибка", "Введите корректное имя шаблона!", MessageBoxIcon.Warning);
                    mess.switchMessage();
                    button1_Click(sender, e);
                }
                foreach (FieldNode a in nodes)
                {
                    result_str += a.type.ToString() + ";";
                    if (a.type == 0)
                    {
                        result_str += a.name + ";";
                        if (a.pathToFile != "")
                        {
                            result_str += a.pathToFile.ToString() + ";";
                        }
                        else
                        {
                            result_str += standartList.SelectedItem.ToString() + ";";
                        }
                    }
                    if (a.type == 1)
                    {
                        result_str += a.name + ";";
                        result_str += a.from.ToString() + ";";
                        result_str += a.to.ToString() + ";";
                    }
                    if(a.type == 2)
                    {
                        result_str += a.name + ";";
                        result_str += a.dateFormat.ToString() + ";";
                        result_str += a.dfrom.ToString() + ";";
                        result_str += a.dto.ToString() + ";";
                    }
                    if(a.type == 3)
                    {
                        result_str += a.name.ToString() + ";";
                        result_str += long.Parse(this.seqFromTxt.Text.Trim()) + ";";
                        result_str += long.Parse(this.seqStepTxt.Text.Trim()) + ";";
                    }
                    if (a.type == 4)
                    {
                        result_str += a.name + ";";
                        if (a.pathToFile != "")
                            result_str += a.pathToFile.ToString() + ";";
                        else
                            result_str += standartList.SelectedValue.ToString() + ";";
                    }
                    result_str += "_";
                }
                using (var db = new MyDBContext())
                {
                    var find = db.Templates.FirstOrDefault(x => x.Name == nameT);
                    if (find != null)
                    {
                        Message mess = new Message(this, "Oшибка!", "Такое имя шаблона уже существует!", MessageBoxIcon.Warning);
                        mess.switchMessage();
                        button1_Click(sender, e);
                        return;
                    }
                    db.Templates.Add(new Template { Name = nameT, Tmp = result_str });
                    db.SaveChanges();
                }
                Message mes1 = new Message(this, "Успех", "Шаблон сохранен", MessageBoxIcon.Warning);
                mes1.switchMessage();
            }
        }
Exemplo n.º 12
0
 private void worker_DoWork(object sender, DoWorkEventArgs e)
 {
     db = new MyDBContext();
     db.Templates.Count();
 }