private void button7_Click(object sender, EventArgs e) { if (numericUpDown1.Text != "0") { int id = Globals.OrderComboItem; Combo item = db.Comboes.FirstOrDefault(c => c.Combo_ID == id); Combo_Price price = db.Combo_Price.FirstOrDefault(c => c.Combo_Price_ID == id); if ((item != null) && (price != null)) { string itemDesc = "ID: " + Convert.ToString(item.Combo_ID) + " Name: " + item.Combo_Name + " Description: " + item.Combo_Description + " Quantity: " + numericUpDown1.Text + " Notes: "; listBox1.Items.Add(itemDesc); Globals ComboItem = new Globals(); ComboItem.OrderItemId = id; ComboItem.OrderItemName = item.Combo_Name; ComboItem.OrderItemDescription = item.Combo_Description; ComboItem.OrderItemPrice = price.Combo_Price1; ComboItem.OrderQuantity = Convert.ToInt32(numericUpDown1.Text); another.Add(ComboItem); } } else { MessageBox.Show("Error:Quantity can't be zero"); } }
private void btnSaveCombo_Click(object sender, EventArgs e) { if (pbxCombo.Image != null) { string phrase = txtComboPrice.Text; double number; bool isNumeric = double.TryParse(phrase, out number); if (isNumeric == true) { if ((Convert.ToDouble(txtComboPrice.Text) > 0) && (txtComboName.Text != "")) { if ((listBox1.Items.Count > 0) /*&& (listBox1.Text != "")*/) { int id = Globals.Combopassing; Combo_Price price = db.Combo_Price.FirstOrDefault(c => c.Combo_Price_ID == id); price.Combo_Price1 = Convert.ToDouble(txtComboPrice.Text); price.Combo_Price_Date = DateTime.Today; //db.Combo_Price.Add(price); int num = listBox1.Items.Count; string str = ""; for (int i = 0; i < num; i++) { str = str + listBox1.Items[i].ToString(); } Combo_Type type = db.Combo_Type.FirstOrDefault(c => c.Combo_Description == cmbComboType.Text); Combo item = db.Comboes.FirstOrDefault(c => c.Combo_Price_ID == id); item.Combo_Name = txtComboName.Text; item.Combo_Price = Convert.ToDouble(txtComboPrice.Text); item.Combo_Description = str; item.Combo_Type_ID = type.Combo_Type_ID; item.Combo_Price_ID = price.Combo_Price_ID; //MessageBox.Show(item.Combo_Description); // db.Comboes.Add(item); ItemsPicture itempic = db.ItemsPictures.FirstOrDefault(c => c.Combo_Item_ID == id); { if (Globals.browse == true) { itempic.ItemName = Globals.fileName; itempic.imageVar = Globals.ConvertImageToBinary(pbxCombo.Image); // itempic.ImageID = item.Combo_ID; // Globals.browse = false; } } db.SaveChanges(); MessageBox.Show("Combo item updated successfully"); Globals.refresher = true; this.Close(); } else { MessageBox.Show("Error:No items added"); } } else { MessageBox.Show("Error:Price value too large OR less thatn zero/Combo name field is empty"); } } else { MessageBox.Show("Error: Price not in correct format"); } } else { MessageBox.Show("Upload a picture"); } }