public Article save(Article article, SqlConnection conn) { try { SqlCommand myCommand; if (article.Id == 0) { myCommand = new SqlCommand("INSERT INTO dbo.article(Nom,Prix,Stock,Image,TVA,PrixAchat) values(@Nom,@Prix,@Stock,@Image,@TVA,@PrixAchat)", conn); } else { myCommand = new SqlCommand("UPDATE dbo.article set Nom = @Nom, Prix = @Prix, Stock = @Stock, Image = @Image, TVA = @TVA, PrixAchat = @PrixAchat where id=@id", conn); } myCommand.Parameters.AddWithValue("@id", article.Id); myCommand.Parameters.AddWithValue("@Nom", article.Nom); myCommand.Parameters.AddWithValue("@Prix", article.Prix); myCommand.Parameters.AddWithValue("@Stock", article.Stock); myCommand.Parameters.AddWithValue("@Image", article.Image); myCommand.Parameters.AddWithValue("@TVA", article.Tva); myCommand.Parameters.AddWithValue("@PrixAchat", article.PrixAchat); CaisseLogger.LogInfo("Triyng to save artice : " + article.ToString()); conn.Open(); myCommand.ExecuteNonQuery(); conn.Close(); return(article); } catch (Exception ex) { CaisseLogger.LogError(ex.ToString()); return(article); } }
public Famille save(Famille famille, SqlConnection conn) { try { SqlCommand myCommand; if (famille.Id == 0) { myCommand = new SqlCommand("INSERT INTO dbo.famille(Nom) values(@Nom)", conn); } else { myCommand = new SqlCommand("UPDATE dbo.article set Nom = @Nom where id = @id", conn); myCommand.Parameters.AddWithValue("@id", famille.Id); } myCommand.Parameters.AddWithValue("@Nom", famille.Nom); CaisseLogger.LogInfo("Triyng to save artice : " + famille.ToString()); conn.Open(); myCommand.ExecuteNonQuery(); CaisseLogger.LogInfo("Article " + famille.ToString() + " saved."); conn.Close(); return(famille); } catch (Exception ex) { CaisseLogger.LogError(ex.ToString()); return(famille); } }
private void form2_VisibleChanged(object sender, EventArgs e) { if (!this.form2.Visible) { try { this.produit = this.form2.Produit; articleRepository.save(produit, conn); } catch (Exception ex) { CaisseLogger.LogError(ex.ToString()); } } }
private void familleFormGlobal_VisibleChanged(object sender, EventArgs e) { if (!this.familleFormGlobal.Visible) { try { this.famille = this.familleFormGlobal.Famille; familleRepository.save(this.famille, conn); } catch (Exception ex) { CaisseLogger.LogError(ex.ToString()); } } }