Пример #1
0
 private void Button3_Click(object sender, EventArgs e)
 {
     using (DBEntities2 db = new DBEntities2())
     {
         karlitos_products edit = new karlitos_products();
         int id;
         if (int.TryParse(textBox1.Text, out int x))
         {
             id = int.Parse(textBox1.Text);
             if (db.karlitos_products.Where(a => a.ProductId == id).Count() == 1)
             {
                 //Console.WriteLine(db.karlitos_products.Where(a => a.ProductId == id).Count());
                 edit                   = db.karlitos_products.Where(a => a.ProductId == id).First();
                 textBox5.Text          = edit.ProductName;
                 textBox2.Text          = edit.SerialNumber;
                 textBox3.Text          = edit.Color;
                 textBox4.Text          = edit.Price.ToString();
                 comboBox1.Text         = "";
                 comboBox1.SelectedText = edit.Type;
                 numericUpDown1.Value   = decimal.Parse(edit.QTY.ToString());
             }
             else
             {
                 id = int.Parse(textBox1.Text);
                 MessageBox.Show("Product with id = " + id + " was not found");
             }
         }
         else
         {
             MessageBox.Show("Id must be a number");
         }
     }
 }
Пример #2
0
 private void Button1_Click(object sender, EventArgs e)
 {
     using (DBEntities2 db = new DBEntities2())
     {
         if (textBox1.Text != "")
         {
             karlitos_products edit = new karlitos_products();
             int id = int.Parse(textBox1.Text);
             edit = db.karlitos_products.Where(a => a.ProductId == id).First();
             if (double.TryParse(textBox4.Text, out double x) == false)
             {
                 MessageBox.Show("Invalid price format");
             }
             else
             {
                 edit.ProductName  = textBox5.Text;
                 edit.SerialNumber = textBox2.Text;
                 edit.Color        = textBox3.Text;
                 edit.Price        = double.Parse(textBox4.Text);
                 edit.Type         = comboBox1.Text;
                 edit.QTY          = long.Parse(numericUpDown1.Value.ToString());
                 db.SaveChanges();
                 this.Close();
             }
         }
         else
         {
             MessageBox.Show("First select id to edit");
         }
     }
 }
Пример #3
0
 private void Button4_Click(object sender, EventArgs e)
 {
     using (DBEntities2 db = new DBEntities2())
     {
         if (textBox1.Text != "")
         {
             karlitos_products del = new karlitos_products();
             int id = int.Parse(textBox1.Text);
             del = db.karlitos_products.Where(a => a.ProductId == id).First();
             db.karlitos_products.Remove(del);
             db.SaveChanges();
             MessageBox.Show("Product deleted");
             this.Close();
         }
         else
         {
             MessageBox.Show("First select id to delete");
         }
     }
 }
Пример #4
0
 private void Button1_Click(object sender, EventArgs e)
 {
     using (DBEntities2 db = new DBEntities2())
     {
         karlitos_products addnew = new karlitos_products();
         if (textBox1.Text != "" || textBox2.Text != "" || comboBox1.Text != "")
         {
             addnew.ProductName  = textBox1.Text;
             addnew.SerialNumber = textBox2.Text;
             addnew.Color        = textBox3.Text;
             if (float.TryParse(textBox4.Text, out float n))
             {
                 addnew.Price = float.Parse(textBox4.Text);
             }
             else
             {
                 MessageBox.Show("Invalid price format." + "\nPrice was set to 0.");
                 addnew.Price = 0;
             }
             addnew.Type = comboBox1.Text;
             addnew.QTY  = long.Parse(numericUpDown1.Value.ToString());
             db.karlitos_products.Add(addnew);
             db.SaveChanges();
             MessageBox.Show("Product added successfully");
             textBox1.Clear();
             textBox2.Clear();
             textBox3.Clear();
             textBox4.Clear();
             comboBox1.Text       = "";
             numericUpDown1.Value = 0;
         }
         else
         {
             MessageBox.Show("Product was not added please fix any errors and try again");
         }
     }
 }