/// <summary>
        /// Load result data to grid
        /// </summary>
        /// <returns></returns>
        public ActionResult CTS270_GetResultList()
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CTS270_ScreenParameter CTS270Param = GetScreenObject <CTS270_ScreenParameter>();
                dsCTS270Data           data        = CTS270Param.data;
                res.ResultData = CommonUtil.ConvertToXml <dtSearchMACheckupResult>(data.dtSearchResult, "Contract\\CTS270", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }
        public ActionResult CTS270()
        {
            CTS270_ScreenParameter CTS270Param = GetScreenObject <CTS270_ScreenParameter>();

            //Clear data if not return from child page
            if (CTS270Param.CallerScreenID != ScreenID.C_SCREEN_ID_REGISTER_MAINTENANCE_CHECKUP)
            {
                CTS270Param.data = null;
            }

            dsCTS270Data data = CTS270Param.data;

            if (data != null)
            {
                //Convert result to current language
                CommonUtil.MappingObjectLanguage <dtSearchMACheckupResult>(data.dtSearchResult);

                //Clear isBtnClick flag to clear session after come back from child page
                CTS270Param.isBtnClick = false;

                ViewBag.MaintenanceCheckupSlipFlag = data.doSearchCondition.MaintenanceCheckupSlipFlag;
                ViewBag.MaintenanceCheckupListFlag = data.doSearchCondition.MaintenanceCheckupListFlag;
                ViewBag.RelatedContractType        = data.doSearchCondition.RelatedContractType ?? "0";
                ViewBag.OperationOffice            = (data.doSearchCondition.OperationOffice == null || data.doSearchCondition.OperationOffice.Contains(",")) ? "" : data.doSearchCondition.OperationOffice;
                ViewBag.ProductName = data.doSearchCondition.ProductName ?? "";
                ViewBag.CheckupInstructionMonthFrom = data.doSearchCondition.CheckupInstructionMonthFrom;
                ViewBag.CheckupInstructionYearFrom  = data.doSearchCondition.CheckupInstructionYearFrom;
                ViewBag.CheckupInstructionMonthTo   = data.doSearchCondition.CheckupInstructionMonthTo;
                ViewBag.CheckupInstructionYearTo    = data.doSearchCondition.CheckupInstructionYearTo;
                ViewBag.SiteName                  = data.doSearchCondition.SiteName ?? "";
                ViewBag.UserCodeContractCode      = data.doSearchCondition.UserCodeContractCode ?? "";
                ViewBag.MAEmployeeName            = data.doSearchCondition.MAEmployeeName ?? "";
                ViewBag.MACheckupNo               = data.doSearchCondition.MACheckupNo ?? "";
                ViewBag.HasCheckupResult          = data.doSearchCondition.HasCheckupResult;
                ViewBag.HaveInstrumentMalfunction = data.doSearchCondition.HaveInstrumentMalfunction;
                ViewBag.NeedToContactSalesman     = data.doSearchCondition.NeedToContactSalesman;
                ViewBag.CurrentIndex              = CTS270Param.CurrentIndex;
                ViewBag.CurrentSortColIndex       = CTS270Param.CurrentSortColIndex;
                ViewBag.CurrentSortType           = CTS270Param.CurrentSortType;
                ViewBag.HasSessionData            = true;
            }
            else
            {
                if (CTS270Param.hasSlipDownloadPermision)
                {
                    ViewBag.MaintenanceCheckupSlipFlag = true;
                }

                if (!CTS270Param.hasSlipDownloadPermision && CTS270Param.hasListDownloadPermision)
                {
                    ViewBag.MaintenanceCheckupListFlag = true;
                }

                ViewBag.CheckupInstructionMonthFrom = DateTime.Now.Month;
                ViewBag.CheckupInstructionYearFrom  = DateTime.Now.Year;
                ViewBag.CheckupInstructionMonthTo   = DateTime.Now.Month;
                ViewBag.CheckupInstructionYearTo    = DateTime.Now.Year;
                ViewBag.CurrentIndex        = 0;
                ViewBag.HasSessionData      = false;
                ViewBag.RelatedContractType = "0";
            }

            ViewBag.PageRow               = CommonValue.ROWS_PER_PAGE_FOR_SEARCHPAGE;
            ViewBag.CallerPage            = CTS270Param.CallerScreenID;
            ViewBag.ViewLabel             = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_CONTRACT, ScreenID.C_SCREEN_ID_SEARCH_MAINTENANCE_CHECKUP, "btnView");
            ViewBag.RegisterLabel         = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_CONTRACT, ScreenID.C_SCREEN_ID_SEARCH_MAINTENANCE_CHECKUP, "btnRegister");
            ViewBag.DeleteLabel           = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_CONTRACT, ScreenID.C_SCREEN_ID_SEARCH_MAINTENANCE_CHECKUP, "btnDelete");
            ViewBag.FunctionIdView        = FunctionID.C_FUNC_ID_VIEW;
            ViewBag.FunctionIdAdd         = FunctionID.C_FUNC_ID_ADD;
            ViewBag.HasSlipRdoPermission  = CTS270Param.hasSlipDownloadPermision;
            ViewBag.HasListRdoPermission  = CTS270Param.hasListDownloadPermision;
            ViewBag.HasRegisterPermission = CTS270Param.hasRegisterPermission;
            ViewBag.HasDeletePermision    = CTS270Param.hasDeletePermision;
            ViewBag.HasDownloadButton     = CTS270Param.hasDownloadButton;
            // Akat K. for enable download when has permission download list
            ViewBag.HasDownloadListPermission = CTS270Param.hasListDownloadPermision;
            ViewBag.HasDownloadSlipPermission = CTS270Param.hasSlipDownloadPermision;

            UpdateScreenObject(CTS270Param);

            return(View("CTS270"));
        }
        /// <summary>
        /// Load search result data to grid
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ActionResult CTS270_Search(doSearchMACheckupCriteria cond)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CTS270_ScreenParameter         CTS270Param = GetScreenObject <CTS270_ScreenParameter>();
                dsCTS270Data                   data        = CTS270Param.data;
                List <dtSearchMACheckupResult> list        = new List <dtSearchMACheckupResult>();

                if (data == null)
                {
                    //Save search condition value
                    dsCTS270Data dsData = new dsCTS270Data();
                    cond.HasCheckupResult          = cond.HasCheckupResult ?? false;
                    cond.HaveInstrumentMalfunction = cond.HaveInstrumentMalfunction ?? false;
                    cond.NeedToContactSalesman     = cond.NeedToContactSalesman ?? false;
                    dsData.doSearchCondition       = cond;

                    //Set default to some search condition
                    CommonUtil c = new CommonUtil();
                    cond.UserCode     = cond.UserCodeContractCode;
                    cond.ContractCode = c.ConvertContractCode(cond.UserCodeContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                    //cond.MACheckupNo = (cond.MACheckupNo == null) ? null : System.Text.RegularExpressions.Regex.Replace(cond.MACheckupNo, "^0+", "");

                    if (cond.OperationOffice == null)
                    {
                        List <OfficeDataDo> clst = CommonUtil.dsTransData.dtOfficeData;
                        StringBuilder       sbOperationOffice = new StringBuilder("");
                        foreach (OfficeDataDo off in clst)
                        {
                            if (off.FunctionSecurity != SECOM_AJIS.Common.Util.ConstantValue.FunctionSecurity.C_FUNC_SECURITY_NO)// filter follow by the combobox
                            {
                                sbOperationOffice.AppendFormat("\'{0}\',", off.OfficeCode);
                            }
                        }
                        cond.OperationOffice = sbOperationOffice.ToString();
                    }

                    //Query for maintenance
                    IMaintenanceHandler hand = ServiceContainer.GetService <IMaintenanceHandler>() as IMaintenanceHandler;
                    list = hand.SearchMACheckup(cond);

                    //Set disable/show Action Buttons
                    setPermissionFlag(list
                                      , (cond.MaintenanceCheckupListFlag.HasValue) ? cond.MaintenanceCheckupListFlag.Value : false
                                      , (cond.MaintenanceCheckupSlipFlag.HasValue) ? cond.MaintenanceCheckupSlipFlag.Value : false
                                      , CTS270Param);

                    //Save search result list
                    dsData.dtSearchResult = list;

                    //Save condition and result into session
                    CTS270Param.data = dsData;
                    UpdateScreenObject(CTS270Param);
                }
                else
                {
                    list = data.dtSearchResult;

                    //Set disable/show Action Buttons
                    setPermissionFlag(list
                                      , data.doSearchCondition.MaintenanceCheckupListFlag ?? false
                                      , data.doSearchCondition.MaintenanceCheckupSlipFlag ?? false
                                      , CTS270Param);
                }

                res.ResultData = CommonUtil.ConvertToXml <dtSearchMACheckupResult>(list, "Contract\\CTS270", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }