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"); } } }
public void SearchByType(string abc) { using (DBEntities2 db = new DBEntities2()) { dataGridView1.DataSource = db.karlitos_products.Where(a => a.Type.Contains(abc)).ToList(); } }
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"); } } }
public bool login() { using (DBEntities2 db = new DBEntities2()) { var user = db.karlitos_users.FirstOrDefault(u => u.Username == textBox1.Text); if (user != null) { if (user.Password == textBox2.Text) { MessageBox.Show("Login succesfull"); return(true); } else { MessageBox.Show("Wrong password"); return(false); } } else { MessageBox.Show("No user found"); return(false); } } }
public void odswiezgrida() { dataGridView1.AutoGenerateColumns = false; using (DBEntities2 db = new DBEntities2()) { dataGridView1.DataSource = db.karlitos_products.ToList(); dataGridView2.DataSource = db.karlitos_products.Where(a => a.Type == "Smartphone").ToList(); dataGridView3.DataSource = db.karlitos_products.Where(a => a.Type == "Tv").ToList(); dataGridView4.DataSource = db.karlitos_products.Where(a => a.Type == "Laptop").ToList(); } }
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"); } } }