almost done
This commit is contained in:
parent
9155095a3e
commit
d9dcf41695
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="dbSrc:///b6add4d8/e01dfe76-6e86-4e8c-ac8c-21ef8c2f8f5a/database/College2/schema/dbo/routine/SearchStudent.sql" dialect="TSQL" />
|
||||
<file url="PROJECT" dialect="GenericSQL" />
|
||||
</component>
|
||||
</project>
|
@ -61,6 +61,8 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs"/>
|
||||
<Compile Include="Properties\AssemblyInfo.cs"/>
|
||||
<Compile Include="state.cs" />
|
||||
<Compile Include="StateManager.cs" />
|
||||
<Compile Include="StudentDataTier.cs" />
|
||||
<EmbeddedResource Include="frmEdit.resx">
|
||||
<DependentUpon>frmEdit.cs</DependentUpon>
|
||||
@ -90,5 +92,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="App.config"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="State.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
||||
</Project>
|
55
Database3/State.xml
Normal file
55
Database3/State.xml
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<states>
|
||||
<state name="Alabama" abbreviation="AL" />
|
||||
<state name="Alaska" abbreviation="AK" />
|
||||
<state name="Arizona" abbreviation="AZ" />
|
||||
<state name="Arkansas" abbreviation="AR" />
|
||||
<state name="California" abbreviation="CA" />
|
||||
<state name="Colorado" abbreviation="CO" />
|
||||
<state name="Connecticut" abbreviation="CT" />
|
||||
<state name="Delaware" abbreviation="DE" />
|
||||
<!--
|
||||
<state name="District of Columbia" abbreviation="DC" />
|
||||
-->
|
||||
<state name="Florida" abbreviation="FL" />
|
||||
<state name="Georgia" abbreviation="GA" />
|
||||
<state name="Hawaii" abbreviation="HI" />
|
||||
<state name="Idaho" abbreviation="ID" />
|
||||
<state name="Illinois" abbreviation="IL" />
|
||||
<state name="Iowa" abbreviation="IA" />
|
||||
<state name="Kansas" abbreviation="KS" />
|
||||
<state name="Kentucky" abbreviation="KY" />
|
||||
<state name="Louisiana" abbreviation="LA" />
|
||||
<state name="Maine" abbreviation="ME" />
|
||||
<state name="Maryland" abbreviation="MD" />
|
||||
<state name="Massachussetts" abbreviation="MA" />
|
||||
<state name="Michigan" abbreviation="MI" />
|
||||
<state name="Minnesota" abbreviation="MN" />
|
||||
<state name="Mississippi" abbreviation="MS" />
|
||||
<state name="Missouri" abbreviation="MO" />
|
||||
<state name="Montana" abbreviation="MT" />
|
||||
<state name="Nebraska" abbreviation="NE" />
|
||||
<state name="Nevada" abbreviation="NV" />
|
||||
<state name="New Hampshire" abbreviation="NH" />
|
||||
<state name="New Jersey" abbreviation="NJ" />
|
||||
<state name="New Mexico" abbreviation="NM" />
|
||||
<state name="New York" abbreviation="NY" />
|
||||
<state name="North Carolina" abbreviation="NC" />
|
||||
<state name="North Dakota" abbreviation="ND" />
|
||||
<state name="Ohio" abbreviation="OH" />
|
||||
<state name="Oklahoma" abbreviation="OK" />
|
||||
<state name="Oregon" abbreviation="OR" />
|
||||
<state name="Pennsylvania" abbreviation="PA" />
|
||||
<state name="Rhode Island" abbreviation="RI" />
|
||||
<state name="South Carolina" abbreviation="SC" />
|
||||
<state name="South Dakota" abbreviation="SD" />
|
||||
<state name="Tennessee" abbreviation="TN" />
|
||||
<state name="Texas" abbreviation="TX" />
|
||||
<state name="Utah" abbreviation="UT" />
|
||||
<state name="Vermont" abbreviation="VT" />
|
||||
<state name="Virginia" abbreviation="VA" />
|
||||
<state name="Washington" abbreviation="WA" />
|
||||
<state name="West Virgina" abbreviation="WV" />
|
||||
<state name="Wisconsin" abbreviation="WI" />
|
||||
<state name="Wyoming" abbreviation="WY" />
|
||||
</states>
|
208
Database3/StateManager.cs
Normal file
208
Database3/StateManager.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
/// ''' Provides the functionality related to retrieving the list
|
||||
|
||||
/// ''' of states for a system;
|
||||
//// reads an xml file
|
||||
/// ''' </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ''' Gets all the states
|
||||
/// ''' </summary>
|
||||
/// ''' <returns>An array of State objects</returns>
|
||||
public static state[] getStates()
|
||||
{
|
||||
//if (myCache[stateKey] == null)
|
||||
PopulateCache();
|
||||
return stateArray;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ''' Takes the abbreviation given and returns the full name
|
||||
/// ''' </summary>
|
||||
/// ''' <returns>The full name for the abbreviation in
|
||||
/// ''' question</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ''' Gets the state object based on the full name
|
||||
/// ''' </summary>
|
||||
/// ''' <param name="name">The full name of the state to
|
||||
/// ''' retrieve</param>
|
||||
/// ''' <returns>A State object for the name given</returns>
|
||||
public static state getStateByName(ref string name)
|
||||
{
|
||||
// if (myCache[stateKey + name] == null)
|
||||
PopulateCache();
|
||||
//return state[stateKey + name];
|
||||
|
||||
return (state)Convert.ChangeType(stateKey, typeof(state[]));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ''' Gets the state object based on the abbreviation
|
||||
/// ''' </summary>
|
||||
/// ''' <param name="abbreviation">The abbreviation of the state
|
||||
/// ''' to retrieve</param>
|
||||
/// ''' <returns>A State object for the abbreviation
|
||||
/// ''' given</returns>
|
||||
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 */;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>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.
|
||||
/// ''' </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -94,6 +94,74 @@ namespace Database3
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
2
Database3/frmEdit.Designer.cs
generated
2
Database3/frmEdit.Designer.cs
generated
@ -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();
|
||||
|
@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
1
Database3/frmSearch.Designer.cs
generated
1
Database3/frmSearch.Designer.cs
generated
@ -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
|
||||
//
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
50
Database3/state.cs
Normal file
50
Database3/state.cs
Normal file
@ -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;
|
||||
/// <summary>
|
||||
/// used to display the states in 3 different forms
|
||||
/// Name ("Pennsylvania"), Abbreviation ("PA") ,
|
||||
/// name and abbreviation ("Pennsylvania (PA) ")
|
||||
/// </summary>
|
||||
/// <param name="nameArg"></param>
|
||||
/// <param name="abbreviationArg"></param>
|
||||
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 + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user