protected void btnFPSave_Click(object sender, EventArgs e) { DataTable dtBasicFInfo = farmingObj.GetBasicFarmingInfo(Convert.ToInt32(ddlFPYear.SelectedValue), Convert.ToInt32(ddlFPProduct.SelectedValue), Convert.ToInt32(ddlFPSeason.SelectedValue)); string[] strFarmer = txtFPFarmerN.Text.Split('-'); string farmerID = string.Empty; //if (strFarmer.Length >= 2) //{ DataTable dtFarmerDetails = far.FamerDetails(strFarmer[0].Trim(), strFarmer[1].Trim(), strFarmer[2].Trim()); farmerID = txtFPFarmerN.Text; //dtFarmerDetails.Rows[0]["FarmerID"].ToString() ; //} if (dtBasicFInfo.Rows.Count > 0) { for (int count = 0; count < dlMainFP.Items.Count; count++) { int PFarmID = Convert.ToInt32(dlMainFP.DataKeys[count].ToString()); GridView gv = (dlMainFP.Items[count].FindControl("gvCrops") as GridView); if (gv.Rows.Count > 0) { decimal PTotalArea = Convert.ToDecimal((dlMainFP.Items[count].FindControl("lblPlotArea") as Label).Text); decimal TotalArea = 0; for (int gvCount = 0; gvCount < gv.Rows.Count; gvCount++) { DataKey dk = gv.DataKeys[gvCount]; int FarmId = !string.IsNullOrEmpty(dk.Values["FarmId"].ToString()) ? Convert.ToInt32(dk.Values["FarmId"].ToString()) : 0; int PlantationId = !string.IsNullOrEmpty(dk.Values["PlantationId"].ToString()) ? Convert.ToInt32(dk.Values["PlantationId"].ToString()) : 0; string PA = (gv.Rows[gvCount].FindControl("txtPlotArea") as TextBox).Text; decimal PlotArea = !string.IsNullOrEmpty(PA) ? Convert.ToDecimal(PA) : 0; TotalArea += PlotArea; DateTime PlantationDate = objMudarApp.GenerateRandomDate(dtBasicFInfo.Rows[0]["PlantationFrom"].ToString(), dtBasicFInfo.Rows[0]["PlantationTo"].ToString()); int FHCount = MudarApp.RandomNumber(Convert.ToInt32(dtBasicFInfo.Rows[0]["1stCutFrom"].ToString()), Convert.ToInt32(dtBasicFInfo.Rows[0]["1stCutTo"].ToString())); int SHCount = MudarApp.RandomNumber(Convert.ToInt32(dtBasicFInfo.Rows[0]["2ndCutFrom"].ToString()), Convert.ToInt32(dtBasicFInfo.Rows[0]["2ndCutTo"].ToString())); string unitid = Guid.NewGuid().ToString(); if (TotalArea <= PTotalArea) { if (FarmId == 0 && PlantationId == 0) { //IsInterCrop is constant false. bool resutl = fp.Farm_PlantationDetails_INSandUPDandDEL(farmerID, FarmId, PlotArea, string.Empty, 0, 0, PFarmID, Convert.ToInt32(ddlFPProduct.SelectedValue), unitid, PlantationDate, PlantationDate.AddDays(FHCount), 0, PlantationDate.AddDays(FHCount + 2), 0, 0, PlantationDate.AddDays(FHCount + SHCount), 0, PlantationDate.AddDays(FHCount + SHCount + 2), 0, 0, 0, false, false, "Aslam", string.Empty, Convert.ToInt32(ddlFPSeason.SelectedValue), PlotArea, MudarApp.Insert, 0, unitid, unitid, 0, 0, string.Empty, string.Empty, Convert.ToInt32(ddlFPYear.SelectedValue), false, 0, 0, 0, 0); } } } } } if (ddlFPProduct.SelectedIndex > 0) { BindDlMainFP(); } } else { //no Basic Information is not schedule. ok } }
protected void btnFarmerInfosumbit_Click(object sender, EventArgs e) { try { bool result = false; int FarmingInfoID = 0; FarmingInfoID = Convert.ToInt32(hfBFID.Value); //DateTime FDate = System.DateTime.Parse(txtPlantationFDate.Text); //DateTime TDate = System.DateTime.Parse(txtPlantationTDate.Text); bool resutl = false; if (FarmingInfoID > 0) { result = farmingObj.FarmingInfo_INSandUPDandDEL(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlProduct.SelectedValue), Convert.ToInt32(ddlSeason.SelectedValue), Convert.ToDateTime(txtPlantationFDate.Text), Convert.ToDateTime(txtPlantationTDate.Text), Convert.ToInt32(txt1stCutF.Text), Convert.ToInt32(txt1stCutT.Text), Convert.ToDecimal(txt1stHCF.Text), Convert.ToDecimal(txt1stHCT.Text), Convert.ToDecimal(txt1stOilF.Text), Convert.ToDecimal(txt1stOilT.Text), Convert.ToInt32(txt2ndCutF.Text), Convert.ToInt32(txt2ndCutT.Text), Convert.ToDecimal(txt2ndHCF.Text), Convert.ToDecimal(txt2ndHCT.Text), Convert.ToDecimal(txt2ndOilF.Text), Convert.ToDecimal(txt2ndOilT.Text), Convert.ToInt32(txtActualF.Text), Convert.ToInt32(txtActualTo.Text), "", "Aslam", MudarApp.Update, FarmingInfoID); if (result) { DataTable dt = new DataTable(); dt = farmingObj.GetProductionInfo(Convert.ToInt32(ddlProduct.SelectedValue), Convert.ToInt32(ddlSeason.SelectedValue)); if (dt.Rows.Count > 0) { DataTable dtBasicFInfo = farmingObj.GetBasicFarmingInfo(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlProduct.SelectedValue), Convert.ToInt32(ddlSeason.SelectedValue)); for (int i = 0; i < dt.Rows.Count; i++) { DateTime PlantationDate = objMudarApp.GenerateRandomDate(dtBasicFInfo.Rows[0]["PlantationFrom"].ToString(), dtBasicFInfo.Rows[0]["PlantationTo"].ToString()); int FHCount = MudarApp.RandomNumber(Convert.ToInt32(dtBasicFInfo.Rows[0]["1stCutFrom"].ToString()), Convert.ToInt32(dtBasicFInfo.Rows[0]["1stCutTo"].ToString())); int SHCount = MudarApp.RandomNumber(Convert.ToInt32(dtBasicFInfo.Rows[0]["2ndCutFrom"].ToString()), Convert.ToInt32(dtBasicFInfo.Rows[0]["2ndCutTo"].ToString())); // First Cut Estimation Herbage Qty int FEHQty = MudarApp.RandomNumber(Convert.ToInt32(dtBasicFInfo.Rows[0]["Qty1stCutHCFrom"].ToString()), Convert.ToInt32(dtBasicFInfo.Rows[0]["Qty1stCutHCTo"].ToString())); // Total Herbage firstcut (estimated) decimal FHerQty = Math.Round((Convert.ToDecimal(dt.Rows[i]["PlantationArea"].ToString()) * FEHQty), 1); // firstcut oil Estimation kgs decimal FEoil = MudarApp.RandomNumber(Convert.ToDecimal(dtBasicFInfo.Rows[0]["1stRecoveryOilFrom"].ToString()), Convert.ToDecimal(dtBasicFInfo.Rows[0]["1stRecoveryOilTo"].ToString())); // Total Oil firstcut(estimated) decimal FOilEsti = Math.Round((FHerQty * FEoil), 1); // firstcut Estimation vs Actual Percentage decimal FEsvsAt = (MudarApp.RandomNumber(Convert.ToDecimal(dtBasicFInfo.Rows[0]["EsvsAc_From"].ToString()), Convert.ToDecimal(dtBasicFInfo.Rows[0]["EsvsAc_To"].ToString()))) / 100; // firstcut Actual Herbage decimal FTHqty = Math.Round((FHerQty * FEsvsAt), 1); // firstcut oil kgs decimal FTOil = Math.Round((FOilEsti * FEsvsAt), 1); // Second Cut Estimation Herbage Qty int SEHQty = MudarApp.RandomNumber(Convert.ToInt32(dtBasicFInfo.Rows[0]["Qty2ndCutHCFrom"].ToString()), Convert.ToInt32(dtBasicFInfo.Rows[0]["Qty2ndCutHCTo"].ToString())); // Total Herbage second cut (estimated) decimal SHerQty = Math.Round((Convert.ToDecimal(dt.Rows[i]["PlantationArea"].ToString()) * SEHQty), 1); // Second Cut oil Estimation kgs decimal SEoil = MudarApp.RandomNumber(Convert.ToDecimal(dtBasicFInfo.Rows[0]["2ndRecoveryOilFrom"].ToString()), Convert.ToDecimal(dtBasicFInfo.Rows[0]["2ndRecoveryOilTo"].ToString())); // Second Cut Total Oil (estimated) decimal SOilEsti = Math.Round((SHerQty * SEoil), 1); // Second Cut Estimation vs Actual Percentage decimal SEsvsAt = (MudarApp.RandomNumber(Convert.ToDecimal(dtBasicFInfo.Rows[0]["EsvsAc_From"].ToString()), Convert.ToDecimal(dtBasicFInfo.Rows[0]["EsvsAc_To"].ToString()))) / 100; // Second Cut Actual Herbage Percentage decimal STHqty = Math.Round((SHerQty * SEsvsAt), 1); // Second Cut oil kgs decimal STOil = Math.Round((SOilEsti * SEsvsAt), 1); resutl = fp.sp_FarmerProduction_UPD(PlantationDate, PlantationDate.AddDays(FHCount), FTHqty, PlantationDate.AddDays(FHCount + 1), FTOil, PlantationDate.AddDays(FHCount + SHCount), SHerQty, PlantationDate.AddDays(FHCount + SHCount + 1), STOil, FTOil + STOil, Convert.ToInt32(dt.Rows[i]["PlantationId"].ToString()), FHerQty, FOilEsti, SHerQty, SOilEsti); } if (resutl) { ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('!!! Update Data Successfully !!!');</script>"); } } } } else { result = farmingObj.FarmingInfo_INSandUPDandDEL(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlProduct.SelectedValue), Convert.ToInt32(ddlSeason.SelectedValue), Convert.ToDateTime(txtPlantationFDate.Text), Convert.ToDateTime(txtPlantationTDate.Text), Convert.ToInt32(txt1stCutF.Text), Convert.ToInt32(txt1stCutT.Text), Convert.ToDecimal(txt1stHCF.Text), Convert.ToDecimal(txt1stHCT.Text), Convert.ToDecimal(txt1stOilF.Text), Convert.ToDecimal(txt1stOilT.Text), Convert.ToInt32(txt2ndCutF.Text), Convert.ToInt32(txt2ndCutT.Text), Convert.ToDecimal(txt2ndHCF.Text), Convert.ToDecimal(txt2ndHCT.Text), Convert.ToDecimal(txt2ndOilF.Text), Convert.ToDecimal(txt2ndOilT.Text), Convert.ToInt32(txtActualF.Text), Convert.ToInt32(txtActualTo.Text), "Aslam", "", MudarApp.Insert, 0); ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('!!! Saved Data Successfully !!!');</script>"); } divBasicForm.Visible = false; btnAddBasic.Visible = false; divAllSeasonNames.Visible = true; btnAddBasic.Visible = true; ClearControls(); } catch (Exception ex) { Response.Write(ex.Message); } }