Пример #1
0
 private void Add_Click(object sender, EventArgs e)
 {
     if (info_textBox.Text != string.Empty &&
         Country_textBox.Text != string.Empty &&
         grain_type_textBox.Text != string.Empty &&
         Price_textBox.Text != string.Empty &&
         cost_price_textBox.Text != string.Empty &&
         Name_textBox.Text != string.Empty &&
         Gramm_numericUpDown.Value != 0)
     {
         Model_Coffee temp = new Model_Coffee(Name_textBox.Text,
                                              Convert.ToDouble(cost_price_textBox.Text.Replace(".", ",")),
                                              Convert.ToDouble(Price_textBox.Text.Replace(".", ",")),
                                              grain_type_textBox.Text, Country_textBox.Text,
                                              Convert.ToInt32(Gramm_numericUpDown.Value), info_textBox.Text);
         comand.Add_BD(temp);
         MessageBox.Show("Новый элемент успешно добавлен", "Добавлен новый элемент", MessageBoxButtons.OK, MessageBoxIcon.Information);
         GC.Collect(GC.GetGeneration(temp));
         this.Close();
     }
     else
     {
         MessageBox.Show("Заполните все поля", "Не все поля заполнены", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #2
0
        internal void Add_BD(Model_Coffee temp)
        {
            using (DataContext db = new DataContext(Resources.ConectString))
            {
                db.GetTable <Model_Coffee>().InsertOnSubmit(temp);
                db.SubmitChanges();
            }

            /* using (SqlConnection connection = new SqlConnection(Resources.ConectString))
             * {
             *   connection.Open(); // открываем соидинение
             *   SqlCommand sqlComm = new SqlCommand(Resources.SQL_Select_ALL, connection);
             *   SqlDataAdapter adapter = new SqlDataAdapter(sqlComm.CommandText, connection);
             *   DataSet data = new DataSet();
             *   adapter.Fill(data);
             *   DataTable dt = data.Tables[0];
             *   DataRow newRow = dt.NewRow();
             *   newRow["Name"] = temp.name;
             *   newRow["Cost_price"] = temp.cost_price;
             *   newRow["Price"] = temp.price;
             *   newRow["Gram_per_serving"] = temp.gram_per_serving;
             *   newRow["Grain_type"] = temp.grain_type;
             *   newRow["Country_of_origin"] = temp.country_of_origin;
             *   newRow["Info"] = temp.info;
             *   dt.Rows.Add(newRow);
             *
             *
             *   SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter);
             *   adapter.Update(data);
             *   data.Clear();
             *   adapter.Fill(data);
             * }*/
        }
Пример #3
0
 public Form_edit_selected(ComboBox comboBox_select_coffe)
 {
     InitializeComponent();
     comand        = new Comand_Coffee();
     Сancel.Click += Сancel_Click;
     Edit.Click   += Edit_Click;
     Load         += Form_edit_selected_Load;
     edit_coffee   = Coffee_list.coffee_list.Find(i => i.name == comboBox_select_coffe.SelectedItem.ToString());
 }
Пример #4
0
 internal void Edit(Model_Coffee edit_coffee, Model_Coffee rezult_coffee)
 {
     using (DataContext db = new DataContext(Resources.ConectString))
     {
         // Получаем таблицу пользователей
         Model_Coffee up_data_coffe = db.GetTable <Model_Coffee>().FirstOrDefault <Model_Coffee>(i => i.name == edit_coffee.name);
         // и изменим у него возраст
         up_data_coffe.Edit_Coffe(rezult_coffee);
         // сохраним изменения
         db.SubmitChanges();
     }
 }
Пример #5
0
 private void Edit_Click(object sender, EventArgs e)
 {
     if (info_textBox.Text != string.Empty &&
         Country_textBox.Text != string.Empty &&
         grain_type_textBox.Text != string.Empty &&
         Price_textBox.Text != string.Empty &&
         cost_price_textBox.Text != string.Empty &&
         Name_textBox.Text != string.Empty &&
         Gramm_numericUpDown.Value != 0)
     {
         rezult_coffee = new Model_Coffee(Name_textBox.Text,
                                          Convert.ToDouble(cost_price_textBox.Text.Replace(".", ",")),
                                          Convert.ToDouble(Price_textBox.Text.Replace(".", ",")),
                                          grain_type_textBox.Text, Country_textBox.Text,
                                          Convert.ToInt32(Gramm_numericUpDown.Value), info_textBox.Text);
         comand.Edit(edit_coffee, rezult_coffee);
         MessageBox.Show("Элемент успешно изменен", "Элемент изменен", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
     }
     else
     {
         MessageBox.Show("Заполните все поля", "Не все поля заполнены", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }