예제 #1
0
 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)
             {
                 DocStock f = DocStockBLL.One(id);
                 if (e.ColumnIndex == 5)
                 {
                     if (DialogResult.Yes == Messages.Confirmation(Mots.Supprimer.ToLower()))
                     {
                         if (DocStockBLL.Delete(f))
                         {
                             DeleteRow(f);
                             Reset();
                             Messages.Succes();
                         }
                     }
                 }
                 else
                 {
                     Populate(f);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
예제 #2
0
        public static List <DocStock> listDocStock(string query)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                NpgsqlCommand    Lcmd = new NpgsqlCommand(query, con);
                NpgsqlDataReader lect = Lcmd.ExecuteReader();
                List <DocStock>  l    = new List <DocStock>();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        DocStock y = oneDocStock((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);
            }
        }
예제 #3
0
 private void btn_save_Click(object sender, EventArgs e)
 {
     Recopie();
     if (current.Control())
     {
         if (!current.Update)
         {
             DocStock f = DocStockBLL.Save(current);
             if (f != null ? f.Id > 0 : false)
             {
                 current.Id          = f.Id;
                 current.Update      = true;
                 rbtn_entree.Enabled = false;
                 rbtn_sortie.Enabled = false;
                 AddRow(f);
                 Messages.Succes();
             }
         }
         else
         {
             if (DocStockBLL.Update(current))
             {
                 UpdateRow(current);
                 Messages.Succes();
             }
         }
         Reset();
     }
 }
예제 #4
0
        public static Int32 currentDocStock(DocStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from doc_stocks where reference = '" + f.Reference + "' and date_doc = '" + f.Date + "'";
                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);
            }
        }
예제 #5
0
        public static DocStock oneDocStock(Int32 id)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from doc_stocks where id = " + id;
                NpgsqlCommand    Lcmd   = new NpgsqlCommand(search, con);
                NpgsqlDataReader lect   = Lcmd.ExecuteReader();
                DocStock         y      = new DocStock();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        y.Id        = id;
                        y.Reference = lect["reference"].ToString();
                        y.Type      = lect["type_doc"].ToString();
                        y.Date      = (DateTime)((lect["date_doc"] != null) ? (!lect["date_doc"].ToString().Trim().Equals("") ? lect["date_doc"] : DateTime.Now) : DateTime.Now);
                        y.Contenus  = BLL.ContenuStockBLL.List("select * from contenu_stock where stock = " + id);
                        y.Update    = true;
                    }
                }
                return(y);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #6
0
        private void UpdateRow(DocStock f)
        {
            int i = Utils.GetRowData(dgv_liste, f.Id);

            if (i < 0)
            {
                dgv_liste.Rows.RemoveAt(i);
                AddRow(f);
            }
        }
예제 #7
0
 private void Populate(DocStock d)
 {
     rbtn_entree.Checked = d.Type.Trim().Equals(Constantes.MOUV_ENTREE);
     rbtn_sortie.Checked = d.Type.Trim().Equals(Constantes.MOUV_SORTIE);
     rbtn_entree.Enabled = false;
     rbtn_sortie.Enabled = false;
     txt_reference.Text  = d.Reference;
     date_save.Value     = d.Date;
     current             = d;
     LoadGrilleContenu(d);
 }
예제 #8
0
 public static bool Delete(DocStock y)
 {
     try
     {
         return(DocStockDAO.deleteDocStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Suppression Impossible", ex);
     }
 }
예제 #9
0
 public static bool Update(DocStock y)
 {
     try
     {
         return(DocStockDAO.updateDocStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Modification Impossible", ex);
     }
 }
예제 #10
0
 public static DocStock Save(DocStock y)
 {
     try
     {
         return(DocStockDAO.saveDocStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Insertion Impossible", ex);
     }
 }
예제 #11
0
 public static Int32 Current(DocStock y)
 {
     try
     {
         return(DocStockDAO.currentDocStock(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Retour Impossible", ex);
     }
 }
예제 #12
0
        private void LoadGrilleContenu(DocStock d)
        {
            dgv_contenu.Rows.Clear();
            string query = "select * from contenu_stock where stock = " + d.Id + " order by id";

            current.Contenus = ContenuStockBLL.List(query);
            foreach (ContenuStock c in current.Contenus)
            {
                AddRowContenu(c);
            }
            ResetContenu();
        }
예제 #13
0
 private void Reset()
 {
     txt_reference.Text  = Utils.ReferenceElement(Constantes.MOUV_ENTREE);
     rbtn_entree.Checked = true;
     date_save.Value     = DateTime.Now;
     rbtn_entree.Enabled = true;
     rbtn_sortie.Enabled = true;
     current             = new DocStock();
     date_save.Focus();
     dgv_contenu.Rows.Clear();
     ResetContenu();
 }
예제 #14
0
        public static bool  deleteDocStock(DocStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        delete = "delete from doc_stocks 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);
            }
        }
예제 #15
0
        public static bool updateDocStock(DocStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        update = "update doc_stocks set reference ='" + f.Reference + "' , type_doc = '" + f.Type + "' , date_doc = '" + f.Date + "' 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);
            }
        }
예제 #16
0
 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)
                 {
                     DocStock f = DocStockBLL.One(id);
                     Populate(f);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
예제 #17
0
        public static DocStock saveDocStock(DocStock f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        insert = "insert into doc_stocks (reference, type_doc, date_doc) values ('" + f.Reference + "','" + f.Type + "','" + f.Date + "')";
                NpgsqlCommand cmd    = new NpgsqlCommand(insert, con);
                cmd.ExecuteNonQuery();
                f.Id = currentDocStock(f);
                return(f);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #18
0
 private void DeleteRow(DocStock f)
 {
     dgv_liste.Rows.RemoveAt(Utils.GetRowData(dgv_liste, f.Id));
 }
예제 #19
0
        public static string ReferenceElement(string type)
        {
            if (!(type == null || type.Trim().Equals("")))
            {
                String reference = "";
                String apercu    = type + "/";
                if ((int)DateTime.Now.Day > 9)
                {
                    apercu += (int)DateTime.Now.Day;
                }
                if ((int)DateTime.Now.Day < 10)
                {
                    apercu += ("0" + (int)DateTime.Now.Day);
                }
                if ((int)DateTime.Now.Month > 9)
                {
                    apercu += (int)DateTime.Now.Month;
                }
                if ((int)DateTime.Now.Month < 10)
                {
                    apercu += ("0" + (int)DateTime.Now.Month);
                }
                apercu += DateTime.Now.Year.ToString().Substring(2);
                apercu += "/";
                DocStock f = DocStockBLL.One(apercu + "%");
                if ((f != null) ? !(f.Reference == null || f.Reference.Trim().Equals("")) : false)
                {
                    reference = f.Reference;
                }
                else
                {
                    reference = "";
                }

                if (!reference.Trim().Equals(""))
                {
                    String partieNum = reference.Replace(apercu, "");
                    if (apercu.Equals(reference.Substring(0, (reference.Length - partieNum.Length))))
                    {
                        int num = Convert.ToInt16(partieNum);
                        if (Convert.ToString(num + 1).Length > 4)
                        {
                            Messages.ShowErreur("Vous ne pouvez plus ajouter ce type de document");
                            return("");
                        }
                        else
                        {
                            for (int i = 0; i < (4 - Convert.ToString(num + 1).Length); i++)
                            {
                                apercu += "0";
                            }
                        }
                        apercu += Convert.ToString(Convert.ToInt16(partieNum) + 1);
                    }
                    else
                    {
                        for (int i = 0; i < 4 - 1; i++)
                        {
                            apercu += "0";
                        }
                        apercu += "1";
                    }
                }
                else
                {
                    for (int i = 0; i < 4 - 1; i++)
                    {
                        apercu += "0";
                    }
                    apercu += "1";
                }
                return(apercu);
            }
            else
            {
                Messages.ShowErreur("Le type du document est incorrect!");
            }
            return(null);
        }
예제 #20
0
 private void AddRow(DocStock f)
 {
     dgv_liste.Rows.Add(new object[] { f.Id, f.Icon, f.Reference, f.Date, f.Type.Equals(Constantes.MOUV_ENTREE) ? Constantes.MOUV_ENTREE_NAME : Constantes.MOUV_SORTIE_NAME, null });
 }