コード例 #1
0
        public override SAPResponse ExecuteQuery()
        {
            System.Diagnostics.Debug.WriteLine("<HEADER_QUERY FROM = 'DATABASE'>");
            using (var dao = new BillingDbContext())
            {
                var sql       = from o in dao.InvoiceProformaHeaders.Where(o => o.No == _no) select o;
                var dbRawHead = sql.FirstOrDefault();
                if (dbRawHead != null)
                {
                    var ver = "Final";
                    if (dbRawHead.Draft)
                    {
                        ver = "Draft";
                    }
                    var head = new RunInvoiceHeaderDTO
                    {
                        BillingDateFrom     = dbRawHead.StartDate,
                        BillingDateTo       = dbRawHead.EndDate,
                        BillingDocsCriteria = dbRawHead.BillingBlock,
                        BillingNo           = dbRawHead.BillingNo,
                        ReasonForRejection  = dbRawHead.ReasonForRejection,
                        SoldToParty         = dbRawHead.SoldToParty,
                        Version             = dbRawHead.Version.ToString(CultureInfo.InvariantCulture),
                        CreatedBy           = dbRawHead.ERNAM,
                        CreateOn            = dbRawHead.ERDAT,
                        Time            = dbRawHead.ERZET,
                        ProformaFlag    = dbRawHead.ProformaFlag,
                        BillingType     = Properties.Settings.Default.BillingType,
                        SoldToPartyName = dbRawHead.SoldToParty,
                        Draft           = dbRawHead.Draft,
                        BillingRun      =
                            dbRawHead.SoldToParty + " | " + dbRawHead.Version + " | " +
                            dbRawHead.Created.ToString("dd MMM yyyy") + " | " + ver
                    };

                    InMemoryCache.Instance.ClearCached(Username + Suffix.REQUEST_HEADER);
                    InMemoryCache.Instance.Cache(Username + Suffix.REQUEST_HEADER, head);

                    var rawHead = new InvoiceProformaHeaderDto
                    {
                        CITY1      = dbRawHead.CITY1,
                        ERDAT      = dbRawHead.ERDAT,
                        ERNAM      = dbRawHead.ERNAM,
                        ERZET      = dbRawHead.ERZET,
                        FKDAT      = dbRawHead.FKDAT,
                        FPAJAK_NO  = dbRawHead.FPAJAK_NO,
                        HTOTAL1    = dbRawHead.HTOTAL1,
                        HTOTAL2    = dbRawHead.HTOTAL2,
                        HTOTAL3    = dbRawHead.HTOTAL3,
                        HTOTAL4    = dbRawHead.HTOTAL4,
                        HTOTAL5    = dbRawHead.HTOTAL5,
                        KUNRG      = dbRawHead.KUNRG,
                        KURRF      = dbRawHead.KURRF,
                        NAME1      = dbRawHead.NAME1,
                        NAME2      = dbRawHead.NAME2,
                        NAME3      = dbRawHead.NAME3,
                        NAME4      = dbRawHead.NAME4,
                        No         = dbRawHead.No,
                        POST_CODE1 = dbRawHead.POST_CODE1,
                        STCEG      = dbRawHead.STCEG,
                        STREET     = dbRawHead.STREET,
                        TDLINE     = dbRawHead.TDLINE,
                        TEXT1      = dbRawHead.TEXT1,
                        VBELN      = dbRawHead.VBELN,
                        VTEXT      = dbRawHead.VTEXT,
                        WAERK      = dbRawHead.WAERK,
                        ZTERM      = dbRawHead.ZTERM
                    };

                    InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_PROFORMA_HEADER);
                    InMemoryCache.Instance.Cache(Username + Suffix.QUERIED_PROFORMA_HEADER, rawHead);

                    InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_VERSION_FROM_DB);
                    InMemoryCache.Instance.Cache(Username + Suffix.QUERIED_VERSION_FROM_DB, dbRawHead.Version);
                    System.Diagnostics.Debug.WriteLine("<HEADER_QUERY VERSION = '" + head.Version + "'/>");

                    InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_FROM_DB);
                    InMemoryCache.Instance.Cache(Username + Suffix.QUERIED_FROM_DB, true);

                    System.Diagnostics.Debug.WriteLine("</HEADER_QUERY>");

                    return(head);
                }
                throw new FaultException("Selected header is null!");
            }
        }
        public override SAPResponse ExecuteQuery()
        {
            InMemoryCache.Instance.ClearCached(Username + Suffix.PERFORMED_INITIAL_SAVE);
            InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_SAP_SESSIONID);
            System.Diagnostics.Debug.WriteLine("<HEADER_QUERY FROM = 'SAP'>");
            var cred = ParseCredential(Username);
            var dest = SAPConnectionFactory.Instance.GetRfcDestination(cred);

            if (dest != null)
            {
                var rawHeader = new InvoiceProformaHeaderDto();
                var repo      = dest.Repository;

                System.Diagnostics.Debug.WriteLine("<HEADER_QUERY START_TIME = '" + DateTime.Now + "'/>");

                var func = repo.CreateFunction("ZBAPI_PRINT_BILLING");
                func.SetValue("BILL_NO", _billingNo);
                func.SetValue("PROFORMA_FLAG", " ");
                func.SetValue("BILLING_BLOCK", " ");
                func.SetValue("REASON_FOR_REJECTION", " ");
                func.SetValue("PAGING", " ");
                func.SetValue("MAXROWS", 1);
                func.Invoke(dest);

                System.Diagnostics.Debug.WriteLine("<HEADER_QUERY END_TIME = '" + DateTime.Now + "'/>");

                var headerTbl = func.GetTable("HEADER");
                headerTbl.CurrentIndex = 0;
                var headerStruct = headerTbl.CurrentRow;
                SAPDataCopier.Instance.CopyFromStruct(headerStruct, rawHeader);

                InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_PROFORMA_HEADER);
                InMemoryCache.Instance.Cache(Username + Suffix.QUERIED_PROFORMA_HEADER, rawHeader);

                var cachedBillingNumbers = InMemoryCache.Instance.GetCached(Username + Suffix.QUERIED_BILLING_NUMBERS) as InvoiceProformaBillingNumberDTO[];
                var head = InMemoryCache.Instance.GetCached(Username + Suffix.REQUEST_HEADER) as RunInvoiceHeaderDTO;
                if (head != null)
                {
                    InMemoryCache.Instance.ClearCached(Username + Suffix.REQUEST_HEADER);
                    head.BillingNo           = _billingNo;
                    head.BillingDocsCriteria = _billingBlock;
                    head.ReasonForRejection  = _reasonForRejection;
                    head.ProformaFlag        = _proformaFlag;
                    head.BillingDateFrom     = head.BillingDateFrom;
                    head.BillingDateTo       = head.BillingDateTo;
                    head.CreatedBy           = rawHeader.ERNAM;
                    head.CreateOn            = rawHeader.ERDAT;
                    head.Time        = rawHeader.ERZET;
                    head.BillingType = Properties.Settings.Default.BillingType;
                    head.BillingRun  = head.SoldToParty + " | 0 | " + DateTime.Now.ToString("dd MMM yyyy") + " | draft";
                    head.Version     = "0";

                    InMemoryCache.Instance.ClearCached(Username + Suffix.REQUEST_HEADER);
                    InMemoryCache.Instance.Cache(Username + Suffix.REQUEST_HEADER, head);

                    if (cachedBillingNumbers != null)
                    {
                        var bil = cachedBillingNumbers.ToList().Find(o => o.VBELN == _billingNo);
                        if (bil != null)
                        {
                            head.SoldToPartyName = bil.NAME1;
                        }
                    }

                    InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_FROM_DB);
                    InMemoryCache.Instance.Cache(Username + Suffix.QUERIED_FROM_DB, false);
                    InMemoryCache.Instance.ClearCached(Username + Suffix.QUERIED_VERSION_FROM_DB);

                    System.Diagnostics.Debug.WriteLine("</HEADER_QUERY>");
                    return(head);
                }
                System.Diagnostics.Debug.WriteLine("</HEADER_QUERY>");
                throw new FaultException("Header not found received username = "******" is not in Session!");
            }
            System.Diagnostics.Debug.WriteLine("</HEADER_QUERY>");
            throw new FaultException("RfcDestination is null!");
        }