Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                University newUniversity = new University
                                           (
                    txtUniversityName.Text.ToUpper(),
                    txtDate.Text,
                    txtLocationUniversity.Text,
                    long.Parse(txtContactUniversity.Text),
                    !string.IsNullOrEmpty(pictureBoxUniversity.ImageLocation) ? File.ReadAllBytes(pictureBoxUniversity.ImageLocation) : this.oldUniversity?.Logo
                                           );

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

                if (this.oldUniversity == null)
                {
                    universityBLO.CreateUniversity(newUniversity);
                }
                else
                {
                    universityBLO.EditUniversity(oldUniversity, newUniversity);
                }

                MessageBox.Show
                (
                    "Save done !",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                );

                Close();
            }
            catch (TypingException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Typing error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (Exception ex)
            {
                ex.WriteToFile();
                MessageBox.Show
                (
                    "An error occurred! Please try again later.",
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                checkForm();

                University newuniversity = new University(
                    txtName.Text,
                    long.Parse(txtTel.Text),
                    pictureBox1.ImageLocation,
                    txtEmail.Text
                    );

                universityBLO.CreateUniversity(olduniversity, newuniversity);

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

                //if (this.olduniversity == null)
                //    universityBLO.CreateUniversity(newuniversity);
                //else
                //    universityBLO.EditUniversity(olduniversity, newuniversity);

                MessageBox.Show(
                    "Save done!",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );

                Close();

                if (callback != null)
                {
                    callback();
                }

                //if (olduniversity != null)
                //    Close();

                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
                    );
            }
        }