delete and edit and new work

This commit is contained in:
EggMan20339 2024-03-25 12:09:20 -04:00
parent adecd7bda0
commit 48dff87b84
6 changed files with 238 additions and 35 deletions

View File

@ -2,11 +2,13 @@
using System.Web.UI;
using System.Data;
using System.Drawing;
using System.Security.Principal;
namespace CH78
{
public partial class Display : Page
{
protected string pageType;
protected void Page_Load(object sender, EventArgs e)
{
string studentID = "";
@ -14,6 +16,8 @@ namespace CH78
if (!IsPostBack)
{
pageType = Request.QueryString["type"].Trim().ToUpper();
// retrieve the querystring
if (String.IsNullOrEmpty(Request.QueryString["ID"]))
{
@ -23,7 +27,7 @@ namespace CH78
else if (Request.QueryString["ID"].Trim().ToUpper() == "NEW")
{
// do nothing
BindDDL();
}
else if (Request.QueryString["type"].Trim().ToUpper() == "VIEW") // display
@ -81,17 +85,7 @@ namespace CH78
//txtSalary.Text = mysalary.ToString("C")
//txtSalary.Enabled = False
txtState.DataSource = StudentDataTier.GetStates();
txtState.DataTextField = "Name";
txtState.DataValueField = "StateID";
txtState.SelectedValue = "1";
txtState.DataBind();
txtGender.DataSource = StudentDataTier.GetGenders();
txtGender.DataTextField = "CommonName";
txtGender.DataValueField = "Gender_ID";
txtGender.SelectedValue = "0";
txtGender.DataBind();
BindDDL();
// txtState.SelectedValue = ds.Tables[0].Rows[0]["state"].ToString();
if (type.ToUpper() == "VIEW")
@ -104,6 +98,18 @@ namespace CH78
}
else if (type.ToUpper() == "EDIT")
{
txtGender.Enabled = true;
txtStuID.Enabled = false;
btnGoStu.Visible = true;
btnCancelStu.Visible = true;
btnGoStu.Text = "UPDATE";
btnCancelStu.Text = "REFRESH";
btnGoStu.ForeColor = Color.Red;
btnCancelStu.ForeColor = Color.Blue;
}
else if (type.ToUpper() == "NEW")
{
txtGender.Enabled = true;
txtStuID.Enabled = false;
btnGoStu.Visible = true;
btnCancelStu.Visible = true;
@ -115,14 +121,68 @@ namespace CH78
}
}
protected void BindDDL()
{
txtState.DataSource = StudentDataTier.GetStates();
txtState.DataTextField = "Name";
txtState.DataValueField = "StateID";
txtState.SelectedValue = "1";
txtState.DataBind();
txtGender.DataSource = StudentDataTier.GetGenders();
txtGender.DataTextField = "CommonName";
txtGender.DataValueField = "Gender_ID";
txtGender.SelectedValue = "0";
txtGender.DataBind();
}
protected void btnCancelStu_OnClick(object sender, EventArgs e)
{
throw new NotImplementedException();
}
protected void btnGoStu_OnClick(object sender, EventArgs e)
{
throw new NotImplementedException();
if (Request.QueryString["type"].Trim().ToUpper() == "VIEW")
{
}
else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT")
{ StudentDataTier.UpdateStudents(0,
txtStuID.Text,
txtFNAME.Text,
txtLNAME.Text,
txtMidInit.Text,
DateTime.Parse(txtDOB.Text),
txtGender.Text,
decimal.Parse(txtActBal.Text),
txtMajor.Text, txtCellPhone.Text,
txtAdr1.Text,
txtCity.Text,
txtState.ToString(),
txtZip.Text,
decimal.Parse(txtCreds.Text));
}
else if (Request.QueryString["type"].Trim().ToUpper() == "NEW")
{ StudentDataTier.UpdateStudents(1,
txtStuID.Text,
txtFNAME.Text,
txtLNAME.Text,
txtMidInit.Text,
DateTime.Parse(txtDOB.Text),
txtGender.Text.ToString(),
decimal.Parse(txtActBal.Text),
txtMajor.Text, txtCellPhone.Text,
txtAdr1.Text,
txtCity.Text,
txtState.Text.ToString(),
txtZip.Text,
decimal.Parse(txtCreds.Text));
}
}
}
}

View File

@ -47,11 +47,7 @@ function SelectAll(id)
<tr>
<td style="width:15%" rowspan="3" valign="middle">
&nbsp;
<asp:HyperLink
ID="hplNew" runat="server" NavigateUrl="~/StudentEdit.aspx?ID=0">
New
Student
</asp:HyperLink>
<asp:Button runat="server" ID="btnNew" Text="Create Student" OnClick="btnNew_OnClick"/>
</td>
<td colspan="2" style="height: 20px; width: 538px;">
@ -95,7 +91,7 @@ function SelectAll(id)
<tr >
<td colspan="2" align="center" style="width: 700px">
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>
<asp:GridView AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" PageSize="2" CssClass="GridView" ID="gvStudent" OnSelectedIndexChanged="grdStudent_SelectedIndexChanged" runat="server" Width="100%">
<asp:GridView AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" PageSize="10" CssClass="GridView" ID="gvStudent" OnSelectedIndexChanged="grdStudent_SelectedIndexChanged" runat="server" Width="100%">
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="Go To First Page" LastPageText="Go To Last Page" Position="Top" />
<Columns>
<asp:TemplateField HeaderText="Student ID">

View File

@ -122,10 +122,10 @@ namespace CH78
txtFName.Text = FNAME;
txtLName.Text = LNAME;
if (textHasValues)
{
// if (textHasValues)
// {
ds = StudentDataTier.SearchStudents(FNAME, LNAME, stuID);
}
// }
// ds = dt.GetStudents();
@ -190,7 +190,35 @@ namespace CH78
protected void Delete_Click(object sender, CommandEventArgs e)
{
try
{
CheckBox chk = new CheckBox();
Label lbl = new Label();
string stuid = "";
StudentDataTier std = new StudentDataTier();
if (gvStudent.Rows.Count > 0) // only do it if there is a row
{
//For Each item As GridView In grdCustomer.items
foreach (GridViewRow row in gvStudent.Rows)
{
//get the selected checkbox
chk = (CheckBox)row.FindControl("chkStudentID");
if (chk.Checked)
{
lbl = (Label)row.Controls[0].FindControl("hidStudentID");
stuid = lbl.Text.Trim();
//delete the record one at a time
StudentDataTier.DeleteStudents(stuid);
}
}
//refresh datagrid
BindData();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
protected void lbtnEdit_Click(object sender, CommandEventArgs e)
@ -211,7 +239,7 @@ namespace CH78
// this script will open a popup
sb.Append("<script language='javascript'>");
sb.Append("window.open('Display.aspx?ID=" + recordToBeEdited.ToString() + "&type=Edit" +"' , 'DisplayEdit',");
sb.Append("'width=525, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("'width=1525, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("</script>");
// register with ClientScript
@ -222,5 +250,34 @@ namespace CH78
throw new Exception(ex.Message, ex.InnerException);
}
}
protected void btnNew_OnClick(object sender, EventArgs e)
{
string recordToBeEdited;
Int64 mEditedRecord = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
try
{
Session["vStudentID"] = txtStudentID.Text.Trim();
Session["vFName"] = txtFName.Text.Trim();
Session["vLName"] = txtLName.Text.Trim();
// this script will open a popup
sb.Append("<script language='javascript'>");
sb.Append("window.open('Display.aspx?ID=NEW&type=NEW' , 'DisplayEdit',");
sb.Append("'width=1525, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("</script>");
// register with ClientScript
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", sb.ToString());
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
}
}

View File

@ -24,13 +24,13 @@ namespace CH78
protected global::System.Web.UI.HtmlControls.HtmlForm frmHome;
/// <summary>
/// hplNew control.
/// btnNew control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HyperLink hplNew;
protected global::System.Web.UI.WebControls.Button btnNew;
/// <summary>
/// Label1 control.

View File

@ -13,13 +13,6 @@ namespace CH78
static SqlConnection myConn = new SqlConnection(connString);
static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand();
private void BindData()
{
}
protected void grdStudnet_RowDataBind(object sender, GridViewRowEventArgs e)
{
@ -140,6 +133,101 @@ namespace CH78
}
}
public static 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";
cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = StuID;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static void UpdateStudents(
int update,
string student_id,
string fname,
string lname,
string midinit,
DateTime dob,
string gender,
Decimal acct_bal,
string major,
// string home_phone,
string cell_phone,
// string work_phone,
string address_one,
string city,
string stu_state,
string zip,
Decimal totalcredits)
{
try
{
string home_phone = "0";
string work_phone = "0";
// open connection
myConn.Open();
//clear any parameters
cmdString.Parameters.Clear();
// command
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
cmdString.CommandText = "UpdateStudent";
cmdString.Parameters.Add("@update", SqlDbType.Int).Value = update;
cmdString.Parameters.Add("@student_id", SqlDbType.VarChar, 6).Value = student_id;
cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 25).Value = fname;
cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 25).Value = lname;
cmdString.Parameters.Add("@midinit", SqlDbType.Char).Value = midinit;
cmdString.Parameters.Add("@dob", SqlDbType.Date).Value = dob;
cmdString.Parameters.Add("@gender", SqlDbType.Char, 6).Value = gender;
cmdString.Parameters.Add("@acct_bal", SqlDbType.Decimal, 7).Value = acct_bal;
cmdString.Parameters.Add("@major", SqlDbType.VarChar, 60).Value = major;
cmdString.Parameters.Add("@home_phone", SqlDbType.VarChar, 15).Value = home_phone;
cmdString.Parameters.Add("@cell_phone", SqlDbType.VarChar, 15).Value = cell_phone;
cmdString.Parameters.Add("@work_phone", SqlDbType.VarChar, 15).Value = work_phone;
cmdString.Parameters.Add("@address_one", SqlDbType.VarChar, 60).Value = address_one;
cmdString.Parameters.Add("@city", SqlDbType.VarChar, 60).Value = city;
cmdString.Parameters.Add("@stu_state", SqlDbType.Char, 2).Value = stu_state;
cmdString.Parameters.Add("@zip", SqlDbType.VarChar, 5).Value = zip;
cmdString.Parameters.Add("@totalcredits", SqlDbType.Decimal, 5).Value = totalcredits;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static DataSet SearchStudents(string fname, string lname, string stuID)
{

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String></wpf:ResourceDictionary>