/// <summary> /// Description: This method is used to save Goal /// <summary> protected void Save_Click(object sender, EventArgs e) { string txtTotal = ""; string txtAverage = ""; string hdnID = ""; string rgdID = ""; string Goal_Applicable_For = ""; DataTable dt = new DataTable(); try { //Pass seperate values for the above variables based on the value selected in "Applicable For" dropdown. if (Convert.ToInt32(ViewState["KPI_ApplicableFor"]) == 0) { txtTotal = "txtItemFleet_Amount"; txtAverage = "txtAvgFleet_Amount"; hdnID = "hdnFleet_Id"; rgdID = "rgdFleetGoals"; Goal_Applicable_For = "FT"; } else if (Convert.ToInt32(ViewState["KPI_ApplicableFor"]) == 1) { txtTotal = "txtItem_Amount"; txtAverage = "txtAverage"; hdnID = "hdnVessel_Id"; rgdID = "rgdItems"; Goal_Applicable_For = "VE"; } else if (Convert.ToInt32(ViewState["KPI_ApplicableFor"]) == 2) { txtTotal = "txtItemVesselType_Amount"; txtAverage = "txtItemAvgVesselType_Amount"; hdnID = "hdnVesselType_Id"; rgdID = "rgdVesselTypeGoals"; Goal_Applicable_For = "VT"; } else if (Convert.ToInt32(ViewState["KPI_ApplicableFor"]) == 3) { txtTotal = ""; txtAverage = ""; hdnID = ""; rgdID = "rgdCompanyGoals"; Goal_Applicable_For = "CY"; } if (Goal_Applicable_For != "CY") { dt = getGoalData(txtTotal, txtAverage, hdnID, rgdID); } else //As the company goal is not populated in radgrid so create a datatable in codebehind to pass the INSERT_KPI_GoalDetail method. { dt.Columns.Add("Vessel_ID"); dt.Columns.Add("Goal"); dt.Columns.Add("Average_Goal"); DataRow dritem = dt.NewRow(); dritem["Goal"] = txtItemCompany_Amount.Text == "" ? Convert.DBNull : Convert.ToDecimal(txtItemCompany_Amount.Text); dritem["Average_Goal"] = txtAvgCompany.Text == "" ? Convert.DBNull : Convert.ToDecimal(txtAvgCompany.Text); dritem["Vessel_ID"] = 1; dt.Rows.Add(dritem); } if (dt.Rows.Count > 0 && Convert.ToInt32(ViewState["KPID"].ToString()) != 0) //Handle the save functionality of already created KPIs. { objKPI.INSERT_KPI_GoalDetail(Convert.ToInt32(ViewState["KPID"].ToString()), dt, UDFLib.ConvertToInteger(Session["UserID"].ToString()), Goal_Applicable_For); ltMessage.Text = "Updated successfully!"; } //Display message when Goal button is clicked without creating a KPI. else { ltMessage.Text = "Please create a KPI!"; } } catch (Exception ex) { UDFLib.WriteExceptionLog(ex); } }