/// <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 grdCounty_RowCommand(object sender, GridViewCommandEventArgs e) { string message = string.Empty; if (e.CommandName == "EditRow") { ViewState["COUNTYID"] = e.CommandArgument; GetCountyById(); SetUpdateMode(true); pnlCountyDetails.Visible = true; pnlSearch.Visible = false; } else if (e.CommandName == "DeleteRow") { // ViewState["CDAPBUDGETID"] = e.CommandArgument; CountyBLL CountyBLLobj = new CountyBLL(); message = CountyBLLobj.DeleteCounty(Convert.ToInt32(e.CommandArgument)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data deleted successfully"; } SetUpdateMode(false); ClearData(); BindGrid(); } 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 COUNTYID = ((Literal)gr.FindControl("litCOUNTYID")).Text; CountyBLL CountyBLLobj = new CountyBLL(); message = CountyBLLobj.ObsoleteCounty(Convert.ToInt32(COUNTYID), Convert.ToString(chk.Checked), Convert.ToInt32(Session["USER_ID"])); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; } ClearData(); BindGrid(); if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Obsoleted", "alert('" + message + "');", true); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Set Grid Data source /// </summary> /// <param name="addRow"></param> /// <param name="deleteRow"></param>e public void searchBind(string County) { CountyBLL CountyBLLobj = new CountyBLL(); grdCounty.DataSource = CountyBLLobj.GetCounties(County); grdCounty.DataBind(); // DDLSearchDistrictName.ClearSelection(); //txtSearchCounty.Text = string.Empty; }
/// <summary> /// Set Grid Data source /// </summary> /// <param name="addRow"></param> /// <param name="deleteRow"></param>e private void BindGrid() { int districtID = Convert.ToInt32(ddlDistrictName.SelectedValue); //int districtID = Convert.ToInt32(ViewState["DISTRICTID"]); CountyBLL CountyBLLobj = new CountyBLL(); grdCounty.DataSource = CountyBLLobj.GetAllCounties(districtID); grdCounty.DataBind(); }
/// <summary> /// to update data to database /// </summary> /// <returns></returns> private void UpdateCounty() { CountyBLL CountyBLLobj = new CountyBLL(); CountyBO CountyBOobj = new CountyBO(); string message = ""; try { if (ViewState["COUNTYID"] != null) { CountyBOobj.CountyID = Convert.ToInt32(ViewState["COUNTYID"].ToString()); } string uID = string.Empty; uID = Session["USER_ID"].ToString(); CountyBOobj.DistrictID = Convert.ToInt32(ddlDistrictName.SelectedItem.Value); CountyBOobj.CountyName = txtCounty.Text.Trim(); CountyBOobj.UpdatedBy = Convert.ToInt32(uID); message = CountyBLLobj.UpdateCounty(CountyBOobj); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; } ClearData(); SetUpdateMode(false); BindGrid(); if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Updated", "alert('" + message + "');", true); } } catch (Exception ex) { throw ex; } finally { CountyBLLobj = null; } }
/// <summary> /// to get county names based on ID /// </summary> /// <returns></returns> private void GetCountyById() { CountyBLL CountyBLLobj = new CountyBLL(); CountyBO CountyBOobj = CountyBLLobj.GetCountyById(Convert.ToInt32(ViewState["COUNTYID"])); if (CountyBOobj != null) { txtCounty.Text = CountyBOobj.CountyName; } ddlDistrictName.ClearSelection(); if (ddlDistrictName.Items.FindByText(CountyBOobj.DistrictName.ToString()) != null) { ddlDistrictName.Items.FindByText(CountyBOobj.DistrictName.ToString()).Selected = true; } CountyBOobj = null; CountyBLLobj = null; }
/// <summary> /// to save data to database /// </summary> /// <returns></returns> private void SaveCounty() { CountyBLL CountyBLLobj = new CountyBLL(); CountyBO CountyBOobj = new CountyBO(); string message = ""; string uID = string.Empty; uID = Session["USER_ID"].ToString(); CountyBOobj.DistrictID = Convert.ToInt32(ddlDistrictName.SelectedItem.Value); CountyBOobj.CountyName = txtCounty.Text.Trim(); CountyBOobj.CreatedBy = Convert.ToInt32(uID); try { message = CountyBLLobj.AddCounty(CountyBOobj); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data saved successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } ClearData(); BindGrid(); } catch (Exception ee) { throw ee; } finally { CountyBLLobj = null; } }