예제 #1
0
        public ActionResult DownloadNotaDebito(int country, int office, DateTime date, int invoice)
        {
            Guid            id       = CommTools.ToGuid(country, office, date.ToInt(), invoice);
            ObjectFileCache cache    = new ObjectFileCache(Config.FILECACHEFOLDER);
            var             buffer   = cache.Get("pdf_" + id, () => ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice));
            string          fileName = string.Format("{0}_{1}_{2:dd-MM-yyyy}_{3}.pdf", country, office, date, invoice);

            return(base.File(buffer, "application/pdf", fileName));
        }
예제 #2
0
        public ActionResult ShowDetails(int country, int office, DateTime date, int invoice)
        {
            Guid id = CommTools.ToGuid(country, office, date.ToInt(), invoice);

            ObjectFileCache cache         = new ObjectFileCache(Config.FILECACHEFOLDER);
            string          bodyFileName  = string.Concat("body_", id);
            string          styleFileName = string.Concat("style_", id);
            string          body          = cache.Get(bodyFileName, () =>
            {
                var buffer1 = ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice, "XML");
                string xml  = Encoding.UTF8.GetString(buffer1);

                var buffer2    = ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice, "HTML4.0", "&rc:Toolbar=False&rc:Section=0");
                var html       = Encoding.UTF8.GetString(buffer2);
                string bodyTag = html.GetTags("body").FirstOrDefault();
                if (bodyTag == null)
                {
                    throw new ArgumentException("Body tag empty");
                }

                var builder = new StringBuilder(bodyTag);
                foreach (string v_number in xml.Search("inv_v_number2\\s*=\\s*\"(?<value>[0-9]+)\"", (Match m) => m.Groups["value"].Value))
                {
                    builder.Replace(v_number, string.Concat("<a href=", Config.SITEROOT, "/Voucher/ShowBy?iso_id=", country, "&v_number=", v_number, " >", v_number, "</a>"));
                }

                bodyTag      = builder.ToString();
                bodyTag      = bodyTag.ReplaceTags("img", new MatchEvaluator(ImgMatchEvaluator));
                var styleTag = html.GetTags("style").FirstOrDefault();
                cache.Set(styleFileName, styleTag);
                return(bodyTag);
            });
            string style = cache.Get(styleFileName, () => string.Empty);


            return(View(new string[] { body, style }));
        }
예제 #3
0
        public byte[] DownloadVouchers(int countryId, int[] voucherIds, string s1, string s2)
        {
            DirectoryInfo session = null;

            try
            {
                SecurityCheckThrow(s1, s2);
                RecordCallHistory("DownloadReport");

                Guid guid = CommTools.ToGuid(countryId, voucherIds.Get(0), voucherIds.Get(1), voucherIds.Get(2));
                var  dir  = new DirectoryInfo(Global.Strings.DOWNLOADROOT);
                dir.EnsureDirectory();
                session = dir.Combine(guid.ToString());
                session.EnsureDirectory();
                var result = dir.CombineFileName(string.Concat(guid.ToString(), ".zip"));

                var dac = VoucherDataAccess.Instance;
                var zac = ZipFileAccess.Instance;

                CString str = "Archive created at";
                str += DateTime.Now;
                str.NewLine();
                str += "Voucher numbers :";
                str.NewLine();

                foreach (int voucherId in voucherIds)
                {
                    bool   isProtected;
                    string sessionId;
                    int    size;

                    FileInfo binFile = null;
                    FileInfo zipFile = null;
                    try
                    {
                        using (var buffer = new MemoryBuffer(MAX_BUFF_SIZE_50MB))
                        {
                            if (dac.SelectVoucherByNumber(countryId, voucherId, out isProtected, out sessionId, out size, buffer.Buffer))
                            {
                                binFile = session.CombineFileName(string.Concat(sessionId, ".bin"));
                                zipFile = session.CombineFileName(string.Concat(sessionId, ".zip"));

                                if (isProtected)
                                {
                                    binFile.WriteAllBytes(buffer.Buffer, size);
                                    binFile.DecriptFile(zipFile);
                                }
                                else
                                {
                                    zipFile.WriteAllBytes(buffer.Buffer, size);
                                }

                                str += voucherId;
                            }
                            else
                            {
                                str += string.Format("Voucher {0} not found", voucherId);
                            }
                        }

                        var files = zac.ExtractFileZip(zipFile.FullName, session.FullName);
                        foreach (var f in files)
                        {
                            if (!f.Extension.EqualNoCase(".pdf") && !f.Name.Contains("_signed"))
                            {
                                f.DeleteSafe();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        str += ex.Message;
                    }
                    finally
                    {
                        str.NewLine();
                        binFile.DeleteSafe();
                        zipFile.DeleteSafe();
                    }
                }

                zac.CreateZip(result.FullName, session.FullName, str.ToString());

                return(null);
            }
            catch (Exception ex)
            {
                throw new FaultException <MyApplicationFault>(new MyApplicationFault(), ex.Message);
            }
            finally
            {
                session.DeleteSafe();
            }
        }
예제 #4
0
        public virtual void PrintVouchersInternal(int allocationId, List <int> voucherNumbers)
        {
            try
            {
                if (string.IsNullOrEmpty(m_PrinterName))
                {
                    throw new ArgumentNullException("PrinterName", "Value can not be null or empty");
                }

                if (string.IsNullOrEmpty(m_ReportType2))
                {
                    throw new ArgumentNullException("ReportType2", "Value can not be null or empty");
                }

                if (string.IsNullOrEmpty(m_PrinterXmlFilePath))
                {
                    throw new ArgumentNullException("PrinterXmlFilePath", "Value can not be null or empty");
                }

                if (!File.Exists(m_PrinterXmlFilePath))
                {
                    throw new IOException("Can not find file");
                }

                AllocationId = allocationId;

                lock (this)
                {
                    while (ms_VPItems.IndexOf(this) != 0)
                    {
                        Monitor.Wait(this, 3000);
                    }
                }

                Printing = new VoucherNumberingAllocationPrinting.VoucherNumberingAllocationPrinting();
                Manager  = new PartyManagement.PartyManagement();

                Allocation = new Func <int, VoucherAllocation>((x) => Printing.RetrieveAllocation(x)).ReTry(allocationId);

                if (Allocation == null)
                {
                    throw new ArgumentNullException("Can not get allocation:".concat(allocationId));
                }

                Retailer = new Func <int, int, Retailer>((x, y) => Manager.RetrieveRetailerDetail(x, y)).ReTry(Allocation.CountryId, Allocation.RetailerId);

                if (Retailer == null)
                {
                    throw new ArgumentNullException("Can not find retailer:".concat(" CountryId: ", Allocation.CountryId, " RetailerId: ", Allocation.RetailerId));
                }

                Office = new Func <int, int, PtfOffice>((x, y) => Manager.RetrievePtfOfficeDetail(x, y)).ReTry(Retailer.CountryId, Retailer.PrinterBranchId);

                if (Office == null)
                {
                    throw new ArgumentNullException("Can not get office:".concat(" CountryId: ", Allocation.CountryId, " PrinterBranchId:", Retailer.PrinterBranchId));
                }

                var guid = CommTools.ToGuid(Allocation.CountryId, Allocation.RetailerId);

                PrinterDetails printer = null;
                CacheManager.Instance.Get <PrinterDetails>(guid, out printer,
                                                           () => new Func <int, int, PrinterDetails>((x, y) => Manager.GetPrinterInfo(x, y)).ReTry(Retailer.CountryId, Allocation.RetailerId));

                if (printer == null || printer.IsEmpty || UseLocalFormat)
                {
                    printer = new PrinterDetails
                    {
                        Name       = "Default",
                        Path       = m_PrinterName,
                        Type2      = m_ReportType2,
                        Xml        = File.ReadAllText(m_PrinterXmlFilePath),
                        IsoID      = Retailer.CountryId,
                        RetailerID = Allocation.RetailerId,
                    };
                }

                if (UseLocalPrinter)
                {
                    printer.Path = m_PrinterName;
                }

                #region LOCAL PRINTER
                //if (!PrintManager.GetInstalledPrinters().Contains(printer.Path, StringComparer.InvariantCultureIgnoreCase))
                //    throw new ApplicationException("Can not find printer ".concat(printer.Path));
                #endregion

                int countryId = Allocation.CountryId;

                InitPrinter("Initialization_".concat(Retailer.Name, DateTime.Now.Ticks));

                RangeFrom = Allocation.RangeFrom / 10;
                RangeTo   = Allocation.RangeTo / 10;

                //  VPrinting.Documents.VoucherPrintLayout250
                Type documentType = Type.GetType(printer.Type2);
                if (documentType == null)
                {
                    throw new ArgumentNullException("documentType", "Can not find type of: ".concat(printer.Type2));
                }

                XmlSerializer formatter = new XmlSerializer(documentType);
                var           layout    = formatter.ToObject <IVoucherLayout>(printer.Xml);
                if (layout == null)
                {
                    throw new ArgumentNullException("layout", "Can not create layout from xml");
                }
                layout.Init();

                CacheManager.Instance.Table[Strings.IVoucherLayout] = layout;

                CacheManager.Instance.Table[Strings.SubRangeFrom] = RangeFrom;

                var multyLines = new Queue <IList <IPrintLine> >();

                int index = 0;

                foreach (int voucher in voucherNumbers)
                {
                    CacheManager.Instance.Table[Strings.Index] = index++;

                    VoucherNo = voucher;

                    //Counting starts from 1 for us.
                    StrVoucherNo = new Func <int, int, bool, string>((x, y, z) => Printing.CreateVoucherNumber(x, y, z)).ReTry(countryId, voucher, false);

                    layout.Clear();
                    layout.DataBind(this, StrVoucherNo, voucher, false);

                    for (int count = 0; count < Repeat[countryId]; count++)
                    {
#if DEBUGGER
                        Debug.WriteLine(string.Format("{0}\t{1}\t{2}", countryId, Retailer.Name, voucher), Strings.VRPINT);
#endif

                        multyLines.Enqueue(new List <IPrintLine>(layout.PrintLines));
                        if (!SimulatePrint && !MultyPagePrint)
                        {
                            layout.PrintVouchers(printer.Path, StrVoucherNo, layout.FormLength, layout.DocumentInitialization, multyLines);
                        }

                        if (Test != null)
                        {
                            Test(this, EventArgs.Empty);
                        }

                        if (PrintOnce)
                        {
                            break;
                        }
                    }

                    if (PrintOnce)
                    {
                        break;
                    }
                }

                if (!SimulatePrint && MultyPagePrint && multyLines.Count > 0)
                {
                    layout.PrintVouchers(printer.Path, Strings.VRPINT, layout.FormLength, layout.DocumentInitialization, multyLines);
                }

                if (!SimulatePrint)
                {
                    new Action <int, int, int>((x, y, z) => Printing.LogVoucherAllocationPrinted(x, y, z)).ReTry(allocationId, Program.currentUser.UserID, Program.currentUser.CountryID);
                    new Action <int, bool, int>((x, y, z) => Printing.SetVoucherAllocationPrinted(x, y, z)).ReTry(allocationId, true, Program.currentUser.UserID);
                }
                //set the printed status to true
            }
            catch (Exception ex)
            {
                if (Error != null)
                {
                    Error(this, new ThreadExceptionEventArgs(ex));
                }
            }
            finally
            {
                if (Done != null)
                {
                    Done(this, EventArgs.Empty);
                }
            }
        }
예제 #5
0
 public System.Guid GetKey()
 {
     return(CommTools.ToGuid(IsoID, RetailerID));
 }