// CMP120
        /// <summary>
        /// Batch Printing Service Process (call sp_CM_DocumentListForPrining)
        /// </summary>
        /// <param name="UserId">User id</param>
        /// <param name="BatchDate">Batch date</param>
        /// <returns></returns>
        public doBatchProcessResult CMP120_PrintingServiceProcess(string UserId, DateTime BatchDate)
        {
            doBatchProcessResult result          = new doBatchProcessResult();
            DocumentHandler      documentHandler = new DocumentHandler();
            ILogHandler          logHandler      = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
            IBillingHandler      billingHandler  = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
            ICommonHandler       comHandler      = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; //Add by Jutarat A. on 17092013

            //--- variable
            string pathFoxit    = ConfigurationManager.AppSettings["PrintPDFFoxit"];
            string pathFileName = string.Empty;

            List <dtDocumentListForPrining> dtDocumentListForPriningData = documentHandler.GetDocumentListForPrining(DocumentType.C_DOCUMENT_TYPE_INCOME, DocumentType.C_DOCUMENT_TYPE_COMMON, BatchDate, null, null);

            if (dtDocumentListForPriningData != null && dtDocumentListForPriningData.Count > 0)
            {
                // Initial value of doBatchProcessResult
                result.Result       = false;
                result.Total        = dtDocumentListForPriningData.Count;
                result.Complete     = 0;
                result.Failed       = 0;
                result.ErrorMessage = string.Empty;

                //logHandler.SearchFoxitProcess("CMP120"); //Add by Jutarat A. on 20082013
                //}

                //Add by Jutarat A. on 17092013
                string strErrorMessage = string.Empty;
                bool   bResult         = comHandler.AllocatePrintingProcess(PrintingFlag.C_PRINTING_FLAG_CMP120, ProcessID.C_PROCESS_ID_PRINTING_SERVICE, ref strErrorMessage);
                if (bResult)
                //End Add
                {
                    foreach (dtDocumentListForPrining list in dtDocumentListForPriningData)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            try
                            {
                                //3.1
                                doDocumentDownloadLog cond = new doDocumentDownloadLog();
                                cond.DocumentNo   = list.DocumentNo;
                                cond.DocumentCode = list.DocumentCode;
                                cond.DocumentOCC  = list.DocumentOCC;
                                cond.DownloadDate = BatchDate;
                                cond.DownloadBy   = ProcessID.C_PROCESS_ID_PRINTING_SERVICE;
                                logHandler.WriteDocumentDownloadLog(cond);

                                //============ Teerapong 23/07/2012 ===============
                                billingHandler.UpdateFirstIssue(list.DocumentNo, cond.DocumentOCC, BatchDate, UserId);
                                //=================================================

                                //3.2 Send data to specified printer to print documents
                                //PrintPDF(list.FilePathDocument);
                                comHandler.PrintPDF(list.FilePathDocument); //Modify by Jutarat A. on 17092013

                                //3.3
                                scope.Complete();
                                result.Complete++;
                            }
                            catch (Exception ex)
                            {
                                scope.Dispose();
                                result.Failed++;
                                result.ErrorMessage += string.Format("DocumentNo {0} DocumentCode {1} DocumentOCC {2} has Error : {3} {4}\n", list.DocumentNo, list.DocumentCode, list.DocumentOCC, ex.Message, ex.InnerException != null ? ex.InnerException.Message : "");

                                break; //Add by Jutarat A. on 03072013
                            }
                        }
                    }

                    bResult = comHandler.ResetPrintingProcess(ProcessID.C_PROCESS_ID_PRINTING_SERVICE); //Add by Jutarat A. on 17092013
                }
                //Add by Jutarat A. on 17092013
                else
                {
                    result.Failed = result.Total;
                    if (String.IsNullOrEmpty(strErrorMessage) == false)
                    {
                        result.ErrorMessage = strErrorMessage;
                    }
                }
                //End Add
            }

            result.Result      = (result.Failed == 0);
            result.BatchStatus = (result.Result ? BatchStatus.C_BATCH_STATUS_SUCCEEDED : BatchStatus.C_BATCH_STATUS_FAILED);
            return(result);
        }
Exemple #2
0
        internal doBatchProcessResult BatchPrintDebtTracingNoticeProcess(string UserId, DateTime BatchDate, string strServiceTypeCode)
        {
            doBatchProcessResult result        = new doBatchProcessResult();
            IncomeHandler        incomeHandler = new IncomeHandler();
            ILogHandler          logHandler    = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
            ICommonHandler       comHandler    = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

            string pathFoxit    = ConfigurationManager.AppSettings["PrintPDFFoxit"];
            string pathFileName = string.Empty;
            string processID    = (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE ? ProcessID.C_PROCESS_ID_PRINTING_DEBT_NOTICE_SALE : ProcessID.C_PROCESS_ID_PRINTING_DEBT_NOTICE_RENTAL);
            string printflag    = (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE ? PrintingFlag.C_PRINTING_FLAG_ICP080 : PrintingFlag.C_PRINTING_FLAG_ICP090);

            List <doDebtTracingDocNoForPrinting> lstDocNo = incomeHandler.GetDebtTracingDocNoForPrinting(BatchDate, strServiceTypeCode);

            if (lstDocNo != null && lstDocNo.Count > 0)
            {
                result.Result       = false;
                result.Total        = lstDocNo.Count;
                result.Complete     = 0;
                result.Failed       = 0;
                result.ErrorMessage = string.Empty;

                string strErrorMessage = string.Empty;
                bool   bResult         = comHandler.AllocatePrintingProcess(printflag, processID, ref strErrorMessage);
                if (bResult)
                {
                    foreach (doDebtTracingDocNoForPrinting doc in lstDocNo)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            try
                            {
                                doDocumentDownloadLog cond = new doDocumentDownloadLog();
                                cond.DocumentNo   = doc.DocumentNo;
                                cond.DocumentCode = doc.DocumentCode;
                                cond.DocumentOCC  = doc.DocumentOCC;
                                cond.DownloadDate = BatchDate;
                                cond.DownloadBy   = processID;
                                logHandler.WriteDocumentDownloadLog(cond);

                                incomeHandler.UpdateDebtTracingNoticePrintFlag(doc.DocumentNo);
                                comHandler.PrintPDF(doc.FilePathDocument);

                                scope.Complete();
                                result.Complete++;
                            }
                            catch (Exception ex)
                            {
                                scope.Dispose();
                                result.Failed++;
                                result.ErrorMessage += string.Format("DocumentNo {0} DocumentCode {1} DocumentOCC {2} has Error : {3} {4}\n"
                                                                     , doc.DocumentNo
                                                                     , doc.DocumentCode
                                                                     , doc.DocumentOCC
                                                                     , ex.Message
                                                                     , ex.InnerException != null ? ex.InnerException.Message : ""
                                                                     );
                                break;
                            }
                        }
                    }

                    bResult = comHandler.ResetPrintingProcess(processID);
                }
                else
                {
                    result.Failed = result.Total;
                    if (String.IsNullOrEmpty(strErrorMessage) == false)
                    {
                        result.ErrorMessage = strErrorMessage;
                    }
                }
            }

            result.Result      = (result.Failed == 0);
            result.BatchStatus = (result.Result ? BatchStatus.C_BATCH_STATUS_SUCCEEDED : BatchStatus.C_BATCH_STATUS_FAILED);
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Reprint Data and get document list for printing
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult CMS460_ReprintData(CMS460_ScreenInputValidate data)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                //Check permission
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_REPRINT_BILLING_RELATED_DOCUMENT, FunctionID.C_FUNC_ID_VIEW) == false)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007);
                    return(Json(res));
                }

                //Check Require field
                if (ModelState.IsValid == false)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    ValidatorUtil.BuildErrorMessage(res, this);
                    return(Json(res));
                }

                IDocumentHandler handler    = ServiceContainer.GetService <IDocumentHandler>() as IDocumentHandler;
                ILogHandler      WriteLog   = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
                ICommonHandler   comHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; //Add by Jutarat A. on 17092013

                List <dtDocumentListForPrining> lst = handler.GetDocumentListForPrining(DocumentType.C_DOCUMENT_TYPE_INCOME, DocumentType.C_DOCUMENT_TYPE_COMMON, data.IssueDate, data.ManagementNoFrom, data.ManagementNoTo);
                if (lst == null || lst.Count <= 0)
                {
                    res.ResultData = false;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                    return(Json(res));
                }
                else
                {
                    //WriteLog.SearchFoxitProcess("CMS460"); //Add by Jutarat A. on 20082013

                    //Add by Jutarat A. on 17092013
                    string strErrorMessage = string.Empty;
                    bool   bResult         = comHandler.AllocatePrintingProcess(PrintingFlag.C_PRINTING_FLAG_CMS460, ScreenID.C_SCREEN_ID_REPRINT_BILLING_RELATED_DOCUMENT, ref strErrorMessage);
                    if (bResult)
                    //End Add
                    {
                        foreach (dtDocumentListForPrining doclist in lst)
                        {
                            // doDocumentDownloadLog
                            doDocumentDownloadLog cond = new doDocumentDownloadLog();
                            cond.DocumentNo   = doclist.DocumentNo;
                            cond.DocumentCode = doclist.DocumentCode;
                            cond.DocumentOCC  = doclist.DocumentOCC;
                            cond.DownloadDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            cond.DownloadBy   = CommonUtil.dsTransData.dtUserData.EmpNo;


                            int isSuccess = WriteLog.WriteDocumentDownloadLog(cond);

                            if (doclist.DocumentCode == ReportID.C_REPORT_ID_ISSUE_LIST)
                            {
                                // print per page

                                string   temPath  = PathUtil.GetTempFileName(".pdf");
                                FileInfo fileInfo = new FileInfo(temPath);

                                if (Directory.Exists(fileInfo.DirectoryName) == false)
                                {
                                    Directory.CreateDirectory(fileInfo.DirectoryName);
                                }

                                int?PageFrom = 0;
                                int?PageTo   = 0;
                                if (data.ManagementNoTo <= doclist.MaxManagementNo)
                                {
                                    if (data.ManagementNoFrom < doclist.MinManagementNo)
                                    {
                                        PageFrom = 1;
                                        PageTo   = (data.ManagementNoTo - doclist.MinManagementNo) + 1;
                                    }
                                    else
                                    {
                                        PageFrom = (data.ManagementNoFrom - doclist.MinManagementNo) + 1;
                                        PageTo   = (data.ManagementNoTo - doclist.MinManagementNo) + 1;
                                    }
                                }
                                else
                                {
                                    if (data.ManagementNoFrom < doclist.MinManagementNo)
                                    {
                                        PageFrom = 1;
                                        PageTo   = (doclist.MaxManagementNo - doclist.MinManagementNo) + 1;
                                    }
                                    else
                                    {
                                        PageFrom = (data.ManagementNoFrom - doclist.MinManagementNo) + 1;
                                        PageTo   = (doclist.MaxManagementNo - doclist.MinManagementNo) + 1;
                                    }
                                }

                                bool iSuccess = ReportUtil.PDFSplitPage(doclist.FilePathDocument, (PageFrom ?? 0), (PageTo ?? 0), temPath);

                                if (iSuccess)
                                {
                                    //PrintPDF(temPath);
                                    comHandler.PrintPDF(temPath); //Modify by Jutarat A. on 17092013
                                }

                                System.IO.File.Delete(temPath);
                            }
                            else
                            {
                                FileInfo fileInfo = new FileInfo(doclist.FilePathDocument);
                                if (fileInfo.Exists)
                                {
                                    //PrintPDF(doclist.FilePathDocument);
                                    comHandler.PrintPDF(doclist.FilePathDocument); //Modify by Jutarat A. on 17092013
                                }
                            }
                        }

                        bResult = comHandler.ResetPrintingProcess(ProcessID.C_PROCESS_ID_PRINTING_SERVICE); //Add by Jutarat A. on 17092013
                    }
                    //Add by Jutarat A. on 17092013
                    else
                    {
                        res.ResultData = false;
                        res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0160);
                        return(Json(res));
                    }
                    //End Add
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
                return(Json(res));
            }
            return(Json(res));
        }