private async void button5_Click(object sender, EventArgs e) { DBhardwaredatabase db = new DBhardwaredatabase(); IQueryable <Harddata> list = db.Hdata;// select a; List <Harddata> endlist; if (comboBox1.Text.Length > 0) { var t1 = comboBox1.Text; list = from a in list where a.Type == comboBox1.Text select a; } if (comboBox2.Text.Length > 0) { var t2 = comboBox2.Text; list = from a in list where a.Type == comboBox2.Text select a; } if (textBox1.Text.Length > 0) { list = from a in list where a.Productname == textBox1.Text select a; } /*else { * list = from a in db.Hdata select a; * } */ listView1.Items.Clear(); endlist = await list.ToListAsync(); foreach (var i in endlist) { System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { i.Productname, i.Brand, i.Type, i.Price, i.Stars }, -1); listViewItem1.Tag = i.id; listView1.Items.Add(listViewItem1); } }
private async void listView1_SelectedIndexChanged(object sender, EventArgs e) { DBhardwaredatabase db = new DBhardwaredatabase(); if (listView1.SelectedItems.Count == 0) { return; } var item = listView1.SelectedItems[0]; int Id = (int)item.Tag; var Imgquery = from Harddata in db.Hdata where Harddata.id == Id select Harddata.Image; try { label2.Visible = false; var Img = await Imgquery.FirstOrDefaultAsync(); String path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Hardware_Database"; pictureBox1.Image = Image.FromFile(path + @"\" + Img.ToString()); } catch { label2.Visible = true; } var descrqr = from Harddata in db.Hdata where Harddata.id == Id select Harddata.Description; var descr = await descrqr.FirstOrDefaultAsync(); textBox4.Text = descr; }
private async void button3_Click(object sender, EventArgs e) { try { DBhardwaredatabase db = new DBhardwaredatabase(); if (listView1.SelectedItems.Count == 0) { return; } var item = listView1.SelectedItems[0]; int id = (int)item.Tag; var todelete = from Harddata in db.Hdata where Harddata.id == id select Harddata; var itemtodelete = await todelete.FirstOrDefaultAsync(); if (itemtodelete == null) { return; } db.Hdata.Remove(itemtodelete); await db.SaveChangesAsync(); listView1.Items.Remove(item); } catch { label3.Visible = true; } }
private async void Form2_Load(object sender, EventArgs e) { DBhardwaredatabase db = new DBhardwaredatabase(); var list = await db.Hdata.ToListAsync(); foreach (var i in list) { System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { i.Productname, i.Brand, i.Type, i.Price, i.Stars }, -1); listViewItem1.Tag = i.id; listView1.Items.Add(listViewItem1); } }
private void button4_Click(object sender, EventArgs e) { listView1.Items.Clear(); DBhardwaredatabase db = new DBhardwaredatabase(); var list = db.Hdata.ToList(); foreach (var i in list) { System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { i.Productname, i.Brand, i.Type, i.Price, i.Stars }, -1); listViewItem1.Tag = i.id; listView1.Items.Add(listViewItem1); } }
private async void button1_Click(object sender, EventArgs e) { try { label6.Visible = label7.Visible = label8.Visible = label9.Visible = label10.Visible = label13.Visible = label15.Visible = false; string text1 = textBox1.Text; string text2 = textBox2.Text; string text3 = textBox3.Text; string text4 = textBox4.Text; if (string.IsNullOrWhiteSpace(text1)) { //If no product name label6.Visible = true; } if (comboBox1.SelectedIndex == -1) { //If no type label7.Visible = true; } if (comboBox2.SelectedIndex == -1) { //If no brand label8.Visible = true; } if (string.IsNullOrWhiteSpace(text2)) { //If no price label9.Visible = true; } if (string.IsNullOrWhiteSpace(text3)) { //If no image label10.Visible = true; } if (string.IsNullOrWhiteSpace(text4)) { //If no discription label13.Visible = true; } if (comboBox3.SelectedIndex == -1) { //If no rate label15.Visible = true; } else { DBhardwaredatabase db = new DBhardwaredatabase(); Harddata h = new Harddata(); h.Productname = textBox1.Text; h.Type = comboBox1.SelectedItem.ToString(); h.Brand = comboBox2.SelectedItem.ToString(); h.Price = textBox2.Text; h.Image = textBox3.Text; h.Stars = comboBox3.SelectedItem.ToString(); h.Description = textBox4.Text; db.Hdata.Add(h); await db.SaveChangesAsync(); Close(); //Clear text boxes, reset to a new state textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); comboBox1.SelectedIndex = -1; comboBox2.SelectedIndex = -1; } } catch { label16.Visible = true; } }