/// <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 grdCopMechansim_RowCommand(object sender, GridViewCommandEventArgs e) { string message = string.Empty; if (e.CommandName == "EditRow") { ViewState["CopMechanismID"] = e.CommandArgument; GetCopMechanismDetails(); SetUpdateMode(true); ScriptManager.RegisterStartupScript(this, this.GetType(), "Added", "setDirty();", true); } else if (e.CommandName == "DeleteRow") { //ViewState["CopMechanismID"] = e.CommandArgument; CopMechanismBLL objCopMechanismBLL = new CopMechanismBLL(); message = objCopMechanismBLL.DeleteCopMechanism(Convert.ToInt32(e.CommandArgument)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data Deleted successfully"; } ClearDetails(); SetUpdateMode(false); BindGrid(false, true); } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } }
/// <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; string CopMechanismID = ((Literal)gr.FindControl("litCopMechanismID")).Text; CopMechanismBLL objCopMechanismBLL = new CopMechanismBLL(); message = objCopMechanismBLL.ObsoleteCopMechanism(Convert.ToInt32(CopMechanismID), Convert.ToString(chk.Checked)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; } BindGrid(false, true); 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(bool addRow, bool deleteRow) { objCopMechanismBLL = new CopMechanismBLL(); objCopMechanism = new CopMechanismBO(); objCopMechanism.CopMechanismName = string.Empty; objCopMechanism.CopMechanismID = 0; grdCopMechansim.DataSource = objCopMechanismBLL.GetALLCopMechanism();//(objCopMechanism); grdCopMechansim.DataBind(); }
/// <summary> /// get the Grid value into textBox /// </summary> private void GetCopMechanismDetails() { objCopMechanismBLL = new CopMechanismBLL(); int CopMechanismID = 0; if (ViewState["CopMechanismID"] != null) { CopMechanismID = Convert.ToInt32(ViewState["CopMechanismID"].ToString()); } objCopMechanism = new CopMechanismBO(); objCopMechanism = objCopMechanismBLL.GetCopMechanismById(CopMechanismID); txtCopingMechanism.Text = objCopMechanism.CopMechanismName; }
//To get coping mechanism from the table MST_COPING_MECHANISM public void Getcopingmechanism() { string COP_MECHANISMID = string.Empty; if (copingmechDropDownList.SelectedValue.ToString() == "") { COP_MECHANISMID = "0"; //msgSaveLabel.Text = null; // if value is select then error msg will display } else { // SHOCKID = typeofshockDropDownList.SelectedValue.ToString(); // get UI screen Value DataSet Ds = new DataSet(); // MajorshockBLL copmech_BLL = new MajorshockBLL(); // Function or object creation for next layer CopMechanismBLL copmech_BLL = new CopMechanismBLL(); //Ds = copmech_BLL.GetCopMech(COP_MECHANISMID); // data pass through object SHOCKID objCopMechanismList = copmech_BLL.GetCopMechanism(); try { //if (Ds.Tables[0].Rows.Count > 0) // Data from BLL if (objCopMechanismList.Count > 0) { copingmechDropDownList.DataSource = objCopMechanismList; //copingmechDropDownList.DataTextField = Ds.Tables[0].Columns[1].ToString(); //copingmechDropDownList.DataValueField = Ds.Tables[0].Columns[0].ToString(); copingmechDropDownList.DataTextField = "CopMechanismName"; copingmechDropDownList.DataValueField = "CopMechanismID"; copingmechDropDownList.DataBind(); // copingmechDropDownList.Items.Insert(0, "--Select--"); } } catch (Exception ee) { throw ee; } finally // set the finally class nothing but Empty the object { copmech_BLL = null; } } }
/// <summary> /// to insert data to database /// </summary> protected void btnSave_Click(object sender, EventArgs e) { string AlertMessage = string.Empty; string message = string.Empty; objCopMechanism = new CopMechanismBO(); objCopMechanismBLL = new CopMechanismBLL(); objCopMechanism.CopMechanismName = txtCopingMechanism.Text.Trim(); if (ViewState["CopMechanismID"] != null) { objCopMechanism.CopMechanismID = Convert.ToInt32(ViewState["CopMechanismID"].ToString()); } objCopMechanism.IsDeleted = "False"; if (Session["userId"] != null) { objCopMechanism.CreatedBy = Convert.ToInt32(Session["USER_ID"].ToString()); } else { objCopMechanism.CreatedBy = 1; //Default Value } if (objCopMechanism.CopMechanismID < 1) { //If CopMechanismID does Not exists then SaveCopMechanism objCopMechanism.CopMechanismID = -1;//For New CopMechanism message = objCopMechanismBLL.AddCopMechanism(objCopMechanism); AlertMessage = "alert('" + message + "');"; if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data saved successfully"; ClearDetails(); BindGrid(true, true); } } else { //If CopMechanismID exists then UpdateCopMechanism message = objCopMechanismBLL.UpdateCopMechanism(objCopMechanism); //For Updating CopMechanism if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; ClearDetails(); BindGrid(true, true); SetUpdateMode(false); } } //ClearDetails(); //BindGrid(true, false); //ViewState["CopMechanismID"] = "-1"; AlertMessage = "alert('" + message + "');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true); }