/// <summary>
        /// Get document's data for downloading.
        /// </summary>
        /// <param name="strPickingListNo">Picking List No.</param>
        /// <returns>Return ActionResult of document's data.</returns>
        public ActionResult IVS240_DownloadPickingList(string strPickingListNo)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                IVS240_ScreenParameter sParam = GetScreenObject <IVS240_ScreenParameter>(); //Add by Jutarat A. on 04122012

                //var docCond = new doDocumentDataCondition()
                //{
                //    DocumentNo = strPickingListNo,
                //    OCC = ConfigName.C_CONFIG_DOC_OCC_DEFAULT,
                //    DocumentCode = ReportID.C_INV_REPORT_ID_PICKING_LIST
                //};
                //IDocumentHandler docHandler = ServiceContainer.GetService<IDocumentHandler>() as IDocumentHandler;
                //var lstDocs = docHandler.GetDocumentDataList(docCond);

                var srvCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                var lstDocs   = srvCommon.GetTbt_DocumentList(strPickingListNo, ReportID.C_INV_REPORT_ID_PICKING_LIST, ConfigName.C_CONFIG_DOC_OCC_DEFAULT);

                if (lstDocs == null || lstDocs.Count <= 0)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0112);
                    res.ResultData = null;
                }
                else
                {
                    string path = PathUtil.GetPathValue(PathUtil.PathName.GeneratedReportPath, lstDocs[0].FilePath);// ReportUtil.GetGeneratedReportPath(lstDocs[0].FilePath);

                    if (System.IO.File.Exists(path) == true)
                    {
                        res.ResultData        = lstDocs[0];
                        sParam.ResultDocument = lstDocs[0]; //Add by Jutarat A. on 04122012
                    }
                    else
                    {
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0112);
                        res.ResultData = null;
                    }
                }
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }
        /// <summary>
        /// Checking user's permission.
        /// </summary>
        /// <param name="param">Screen's parameter.</param>
        /// <returns>Return ActionResult of the screen.</returns>
        public ActionResult IVS240_Authority(IVS240_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                ICommonHandler srvCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (srvCommon.IsSystemSuspending())
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    //res.ResultData = MessageUtil.MessageList.MSG0049.ToString();
                    return(Json(res));
                }

                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_PICKING_LIST, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    //res.ResultData = MessageUtil.MessageList.MSG0053.ToString();
                    return(Json(res));
                }

                IInventoryHandler srvInv = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                if (srvInv.CheckFreezedData() == 0)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4002);
                    //res.ResultData = MessageUtil.MessageList.MSG4002.ToString();
                    return(Json(res));
                }

                if (srvInv.CheckStartedStockChecking() == 0)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4003);
                    //res.ResultData = MessageUtil.MessageList.MSG4003.ToString();
                    return(Json(res));
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(InitialScreenEnvironment <IVS240_ScreenParameter>("IVS240", param, res));
        }
        /// <summary>
        /// Download document.
        /// </summary>
        /// <param name="strDocumentNo">Document No.</param>
        /// <param name="documentOCC">Document OCC.</param>
        /// <param name="strDocumentCode">Document Code.</param>
        /// <param name="fileName">File Name.</param>
        /// <returns>Return ActionResult of file's stream.</returns>
        //public ActionResult IVS240_DownloadPdfAndWriteLog(string strDocumentNo, string documentOCC, string strDocumentCode, string fileName)
        public ActionResult IVS240_DownloadPdfAndWriteLog(string k) //Modify by Jutarat A. on 04122012
        {
            Stream reportStream = null;                             //Add by Jutarat A. on 04122012

            try
            {
                //Modify by Jutarat A. on 04122012
                IVS240_ScreenParameter sParam = GetScreenObject <IVS240_ScreenParameter>(k);
                if (sParam.ResultDocument != null)
                {
                    doDocumentDownloadLog doDownloadLog = new doDocumentDownloadLog()
                    {
                        DocumentNo   = sParam.ResultDocument.DocumentNo,   //strDocumentNo,
                        DocumentCode = sParam.ResultDocument.DocumentCode, //strDocumentCode,
                        DocumentOCC  = sParam.ResultDocument.DocumentOCC,  //documentOCC,
                        DownloadDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                        DownloadBy   = CommonUtil.dsTransData.dtUserData.EmpNo
                    };

                    ILogHandler handlerLog = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
                    int         isSuccess  = handlerLog.WriteDocumentDownloadLog(doDownloadLog);

                    if (sParam.ResultStream != null)
                    {
                        reportStream        = sParam.ResultStream;
                        sParam.ResultStream = null;
                    }
                    else
                    {
                        IDocumentHandler handlerDoc = ServiceContainer.GetService <IDocumentHandler>() as IDocumentHandler;
                        reportStream = handlerDoc.GetDocumentReportFileStream(sParam.ResultDocument.FilePath); //(fileName);
                    }
                }
                //End Modify

                return(File(reportStream, "application/pdf"));
            }
            catch (Exception ex)
            {
                ObjectResultData res = new ObjectResultData();
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }
        /// <summary>
        /// Confirming picking list registration.
        /// </summary>
        /// <param name="lstInstallationSlipNo">List of installation slip no. for registering.</param>
        /// <returns>Return ActionResult of confirmation process result.</returns>
        public ActionResult IVS240_ConfirmPickingList(List <string> lstInstallationSlipNo)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION; //All message during confirmation process must be information dialog box.

            try
            {
                IVS240_ScreenParameter sParam = GetScreenObject <IVS240_ScreenParameter>(); //Add by Jutarat A. on 04122012

                ICommonHandler srvCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (srvCommon.IsSystemSuspending())
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);
                    return(Json(res));
                }

                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_PICKING_LIST, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);
                    return(Json(res));
                }

                if (lstInstallationSlipNo == null || lstInstallationSlipNo.Count <= 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4063);
                    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);
                    return(Json(res));
                }

                IInventoryHandler srvInv   = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                List <string>     lstError = new List <string>();

                List <tbt_InventorySlip> lstInvSlip = new List <tbt_InventorySlip>();
                foreach (var strInstallationSlipNo in lstInstallationSlipNo)
                {
                    var lstTempInvSlip = srvInv.GetTbt_InventorySlip(null, strInstallationSlipNo);
                    //if (lstInvSlip.Count > 0 && lstInvSlip[0].PickingListNo != null)
                    //{
                    //    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4064
                    //        , new string[] { strInstallationSlipNo });
                    //    lstError.Add(strInstallationSlipNo);
                    //}

                    if (lstTempInvSlip.Any(p => p.PickingListNo != null))
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4064
                                            , new string[] { strInstallationSlipNo });
                        lstError.Add(strInstallationSlipNo);
                        res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, lstError, null);
                        return(Json(res));
                    }

                    lstInvSlip.AddRange(lstTempInvSlip);
                }

                //if (lstError.Count > 0)
                //{
                //    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, lstError, null);
                //    return Json(res);
                //}

                string strPickingListNo = srvInv.GeneratePickingListNo();

                #region //R2
                foreach (var slip in lstInvSlip)
                {
                    slip.PickingListNo = strPickingListNo;

                    //Comment by Jutarat A. on 30052013 (Set at UpdateTbt_InventorySlip())
                    //slip.UpdateBy = CommonUtil.dsTransData.dtUserData.EmpNo;
                    //slip.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    //End Comment
                }
                #endregion

                srvInv.UpdateTbt_InventorySlip(lstInvSlip);

                IInventoryDocumentHandler srvInvDoc = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;

                //srvInvDoc.GenerateIVR170FilePath(strPickingListNo, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                sParam.ResultStream = srvInvDoc.GenerateIVR170(strPickingListNo, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime); //Modify by Jutarat A. on 04122012

                res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(true, null, strPickingListNo);
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
                res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);;
                return(Json(res));
            }
        }