Beispiel #1
0
        public static List <ContenuStock> listContenuStock(string query)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                NpgsqlCommand       Lcmd = new NpgsqlCommand(query, con);
                NpgsqlDataReader    lect = Lcmd.ExecuteReader();
                List <ContenuStock> l    = new List <ContenuStock>();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        ContenuStock y = oneContenuStock((Int32)((lect["id"] != null) ? (!lect["id"].ToString().Trim().Equals("") ? lect["id"] : 0) : 0));
                        l.Add(y);
                    }
                }
                return(l);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
 private void btn_add_Click(object sender, EventArgs e)
 {
     RecopieContenu();
     if (current_contenu.Control())
     {
         if (!current_contenu.Update)
         {
             ContenuStock f = ContenuStockBLL.Save(current_contenu);
             if (f != null ? f.Id > 0 : false)
             {
                 current_contenu.Id     = f.Id;
                 current_contenu.Update = true;
                 AddRowContenu(f);
                 Messages.Succes();
                 ResetContenu();
             }
         }
         else
         {
             if (ContenuStockBLL.Update(current_contenu))
             {
                 UpdateRowContenu(current_contenu);
                 Messages.Succes();
                 ResetContenu();
             }
         }
     }
 }
 private void dgv_contenu_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (dgv_contenu.CurrentRow.Cells["_id_"].Value != null)
         {
             Int32 id = Convert.ToInt32(dgv_contenu.CurrentRow.Cells["_id_"].Value);
             if (id > 0)
             {
                 ContenuStock f = ContenuStockBLL.One(id);
                 if (e.ColumnIndex == 4)
                 {
                     if (DialogResult.Yes == Messages.Confirmation(Mots.Supprimer.ToLower()))
                     {
                         if (ContenuStockBLL.Delete(f))
                         {
                             DeleteRowContenu(f);
                             ResetContenu();
                             Messages.Succes();
                         }
                     }
                 }
                 else
                 {
                     PopulateContenu(f);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
Beispiel #4
0
        public static ContenuStock oneContenuStock(Int32 id)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from contenu_stock where id = " + id;
                NpgsqlCommand    Lcmd   = new NpgsqlCommand(search, con);
                NpgsqlDataReader lect   = Lcmd.ExecuteReader();
                ContenuStock     y      = new ContenuStock();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        y.Id       = id;
                        y.Prix     = (Double)((lect["prix"] != null) ? (!lect["prix"].ToString().Trim().Equals("") ? lect["prix"] : 0) : 0);
                        y.Quantite = (Double)((lect["quantite"] != null) ? (!lect["quantite"].ToString().Trim().Equals("") ? lect["quantite"] : 0) : 0);
                        y.Article  = BLL.ArticlesBLL.One((Int32)((lect["article"] != null) ? (!lect["article"].ToString().Trim().Equals("") ? lect["article"] : 0) : 0));
                        y.Update   = true;
                    }
                }
                return(y);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
Beispiel #5
0
        public static Int32 currentContenuStock(ContenuStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from contenu_stock where stock = " + f.Stock.Id + " order by id desc limit 1";
                NpgsqlCommand    Lcmd   = new NpgsqlCommand(search, con);
                NpgsqlDataReader lect   = Lcmd.ExecuteReader();
                Int32            id     = new Int32();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        id = (Int32)((lect["id"] != null) ? (!lect["id"].ToString().Trim().Equals("") ? lect["id"] : 0) : 0);
                    }
                }
                return(id);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(0);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
 private void ResetContenu()
 {
     com_article.Text    = null;
     txt_prix.Value      = 0;
     txt_qte.Value       = 1;
     com_article.Enabled = true;
     current_contenu     = new ContenuStock();
 }
 private void PopulateContenu(ContenuStock c)
 {
     com_article.Text    = c.Article.Designation;
     txt_prix.Value      = Convert.ToDecimal(c.Prix);
     txt_qte.Value       = Convert.ToDecimal(c.Quantite);
     com_article.Enabled = false;
     current_contenu     = c;
 }
        private void UpdateRowContenu(ContenuStock f)
        {
            int i = Utils.GetRowData(dgv_contenu, f.Id);

            if (i < 0)
            {
                dgv_contenu.Rows.RemoveAt(Utils.GetRowData(dgv_contenu, f.Id));
                AddRowContenu(f);
            }
        }
 public static bool Update(ContenuStock y)
 {
     try
     {
         return(ContenuStockDAO.updateContenuStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Modification Impossible", ex);
     }
 }
 public static ContenuStock Save(ContenuStock y)
 {
     try
     {
         return(ContenuStockDAO.saveContenuStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Insertion Impossible", ex);
     }
 }
 public static Int32 Current(ContenuStock y)
 {
     try
     {
         return(ContenuStockDAO.currentContenuStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Retour Impossible", ex);
     }
 }
 public static bool Delete(ContenuStock y)
 {
     try
     {
         return(ContenuStockDAO.deleteContenuStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Suppression Impossible", ex);
     }
 }
Beispiel #13
0
        public static bool updateContenuStock(ContenuStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        update = "update contenu_stock set prix =" + f.Prix + " , quantite =" + f.Quantite + " where id = " + f.Id;
                NpgsqlCommand cmd    = new NpgsqlCommand(update, con);
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(false);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
Beispiel #14
0
        public static bool  deleteContenuStock(ContenuStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        delete = "delete from contenu_stock where id = " + f.Id;
                NpgsqlCommand cmd    = new NpgsqlCommand(delete, con);
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(false);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
 private void dgv_contenu_SelectionChanged(object sender, EventArgs e)
 {
     try
     {
         if (dgv_contenu.Rows.Count > 0)
         {
             if (dgv_contenu.CurrentRow.Cells["_id_"].Value != null)
             {
                 Int32 id = (Int32)dgv_contenu.CurrentRow.Cells["_id_"].Value;
                 if (id > 0)
                 {
                     ContenuStock f = ContenuStockBLL.One(id);
                     PopulateContenu(f);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
Beispiel #16
0
        public static ContenuStock saveContenuStock(ContenuStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        insert = "insert into contenu_stock (prix, quantite, article, stock) values (" + f.Prix + "," + f.Quantite + "," + f.Article.Id + "," + f.Stock.Id + ")";
                NpgsqlCommand cmd    = new NpgsqlCommand(insert, con);
                cmd.ExecuteNonQuery();
                f.Id = currentContenuStock(f);
                return(f);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
 private void AddRowContenu(ContenuStock f)
 {
     dgv_contenu.Rows.Add(new object[] { f.Id, f.Article.Designation, f.Quantite, f.Prix, null });
 }
 private void DeleteRowContenu(ContenuStock f)
 {
     dgv_contenu.Rows.RemoveAt(Utils.GetRowData(dgv_contenu, f.Id));
 }