Beispiel #1
0
        /// <summary>
        /// Write history of downloaded document log
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public int WriteDocumentDownloadLog(doDocumentDownloadLog cond)
        {
            try
            {
                int iResult = -1000;

                ApplicationErrorException.CheckMandatoryField(cond);

                using (TransactionScope t = new TransactionScope())
                {
                    // do stuff... update, delete
                    iResult = base.WriteDocumentDownloadLog(cond.DocumentNo, cond.DocumentCode, cond.DownloadDate, cond.DownloadBy, cond.DocumentOCC);

                    t.Complete();
                }

                return(iResult);
            }
            catch (Exception)
            {
                throw;
            }
        }
        // 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);
        }