public bool Delete(ComandaBLL c) { bool isSucces = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "DELETE FROM COMANDA WHERE comanda_id=@comanda_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@comanda_id", c.comanda_id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucces = true; } else { isSucces = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSucces); }
public bool Update(ComandaBLL c) { bool isSucces = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "UPDATE COMANDA SET adresa_id=@adresa_id, data_comanda=@data_comanda, data_expediere=@data_expediere, stare=@stare WHERE comanda_id=@comanda_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@comanda_id", c.comanda_id); cmd.Parameters.AddWithValue("@adresa_id", c.adresa_id); cmd.Parameters.AddWithValue("@data_comanda", c.data_comanda); cmd.Parameters.AddWithValue("@data_expediere", c.data_expediere); cmd.Parameters.AddWithValue("@stare", c.stare); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucces = true; } else { isSucces = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSucces); }
public bool Insert(ComandaBLL c) { bool isSucces = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "INSERT INTO COMANDA (adresa_id, data_comanda, data_expediere, stare) VALUES ( @adresa_id, @data_comanda, @data_expediere, @stare)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@adresa_id", c.adresa_id); cmd.Parameters.AddWithValue("@data_comanda", c.data_comanda); cmd.Parameters.AddWithValue("@data_expediere", c.data_expediere); cmd.Parameters.AddWithValue("@stare", c.stare); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucces = true; } else { isSucces = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSucces); }
private void comanda_Click(object sender, RoutedEventArgs e) { if ((bool)cash.IsChecked || (bool)card.IsChecked) { string modalitatePlata = ((bool)cash.IsChecked) == true ? "cash" : "card"; string data = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Comanda comanda = new Comanda(0, client.IdClient, data, pretTotal, modalitatePlata); try { ComandaBLL.insertComanda(comanda); comanda = (Comanda)ComandaBLL.selectComanda(comanda); //MessageBox.Show(comanda.ToString()); DetaliiComandaBLL detaliiComandaBLL = new DetaliiComandaBLL(); for (int i = 0; i < produseCos.Count; i++) { DetaliiComanda dc = new DetaliiComanda(comanda.IdComanda, produseCos[i].Nume, produseCos[i].Pret, cantitateProdusCos[i]); //MessageBox.Show(dc.ToString()); detaliiComandaBLL.insertDetaliiComanda(dc); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } produseCos.Clear(); cantitateProdusCos.Clear(); deseneazaCos(); MessageBox.Show("Cosul de cumparaturi a fost inregistrat"); //MessageBox.Show(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } else { MessageBox.Show("Nu ati ales modalitatea de plata!"); } }