public void connectionTest()
 {
     using (var db = new MyDBContext())
     {
         db.Templates.Add(new Template { Name = "name", Tmp = "string" });
         db.SaveChanges();
     }
 }
 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();
     }
 }
 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);
 }
        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();
            }
        }
 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("Шаблон сохранен!");
 }
Exemple #6
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++;
            }
        }
Exemple #7
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();
            }
        }