reservation Grid(.cs)
DALSky objDalSky;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] != null)
{
objDalSky = new DALSky();
if (!IsPostBack)
{
setGridData();
}
}
else
{
Response.Redirect("../Login.aspx");
}
}
protected void grdvwReservation_RowEditing(object sender, GridViewEditEventArgs e)
{
grdvwReservation.EditIndex = e.NewEditIndex;
setGridData();
}
protected void grdvwReservation_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grdvwReservation.EditIndex = -1;
setGridData();
}
//row updating
protected void grdvwReservation_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtRes_id = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtResId");
TextBox txtDate = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtDate");
TextBox txtTelephone = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtPhoneNo");
TextBox txtFirstName = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFnm");
TextBox txtLastName = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtLnm");
TextBox txtResNo = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtResrv");
TextBox txtEmail = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtEmail");
TextBox txtAddress = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtAddress");
// TextBox txtProgState = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtProgState");
DropDownList drpdwnProgState = (DropDownList)grdvwReservation.Rows[e.RowIndex].FindControl("drpdwnProgState");
TextBox txtDriver = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtDriver");
TextBox txtFltTime = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFlTime");
TextBox txtTrpTyp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtTrip");
DropDownList drpdwnFrType = (DropDownList)grdvwReservation.Rows[e.RowIndex].FindControl("drpdwnFrTyp");
TextBox txtFare= (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtCost");
TextBox txtRundTrp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtRTrp");
TextBox txtRdTyp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtTpTyp");
TextBox txtFltNo = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFltNo");
TextBox txtComments = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtCmnts");
try
{
ArrayList parameters = new ArrayList();
parameters.Add(Convert.ToInt32(txtRes_id.Text));
parameters.Add(txtDate.Text);
parameters.Add(txtTelephone.Text);
parameters.Add(txtFirstName.Text);
parameters.Add(txtLastName.Text);
parameters.Add(txtResNo.Text);
parameters.Add(txtEmail.Text);
parameters.Add(txtAddress.Text);
parameters.Add(drpdwnProgState.SelectedItem.Text);
//new parameters
parameters.Add(txtDriver.Text);//Driver_Name
parameters.Add(txtFltTime.Text);//AirLine_Time
parameters.Add(txtTrpTyp.Text);//Airport_Trip
parameters.Add(drpdwnFrType.Text);//Fare_Type
parameters.Add(Math.Round(Convert.ToDecimal(txtFare.Text)));//Cost
parameters.Add(txtRundTrp.Text);//Round_Trip
parameters.Add(txtRdTyp.Text);//Ride_Type
parameters.Add(txtFltNo.Text);//AirLine_Name
parameters.Add(txtComments.Text);//Comments
int result = objDalSky.UpdateReservationGrid(parameters);
}
catch (Exception)
{
throw;
}
grdvwReservation.EditIndex = -1;
setGridData();
}
//
protected void grdvwReservation_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[15].Visible = false;
e.Row.Cells[16].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
//Change the griview row color accourding to trip
if (drv["Airport_Trip"].ToString() == "TO")
{
e.Row.BackColor = System.Drawing.Color.FromName("#CCCC00");
}
else
{
e.Row.BackColor = System.Drawing.Color.FromName("#CC99FF");
}
//Label txprogress = (Label)e.Row.FindControl("lblProgState");
//remove the united state part from address
string address = drv["Address"].ToString();
e.Row.Cells[9].Text = address.Replace(", United States","");
//bind the data on progress state dropdownlist
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList drpdwnProgState = (e.Row.FindControl("drpdwnProgState") as DropDownList);
//string progess = (e.Row.FindControl("lblDProgState") as Label).Text;
if (drpdwnProgState != null)
{
drpdwnProgState.Items.FindByValue(drv["Progress_State"].ToString()).Selected = true;
}
}
//bind the data on fare type dropdownlist
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList drpdwnFrTyp = (e.Row.FindControl("drpdwnFrTyp") as DropDownList);
//string progess = (e.Row.FindControl("lblDProgState") as Label).Text;
if (drpdwnFrTyp != null)
{
// drpdwnFrTyp.Items.FindByValue(drv["Fare_Type"].ToString()).Selected = true;
}
}
//Reservation delete Confirmation Javascript
string item = drv["Reservation_No"].ToString();
foreach (Button button in e.Row.Cells[20].Controls.OfType<Button>())
{
if (button.CommandName == "Delete")
{
button.Attributes["onclick"] = "if(!confirm('Do you want to delete Reservation " + item + "?')){ return false; };";
}
}
}
}
protected void grdvwReservation_SelectedIndexChanged(object sender, EventArgs e)
{
Session["resid"] = (grdvwReservation.SelectedRow.FindControl("lblResId") as Label).Text;
Response.Redirect("EditReservation.aspx");
}
protected void grdvwReservation_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//get the reservation id from gridview. The reservation primarty key is set as the datakeynames
int res_id = (int)grdvwReservation.DataKeys[e.RowIndex].Value;
int result = objDalSky.DeleteReservation(res_id);
setGridData();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] != null)
{
objDalSky = new DALSky();
if (!IsPostBack)
{
setGridData();
}
}
else
{
Response.Redirect("../Login.aspx");
}
}
protected void grdvwReservation_RowEditing(object sender, GridViewEditEventArgs e)
{
grdvwReservation.EditIndex = e.NewEditIndex;
setGridData();
}
protected void grdvwReservation_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grdvwReservation.EditIndex = -1;
setGridData();
}
//row updating
protected void grdvwReservation_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtRes_id = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtResId");
TextBox txtDate = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtDate");
TextBox txtTelephone = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtPhoneNo");
TextBox txtFirstName = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFnm");
TextBox txtLastName = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtLnm");
TextBox txtResNo = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtResrv");
TextBox txtEmail = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtEmail");
TextBox txtAddress = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtAddress");
// TextBox txtProgState = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtProgState");
DropDownList drpdwnProgState = (DropDownList)grdvwReservation.Rows[e.RowIndex].FindControl("drpdwnProgState");
TextBox txtDriver = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtDriver");
TextBox txtFltTime = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFlTime");
TextBox txtTrpTyp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtTrip");
DropDownList drpdwnFrType = (DropDownList)grdvwReservation.Rows[e.RowIndex].FindControl("drpdwnFrTyp");
TextBox txtFare= (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtCost");
TextBox txtRundTrp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtRTrp");
TextBox txtRdTyp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtTpTyp");
TextBox txtFltNo = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFltNo");
TextBox txtComments = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtCmnts");
try
{
ArrayList parameters = new ArrayList();
parameters.Add(Convert.ToInt32(txtRes_id.Text));
parameters.Add(txtDate.Text);
parameters.Add(txtTelephone.Text);
parameters.Add(txtFirstName.Text);
parameters.Add(txtLastName.Text);
parameters.Add(txtResNo.Text);
parameters.Add(txtEmail.Text);
parameters.Add(txtAddress.Text);
parameters.Add(drpdwnProgState.SelectedItem.Text);
//new parameters
parameters.Add(txtDriver.Text);//Driver_Name
parameters.Add(txtFltTime.Text);//AirLine_Time
parameters.Add(txtTrpTyp.Text);//Airport_Trip
parameters.Add(drpdwnFrType.Text);//Fare_Type
parameters.Add(Math.Round(Convert.ToDecimal(txtFare.Text)));//Cost
parameters.Add(txtRundTrp.Text);//Round_Trip
parameters.Add(txtRdTyp.Text);//Ride_Type
parameters.Add(txtFltNo.Text);//AirLine_Name
parameters.Add(txtComments.Text);//Comments
int result = objDalSky.UpdateReservationGrid(parameters);
}
catch (Exception)
{
throw;
}
grdvwReservation.EditIndex = -1;
setGridData();
}
//
protected void grdvwReservation_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[15].Visible = false;
e.Row.Cells[16].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
//Change the griview row color accourding to trip
if (drv["Airport_Trip"].ToString() == "TO")
{
e.Row.BackColor = System.Drawing.Color.FromName("#CCCC00");
}
else
{
e.Row.BackColor = System.Drawing.Color.FromName("#CC99FF");
}
//Label txprogress = (Label)e.Row.FindControl("lblProgState");
//remove the united state part from address
string address = drv["Address"].ToString();
e.Row.Cells[9].Text = address.Replace(", United States","");
//bind the data on progress state dropdownlist
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList drpdwnProgState = (e.Row.FindControl("drpdwnProgState") as DropDownList);
//string progess = (e.Row.FindControl("lblDProgState") as Label).Text;
if (drpdwnProgState != null)
{
drpdwnProgState.Items.FindByValue(drv["Progress_State"].ToString()).Selected = true;
}
}
//bind the data on fare type dropdownlist
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList drpdwnFrTyp = (e.Row.FindControl("drpdwnFrTyp") as DropDownList);
//string progess = (e.Row.FindControl("lblDProgState") as Label).Text;
if (drpdwnFrTyp != null)
{
// drpdwnFrTyp.Items.FindByValue(drv["Fare_Type"].ToString()).Selected = true;
}
}
//Reservation delete Confirmation Javascript
string item = drv["Reservation_No"].ToString();
foreach (Button button in e.Row.Cells[20].Controls.OfType<Button>())
{
if (button.CommandName == "Delete")
{
button.Attributes["onclick"] = "if(!confirm('Do you want to delete Reservation " + item + "?')){ return false; };";
}
}
}
}
protected void grdvwReservation_SelectedIndexChanged(object sender, EventArgs e)
{
Session["resid"] = (grdvwReservation.SelectedRow.FindControl("lblResId") as Label).Text;
Response.Redirect("EditReservation.aspx");
}
protected void grdvwReservation_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//get the reservation id from gridview. The reservation primarty key is set as the datakeynames
int res_id = (int)grdvwReservation.DataKeys[e.RowIndex].Value;
int result = objDalSky.DeleteReservation(res_id);
setGridData();
}
0 comments:
Post a Comment