Exemple #1
0
        private void AddSectionForm_Load(object sender, EventArgs e)
        {
            InsertButton.Select();

            //EXCEPTION 1
            try
            {
                variables           = new Variables();
                opacityform         = new OpacityForm();
                cryptography        = new Cryptography();
                sqlconnectionconfig = new SQLConnectionConfig();

                RegistryKey registrykey = Registry.CurrentUser.OpenSubKey(@variables.pathname);
                string      tempdata    = registrykey.GetValue("SQLServerConnectionString").ToString();

                //USER SQLSERVER CONNECTION SETTINGS
                sqlconnectionconfig.SqlConnectionString = cryptography.Decrypt(tempdata);
                sqlconnection = new SqlConnection(sqlconnectionconfig.SqlConnectionString);
                sqlconnection.Open();

                //INNER EXCEPTION 1
                try
                {
                    Init_NewSectionID();
                    RetriveSectionData();
                    RetrieveSchoolYearList();
                }

                catch (Exception exception)
                {
                    opacityform.Show();
                    MessageBox.Show(exception.ToString(), "@Add Section Form Inner Exception 1",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    opacityform.Hide();
                }
            }

            catch (Exception exception)
            {
                opacityform.Show();
                MessageBox.Show(exception.ToString(), "@Add Section Form Exception 1",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                opacityform.Hide();
            }
        }
Exemple #2
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            //EXCEPTION 2
            try
            {
                opacityform        = new OpacityForm();
                darkeropacityform  = new DarkerOpacityForm();
                notificationwindow = new NotificationWindow();

                if (SchoolYearTextbox.Text.Trim().Length < 1)
                {
                    notificationwindow.CaptionText    = "MESSAGE CONTENT";
                    notificationwindow.MsgImage.Image = Properties.Resources.warning;
                    notificationwindow.MessageText    = "PLEASE PROVIDE A SCHOOL YEAR !";

                    darkeropacityform.Show();
                    notificationwindow.ShowDialog();
                    darkeropacityform.Hide();
                }

                else if (!SchoolYearTextbox.Text.Trim().ToUpper().Contains("S.Y."))
                {
                    notificationwindow.CaptionText    = "MESSAGE CONTENT";
                    notificationwindow.MsgImage.Image = Properties.Resources.warning;
                    notificationwindow.MessageText    = "PLEASE FOLLOW AND PROVIDE\nTHE SPECIFIED SCHOOL YEAR FORMAT !";

                    darkeropacityform.Show();
                    notificationwindow.ShowDialog();
                    darkeropacityform.Hide();
                }

                else
                {
                    //INNER EXCEPTION 2
                    try
                    {
                        string TempQuery = "SELECT COUNT(*) FROM [Tbl.SchoolYear] WHERE [SCHOOL YEAR] = '" +
                                           SchoolYearTextbox.Text.Trim().ToUpper() + "'";
                        sqldataadapter = new SqlDataAdapter(TempQuery, sqlconnection);
                        DataTable datatable0 = new DataTable();
                        sqldataadapter.Fill(datatable0);


                        if (datatable0.Rows[0][0].ToString() == "1")
                        {
                            notificationwindow.CaptionText    = "MESSAGE CONTENT";
                            notificationwindow.MsgImage.Image = Properties.Resources.warning;
                            notificationwindow.MessageText    = "THAT SCHOOL YEAR ALREADY EXIST !";

                            darkeropacityform.Show();
                            notificationwindow.ShowDialog();
                            darkeropacityform.Hide();
                        }

                        else if (datatable0.Rows[0][0].ToString() == "0")
                        {
                            string InsertQuery = "INSERT INTO [Tbl.SchoolYear]([ENTRY ID], [SCHOOL YEAR], [WAS SET]) VALUES(@EntryID, @schoolyear, @ws)";
                            sqlcommand = new SqlCommand(InsertQuery, sqlconnection);
                            sqlcommand.Parameters.AddWithValue("@EntryID", Prefix_ID + NewEntryID.ToString());
                            sqlcommand.Parameters.AddWithValue("@schoolyear", SchoolYearTextbox.Text.Trim().ToUpper());
                            sqlcommand.Parameters.AddWithValue("@ws", "0");
                            sqlcommand.ExecuteNonQuery();

                            RetrieveSchoolYearData();
                            SchoolYearTextbox.ResetText();
                            InsertButton.Select();
                            Init_NewEntryID();
                        }
                    }

                    catch (Exception exception)
                    {
                        opacityform.Show();
                        MessageBox.Show(exception.StackTrace.ToString(), "@Add School Year Form Inner Exception 2",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        opacityform.Hide();
                    }
                }
            }

            catch (Exception exception)
            {
                opacityform.Show();
                MessageBox.Show(exception.StackTrace.ToString(), "@Add School Year Form Exception 2",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                opacityform.Hide();
            }
        }
Exemple #3
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            //EXCEPTION 3
            try
            {
                variables          = new Variables();
                opacityform        = new OpacityForm();
                darkeropacityform  = new DarkerOpacityForm();
                notificationwindow = new NotificationWindow();

                if (SectionNameTextbox.Text.Trim().Length < 1 || MaxStudentTextbox.Text.Trim().Length < 1)
                {
                    notificationwindow.CaptionText    = "MESSAGE CONTENT";
                    notificationwindow.MsgImage.Image = Properties.Resources.warning;
                    notificationwindow.MessageText    = "PLEASE PROVIDE SECTION NAME,\nMAXIMUM STUDENTS AND SCHOOL YEAR !";

                    darkeropacityform.Show();
                    notificationwindow.ShowDialog();
                    darkeropacityform.Hide();
                }

                else if (isNumber(MaxStudentTextbox.Text.Trim()) == false)
                {
                    notificationwindow.CaptionText    = "MESSAGE CONTENT";
                    notificationwindow.MsgImage.Image = Properties.Resources.warning;
                    notificationwindow.MessageText    = "INVALID DATA ON MAXIMUM STUDENTS !";

                    darkeropacityform.Show();
                    notificationwindow.ShowDialog();
                    darkeropacityform.Hide();
                }

                else
                {
                    //INNER EXCEPTION 3
                    try
                    {
                        string TempQuery = "SELECT COUNT(*) FROM [Tbl.Sections] WHERE [SECTION NAME] = '" +
                                           SectionNameTextbox.Text.Trim().ToUpper() + "' AND [SCHOOL YEAR] = '" + CurrentSchoolYearDropdown.selectedValue.ToString() + "'";

                        sqldataadapter = new SqlDataAdapter(TempQuery, sqlconnection);
                        DataTable datatable = new DataTable();
                        sqldataadapter.Fill(datatable);

                        if (datatable.Rows[0][0].ToString() == "1")
                        {
                            notificationwindow.CaptionText    = "MESSAGE CONTENT";
                            notificationwindow.MsgImage.Image = Properties.Resources.warning;
                            notificationwindow.MessageText    = "THAT SECTION ALREADY EXIST FOR \nSCHOOL YEAR " + CurrentSchoolYearDropdown.selectedValue.ToString();

                            darkeropacityform.Show();
                            notificationwindow.ShowDialog();
                            darkeropacityform.Hide();
                        }

                        else if (datatable.Rows[0][0].ToString() == "0")
                        {
                            RegistryKey registrykey = Registry.CurrentUser.OpenSubKey(@variables.pathname);
                            CurrentSectionCount = registrykey.GetValue("NofMaxSections").ToString();

                            if (int.Parse(CurrentSectionCount) < 10)
                            {
                                sqlquery5 = "INSERT INTO [Tbl.Sections]([SECTION ID], [SECTION NAME], [MAXIMUM STUDENTS], ENROLLED, [SCHOOL YEAR])" +
                                            " VALUES(@sectionid, @section_name, @maximumstudents, @enrolled, @schoolyear)";
                                sqlcommand = new SqlCommand(sqlquery5, sqlconnection);
                                sqlcommand.Parameters.AddWithValue("@sectionid", Prefix + NewSectionID.ToString());
                                sqlcommand.Parameters.AddWithValue("@section_name", SectionNameTextbox.Text.Trim().ToUpper());
                                sqlcommand.Parameters.AddWithValue("@maximumstudents", MaxStudentTextbox.Text.Trim());
                                sqlcommand.Parameters.AddWithValue("@enrolled", "0");
                                sqlcommand.Parameters.AddWithValue("@schoolyear", CurrentSchoolYearDropdown.selectedValue.ToString().ToUpper());
                                sqlcommand.ExecuteNonQuery();

                                //UPDATE SECTION COUNT
                                RegistryKey updateregistrykey = Registry.CurrentUser.CreateSubKey(@variables.pathname);
                                updateregistrykey.SetValue("NofMaxSections", (int.Parse(CurrentSectionCount) + 1).ToString());

                                Init_NewSectionID();
                                RetriveSectionData();

                                SectionNameTextbox.ResetText();
                                MaxStudentTextbox.ResetText();

                                CurrentSchoolYearDropdown.selectedIndex = 0;
                                InsertButton.Select();
                            }

                            else if (int.Parse(CurrentSectionCount) == 10)
                            {
                                notificationwindow.CaptionText    = "MESSAGE CONTENT";
                                notificationwindow.MsgImage.Image = Properties.Resources.error;
                                notificationwindow.MessageText    = "YOU CAN ONLY CREATE 10 SECTIONS\nEVERY SCHOOL YEAR !";

                                darkeropacityform.Show();
                                notificationwindow.ShowDialog();
                                darkeropacityform.Hide();
                            }
                        }
                    }

                    catch (Exception exception)
                    {
                        opacityform.Show();
                        MessageBox.Show(exception.Message.ToString(), "@Add Section Form Inner Exception 3",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        opacityform.Hide();
                    }
                }
            }

            catch (Exception exception)
            {
                opacityform.Show();
                MessageBox.Show(exception.Message.ToString(), "@Add Section Form Exception 2",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                opacityform.Hide();
            }
        }