Пример #1
0
 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);
     }
 }
Пример #2
0
        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);
            }
        }