/// <summary> /// Set Grid Data source /// </summary> /// <param name="addRow"></param> /// <param name="deleteRow"></param>e private void BindGrid(bool addRow, bool deleteRaow) { CropNameBLL CropNameBLLObj = new CropNameBLL(); gvCropName.DataSource = CropNameBLLObj.GetAllCropNameDetails(); gvCropName.DataBind(); }
public static string[] GetUnitName(string Units) { string[] Ids = Units.Split('|'); int cropID = Convert.ToInt32(Ids[0]); int CropDesID = Convert.ToInt32(Ids[1]); CropNameBLL objCropNameBLL = new CropNameBLL(); CropNameBO objCropname = objCropNameBLL.GetCropNameById(cropID); string[] arrCrop = { "", "" }; string unitMeasureName = ""; string cropRate = ""; CropRateBLL objCropRateBLL = new CropRateBLL(); CropRateBO objCropRateBO = objCropRateBLL.GetCropRateByDistrict(cropID, CropDesID, Convert.ToInt32(HttpContext.Current.Session["HH_ID"])); if (objCropname != null) { unitMeasureName = objCropname.UnitName; if (objCropRateBO != null) { cropRate = objCropRateBO.CropRate; } } arrCrop[0] = unitMeasureName; arrCrop[1] = cropRate; return(arrCrop); }
/// <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 cropID = ((Literal)gr.FindControl("litCROPID")).Text; CropNameBLL CropNameBLLObj = new CropNameBLL(); message = CropNameBLLObj.ObsoleteCropName(Convert.ToInt32(cropID), 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> /// to fetch values to dropdownlist /// </summary> private void GetCropName() { CropNameBLL BLLobj = new CropNameBLL(); ddlCropName.DataSource = BLLobj.GetCropNameDetails(); ddlCropName.DataTextField = "CropName"; ddlCropName.DataValueField = "CROPID"; ddlCropName.DataBind(); }
/// <summary> /// To fetch details and assign to textbox /// </summary> private void GetCropNameDeatails() { int CROPID = 0; if (ViewState["CROPID"] != null) { CROPID = Convert.ToInt32(ViewState["CROPID"].ToString()); } CropNameBLL CropNameBLLObj = new CropNameBLL(); CropNameBO CropNameBOObj = CropNameBLLObj.GetCropNameById(CROPID); txtCropName.Text = CropNameBOObj.CropName; txtCropNameID.Text = CropNameBOObj.CROPID.ToString(); ddlUnitOfmeasure.ClearSelection(); if (ddlUnitOfmeasure.Items.FindByText(CropNameBOObj.UnitName.ToString()) != null) { ddlUnitOfmeasure.Items.FindByText(CropNameBOObj.UnitName.ToString()).Selected = 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 gvCropName_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { ViewState["CROPID"] = e.CommandArgument; int CropEditID = Convert.ToInt32(ViewState["CROPID"]); GridViewRow row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer; //if (row != null) //{ // txtCropName.Text = row.Cells[1].Text.ToString(); // ddlUnitOfmeasure.SelectedItem.Text = row.Cells[2].Text.ToString(); //} SetUpdateMode(true); GetCropNameDeatails(); ScriptManager.RegisterStartupScript(this, this.GetType(), "Added", "setDirty();", true); } else if (e.CommandName == "DeleteRow") { CropNameBLL CropNameBLLObj = new CropNameBLL(); string message = string.Empty; message = CropNameBLLObj.DeleteCropTypeRow(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); } ClearCropName(); SetUpdateMode(false); BindGrid(false, true); } }
/// <summary> /// To save details to the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveCropNameDetails(CropNameBO CropNameBOObj) { string message = ""; if (txtCropNameID.Text.ToString().Trim() == string.Empty) { try { CropNameBOObj = new CropNameBO(); CropNameBLL CropNameBLLObj = new CropNameBLL(); CropNameBOObj.CropName = txtCropName.Text.ToString().Trim(); CropNameBOObj.CROPID = Convert.ToInt32(ViewState["CROPID"]); CropNameBOObj.UnitMeasure = Convert.ToInt32(ddlUnitOfmeasure.SelectedValue); CropNameBOObj.CreatedBy = Convert.ToInt32(Session["USER_ID"].ToString()); message = CropNameBLLObj.InsertCropNameDetails(CropNameBOObj); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data saved successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } BindGrid(true, true); } catch (Exception ex) { throw ex; } } else { try { CropNameBOObj = new CropNameBO(); CropNameBLL CropNameBLLObj = new CropNameBLL(); CropNameBOObj.CropName = txtCropName.Text.ToString().Trim(); int CROPID = Convert.ToInt32(ViewState["CROPID"]); CropNameBOObj.UnitMeasure = Convert.ToInt32(ddlUnitOfmeasure.SelectedItem.Value); CropNameBOObj.CreatedBy = Convert.ToInt32(Session["USER_ID"].ToString()); message = CropNameBLLObj.UpdateCropNameDetails(CropNameBOObj, CROPID); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data updated successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } ClearCropName(); BindGrid(true, true); } catch (Exception ex) { throw ex; } finally { CropNameBOObj = null; } } SetUpdateMode(false); }