예제 #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            string action = entity.Id > 0 ? "Modification" : "Insertion";

            try
            {
                GroupeMatiere y = RecopieView();
                if (ControleView(y))
                {
                    if (y.Id > 0)
                    {
                        dao.Update(y);
                        Action(y, 2, false);
                    }
                    else
                    {
                        y         = dao.Insert(y);
                        entity.Id = y.Id;
                        Action(y, 1, false);
                    }
                    ResetView();
                    Messages.Succes();
                }
            }
            catch (Exception ex)
            {
                Messages.Error(action + " impossible!");
                Logs.Exception("Form_Groupe_Matiere (btn_save_Click)", ex);
            }
        }
예제 #2
0
        private void dgv_groupe_MouseDown(object sender, MouseEventArgs e)
        {
            DataGridView.HitTestInfo info = dgv_groupe.HitTest(e.X, e.Y); //get info
            int pos = dgv_groupe.HitTest(e.X, e.Y).RowIndex;

            if (pos > -1)
            {
                if (dgv_groupe.Rows[pos].Cells["id"].Value != null)
                {
                    Int32 id = (Int32)dgv_groupe.Rows[pos].Cells["id"].Value;
                    if (id > 0)
                    {
                        GroupeMatiere y = dao.Result.Find(x => x.Id == id);
                        if (y != null ? y.Id > 0 : false)
                        {
                            switch (e.Button)
                            {
                            case MouseButtons.Right:
                            {
                                select = y;
                                ResetData();
                                dgv_groupe.Rows[pos].Selected = true;         //Select the row
                            }
                            break;

                            default:
                                LoadOnView(y);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
 private void ResetView()
 {
     txt_code.ResetText();
     txt_intitule.ResetText();
     select = new GroupeMatiere();
     entity = new GroupeMatiere();
 }
예제 #4
0
 private bool ControleView(GroupeMatiere y)
 {
     if (y.Code != null ? y.Code.Trim().Length < 1 : true)
     {
         Messages.Error("Vous devez specifier le code");
         return(false);
     }
     return(true);
 }
예제 #5
0
        private GroupeMatiere RecopieView()
        {
            GroupeMatiere y = new GroupeMatiere(entity.Id);

            y.Code     = txt_code.Text.Trim();
            y.Intitule = txt_intitule.Text.Trim();
            y.Position = entity.Position;
            return(y);
        }
예제 #6
0
        private void LoadAll(bool avance, bool init)
        {
            dao.AddParam(new ParametreRequete("y.langue.id", "langue", Constantes.LANGUE.Id, "=", "AND"));
            dao.ExecuteDynamicQuery(GroupeMatiere.ToTable(), "y.position desc, y.code", avance, init);

            objet_groupe.ClearDataGridView(true);
            foreach (GroupeMatiere g in dao.Result)
            {
                Action(g, 1, true);
            }

            btn_prev.Enabled = !dao.disPrev;
            btn_next.Enabled = !dao.disNext;
            lb_position.Text = dao.currentPage + "/" + dao.totalPage;
        }
예제 #7
0
        private void Action(GroupeMatiere y, int action, bool load)// action : 1 pour sauvegarder - 2 pour modifier - 3 pour supprimer
        {
            int idx = Utils.GetRowData(dgv_groupe, y.Id);

            object[] row = new object[] { y.Id, y.Code, y.Intitule };
            switch (action)
            {
            case 1:
                objet_groupe.WriteDataGridView(row);
                if (dgv_groupe.Rows.Count > dao.max)
                {
                    objet_groupe.RemoveDataGridView(dgv_groupe.Rows.Count - 1);
                }
                if (!load)
                {
                    dao.Result.Add(y);
                }
                break;

            case 2:
                if (idx > -1)
                {
                    objet_groupe.RemoveDataGridView(idx);
                    objet_groupe.WriteDataGridView(idx, row);
                }
                if (!load)
                {
                    idx = dao.Result.FindIndex(x => y.Id == x.Id);
                    if (idx > -1)
                    {
                        dao.Result[idx] = y;
                    }
                }
                break;

            default:
                if (idx > -1)
                {
                    objet_groupe.RemoveDataGridView(idx);
                }
                if (!load)
                {
                    dao.Result.Remove(y);
                }
                break;
            }
        }
예제 #8
0
 private void LoadOnView(GroupeMatiere y)
 {
     txt_code.Text     = y.Code;
     txt_intitule.Text = y.Intitule;
     entity            = y;
 }