public static CReturnData LoadData(CParam param)
    {
        CReturnData       result = new CReturnData();
        PTTGC_EPIEntities db     = new PTTGC_EPIEntities();

        if (!UserAcc.UserExpired())
        {
            result.incData      = new cDataInc();
            result.lstComplaint = new List <cComplaint>();
            result.lstStatus    = new List <sysGlobalClass.T_TEPI_Workflow>();
            int nIndID  = SystemFunction.GetIntNullToZero(param.sIndID);
            int nOprtID = SystemFunction.GetIntNullToZero(param.sOprtID);
            int nFacID  = SystemFunction.GetIntNullToZero(param.sFacID);
            result.hdfPRMS = SystemFunction.GetPermission_EPI_FROMS(nIndID, nFacID) + "";
            string sYear = param.sYear;

            var itemPrdInc = db.mTProductIndicator.FirstOrDefault(w => w.IDIndicator == 1);
            result.incData.ProductID    = itemPrdInc.ProductID;
            result.incData.sUnit        = itemPrdInc.sUnit;
            result.incData.sProductName = itemPrdInc.ProductName;
            result.incData.nUnitID      = 66;
            result.incData.sTarget      = "";
            #region EPI_FORM
            var itemEPI_FORM = db.TEPI_Forms.FirstOrDefault(w => w.sYear == sYear && w.IDIndicator == nIndID && w.OperationTypeID == nOprtID && w.FacilityID == nFacID);
            if (itemEPI_FORM != null)
            {
                var itemDataComplaint = db.TComplaint_Product.FirstOrDefault(w => w.FormID == itemEPI_FORM.FormID);
                #region Data Indicator
                if (itemDataComplaint != null)
                {
                    var itemUnit = db.mTUnit.FirstOrDefault(w => w.UnitID == itemDataComplaint.UnitID);
                    result.incData.nUnitID    = itemDataComplaint.UnitID;
                    result.incData.sUnit      = itemUnit != null ? itemUnit.UnitName : result.incData.sUnit;
                    result.incData.sTarget    = itemDataComplaint.Target;
                    result.incData.M1         = itemDataComplaint.M1;
                    result.incData.M2         = itemDataComplaint.M2;
                    result.incData.M3         = itemDataComplaint.M3;
                    result.incData.M4         = itemDataComplaint.M4;
                    result.incData.M5         = itemDataComplaint.M5;
                    result.incData.M6         = itemDataComplaint.M6;
                    result.incData.M7         = itemDataComplaint.M7;
                    result.incData.M8         = itemDataComplaint.M8;
                    result.incData.M9         = itemDataComplaint.M9;
                    result.incData.M10        = itemDataComplaint.M10;
                    result.incData.M11        = itemDataComplaint.M11;
                    result.incData.M12        = itemDataComplaint.M12;
                    result.incData.IsCheckM1  = itemDataComplaint.IsCheckM1;
                    result.incData.IsCheckM2  = itemDataComplaint.IsCheckM2;
                    result.incData.IsCheckM3  = itemDataComplaint.IsCheckM3;
                    result.incData.IsCheckM4  = itemDataComplaint.IsCheckM4;
                    result.incData.IsCheckM5  = itemDataComplaint.IsCheckM5;
                    result.incData.IsCheckM6  = itemDataComplaint.IsCheckM6;
                    result.incData.IsCheckM7  = itemDataComplaint.IsCheckM7;
                    result.incData.IsCheckM8  = itemDataComplaint.IsCheckM8;
                    result.incData.IsCheckM9  = itemDataComplaint.IsCheckM9;
                    result.incData.IsCheckM10 = itemDataComplaint.IsCheckM10;
                    result.incData.IsCheckM11 = itemDataComplaint.IsCheckM11;
                    result.incData.IsCheckM12 = itemDataComplaint.IsCheckM12;
                }
                #endregion

                #region Data Complaint
                result.lstComplaint = db.TComplaint.Where(w => w.FormID == itemEPI_FORM.FormID).Select(s => new cComplaint
                {
                    nComplaintID      = s.nComplaintID,
                    nComplaintTypeID  = s.nComplaintTypeID,
                    ComplaintDate     = s.ComplaintDate.HasValue ? s.ComplaintDate.Value : (DateTime?)null,
                    sIssueBy          = s.sIssueBy,
                    sSubject          = s.sSubject,
                    nComplaintByID    = s.nComplaintByID,
                    sComplaintByOther = s.sComplaintByOther,
                    sDetail           = s.sDetail,
                    sCorrectiveAction = s.sCorrectiveAction,
                    sStatus           = s.sStatus,
                    nMonth            = s.ComplaintDate.HasValue ? s.ComplaintDate.Value.Month : 0,
                    IsDel             = false,
                    IsNew             = false,
                    IsSubmited        = true,
                    IsShow            = true,
                }).ToList();
                result.lstComplaint.ForEach(f =>
                {
                    f.sIssueDate    = f.ComplaintDate.HasValue ? f.ComplaintDate.Value.ToString("dd/MM/yyyy") : "";
                    f.ComplaintDate = null;
                });
                var lstFileComplaint = db.TComplaint_File.Where(w => w.FormID == itemEPI_FORM.FormID).ToList();
                var lstImpact        = db.TComplaint_Impact.Where(w => w.FormID == itemEPI_FORM.FormID).ToList();
                foreach (var itemComplaint in result.lstComplaint)
                {
                    itemComplaint.lstImpact = new List <TComplaint_Impact>();
                    itemComplaint.lstImpact = lstImpact.Where(w => w.nComplaintID == itemComplaint.nComplaintID).Select(s => new TComplaint_Impact
                    {
                        nImpactTypeID = s.nImpactTypeID,
                        sOther        = s.sOther
                    }).ToList();

                    itemComplaint.lstFile = new List <sysGlobalClass.FuncFileUpload.ItemData>();
                    itemComplaint.lstFile = lstFileComplaint.Where(w => w.nComplaintID == itemComplaint.nComplaintID).Select(s => new sysGlobalClass.FuncFileUpload.ItemData
                    {
                        ID             = s.nFileID,
                        FileName       = s.sFileName,
                        SaveToFileName = s.sSysFileName,
                        SaveToPath     = s.sPath,
                        url            = s.sPath + s.sSysFileName,
                        IsNewFile      = false,
                        IsCompleted    = true,
                        sDelete        = "N",
                        sDescription   = s.sDescription,
                    }).ToList();
                }
                #endregion

                #region Status Month
                result.lstStatus = db.TEPI_Workflow.Where(w => w.FormID == itemEPI_FORM.FormID).Select(s => new sysGlobalClass.T_TEPI_Workflow {
                    nMonth = s.nMonth, nStatusID = s.nStatusID
                }).ToList();
                #endregion
            }
            else
            {
                for (int i = 1; i <= 12; i++)
                {
                    result.lstStatus.Add(new sysGlobalClass.T_TEPI_Workflow {
                        nMonth = i, nStatusID = 0
                    });
                }
                result.incData.sTarget    = "";
                result.incData.M1         = "";
                result.incData.M2         = "";
                result.incData.M3         = "";
                result.incData.M4         = "";
                result.incData.M5         = "";
                result.incData.M6         = "";
                result.incData.M7         = "";
                result.incData.M8         = "";
                result.incData.M9         = "";
                result.incData.M10        = "";
                result.incData.M11        = "";
                result.incData.M12        = "";
                result.incData.IsCheckM1  = "N";
                result.incData.IsCheckM2  = "N";
                result.incData.IsCheckM3  = "N";
                result.incData.IsCheckM4  = "N";
                result.incData.IsCheckM5  = "N";
                result.incData.IsCheckM6  = "N";
                result.incData.IsCheckM7  = "N";
                result.incData.IsCheckM8  = "N";
                result.incData.IsCheckM9  = "N";
                result.incData.IsCheckM10 = "N";
                result.incData.IsCheckM11 = "N";
                result.incData.IsCheckM12 = "N";
            }
            #endregion
            result.Status = SystemFunction.process_Success;
        }
        else
        {
            result.Status = SystemFunction.process_SessionExpired;
        }
        return(result);
    }
 public static sysGlobalClass.TRetunrLoadData GetLoadData(IntensityClass it)
 {
     sysGlobalClass.TRetunrLoadData o = new sysGlobalClass.TRetunrLoadData();
     try
     {
         if (!UserAcc.UserExpired())
         {
             PTTGC_EPIEntities db = new PTTGC_EPIEntities();
             bool IsNew           = false;
             int  nFormID         = 0;
             var  qEPIFomr        = db.TEPI_Forms.Where(w => w.IDIndicator == it.nIndicator && w.sYear == it.sYear && w.OperationTypeID == it.nOperationType && w.FacilityID == it.nFacility).FirstOrDefault();
             if (qEPIFomr == null)
             {
                 IsNew = true;
                 string sYearDel = (SystemFunction.GetIntNullToZero(it.sYear) - 1) + "";
                 qEPIFomr = db.TEPI_Forms.Where(w => w.IDIndicator == it.nIndicator && w.sYear == sYearDel && w.OperationTypeID == it.nOperationType && w.FacilityID == it.nFacility).FirstOrDefault();
             }
             if (qEPIFomr != null)
             {
                 nFormID = qEPIFomr.FormID;
             }
             var lstOther = db.TIntensity_Other.Where(w => w.FormID == nFormID).AsEnumerable().Select(s => new sysGlobalClass.T_TIntensity_Other
             {
                 UnderProductID = s.UnderProductID, // Header
                 nProductID     = s.ProductID,
                 sIndicator     = s.ProductName,
                 cTotal         = "N",
                 cTotalAll      = "N",
                 FormID         = s.FormID,
                 M1             = s.M1 != null && !IsNew ? s.M1 : "",
                 M2             = s.M2 != null && !IsNew ? s.M2 : "",
                 M3             = s.M3 != null && !IsNew ? s.M3 : "",
                 M4             = s.M4 != null && !IsNew ? s.M4 : "",
                 M5             = s.M5 != null && !IsNew ? s.M5 : "",
                 M6             = s.M6 != null && !IsNew ? s.M6 : "",
                 M7             = s.M7 != null && !IsNew ? s.M7 : "",
                 M8             = s.M8 != null && !IsNew ? s.M8 : "",
                 M9             = s.M9 != null && !IsNew ? s.M9 : "",
                 M10            = s.M10 != null && !IsNew ? s.M10 : "",
                 M11            = s.M11 != null && !IsNew ? s.M11 : "",
                 M12            = s.M12 != null && !IsNew ? s.M12 : "",
                 IsActive       = true,
                 sTarget        = !IsNew ? s.Target : "",
                 nFactor        = s.Factor,
             }).ToList();
             var efi_wf = db.TEPI_Workflow.Where(w => w.FormID == nFormID).Select(s => new sysGlobalClass.T_TEPI_Workflow
             {
                 nReportID = s.nReportID,
                 FormID    = s.FormID,
                 nMonth    = s.nMonth,
                 nStatusID = IsNew ? 0 : s.nStatusID.HasValue ? s.nStatusID : 0,
                 nActionBy = s.nActionBy,
                 dAction   = s.dAction
             }).ToList();
             if (IsNew)
             {
                 efi_wf = new List <sysGlobalClass.T_TEPI_Workflow>();
             }
             o.lstwf = efi_wf;
             o.lstIn = (from i in db.mTProductIndicator.Where(w => w.IDIndicator.Value == it.nIndicator).AsEnumerable()
                        from u in db.TIntensityUseProduct.Where(w => w.OperationTypeID == it.nOperationType && w.ProductID == i.ProductID).AsEnumerable()
                        from d in db.TIntensityDominator.Where(w => w.ProductID == i.ProductID && w.FormID == nFormID).AsEnumerable().DefaultIfEmpty()
                        from s in db.mTProductIndicatorUnit.Where(w => w.ProductID == u.ProductID && w.IDIndicator == i.IDIndicator).DefaultIfEmpty()
                        from un in db.mTUnit.Where(w => w.UnitID == s.UnitID).DefaultIfEmpty()
                        select new sysGlobalClass.TData_Intensity
             {
                 ProductID = i.ProductID,
                 ProductName = i.ProductName,
                 cTotal = i.cTotal,
                 cTotalAll = i.cTotalAll,
                 nGroupCalc = i.nGroupCalc ?? 0,
                 nOrder = u.nOrder ?? 0,
                 sUnit = s != null && un != null ? un.UnitName : i.sUnit,
                 UnitID = s != null && un != null ? s.UnitID : 0,
                 sType = i.sType,
                 M1 = d != null && !IsNew ? d.M1 != null ? d.M1 : "" : "",
                 M2 = d != null && !IsNew ? d.M2 != null ? d.M2 : "" : "",
                 M3 = d != null && !IsNew ? d.M3 != null ? d.M3 : "" : "",
                 M4 = d != null && !IsNew ? d.M4 != null ? d.M4 : "" : "",
                 M5 = d != null && !IsNew ? d.M5 != null ? d.M5 : "" : "",
                 M6 = d != null && !IsNew ? d.M6 != null ? d.M6 : "" : "",
                 M7 = d != null && !IsNew ? d.M7 != null ? d.M7 : "" : "",
                 M8 = d != null && !IsNew ? d.M8 != null ? d.M8 : "" : "",
                 M9 = d != null && !IsNew ? d.M9 != null ? d.M9 : "" : "",
                 M10 = d != null && !IsNew ? d.M10 != null ? d.M10 : "" : "",
                 M11 = d != null && !IsNew ? d.M11 != null ? d.M11 : "" : "",
                 M12 = d != null && !IsNew ? d.M12 != null ? d.M12 : "" : "",
                 nTotal = d != null && !IsNew ? d.nTotal != null ? d.nTotal : "" : "",
                 Target = d != null && !IsNew ? d.Target : "",
                 lstarrDetail = lstOther.Where(w => w.UnderProductID == i.ProductID).ToList(),
                 sRemark = !IsNew ? db.TIntensity_Remark.Any(w => w.FormID == nFormID && w.ProductID == i.ProductID) ? db.TIntensity_Remark.AsEnumerable().LastOrDefault(w => w.FormID == nFormID && w.ProductID == i.ProductID).sRemark : "" : "",
             }).OrderBy(k => k.nOrder).ToList();
             o.lstDataFile = db.TEPI_Forms_File.Where(w => w.FormID == nFormID).Select(s => new sysGlobalClass.FuncFileUpload.ItemData
             {
                 ID             = s.nFileID,
                 FileName       = s.sFileName,
                 SaveToFileName = s.sSysFileName,
                 url            = s.sPath + s.sSysFileName,
                 SaveToPath     = s.sPath,
                 IsNewFile      = false,
                 sDelete        = "N",
                 sDescription   = s.sDescription,
             }).ToList();
             if (IsNew)
             {
                 o.lstDataFile = new List <sysGlobalClass.FuncFileUpload.ItemData>();
             }
             o.hdfPRMS = SystemFunction.GetPermission_EPI_FROMS(it.nIndicator, it.nFacility);
             o.sStatus = SystemFunction.process_Success;
             o.sMsg    = "";
         }
         else
         {
             o.sStatus = SystemFunction.process_SessionExpired;
             o.sMsg    = "Session Expired !!";
         }
     }
     catch (Exception ex)
     {
         o.sStatus = SystemFunction.process_Failed;
         o.sMsg    = ex.ToString();
     }
     return(o);
 }