From d9dcf41695efcea339f06e1299b4b4c0e36eec2d Mon Sep 17 00:00:00 2001
From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com>
Date: Thu, 15 Feb 2024 11:52:59 -0500
Subject: [PATCH] almost done
---
.../.idea/sqldialects.xml | 1 -
Database3/Database3.csproj | 5 +
Database3/State.xml | 55 +++++
Database3/StateManager.cs | 208 ++++++++++++++++++
Database3/StudentDataTier.cs | 128 ++++++++---
Database3/frmEdit.Designer.cs | 2 +
Database3/frmEdit.cs | 75 +++++++
Database3/frmSearch.Designer.cs | 1 +
Database3/frmSearch.cs | 21 +-
Database3/state.cs | 50 +++++
10 files changed, 514 insertions(+), 32 deletions(-)
create mode 100644 Database3/State.xml
create mode 100644 Database3/StateManager.cs
create mode 100644 Database3/state.cs
diff --git a/.idea/.idea.CNSA-212-Personal-CAS/.idea/sqldialects.xml b/.idea/.idea.CNSA-212-Personal-CAS/.idea/sqldialects.xml
index 20ffcb4..584f587 100644
--- a/.idea/.idea.CNSA-212-Personal-CAS/.idea/sqldialects.xml
+++ b/.idea/.idea.CNSA-212-Personal-CAS/.idea/sqldialects.xml
@@ -1,7 +1,6 @@
-
\ No newline at end of file
diff --git a/Database3/Database3.csproj b/Database3/Database3.csproj
index f72f4b8..830b6e5 100644
--- a/Database3/Database3.csproj
+++ b/Database3/Database3.csproj
@@ -61,6 +61,8 @@
+
+
frmEdit.cs
@@ -90,5 +92,8 @@
+
+
+
\ No newline at end of file
diff --git a/Database3/State.xml b/Database3/State.xml
new file mode 100644
index 0000000..923e18f
--- /dev/null
+++ b/Database3/State.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Database3/StateManager.cs b/Database3/StateManager.cs
new file mode 100644
index 0000000..4420893
--- /dev/null
+++ b/Database3/StateManager.cs
@@ -0,0 +1,208 @@
+using System;
+using System.Collections.Generic;
+using System.Collections;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Security;
+using Microsoft.VisualBasic;
+using System.Windows;
+using System.Xml;
+using System.Web;
+//using System.Web.Caching;
+
+namespace Traffic
+{
+ ///
+
+ /// ''' Provides the functionality related to retrieving the list
+
+ /// ''' of states for a system;
+ //// reads an xml file
+ /// '''
+ public static class StateManager
+ {
+ // Cache object that will be used to store and retrieve items from
+ // the cache and constants used within this object
+ // private static Cache myCache = System.Web.HttpRuntime.Cache();
+ private static string stateKey = "StateKey";
+ public static string applicationConstantsFileName = AppDomain.CurrentDomain.BaseDirectory + "State.xml"; // = Strings.Replace(System.AppDomain.CurrentDomain.BaseDirectory + "State.xml", "/", @"\");
+ // "States.config", "/", "\")
+ private static state[] stateArray;
+ private static ArrayList errorList;
+
+
+ // Tells you whether or not any errors have occurred w/in the module
+ public static bool hasErrors
+ {
+ get
+ {
+ if (errorList == null || errorList.Count == 0)
+ return false;
+ else
+ return true;
+ }
+ }
+
+
+ // Retrieves an array list of Exception objects
+ public static ArrayList getErrors
+ {
+ get
+ {
+ return errorList;
+ }
+ }
+
+
+ // Private method used to add errors to the errorList
+ private static void addError(ref Exception e)
+ {
+ if (errorList == null)
+ errorList = new ArrayList();
+ errorList.Add(e);
+ }
+
+ ///
+ /// ''' Gets all the states
+ /// '''
+ /// ''' An array of State objects
+ public static state[] getStates()
+ {
+ //if (myCache[stateKey] == null)
+ PopulateCache();
+ return stateArray;
+ }
+
+
+ ///
+ /// ''' Takes the abbreviation given and returns the full name
+ /// '''
+ /// ''' The full name for the abbreviation in
+ /// ''' question
+ private static string convertAbbreviationToName(ref string abbreviation)
+ {
+ XmlDocument xmlFile = new XmlDocument();
+
+ try
+ {
+ applicationConstantsFileName = applicationConstantsFileName.Replace("/", @"\");
+ xmlFile.Load(applicationConstantsFileName);
+ XmlNode theNode = xmlFile.SelectSingleNode("descendant::state[@abbreviation='" + abbreviation + "']");
+
+ if (theNode != null)
+ return theNode.Attributes.GetNamedItem("name").Value;
+ }
+ catch (Exception e)
+ {
+ addError(ref e);
+ }
+
+ return null;
+ }
+
+
+ ///
+ /// ''' Gets the state object based on the full name
+ /// '''
+ /// ''' The full name of the state to
+ /// ''' retrieve
+ /// ''' A State object for the name given
+ public static state getStateByName(ref string name)
+ {
+ // if (myCache[stateKey + name] == null)
+ PopulateCache();
+ //return state[stateKey + name];
+
+ return (state)Convert.ChangeType(stateKey, typeof(state[]));
+ }
+
+
+ ///
+ /// ''' Gets the state object based on the abbreviation
+ /// '''
+ /// ''' The abbreviation of the state
+ /// ''' to retrieve
+ /// ''' A State object for the abbreviation
+ /// ''' given
+ public static state getStateByAbbreviation(ref string abbreviation)
+ {
+ string name = convertAbbreviationToName(ref abbreviation);
+ if (name != null)
+ return getStateByName(ref name);
+ else
+ return null/* TODO Change to default(_) if this is not a reference type */;
+ }
+
+
+ /// The manager attempts to load the XML
+ /// ''' file and store it in the cache with a dependency on the XML
+ /// ''' file itself.' This means that any time the XML file changes, it
+ /// ''' is removed from the cache. When the methods that return State
+ /// ''' objects are called again, the XML file won't exist in memory
+ /// ''' and the PopulateCache will be re-called.
+ /// '''
+ private static void PopulateCache()
+ {
+ XmlDocument xmlFile = new XmlDocument();
+ // Dim theState As State
+ XmlNode theNode;
+ string theName, theAbbreviation;
+ int i = 0;
+
+ try
+ {
+ applicationConstantsFileName = applicationConstantsFileName.Replace("/", @"\");
+ xmlFile.Load(applicationConstantsFileName);
+
+ // Attempt to find the element given the "key" for that tag
+ XmlNodeList elementList = xmlFile.GetElementsByTagName("state");
+
+ if (elementList != null)
+ {
+ stateArray = (state[])Array.CreateInstance(typeof(state), elementList.Count);
+
+ // Loop through each element that has the name we're looking for
+ for (i = 0; i <= elementList.Count - 1; i++)
+ {
+ theNode = elementList[i];
+
+ // Get the name for that tag
+ if (theNode.Attributes.GetNamedItem("name") != null)
+ theName = theNode.Attributes.GetNamedItem("name").Value;
+ else
+ theName = null;
+
+ // Get the abbreviation for that tag
+ if (theNode.Attributes.GetNamedItem("abbreviation") != null)
+ theAbbreviation = theNode.Attributes.GetNamedItem("abbreviation").Value;
+ else
+ theAbbreviation = null;
+
+ // Populate that location in the array with the
+ // values for the tag
+ stateArray[i] = new state(ref theName, ref theAbbreviation);
+
+ // Insert the state into cache
+ //// myCache.Insert(stateKey + theName, stateArray[i], new CacheDependency(applicationConstantsFileName));
+ }
+
+ // Insert the state array into cache
+ //// myCache.Insert(stateKey, stateArray, new CacheDependency(applicationConstantsFileName));
+ }
+ }
+ catch (Exception e)
+ {
+ addError(ref e);
+ }
+ }
+ }
+
+}
diff --git a/Database3/StudentDataTier.cs b/Database3/StudentDataTier.cs
index 7a58fc6..afe2492 100644
--- a/Database3/StudentDataTier.cs
+++ b/Database3/StudentDataTier.cs
@@ -61,38 +61,106 @@ namespace Database3
{
- try
- {
- // open connection
- myConn.Open();
- //clear any parameters
- cmdString.Parameters.Clear();
- // command
- cmdString.Connection = myConn;
- cmdString.CommandType = CommandType.StoredProcedure;
- cmdString.CommandTimeout = 1500;
- cmdString.CommandText = "GetByStudentIDS";
- // Define input parameter
- cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = StuID;
- // adapter and dataset
- SqlDataAdapter aAdapter = new SqlDataAdapter();
- aAdapter.SelectCommand = cmdString;
- DataSet aDataSet = new DataSet();
+ try
+ {
+ // open connection
+ myConn.Open();
+ //clear any parameters
+ cmdString.Parameters.Clear();
+ // command
+ cmdString.Connection = myConn;
+ cmdString.CommandType = CommandType.StoredProcedure;
+ cmdString.CommandTimeout = 1500;
+ cmdString.CommandText = "GetByStudentIDS";
+ // Define input parameter
+ cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = StuID;
+ // adapter and dataset
+ SqlDataAdapter aAdapter = new SqlDataAdapter();
+ aAdapter.SelectCommand = cmdString;
+ DataSet aDataSet = new DataSet();
- // fill adapter
- aAdapter.Fill(aDataSet);
+ // fill adapter
+ aAdapter.Fill(aDataSet);
- // return dataSet
- return aDataSet;
- }
- catch (Exception ex)
- {
- throw new ArgumentException(ex.Message);
- }
- finally
- {
- myConn.Close();
- }
+ // return dataSet
+ return aDataSet;
+ }
+ catch (Exception ex)
+ {
+ throw new ArgumentException(ex.Message);
+ }
+ finally
+ {
+ myConn.Close();
+ }
+ }
+
+ public void DeleteStudents(string StuID)
+ {
+
+
+ try
+ {
+ // open connection
+ myConn.Open();
+ //clear any parameters
+ cmdString.Parameters.Clear();
+ // command
+ cmdString.Connection = myConn;
+ cmdString.CommandType = CommandType.StoredProcedure;
+ cmdString.CommandTimeout = 1500;
+ cmdString.CommandText = "DELETESTUDENT";
+ // Define input parameter
+ cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = StuID;
+
+ object result = cmdString.ExecuteScalar();
+
+ }
+ catch (Exception ex)
+ {
+ throw new ArgumentException(ex.Message);
+ }
+ finally
+ {
+ myConn.Close();
+ }
+
+ }
+
+ public void UpdateStudent(string studid, string firstname, string lastname, DateTime dob, decimal acctbal, string Gender,decimal totalCreds, string state)
+ {
+ try
+ {
+ myConn.Open();
+
+ cmdString.Parameters.Clear();
+
+ cmdString.Connection = myConn;
+ cmdString.CommandType = CommandType.StoredProcedure;
+ cmdString.CommandTimeout = 1500;
+
+ cmdString.CommandText = "UPDATESTUDENTBYID";
+
+ cmdString.Parameters.Add("@student_id", SqlDbType.VarChar, 6).Value = studid;
+ cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 25).Value = firstname;
+ cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 25).Value = lastname;
+ cmdString.Parameters.Add("@balance", SqlDbType.Decimal, 7).Value = acctbal;
+ cmdString.Parameters.Add("@dob", SqlDbType.Date).Value = dob;
+ cmdString.Parameters.Add("@gender", SqlDbType.Char, 6).Value = Gender;
+ cmdString.Parameters.Add("@credits", SqlDbType.Decimal, 5).Value = totalCreds;
+ cmdString.Parameters.Add("@state", SqlDbType.Char, 2).Value = state;
+
+ cmdString.ExecuteScalar();
+
+ }
+ catch (Exception ex)
+ {
+ throw new ArgumentException(ex.Message);
+ }
+ finally
+ {
+ myConn.Close();
+ }
}
}
diff --git a/Database3/frmEdit.Designer.cs b/Database3/frmEdit.Designer.cs
index 008b820..9437a87 100644
--- a/Database3/frmEdit.Designer.cs
+++ b/Database3/frmEdit.Designer.cs
@@ -130,6 +130,7 @@ namespace Database3
this.btnUpdate.TabIndex = 8;
this.btnUpdate.Text = "Update";
this.btnUpdate.UseVisualStyleBackColor = true;
+ this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
//
// txtStuID
//
@@ -214,6 +215,7 @@ namespace Database3
this.Controls.Add(this.lblDisStuID);
this.Name = "frmEdit";
this.Text = "frmEdit";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form_Closing);
this.Load += new System.EventHandler(this.frmEdit_Load);
this.ResumeLayout(false);
this.PerformLayout();
diff --git a/Database3/frmEdit.cs b/Database3/frmEdit.cs
index c8c7d36..61e4bc7 100644
--- a/Database3/frmEdit.cs
+++ b/Database3/frmEdit.cs
@@ -1,6 +1,7 @@
using System;
using System.Data;
using System.Windows.Forms;
+using Traffic;
namespace Database3
{
@@ -11,6 +12,13 @@ namespace Database3
InitializeComponent();
}
+ private void Form_Closing(object sender, FormClosingEventArgs e)
+ {
+
+ frmSearch.btnSearch_Click(sender, e);
+
+ }
+
private void frmEdit_Load(object sender, EventArgs e)
{
// txtStuID.Text = frmSearch.myID;
@@ -40,5 +48,72 @@ namespace Database3
}
}
+
+ private void btnUpdate_Click(object sender, EventArgs e)
+ {
+ string studid = "";
+ string firstname = "";
+ string lastname = "";
+ DateTime dob = new DateTime(1/1/1111);
+ decimal acctbal = 0;
+ string gender = "";
+ decimal credits = 0;
+ string state = "";
+
+ try
+ {
+ DataSet ds = new DataSet();
+ StudentDataTier stuDT = new StudentDataTier();
+
+ studid = txtStuID.Text.Trim();
+ firstname = txtfname.Text.Trim();
+ lastname = txtlname.Text.Trim();
+ try
+ {
+ dob = DateTime.Parse(txtDOB.Text.Trim());
+
+ }
+ catch (Exception exception)
+ {
+ }
+
+ try
+ {
+ acctbal = decimal.Parse(txtSalary.Text.Trim());
+
+ }
+ catch (Exception exception)
+ {
+ }
+
+
+
+ gender = cboGender.Text.Trim();
+ if (gender != "MALE" && gender != "FEMALE")
+ {
+
+ gender = "NA";
+
+ }
+ try
+ {
+
+ credits = decimal.Parse(txtCredits.Text.Trim());
+
+ }
+ catch (Exception exception)
+ {
+ }
+ state = cboState.Text.Trim();
+
+ stuDT.UpdateStudent(studid, firstname, lastname, dob, acctbal, gender, credits, state);
+
+ }
+ catch
+ {
+
+ }
+
+ }
}
}
\ No newline at end of file
diff --git a/Database3/frmSearch.Designer.cs b/Database3/frmSearch.Designer.cs
index 20a2175..9605e8c 100644
--- a/Database3/frmSearch.Designer.cs
+++ b/Database3/frmSearch.Designer.cs
@@ -96,6 +96,7 @@
this.cmuDelete.Name = "cmuDelete";
this.cmuDelete.Size = new System.Drawing.Size(152, 22);
this.cmuDelete.Text = "Delete";
+ this.cmuDelete.Click += new System.EventHandler(this.cmuDelete_Click);
//
// lblDislname
//
diff --git a/Database3/frmSearch.cs b/Database3/frmSearch.cs
index 4650c1a..66d884f 100644
--- a/Database3/frmSearch.cs
+++ b/Database3/frmSearch.cs
@@ -38,7 +38,9 @@ namespace Database3
}
- private void btnSearch_Click(object sender, EventArgs e)
+
+
+ public void btnSearch_Click(object sender, EventArgs e)
{
string studentid = "9999999999";
string lname = "9999999999";
@@ -118,6 +120,23 @@ namespace Database3
{
dgvStudents_DoubleClick(sender, e);
}
+
+ private void cmuDelete_Click(object sender, EventArgs e)
+ {
+ string studentid = "";
+
+ DataSet ds = new DataSet();
+ StudentDataTier stuDT = new StudentDataTier();
+
+ DataGridViewRow row = dgvStudents.SelectedRows[0];
+
+ studentid = row.Cells[0].Value.ToString().Trim();
+
+ stuDT.DeleteStudents(studentid);
+
+ btnSearch_Click(sender, e);
+
+ }
}
}
diff --git a/Database3/state.cs b/Database3/state.cs
new file mode 100644
index 0000000..878ca95
--- /dev/null
+++ b/Database3/state.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Traffic
+{
+ public class state
+ {
+ private string nameString;
+ private string abbreviationString;
+ ///
+ /// used to display the states in 3 different forms
+ /// Name ("Pennsylvania"), Abbreviation ("PA") ,
+ /// name and abbreviation ("Pennsylvania (PA) ")
+ ///
+ ///
+ ///
+ public state(ref string nameArg, ref string abbreviationArg)
+ {
+ abbreviationString = abbreviationArg;
+ nameString = nameArg;
+ }
+
+ public string Name
+ {
+ get
+ {
+ return nameString;
+ }
+ }
+
+ public string Abbreviation
+ {
+ get
+ {
+ return abbreviationString;
+ }
+ }
+
+ public string FullAndAbbrev
+ {
+ get
+ {
+ return nameString + " (" + abbreviationString + ")";
+ }
+ }
+ }
+}