public List <AdressObj> getAdress(string pid) { string query = "SELECT pid,adress,aid FROM adress WHERE pid='" + pid + "';"; List <AdressObj> adress = new List <AdressObj>(); if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { AdressObj ao = new AdressObj(); ao.setPid(dataReader["pid"].ToString()); ao.setAdress(dataReader["adress"].ToString()); ao.setAid(dataReader["aid"].ToString()); adress.Add(ao); } this.CloseConnection(); return(adress); } else { Console.WriteLine("Unsuccessful connection !"); return(adress); } }
private void place_order_Click(object sender, EventArgs e) { if (cartList.Count <= 0) { MessageBox.Show("Your cart is empty !"); } else { OrderObj o = new OrderObj(); o.setOid(oidGenerator()); o.setUid(f1.u.getUid()); Dictionary <string, string> od = new Dictionary <string, string>(); int i; string pids = ""; int totalPrice = 0; for (i = 0; i < cartList.Count; i++) { pids += cartList[i].getPid() + ","; totalPrice += cartList[i].getPrice() * cartList[i].getProductCount(); } od.Add("pids", pids); od.Add("totalPrice", totalPrice.ToString()); AdressObj ao = (AdressObj)adressCB.SelectedItem; if (adressCB.SelectedIndex < 0) { MessageBox.Show("Please choose an adress"); } else { od.Add("adress", ao.getAid()); o.setDetails(generateDictionaryString(od)); conn.sendCommand(conn.insertOrder(o)); MessageBox.Show("Order send ! "); panel1.Controls.Clear(); f1.clearCart(); } } }