Exemple #1
0
        /// <summary>
        /// Mothod for download document (PDF) and write history to download log
        /// </summary>
        /// <param name="strDocumentNo"></param>
        /// <param name="documentOCC"></param>
        /// <param name="strDocumentCode"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public ActionResult CMS030_DownloadPdfAndWriteLog(string strDocumentNo, string documentOCC, string strDocumentCode, string fileName)
        {
            ObjectResultData       res    = new ObjectResultData();
            CMS030_ScreenParameter sParam = GetScreenObject <CMS030_ScreenParameter>(); //Add by Jutarat A. on 17082012

            using (TransactionScope t = new TransactionScope())
            {
                try
                {
                    // doDocumentDownloadLog
                    doDocumentDownloadLog cond = new doDocumentDownloadLog();
                    cond.DocumentNo   = strDocumentNo;
                    cond.DocumentCode = strDocumentCode;
                    cond.DownloadDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    cond.DownloadBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                    cond.DocumentOCC = documentOCC;

                    ILogHandler handlerLog = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
                    int         isOK       = handlerLog.WriteDocumentDownloadLog(cond);

                    //Update firstIssueFlag for invoice report
                    if (cond.DocumentCode == ReportID.C_REPORT_ID_INVOICE)
                    {
                        IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                        billingHandler.UpdateFirstIssue(cond.DocumentNo, cond.DocumentOCC, cond.DownloadDate.Value, CommonUtil.dsTransData.dtUserData.EmpNo);
                    }

                    IDocumentHandler handlerDoc   = ServiceContainer.GetService <IDocumentHandler>() as IDocumentHandler;
                    Stream           reportStream = handlerDoc.GetDocumentReportFileStream(fileName);

                    FileInfo fileinfo = new FileInfo(fileName);
                    if (fileinfo.Extension.ToUpper().Equals(".CSV"))
                    {
                        //Modify by Jutarat A. on 17082012
                        //FileStreamResult result = File(reportStream, "text/csv");
                        //result.FileDownloadName = fileinfo.Name;
                        //t.Complete();
                        //return result;
                        sParam.FileName     = fileinfo.Name;
                        sParam.StreamReport = reportStream;
                        res.ResultData      = true;

                        t.Complete();
                        return(Json(res));
                        //End Modify
                    }
                    else
                    {
                        t.Complete();
                        return(File(reportStream, "application/pdf"));
                    }
                }
                catch (Exception ex)
                {
                    t.Dispose();
                    res.AddErrorMessage(ex);
                    return(Json(res));
                }
            }
        }
        // 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);
        }