//protected void grdConsultant_RowDataBound(object sender, GridViewRowEventArgs e) //{ // if (e.Row.RowType == DataControlRowType.DataRow) // { // int consultantID = (int)DataBinder.Eval(e.Row.DataItem, "ConsultID"); // CheckBox chkObsolete = (CheckBox)e.Row.FindControl("chkObsolete"); // string isDeleted = DataBinder.Eval(e.Row.DataItem, "IsDeleted").ToString(); // chkObsolete.Attributes.Add("onclick", string.Format("MakeObsolete(this,{0});", consultantID)); // if (isDeleted == "TRUE") // chkObsolete.Checked = true; // //chkObsolete.Attributes.Add("onclick", string.Format("RevokeObsolete({0});", consultantID)); // } //} /// <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 consultantID = ((Literal)gr.FindControl("litConsultantID")).Text; ConsultantBLL objConBLL = new ConsultantBLL(); objConBLL.ObsoleteConsultant(Convert.ToInt32(consultantID), 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) { ConsultantBO objCon = new ConsultantBO(); ConsultantBLL objConBLL = new ConsultantBLL(); grdConsultant.DataSource = objConBLL.GetConsultant(Convert.ToInt32(Session["PROJECT_ID"])); grdConsultant.DataBind(); }
/// <summary> /// To bind values to dropdownlist /// </summary> private void Bindconsultantname() { ConsultantBO objCon = new ConsultantBO(); ConsultantBLL objConBLL = new ConsultantBLL(); ddlconsultantname.DataSource = objConBLL.GetConsultant(0); ddlconsultantname.DataTextField = "ConsultName"; ddlconsultantname.DataValueField = "ConsultID"; ddlconsultantname.DataBind(); }
/// <summary> /// Saves details to the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Save_Click(object sender, EventArgs e) { string message = ""; ConsultantBO objCon = new ConsultantBO(); objCon.ConsultID = int.Parse(ViewState["CONSULTANTID"].ToString()); objCon.ProjectID = Convert.ToInt32(Session["PROJECT_ID"]); objCon.ConsultName = txtConsultantname.Text.Trim(); objCon.ConsultType = DrpConsultantType.SelectedItem.Value; objCon.EmailAddress = TxtEmailaddress.Text.Trim(); string strMax = TxtAddress.Text.ToString().Trim(); if (strMax.Trim().Length >= 399) { strMax = TxtAddress.Text.ToString().Trim().Substring(0, 399); } objCon.Address = strMax; objCon.ConNumber = TxtContactNum.Text.Trim(); objCon.ConPerson = TxtContactPerson.Text.Trim(); ConsultantBLL objConBLL = new ConsultantBLL(); if (objCon.ConsultID == 0) { objCon.CreatedBy = Convert.ToInt32(Session["USER_ID"]); message = objConBLL.AddConsultant(objCon); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data saved successfully"; } } else { objCon.UpdatedBy = Convert.ToInt32(Session["USER_ID"]); objConBLL.UpdateConsultant(objCon); message = "Data updated successfully"; SetUpdateMode(false); } ClearDetails(); BindGrid(true, false); if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } }
/// <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 grdConsultant_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { ViewState["CONSULTANTID"] = e.CommandArgument; ConsultantBO objCon = new ConsultantBO(); ConsultantBLL objConBLL = new ConsultantBLL(); objCon = objConBLL.GetConsultantByID(Convert.ToInt32(ViewState["CONSULTANTID"])); if (objCon != null) { txtConsultantname.Text = objCon.ConsultName; DrpConsultantType.ClearSelection(); if (DrpConsultantType.Items.FindByValue(objCon.ConsultType) != null) { DrpConsultantType.Items.FindByValue(objCon.ConsultType).Selected = true; } TxtEmailaddress.Text = objCon.EmailAddress; TxtAddress.Text = objCon.Address; TxtContactNum.Text = objCon.ConNumber; TxtContactPerson.Text = objCon.ConPerson; } SetUpdateMode(true); } else if (e.CommandName == "DeleteRow") { ConsultantBLL objConBLL = new ConsultantBLL(); objConBLL.DeleteConsultant(Convert.ToInt32(e.CommandArgument)); ClearDetails(); SetUpdateMode(false); BindGrid(false, true); } }