protected void Page_Load(object sender, EventArgs e) { int tbl_id = Convert.ToInt32(RouteData.Values["tbl_id"]); if (!IsPostBack) { if (tbl_id > 0) // if there is a table id { lbtnUpdate.Text = "Update"; TableCS mt = new TableCS(tbl_id); txtName.Text = mt.Tbl_Name; txtDescription.Text = mt.Tbl_Desc; ddlSection.SelectedValue = mt.Sect_ID.ToString(); txtSeatCount.Text = mt.Tbl_Seat_Cnt.ToString(); chkIsActive.Checked = mt.Tbl_Active; } else // if no table id go to add { lbtnUpdate.Text = "Add"; TableCS mt = new TableCS(tbl_id); txtName.Text = String.Empty; txtDescription.Text = String.Empty; ddlSection.SelectedValue = null; txtSeatCount.Text = String.Empty; chkIsActive.Checked = false; } } }
protected void Page_Load(object sender, EventArgs e) { int tbl_id = Convert.ToInt32(RouteData.Values["tbl_id"]); TableCS mt = new TableCS(tbl_id); lblTbl_ID.Text = String.Concat("Item_ID: ", mt.Tbl_ID).ToString(); lblSect_ID.Text = String.Concat("Menu_Id: ", mt.Sect_ID).ToString(); lblTbl_Name.Text = String.Concat("Cat_Id: ", mt.Tbl_Name).ToString(); lblTbl_Desc.Text = String.Concat("Item_Name: ", mt.Tbl_Desc).ToString(); // txtName.Text = String.Concat(mt.Item_Name); lblTbl_Seat_Cnt.Text = String.Concat("Item_Desc: ", mt.Tbl_Seat_Cnt).ToString(); lblTbl_Active.Text = String.Concat("Item_Active: ", mt.Tbl_Active).ToString(); }
protected void lbtnUpdate_Click(object sender, EventArgs e) { string updateBUTTON = lbtnUpdate.Text; if (updateBUTTON == "Update") // update table { TableCS sr = new TableCS(); if (RouteData.Values["tbl_id"] != null) { bool success = false; sr.Tbl_ID = Convert.ToInt32(RouteData.Values["tbl_id"]); sr.Sect_ID = Convert.ToInt32(ddlSection.SelectedValue); sr.Tbl_Name = txtName.Text.Trim(); sr.Tbl_Desc = txtDescription.Text.Trim(); sr.Tbl_Seat_Cnt = Convert.ToInt32(txtSeatCount.Text); sr.Tbl_Active = chkIsActive.Checked; success = TableCS.UpdateTable(sr); if (success) // if update menu is true { Response.Redirect("/Admin/Tables"); } } } else // insert table { bool success = false; TableCS sr = new TableCS(); sr.Tbl_ID = Convert.ToInt32(RouteData.Values["tbl_id"]); sr.Sect_ID = Convert.ToInt32(ddlSection.SelectedValue.ToString()); sr.Tbl_Name = txtName.Text.Trim(); sr.Tbl_Desc = txtDescription.Text.Trim(); sr.Tbl_Seat_Cnt = Convert.ToInt32(txtSeatCount.Text); sr.Tbl_Active = chkIsActive.Checked; success = TableCS.InsertTable(sr); if (success) // if insert menu is true { Response.Redirect("/Admin/Tables"); } } }
public static bool UpdateTable(TableCS sr) { bool blnSuccess = false; SqlConnection cn = new SqlConnection( ConfigurationManager.ConnectionStrings["SE256_MurilloConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand("tables_update", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add( "@tbl_id", SqlDbType.Int).Value = sr.Tbl_ID; cmd.Parameters.Add( "@sect_id", SqlDbType.Int).Value = sr.Sect_ID; cmd.Parameters.Add( "@tbl_name", SqlDbType.VarChar).Value = sr.Tbl_Name; cmd.Parameters.Add( "@tbl_desc", SqlDbType.VarChar).Value = sr.Tbl_Desc; cmd.Parameters.Add( "@tbl_seat_cnt", SqlDbType.Int).Value = sr.Tbl_Seat_Cnt; cmd.Parameters.Add( "@tbl_active", SqlDbType.Bit).Value = sr.Tbl_Active; try { cn.Open(); cmd.ExecuteNonQuery(); blnSuccess = true; } catch (Exception exc) { //error -> notify user exc.ToString(); blnSuccess = false; } finally { cn.Close(); } return(blnSuccess); }