Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Etablissement newEtablissement = new Etablissement(

                    txtName.Text,
                    textBox1.Text,
                    txtEmail.Text,
                    !string.IsNullOrEmpty(pictureBox1.ImageLocation) ? File.ReadAllBytes(pictureBox1.ImageLocation) : this.oldEtablissement.Logo,
                    int.Parse(txtTel.Text),
                    textBP.Text
                    );

                EtablissementBLO universityBLO = new EtablissementBLO(ConfigurationManager.AppSettings["DbFolder"]);

                if (this.oldEtablissement == null)
                {
                    universityBLO.CreateEtablissement(newEtablissement);
                }
                else
                {
                    universityBLO.EditEtablissement(oldEtablissement, newEtablissement);
                }

                MessageBox.Show(
                    "Save done!",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
                txtEmail.Clear();
                txtName.Clear();
                txtTel.Clear();
                pictureBox1.ImageLocation = null;
                loadData();
            }
            catch (TypingException ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "Typing error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );
            }
            catch (DuplicateNameException ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "Duplicate error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "key not found error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );
            }
            catch (Exception ex)
            {
                ex.WriteToFile();

                MessageBox.Show(
                    "An error occured please try again",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
Exemplo n.º 2
0
 public frmEtblissement()
 {
     InitializeComponent();
     dataGridView1.AutoGenerateColumns = false;
     EtablissementBLO = new EtablissementBLO(ConfigurationManager.AppSettings["DbFolder"]);
 }