private void frmMain_Load(object sender, EventArgs e) { set s = new set(); s.recall(); Methods m = new Methods(); m.MemExpire(); if (db.con.State.Equals(ConnectionState.Open)) { db.con.Close(); } //Open login form frmLogin f = new frmLogin(); f.ShowDialog(); if (cvar.UType == "Mem") { Mem.Visible = true; User.Text = "Member"; } else if (cvar.UType == "Lib") { Issues.Visible = MgBook.Visible = MgMem.Visible = Notif.Visible = true; } else if (cvar.UType == "Admin") { Mem.Visible = Issues.Visible = MgBook.Visible = MgMem.Visible = Admin.Visible = Notif.Visible = EditAcc.Visible = true; } if (cvar.UType == "Admin" || cvar.UType == "Lib") { User.Text = cvar.UText; //Check for Notifications if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } int N = 0; DateTime[] nLend = new DateTime[] { };; string[] nMemID = new string[] { }; string[] nMemType = new string[] { }; string[] nBookID = new string[] { }; string[] nTitleID = new string[] { }; string[] nTitle = new string[] { }; double[] nPrice = new double[] { }; bool NError = false; m.Notif(ref N, ref nLend, ref nMemID, ref nMemType, ref nBookID, ref nTitleID, ref nTitle, ref nPrice, ref NError); if (N > 0) // If notifications are there. { Notif.BackColor = Color.Red; DialogResult notif = MessageBox.Show(string.Format("There are {0} alert notifications about the books which have not been returned for a long time. Do you want to check the notification window?", N), "Alert Notifications Pending", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (notif == DialogResult.Yes) { frmNotif n = new frmNotif(); n.ShowDialog(); } } if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } } }
private void loadSettingsToolStripMenuItem_Click(object sender, EventArgs e) { set s = new set(); s.recall(); }
private void setSave() { //Disclaim free boxes if (AtxtBTime.Text == "" || CtxtBTime.Text == "" || AtxtNoBooks.Text == "" || CtxtNoBooks.Text == "" || AtxtExpire.Text == "" || CtxtExpire.Text == "" || AtxtAlert.Text == "" || CtxtAlert.Text == "" || AtxtLostBookTimes.Text == "" || CtxtLostBookTimes.Text == "" || AtxtNewC.Text == "" || CtxtNewC.Text == "" || AtxtRenewC.Text == "" || CtxtRenewC.Text == "") { MessageBox.Show("No fields should be left blank. Fill all fields with numbers and try again", "Blank values", MessageBoxButtons.OK, MessageBoxIcon.Error); goto End; } //Remove aingle double quotes in textboxes foreach (Control c in this.Controls) { if (c is TextBox || c is ComboBox) { c.Text = c.Text.Replace("'", ""); c.Text = c.Text.Replace("\"", ""); } } //Declarations, move all text to two string arrays and variable string[,] SValueSI = new string[, ] { { AtxtBTime.Text, CtxtBTime.Text }, { AtxtNoBooks.Text, CtxtNoBooks.Text }, { AtxtExpire.Text, CtxtExpire.Text }, { AtxtAlert.Text, CtxtAlert.Text }, { AtxtLostBookTimes.Text, CtxtLostBookTimes.Text } }; string[,] SValueSD = new string[, ] { { AtxtFine.Text, CtxtFine.Text }, { AtxtRenewC.Text, CtxtRenewC.Text }, { AtxtNewC.Text, CtxtNewC.Text } }; string AgeMinS = AtxtAgeMin.Text; //Declare arrays of column names of Setting table for DB purposes. string[] SType = new string[] { "A", "C" }; string[] SNameI = new string[] { "Btime", "NoBooks", "Expire", "Alert", "LostBookTimes" }; string[] SNameD = new string[] { "Fine", "RenewC", "NewC" }; //Create a double and int arrays and variable int[,] SValueI = new int[, ] { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; double[,] SValueD = new double[, ] { { 0, 0 }, { 0, 0 }, { 0, 0 } }; int AgeMinI; //Try Parsing in Main for loop for each dimension set in SValueSI for (int i = 0; i < SValueSI.Length / 2; i++) { //Try parsing each item of each dimension set of SValueSI for (int j = 0; j < 2; j++) { //Try to parse respective values to int and move them to integer array. bool isNum = int.TryParse(SValueSI[i, j], out SValueI[i, j]); //If not an integer, raise message and stop. if (isNum == false) { MessageBox.Show("One or many of the values you entered is invalid. Please correct them and and try saving agian.", "Invalid Values", MessageBoxButtons.OK, MessageBoxIcon.Error); goto End; } } } //Try Parsing in Main for loop for each dimension set in SValueSI for (int i = 0; i < SValueSD.Length / 2; i++) { //Try parsing each item of each dimension set of SValueSI for (int j = 0; j < 2; j++) { //Try to parse respective values to int and move them to double array. bool isNum = double.TryParse(SValueSD[i, j], out SValueD[i, j]); //If not a double, raise message and stop. if (isNum == false) { MessageBox.Show("One or many of the values you entered is invalid. Please correct them and and try saving agian.", "Invalid Values", MessageBoxButtons.OK, MessageBoxIcon.Error); goto End; } } } //Try Parsing AgeMin bool isNum1 = int.TryParse(AgeMinS, out AgeMinI); if (isNum1 == false) { MessageBox.Show("The mimum age value you entered is not a valid number. Please correct it and and try saving agian.", "Invalid Age", MessageBoxButtons.OK, MessageBoxIcon.Error); goto End; } //Disclaimer DialogResult sure = MessageBox.Show("Are you sure you want to update the preference data with these values?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (sure == DialogResult.No) { goto End; // If disagree, stop. } // If agree, continue, add values to database //Open connection if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } // Main For loop of Int to repeatedly add interger values to DB (using SNameI) and add values from SValue[*,_] 10 times. for (int iSN = 0; iSN < SNameI.Length; iSN++) { // Sub for loop to repeatedly add values to DB (using SType) and add from SValue[_,*] twice during each main loop. for (int iST = 0; iST < SType.Length; iST++) { string sqlSet = string.Format("UPDATE Setting SET SValue = {0} WHERE SName = '{1}' AND SType = '{2}'", SValueI[iSN, iST], SNameI[iSN], SType[iST]); OleDbCommand cmdSet = new OleDbCommand(sqlSet, db.con); cmdSet.ExecuteNonQuery(); } } // Main For loop of double to repeatedly retrive double values from DB (using SNameD) and add values to SValue[*,_] 15 times. for (int iSN = 0; iSN < SNameD.Length; iSN++) { // Sub for loop to repeatedly add values from DB (using SType) and add to SValue[_,*] twice during each main loop. for (int iST = 0; iST < SType.Length; iST++) { string sqlSet = string.Format("UPDATE Setting SET SValue = {0} WHERE SName = '{1}' AND SType = '{2}'", SValueD[iSN, iST], SNameD[iSN], SType[iST]); OleDbCommand cmdSet = new OleDbCommand(sqlSet, db.con); cmdSet.ExecuteNonQuery(); } } string sqlSetAge = string.Format("UPDATE Setting SET SValue = {0} WHERE SName = 'AgeMin'", AgeMinI); OleDbCommand cmdSetAge = new OleDbCommand(sqlSetAge, db.con); cmdSetAge.ExecuteNonQuery(); //Recall The new settings set s = new set(); s.recall(); //All successfull MessageBox.Show("Preferences have been saved succesfully", "Saving successful", MessageBoxButtons.OK, MessageBoxIcon.Information); isSave = true; End : if (db.con.State.Equals(ConnectionState.Open)) { db.con.Close(); } ; }