private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int id = Int32.Parse(comboBox1.SelectedItem.ToString()); DataManager.product details = db.getProductById(id); textBox1.Text = details.name; textBox2.Text = details.des; textBox3.Text = details.price.ToString(); imageByte = details.image; MemoryStream imageBlob = new MemoryStream(imageByte); pictureBox1.Image = Image.FromStream(imageBlob); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; }
private void button3_Click(object sender, EventArgs e) { label3.Visible = false; if (comboBox1.SelectedItem == null) { return; } int qun = 0; if (!Int32.TryParse(textBox1.Text, out qun) || qun == 0) { label3.Visible = true; return; } DataManager.product selected = new DataManager.product(); foreach (DataManager.product temp in products) { if (temp.name.Equals(comboBox1.SelectedItem.ToString())) { selected = temp; break; } } float totalPrice = qun * selected.price; int imageIndex = 0; foreach (List <int> tempIndex in mapImages) { if (tempIndex[0] == selected.id) { imageIndex = tempIndex[1]; } } string[] items = new string[5]; items[0] = selected.id.ToString(); items[1] = selected.name; items[2] = selected.price.ToString(); items[3] = textBox1.Text; items[4] = totalPrice.ToString(); ListViewItem lvi = new ListViewItem(items); lvi.ImageIndex = imageIndex; listView1.Items.Add(lvi); calculatePayment(); }
public DataManager.product getProductById(int id) { DataManager.product retVal = new DataManager.product(); conn.Open(); string sql = "SELECT * FROM product WHERE id='" + id + "'"; SQLiteCommand sqCommand = new SQLiteCommand(sql, conn); SQLiteDataReader sqReader = sqCommand.ExecuteReader(); if (sqReader.Read()) { retVal.id = id; retVal.name = sqReader.GetString(1); retVal.des = sqReader.GetString(2); retVal.price = sqReader.GetFloat(3); retVal.image = (byte[])sqReader.GetValue(4); } sqReader.Close(); conn.Close(); return(retVal); }
public List <DataManager.product> getAllProducts() { List <DataManager.product> retVal = new List <DataManager.product>(); conn.Open(); string sql = "SELECT * FROM product"; SQLiteCommand sqCommand = new SQLiteCommand(sql, conn); SQLiteDataReader sqReader = sqCommand.ExecuteReader(); while (sqReader.Read()) { DataManager.product temp = new DataManager.product(); temp.id = sqReader.GetInt32(0); temp.name = sqReader.GetString(1); temp.des = sqReader.GetString(2); temp.price = sqReader.GetFloat(3); temp.image = (byte[])sqReader.GetValue(4); retVal.Add(temp); } sqReader.Close(); conn.Close(); return(retVal); }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { listView2.Items.Clear(); textBox2.Text = textBox1.Text = textBox4.Text = "0"; ListViewItem lvi; try { lvi = listView1.SelectedItems[0]; } catch (Exception) { return; } int saleId = Int32.Parse(lvi.SubItems[0].Text); textBox1.Text = lvi.SubItems[3].Text; textBox2.Text = lvi.SubItems[2].Text; textBox4.Text = lvi.SubItems[4].Text; List <DataManager.saleDetails> saleDetail = new List <DataManager.saleDetails>(); foreach (DataManager.sale tempSale in sales) { if (tempSale.id == saleId) { saleDetail = tempSale.det; break; } } foreach (DataManager.saleDetails tempSaleDetail in saleDetail) { DataManager.product selected = new DataManager.product(); foreach (DataManager.product temp in products) { if (temp.id == tempSaleDetail.itemId) { selected = temp; break; } } float totalPrice = tempSaleDetail.qun * selected.price; int imageIndex = 0; foreach (List <int> tempIndex in mapImages) { if (tempIndex[0] == selected.id) { imageIndex = tempIndex[1]; } } string[] items = new string[5]; items[0] = selected.id.ToString(); items[1] = selected.name; items[2] = selected.price.ToString(); items[3] = tempSaleDetail.qun.ToString(); items[4] = totalPrice.ToString(); ListViewItem lvi2 = new ListViewItem(items); lvi2.ImageIndex = imageIndex; listView2.Items.Add(lvi2); } }