/* Old Code
         * /// <summary>
         * /// Download attach file
         * /// </summary>
         * /// <param name="AttachID"></param>
         * /// <returns></returns>
         * public ActionResult CTS260_DownloadAttach(string AttachID)
         * {
         *  ObjectResultData res = new ObjectResultData();
         *  ICommonHandler commonhandler = ServiceContainer.GetService<ICommonHandler>() as ICommonHandler;
         *
         *  try
         *  {
         *      CTS260_ScreenParameter param = GetScreenObject<CTS260_ScreenParameter>();
         *      var downloadFileStream = commonhandler.GetAttachFileForDownload(int.Parse(AttachID), param.strProjectCode);
         *      var downloadFileName = commonhandler.GetTbt_AttachFile(param.strProjectCode, int.Parse(AttachID), null);
         *      //var downloadFileName = commonhandler.GetAttachFileName(sParam.strIncidentID, int.Parse(AttachID), null);
         *      //var attachFile = commonhandler.GetAttachFile(AttachmentModule.Incident, ReleateID, int.Parse(AttachID));
         *      //var fileNameLst = commonhandler.GetAttachFileName(ReleateID, int.Parse(AttachID), true);
         *
         *      string fileName = downloadFileName[0].FileName;
         *      return File(downloadFileStream, "application/octet-stream", fileName);
         *  }
         *  catch (Exception ex)
         *  {
         *      res.AddErrorMessage(ex);
         *  }
         *
         *  return Json(res);
         * }*/

        //Add by Jutarat A. on 31012013
        /// <summary>
        /// Download attach file
        /// </summary>
        /// <param name="AttachID"></param>
        public void CTS260_DownloadAttach(string AttachID)
        {
            ICommonHandler         commonhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            CTS260_ScreenParameter param         = GetScreenObject <CTS260_ScreenParameter>();

            Stream downloadFileStream = commonhandler.GetAttachFileForDownload(int.Parse(AttachID), param.strProjectCode);
            List <tbt_AttachFile> downloadFileName = commonhandler.GetTbt_AttachFile(param.strProjectCode, int.Parse(AttachID), null);

            this.DownloadAllFile(downloadFileName[0].FileName, downloadFileStream);
        }
        /// <summary>
        /// Get project data for view
        /// </summary>
        /// <param name="strProjectCode"></param>
        /// <returns></returns>
        public ActionResult CTS260_GetProjectForView(string strProjectCode)
        {
            ObjectResultData res = new ObjectResultData();

            if (CommonUtil.IsNullOrEmpty(strProjectCode))
            {
                res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, "CTS260",
                                    MessageUtil.MODULE_COMMON,
                                    MessageUtil.MessageList.MSG0007,
                                    new string[] { "lblProjectCode" },
                                    new string[] { "ProjectCode" });
                res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                return(Json(res));
            }

            IProjectHandler      Projh      = ServiceContainer.GetService <IProjectHandler>() as IProjectHandler;
            List <doTbt_Project> lstProject = Projh.GetTbt_ProjectForView(strProjectCode);

            if (lstProject.Count <= 0)
            {
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0091,
                                    new string[] { strProjectCode },
                                    new string[] { "ProjectCode" });
                return(Json(res));
            }
            else
            {
                //CommonUtil.dsTransData.dtCommonSearch.ProjectCode = strProjectCode;
                CommonUtil comUtil = new CommonUtil();

                //CommonUtil.dsTransData.dtCommonSearch.ProjectCode = comUtil.ConvertProjectCode(lstProject[0].ProjectCode,CommonUtil.CONVERT_TYPE.TO_SHORT);
                //CommonUtil.dsTransData.dtCommonSearch.ContractCode = null;
                CTS260_ScreenParameter param = GetScreenObject <CTS260_ScreenParameter>();
                param.CommonSearch = new ScreenParameter.CommonSearchDo()
                {
                    ProjectCode = comUtil.ConvertProjectCode(lstProject[0].ProjectCode, CommonUtil.CONVERT_TYPE.TO_SHORT)
                };
            }
            EmployeeMappingList emlst = new EmployeeMappingList();

            emlst.AddEmployee(lstProject.ToArray());
            IEmployeeMasterHandler Emph = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;

            Emph.EmployeeListMapping(emlst);

            MiscTypeMappingList miscMapList = new MiscTypeMappingList();

            miscMapList.AddMiscType(lstProject.ToArray());
            ICommonHandler comh = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

            comh.MiscTypeMappingList(miscMapList);

            return(Json(lstProject));
        }
        /// <summary>
        /// load attach file to grid attach
        /// </summary>
        /// <returns></returns>
        public ActionResult CTS260_LoadGridAttachedDocList()
        {
            ICommonHandler   commonhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            ObjectResultData res           = new ObjectResultData();

            try
            {
                CTS260_ScreenParameter         param           = GetScreenObject <CTS260_ScreenParameter>();
                List <dtAttachFileForGridView> lstAttachedName = commonhandler.GetAttachFileForGridView(param.strProjectCode);
                res.ResultData = CommonUtil.ConvertToXml <dtAttachFileForGridView>(lstAttachedName, "Contract\\CTS260_attach", CommonUtil.GRID_EMPTY_TYPE.INSERT);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        public ActionResult CTS260()
        {
            CTS260_ScreenParameter param = GetScreenObject <CTS260_ScreenParameter>();

            if (param != null)
            {
                ViewBag.strProjectCode = param.strProjectCode;
            }


            IProjectHandler ProjH = ServiceContainer.GetService <IProjectHandler>() as IProjectHandler;
            List <tbt_ProjectStockoutBranchIntrumentDetails> lstBranch;

            lstBranch = ProjH.GetTbt_ProjectStockoutBranchIntrumentDetails(param.strProjectCode);
            if (lstBranch.Count > 0)
            {
                ViewBag.BranchDDL = lstBranch[0].ProjectCodeBranchNo;
            }
            return(View());
        }
        /// <summary>
        /// Authority screen CTS260
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult CTS260_Authority(CTS260_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_PROJ_VIEW))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }
                //Valid Cond

                //if (CommonUtil.IsNullOrEmpty(param.strProjectCode))
                //{
                //    if (!CommonUtil.IsNullOrEmpty(CommonUtil.dsTransData.dtCommonSearch.ProjectCode))
                //    {
                //        param.strProjectCode = CommonUtil.dsTransData.dtCommonSearch.ProjectCode;
                //    }
                //}
                if (param.CommonSearch != null)
                {
                    if (CommonUtil.IsNullOrEmpty(param.CommonSearch.ProjectCode) == false)
                    {
                        param.strProjectCode = param.CommonSearch.ProjectCode;
                    }
                }

                //ValidatorUtil.BuildErrorMessage(res, this, null);
                //if (res.IsError)
                //{
                //    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                //    return Json(res);
                //}
                //if (CommonUtil.IsNullOrEmpty(param.strProjectCode))
                //{
                //    res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3216, new string[] { "lblProjectCode" });
                //    return Json(res);
                //}

                //IProjectHandler Projh = ServiceContainer.GetService<IProjectHandler>() as IProjectHandler;
                //List<doTbt_Project> lstProject = Projh.GetTbt_ProjectForView(param.strProjectCode);
                //if (lstProject.Count <= 0)
                //{
                //    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0091, new string[] { param.strProjectCode });
                //    return Json(res);
                //}
                if (CommonUtil.IsNullOrEmpty(param.strProjectCode) == false)
                {
                    IProjectHandler      projH         = ServiceContainer.GetService <IProjectHandler>() as IProjectHandler;
                    List <doTbt_Project> doTbt_Project = projH.GetTbt_ProjectForView(param.strProjectCode);
                    if (doTbt_Project.Count <= 0)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0091, new string[] { param.strProjectCode });
                        return(Json(res));
                    }
                }

                // param.strProjectCode = "p0000132";
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(InitialScreenEnvironment <CTS260_ScreenParameter>("CTS260", param, res));
        }