private void dgv_liste_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (dgv_liste.CurrentRow.Cells["id_"].Value != null)
         {
             Int32 id = Convert.ToInt32(dgv_liste.CurrentRow.Cells["id_"].Value);
             if (id > 0)
             {
                 FamillesArticle f = FamillesArticleBLL.One(id);
                 if (e.ColumnIndex == 5)
                 {
                     if (DialogResult.Yes == Messages.Confirmation(Mots.Supprimer.ToLower()))
                     {
                         if (FamillesArticleBLL.Delete(f))
                         {
                             DeleteRow(f);
                             Reset();
                             Messages.Succes();
                         }
                     }
                 }
                 else
                 {
                     Populate(f);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
Пример #2
0
        public static FamillesArticle saveFamillesArticle(FamillesArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string insert = "insert into familles_article (reference,designation,description) values ('" + f.Reference + "','" + f.Designation + "','" + f.Description + "')";
                if (f.Parent != null ? f.Parent.Id > 0 : false)
                {
                    insert = "insert into familles_article (reference,designation,description,parent) values ('" + f.Reference + "','" + f.Designation + "','" + f.Description + "'," + f.Parent.Id + ")";
                }
                NpgsqlCommand cmd = new NpgsqlCommand(insert, con);
                cmd.ExecuteNonQuery();
                f.Id = currentFamillesArticle(f);
                return(f);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
 private void btn_save_Click(object sender, EventArgs e)
 {
     Recopie();
     if (current.Control())
     {
         if (!current.Update)
         {
             FamillesArticle f = FamillesArticleBLL.Save(current);
             if (f != null ? f.Id > 0 : false)
             {
                 current.Id     = f.Id;
                 current.Update = true;
                 AddRow(f);
                 Messages.Succes();
             }
         }
         else
         {
             if (FamillesArticleBLL.Update(current))
             {
                 UpdateRow(current);
                 Messages.Succes();
             }
         }
         Reset();
     }
 }
Пример #4
0
        public static List <FamillesArticle> listFamillesArticle(string query)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                NpgsqlCommand          Lcmd = new NpgsqlCommand(query, con);
                NpgsqlDataReader       lect = Lcmd.ExecuteReader();
                List <FamillesArticle> l    = new List <FamillesArticle>();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        FamillesArticle y = oneFamillesArticle((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);
            }
        }
Пример #5
0
        private void com_parent_SelectedIndexChanged(object sender, EventArgs e)
        {
            FamillesArticle a = com_parent.SelectedItem as FamillesArticle;

            a       = familles.Find(x => x.Id == a.Id);
            famille = a;
        }
Пример #6
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            FamillesArticle f = new FamillesArticle();

            f.Reference   = txt_reference.Text.Trim();
            f.Designation = txt_designation.Text.Trim();
            f.Description = txt_description.Text.Replace("'", "''");
            if (famille != null ? famille.Id > 0 : false)
            {
                f.Parent = famille;
            }
            if (f.Control())
            {
                f = FamillesArticleBLL.Save(f);
                if (f != null ? f.Id > 0 : false)
                {
                    current.familles.Add(f);
                    current.com_famille.Refresh();
                    if (current.current != null ? current.current.Id > 0 : false)
                    {
                        current.current.Famille = f;
                    }
                    current.com_famille.DataSource = new BindingSource(current.familles, null);
                    current.com_famille.Text       = f.Designation;
                    this.Close();
                }
            }
        }
Пример #7
0
        public static Int32 currentFamillesArticle(FamillesArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from familles_article where reference = '" + f.Reference + "' and designation = '" + f.Designation + "' and description = '" + f.Description + "'";
                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);
            }
        }
Пример #8
0
        public static bool updateFamillesArticle(FamillesArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string update = "update familles_article set reference ='" + f.Reference + "' , designation ='" + f.Designation + "' , description = '" + f.Description + "' where id = " + f.Id;
                if (f.Parent != null ? f.Parent.Id > 0 : false)
                {
                    update = "update familles_article set reference ='" + f.Reference + "' , designation ='" + f.Designation + "' , description = '" + f.Description + "' , parent = " + f.Parent.Id + " 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);
            }
        }
 private void Reset()
 {
     txt_reference.ResetText();
     txt_designation.ResetText();
     txt_description.ResetText();
     com_parent.ResetText();
     current = new FamillesArticle();
     LoadFamille();
 }
Пример #10
0
 public static bool Delete(FamillesArticle y)
 {
     try
     {
         return(FamillesArticleDAO.deleteFamillesArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Suppression Impossible", ex);
     }
 }
Пример #11
0
 public static bool Update(FamillesArticle y)
 {
     try
     {
         return(FamillesArticleDAO.updateFamillesArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Modification Impossible", ex);
     }
 }
Пример #12
0
 public static Int32 Current(FamillesArticle y)
 {
     try
     {
         return(FamillesArticleDAO.currentFamillesArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Retour Impossible", ex);
     }
 }
Пример #13
0
 public static FamillesArticle Save(FamillesArticle y)
 {
     try
     {
         return(FamillesArticleDAO.saveFamillesArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Insertion Impossible", ex);
     }
 }
Пример #14
0
        public static bool data(FamillesArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                return(true);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(false);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
        private void Populate(FamillesArticle f)
        {
            FamillesArticle f_ = FamillesArticleBLL.One(f.Id);

            txt_reference.Text   = f_.Reference;
            txt_designation.Text = f_.Designation;
            txt_description.Text = f_.Description;
            current = f;
            LoadFamille();
            if (f_.Parent != null ? f_.Parent.Id > 0 : false)
            {
                com_parent.Text = f_.Parent.Designation;
                current.Parent  = f_.Parent;
            }
            else
            {
                com_parent.ResetText();
                current.Parent = null;
            }
        }
Пример #16
0
        public static bool deleteFamillesArticle(FamillesArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        delete = "delete from familles_article 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_liste_SelectionChanged(object sender, EventArgs e)
 {
     try
     {
         if (dgv_liste.Rows.Count > 0)
         {
             if (dgv_liste.CurrentRow.Cells["id_"].Value != null)
             {
                 Int32 id = (Int32)dgv_liste.CurrentRow.Cells["id_"].Value;
                 if (id > 0)
                 {
                     FamillesArticle f = FamillesArticleBLL.One(id);
                     Populate(f);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
Пример #18
0
        public static FamillesArticle oneFamillesArticle(Int32 id)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select f.*, p.designation as designation_ from familles_article f left join familles_article p on f.parent = p.id where f.id = " + id;
                NpgsqlCommand    Lcmd   = new NpgsqlCommand(search, con);
                NpgsqlDataReader lect   = Lcmd.ExecuteReader();
                FamillesArticle  y      = new FamillesArticle();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        y.Id          = id;
                        y.Reference   = lect["reference"].ToString();
                        y.Designation = lect["designation"].ToString();
                        y.Description = lect["description"].ToString();
                        Int32 id_ = (Int32)((lect["parent"] != null) ? (!lect["parent"].ToString().Trim().Equals("") ? lect["parent"] : 0) : 0);
                        y.Parent = new FamillesArticle(id_, lect["designation_"].ToString());
                        y.Sous   = listFamillesArticle("select * from familles_article where parent = " + id);
                        y.Update = true;
                    }
                }
                return(y);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
 private void AddRow(FamillesArticle f)
 {
     dgv_liste.Rows.Add(new object[] { f.Id, f.Reference, f.Designation, f.Parent != null ? f.Parent.Designation : "", f.Description, null });
 }
 private void DeleteRow(FamillesArticle f)
 {
     dgv_liste.Rows.RemoveAt(Utils.GetRowData(dgv_liste, f.Id));
 }
 private void UpdateRow(FamillesArticle f)
 {
     dgv_liste.Rows.RemoveAt(Utils.GetRowData(dgv_liste, f.Id));
     f = FamillesArticleBLL.One(f.Id);
     AddRow(f);
 }