Beispiel #1
0
        private void btEnregistrer_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtCode.Text == "")
                {
                    this.ActiveControl = txtCode;
                    throw new ArgumentException("La saisie du code est obligatoire!");
                }
                if (txtIntitule.Text == "")
                {
                    this.ActiveControl = txtIntitule;
                    txtIntitule.Focus();
                    throw new ArgumentException("la saisie du l'intitule est obligatoire");
                }
                using (DbSage db = new DbSage())
                {
                    string code = txtCode.Text;
                    if (_mode == Mode.Ajouter && db.F_Service.Count(item => item.SE_Code == code) > 0)
                    {
                        this.ActiveControl = txtCode;
                        txtCode.Focus();
                        throw new ArgumentException("Ce code existe déja!");
                    }
                }
                F_Service service = new F_Service()
                {
                    SE_Code     = txtCode.Text,
                    SE_intitule = txtIntitule.Text,
                    SE_No       = _mode == Mode.Modifier ? _service.SE_No : 0,
                };

                using (DbSage db = new DbSage())
                {
                    if (_mode == Mode.Ajouter)
                    {
                        db.F_Service.Add(service);
                    }
                    else if (_mode == Mode.Modifier)
                    {
                        db.F_Service.Add(service);
                        db.Entry(_service).State = System.Data.Entity.EntityState.Modified;
                    }
                    db.SaveChanges();
                };
                BindListe();
                btNouveau_Click(null, null);
            }

            catch (Exception ex)
            {
                Program.ErrorMessage(ex.Message);
            }
        }
Beispiel #2
0
        private void olvSalarie_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView1.SelectedRowsCount != 1)
                {
                    return;
                }
                F_Service row = (F_Service)(gridView1.GetRow(gridView1.FocusedRowHandle));
                txtCode.Text        = row.SE_Code;
                txtIntitule.Text    = row.SE_intitule;
                txtCode.Enabled     = false;
                btSupprimer.Enabled = true;
                _mode = Mode.Modifier;

                this.ActiveControl = txtIntitule;
                txtIntitule.Focus();
            }
            catch (Exception ex)
            {
                Program.ErrorMessage(ex.Message);
            }
        }