/// <summary> /// Set edit mode for edit comand /// Delete data from the database for delete comand /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gvGoalElement_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { ViewState["GOALELEMENTID"] = e.CommandArgument; MNEGoalElementBLL MNEGoalElementBLLObj = new MNEGoalElementBLL(); MNEGoalElementBOL MNEGoalElementBOLObj = new MNEGoalElementBOL(); MNEGoalElementBOLObj = MNEGoalElementBLLObj.GetMNEGoalElementDetailsbyID(Convert.ToInt32(ViewState["GOALELEMENTID"])); txtGoalElement.Text = MNEGoalElementBOLObj.GoalElement; SetUpdateMode(true); } else if (e.CommandName == "DeleteRow") { string message = string.Empty; MNEGoalElementBLL MNEGoalElementBLLObj = new MNEGoalElementBLL(); message = MNEGoalElementBLLObj.DeleteGoalElement(Convert.ToInt32(e.CommandArgument)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data deleted successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } ClearData(); SetUpdateMode(false); BindGrid(); } }
/// <summary> /// Update Database Make data as Obsoluted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void IsObsolete_CheckedChanged(Object sender, EventArgs e) { string message = string.Empty; try { CheckBox chk = (CheckBox)sender; GridViewRow gr = (GridViewRow)chk.Parent.Parent; int GoalID = Convert.ToInt32(((Literal)gr.FindControl("litGOALID")).Text); MNEGoalElementBLL MNEGoalElementBLLObj = new MNEGoalElementBLL(); message = MNEGoalElementBLLObj.ObsoleteGoalElement(GoalID, Convert.ToString(chk.Checked)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; } BindGrid(); if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Set Grid Data source /// </summary> /// <param name="addRow"></param> /// <param name="deleteRow"></param>e private void BindGrid() { MNEGoalElementBLL MNEGoalElementBLLObj = new MNEGoalElementBLL(); gvGoalElement.DataSource = MNEGoalElementBLLObj.GetAllMNEGoalElementDetails(); gvGoalElement.DataBind(); }
/// <summary> /// To save details to database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { MNEGoalElementBOL MNEGoalElementBOObj = null; string message = ""; if (Convert.ToInt32(ViewState["GOALELEMENTID"]) == 0) { try { MNEGoalElementBOObj = new MNEGoalElementBOL(); MNEGoalElementBLL MNEGoalElementBLLObj = new MNEGoalElementBLL(); MNEGoalElementBOObj.GoalElement = txtGoalElement.Text.Trim(); MNEGoalElementBOObj.CreatedBy = Convert.ToInt32(Session["USER_ID"].ToString()); message = MNEGoalElementBLLObj.InsertMNEGoalElementDetails(MNEGoalElementBOObj); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data saved successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } } catch (Exception ex) { throw ex; } } else { try { MNEGoalElementBOObj = new MNEGoalElementBOL(); MNEGoalElementBLL MNEGoalElementBLLObj = new MNEGoalElementBLL(); MNEGoalElementBOObj.GoalElementID = Convert.ToInt32(ViewState["GOALELEMENTID"]); MNEGoalElementBOObj.GoalElement = txtGoalElement.Text.ToString().Trim(); MNEGoalElementBOObj.CreatedBy = Convert.ToInt32(Session["USER_ID"].ToString()); message = MNEGoalElementBLLObj.UpdateGoalElement(MNEGoalElementBOObj); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } } catch (Exception ex) { throw ex; } finally { MNEGoalElementBOObj = null; } } BindGrid(); ClearData(); }