/// <summary> /// Based on search criteria , method will search the different PMS KPIvalues and pivot the Monthwise values into columns /// </summary> private void BindKPI() { try { string sStartDate = txtStartDate.Text; string sEndDate = txtEndDate.Text; if (sStartDate != "" && sEndDate != "") { DateTime StartDate = Convert.ToDateTime(UDFLib.ConvertToDefaultDt(txtStartDate.Text)); //ConvertToDefaultDt() method is used to change the user selected date format to the default format, the format in which date is saved in database. DateTime EndDate = Convert.ToDateTime(UDFLib.ConvertToDefaultDt(txtEndDate.Text)); DateTime prevMonthLastDate = EndDate.AddDays(-EndDate.Day); string lastMonth = String.Format("{0:y}", prevMonthLastDate); hdnLastMonth.Value = lastMonth; DataSet ds = objKPI.Get_PM_Overdue((DataTable)Session["Vessel_Id"], StartDate, EndDate, null); DataTable dt = ds.Tables[0]; string[] Pkey_cols = new string[] { "VesselID", "KPI_ID" }; string[] Hide_cols = new string[] { "ID", "KPI_ID", "Effective_Date" }; DataTable dt1 = objKPI.PivotTable("MonthYear", "Value", "", Pkey_cols, Hide_cols, dt); DataView dtVesselIDs = new DataView(dt1); DataTable distinctValues = dtVesselIDs.ToTable(true, "VesselID"); string Vessel_Ids = ""; foreach (DataRow dr in distinctValues.Rows) { Vessel_Ids = Vessel_Ids + "," + dr["VesselID"].ToString(); } Vessel_Ids = Vessel_Ids.Trim(','); hdnVessel_IDs.Value = Vessel_Ids; if (StartDate <= EndDate) { if ((EndDate - StartDate).TotalDays >= 28 || EndDate.Month != StartDate.Month) { if (dt1.Rows.Count > 0) { gvPMSOverdue.DataSource = dt1; gvPMSOverdue.DataBind(); gvPMSOverdue.Visible = true; string jsMethodName = null; jsMethodName = "$(document).ready(function () {showChart('" + Vessel_Ids + "','" + Convert.ToDateTime(UDFLib.ConvertToDefaultDt(txtStartDate.Text)).ToString("yyyy-MM-dd") + "','" + lastMonth + "' ) });"; ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "uniqueKey", jsMethodName, true); } else { gvPMSOverdue.Visible = false; string msg2 = String.Format("showAlert('No record available! ')"); ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "uniqueKey", msg2, true); } } else { gvPMSOverdue.Visible = false; string msg2 = String.Format("showAlert('No record available between this date range! ')"); ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "uniqueKey", msg2, true); } } else { gvPMSOverdue.Visible = false; string msg2 = String.Format("showAlert('Start Date should not be greater than End Date ')"); ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "uniqueKey", msg2, true); } } } catch (Exception ex) { UDFLib.WriteExceptionLog(ex); } }