Beispiel #1
0
        private void SystemDefaultsForm_Load(object sender, EventArgs e)
        {
            SaveButton.Select();
            int BoundsWidth  = Screen.PrimaryScreen.Bounds.Width;
            int BoundsHeight = Screen.PrimaryScreen.Bounds.Height;
            int X_Coordinate = BoundsWidth - this.Width;
            int Y_Coordinate = BoundsHeight - this.Height;

            Location = new Point(X_Coordinate / 2, (Y_Coordinate / 2) + 10);

            //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
                {
                    //DON'T MIND THIS !
                    Where_To_Check_Radio_Buttons();

                    //DISPLAY CURRENT SCHOOL YEAR
                    Init_Current_SchoolYear();

                    //INITIALIZE SCHOOL YEAR DROPDOWN AND ID
                    Retrieve_School_Year_List_And_ID();

                    //CHECK VALIDITY OF SECTIONS
                    Enable_Or_Disable_2ndSaveButton();

                    //INITIALIZE SECTION ID DROPDOWN
                    Retrieve_SectionID_List();

                    //POPULATE DATAGRIDVIES
                    Load_Section_Records();
                    Load_School_Year_Records();
                }

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

            catch (Exception exception)
            {
                opacityform.Show();
                MessageBox.Show(exception.ToString(), "@Other Settings Form Exception 1",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                opacityform.Hide();
            }
        }
Beispiel #2
0
        //SAVE CURRENT SCHOOL YEAR
        private void SaveButton_Click(object sender, EventArgs e)
        {
            variables   = new Variables();
            opacityform = new OpacityForm();

            //EXCEPTION 2
            try
            {
                darkeropacityform  = new DarkerOpacityForm();
                notificationwindow = new NotificationWindow();

                string GetID = "SELECT [ENTRY ID] FROM [Tbl.SchoolYear] WHERE [SCHOOL YEAR] = '" +
                               CurrentSchoolYearDropdown.selectedValue.ToString() + "'";
                sqlcommand = new SqlCommand(GetID, sqlconnection);
                SqlDataReader sqldatareader = sqlcommand.ExecuteReader();

                while (sqldatareader.Read())
                {
                    EntryID = sqldatareader.GetString(0);
                }
                sqldatareader.Close();

                string TempQuery = "SELECT COUNT(*) FROM [Tbl.CurrentSchoolYear]";
                sqldataadapter = new SqlDataAdapter(TempQuery, sqlconnection);
                DataTable datatable = new DataTable();
                sqldataadapter.Fill(datatable);

                if (int.Parse(datatable.Rows[0][0].ToString()) > 0)
                {
                    string UpdateQuery0 = "UPDATE [Tbl.CurrentSchoolYear] SET [CURRENT SCHOOL YEAR] = @currentschoolyear, [SCHOOL YEAR ID] = @slyid";
                    sqlcommand = new SqlCommand(UpdateQuery0, sqlconnection);
                    sqlcommand.Parameters.AddWithValue("@currentschoolyear", CurrentSchoolYearDropdown.selectedValue.ToString());
                    sqlcommand.Parameters.AddWithValue("@slyid", EntryID);
                    sqlcommand.ExecuteNonQuery();

                    string UpdateQuery1 = "UPDATE [Tbl.SchoolYear] SET [WAS SET] = @ws WHERE [ENTRY ID] = '" + EntryID + "'";
                    sqlcommand = new SqlCommand(UpdateQuery1, sqlconnection);
                    sqlcommand.Parameters.AddWithValue("@ws", "1");
                    sqlcommand.ExecuteNonQuery();

                    notificationwindow.CaptionText    = "MESSAGE CONTENT";
                    notificationwindow.MsgImage.Image = Properties.Resources.check;
                    notificationwindow.MessageText    = "CURRENT SCHOOL YEAR WAS\nSET TO " + CurrentSchoolYearDropdown.selectedValue.ToString();

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

                    //SYNC NEW CURRENT SECTION LABEL
                    CurrentSchoolYearLabel.Text = "* CURRENT SCHOOL YEAR: " + CurrentSchoolYearDropdown.selectedValue.ToString();

                    //RESET CONTROL STATE
                    CurrentSchoolYearDropdown.selectedIndex = 0;
                }

                else if (datatable.Rows[0][0].ToString() == "0")
                {
                    string UpdateQuery0_0 = "INSERT INTO [Tbl.CurrentSchoolYear]([CURRENT SCHOOL YEAR], [SCHOOL YEAR ID]) VALUES(@currentschoolyear, @slyid)";
                    sqlcommand = new SqlCommand(UpdateQuery0_0, sqlconnection);
                    sqlcommand.Parameters.AddWithValue("@currentschoolyear", CurrentSchoolYearDropdown.selectedValue.ToString());
                    sqlcommand.Parameters.AddWithValue("@slyid", EntryID);
                    sqlcommand.ExecuteNonQuery();

                    string UpdateQuery1 = "UPDATE [Tbl.SchoolYear] SET [WAS SET] = @ws WHERE [ENTRY ID] = '" + EntryID + "'";
                    sqlcommand = new SqlCommand(UpdateQuery1, sqlconnection);
                    sqlcommand.Parameters.AddWithValue("@ws", "1");
                    sqlcommand.ExecuteNonQuery();

                    notificationwindow.CaptionText    = "MESSAGE CONTENT";
                    notificationwindow.MsgImage.Image = Properties.Resources.check;
                    notificationwindow.MessageText    = "CURRENT SCHOOL YEAR WAS\nSET TO " + CurrentSchoolYearDropdown.selectedValue.ToString();

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

                    //SYNC NEW CURRENT SECTION LABEL
                    CurrentSchoolYearLabel.Text = "* CURRENT SCHOOL YEAR: " + CurrentSchoolYearDropdown.selectedValue.ToString();

                    //RESET CONTROL STATE
                    CurrentSchoolYearDropdown.selectedIndex = 0;
                }

                //UPDATE REGISTRY VALUES
                RegistryKey updateregistrykey = Registry.CurrentUser.CreateSubKey(@variables.pathname);
                updateregistrykey.SetValue("NofMaxSections", "0");
            }

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