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"); } } }
private void Button4_Click(object sender, EventArgs e) { using (DBEntities2 db = new DBEntities2()) { karlitos_users add = new karlitos_users(); int user = db.karlitos_users.Where(a => a.Username == textBox5.Text).Count(); if (textBox3.Text == textBox4.Text) { if (user != 0) { MessageBox.Show("Username is already in use"); textBox5.Clear(); textBox3.Clear(); textBox4.Clear(); } else { add.Username = textBox5.Text; add.Password = textBox3.Text; db.karlitos_users.Add(add); db.SaveChanges(); panel1.Hide(); } } else { textBox3.Clear(); textBox4.Clear(); MessageBox.Show("Passwords must match"); } } }
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"); } } }
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"); } } }