SBO二次开发之WebService采购订单接口方法:

 
 public string AddOPORFromXML()
    {
        string sXmlFileName ;
        long iElementCount = 0;
        long iCounter = 0;
        string sErrMsg;
        int lErrCode;
        long lRetCode;
        SAPbobsCOM.Documents ERP_oPOR;
        // setting the file name
        try
        {
            sXmlFileName = System.IO.Directory.GetParent(System.Windows.Forms.Application.StartupPath).ToString();
            //sXmlFileName = System.IO.Directory.GetParent(sXmlFileName).ToString() + @"\OPOR.xml";
          
            Get the number of Business object in the file ...
            sXmlFileName =   @"D:\Interface_SCM\Web\OPOR.xml";
            iElementCount = oCompany.GetXMLelementCount(sXmlFileName);
            iElementCount = oCompany.GetXMLelementCount(@"D:\Interface_SCM\Web\OPOR.xml");
            // start a transaction
            // starting a transaction means that nothing changes in the DB
            // untill we end the transaction with the commit flag
            // if an error is encountered the transaction rolls back
            // which means that all changes as of the StartTransaction
            // are discarded
            oCompany.StartTransaction();
            // Run a loop through the objects and when with in the file
            // and the objects to the DB
            for (iCounter = 0; iCounter <= iElementCount - 1; iCounter++)
            {
                // get the objects type at the specified position
                oCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;
                switch (oCompany.GetXMLobjectType(sXmlFileName, System.Convert.ToInt32(iCounter)))
                {
                    case SAPbobsCOM.BoObjectTypes.oPurchaseOrders:
                        // get the business object data from the file
                        ERP_oPOR = ((SAPbobsCOM.Documents)(oCompany.GetBusinessObjectFromXML(sXmlFileName, System.Convert.ToInt32(iCounter))));
                        // add the object to the data base
                        ERP_oPOR.Add();
                        break;
                }

                // Check for errors during connect
                // if an error is encountered the transaction will
                // terminate automatically
                oCompany.GetLastError(out lErrCode, out sErrMsg);
                if (lErrCode != 0)
                {
                    // exiting the sub
                    return (sErrMsg + "Transaction will be rolled back");
                }
            }
            // the objects will added to the DB only at this point
            oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
            return ("采购订单添加成功!");
        }
        catch (Exception ex)
        {
            return (ex.Message);
        }
    }
 

 
WebServcie服务文件:WebServcie.asmx

 
/// <summary>
/// WebService 的摘要说明222
/// </summary>
[WebService(Namespace = " http://easybuy.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
    public WebService () {
        //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();
    }
    /// <summary>
    /// 【SCM接口】
    /// </summary>
    /// <param name="DocNum"></param>
    /// <returns></returns>
    [WebMethod(Description = "【SCM接口】SCM采购订单同步到SBO系统中;参数:采购订单XML对象")]
    public string AddOPORFromXML()
    {
        SCM OPOR = new SCM();
        return OPOR.AddOPORFromXML();
    }
}

 
XML文件内容如下:OPOR..XML

 
<?xml version="1.0" encoding="UTF-16"?>
<BOM>
 <BO>
  <AdmInfo>
   <Object>22</Object>
   <Version>2</Version>
  </AdmInfo>
  <Documents>
   <row>
    <DocNum>18881</DocNum>
    <DocType>dDocument_Items</DocType>
    <HandWritten>tNO</HandWritten>
    <DocDate>20110906</DocDate>
    <DocDueDate>20110906</DocDueDate>
    <CardCode>1000349</CardCode>
    <CardName>北京1234贸易有限公司</CardName>
    <NumAtCard>189</NumAtCard>
    <DocCurrency>RMB</DocCurrency>
    <DocRate>1.000000</DocRate>
    <DocTotal>18170.000000</DocTotal>
    <Reference1>18881</Reference1>
    <Comments>SCM接口自动生成</Comments>
    <JournalMemo>采购订单 - 1000349</JournalMemo>
    <PaymentGroupCode>-1</PaymentGroupCode>
    <DocTime>1456</DocTime>
    <SalesPersonCode>-1</SalesPersonCode>
    <TransportationCode>-1</TransportationCode>
    <Confirmed>tYES</Confirmed>
    <SummeryType>dNoSummary</SummeryType>
    <ShowSCN>tNO</ShowSCN>
    <Series>10</Series>
    <TaxDate>20110906</TaxDate>
    <PartialSupply>tYES</PartialSupply>
    <DocObjectCode>22</DocObjectCode>
    <DiscountPercent>0.000000</DiscountPercent>
    <RevisionPo>tNO</RevisionPo>
    <BlockDunning>tNO</BlockDunning>
    <Pick>tNO</Pick>
    <PaymentBlock>tNO</PaymentBlock>
    <MaximumCashDiscount>tNO</MaximumCashDiscount>
    <WareHouseUpdateType>dwh_OrdersFromVendors</WareHouseUpdateType>
    <Rounding>tNO</Rounding>
    <DeferredTax>tNO</DeferredTax>
    <NumberOfInstallments>1</NumberOfInstallments>
    <ApplyTaxOnFirstInstallment>tNO</ApplyTaxOnFirstInstallment>
    <DocumentSubType>bod_None</DocumentSubType>
    <Address2>CN</Address2>
    <UseShpdGoodsAct>tNO</UseShpdGoodsAct>
    <IsPayToBank>tNO</IsPayToBank>
    <DownPayment>0.000000</DownPayment>
    <ReserveInvoice>tNO</ReserveInvoice>
    <LanguageCode>15</LanguageCode>
    <SequenceModel>0</SequenceModel>
    <UseCorrectionVATGroup>tNO</UseCorrectionVATGroup>
    <DownPaymentAmount>0.000000</DownPaymentAmount>
    <DownPaymentPercentage>0.000000</DownPaymentPercentage>
    <DownPaymentType>dptInvoice</DownPaymentType>
    <DownPaymentAmountSC>0.000000</DownPaymentAmountSC>
    <DownPaymentAmountFC>0.000000</DownPaymentAmountFC>
    <VatPercent>0.000000</VatPercent>
    <OpeningRemarks></OpeningRemarks>
    <ClosingRemarks></ClosingRemarks>
    <RoundingDiffAmount>0.000000</RoundingDiffAmount>
    <U_FreightStatus>C</U_FreightStatus>
    <U_Carriesfee>0.000000</U_Carriesfee>
    <U_Insurance>0.000000</U_Insurance>
    <U_Agnomen>0.000000</U_Agnomen>
    <U_Weightss>0.000000</U_Weightss>
    <U_InstancyLevel>1</U_InstancyLevel>
    <U_PayMethod>1</U_PayMethod>
    <U_Poundage>0.000000</U_Poundage>
    <U_Invoicetypes>0</U_Invoicetypes>
    <U_SendPlace>110100</U_SendPlace>
    <U_AssetUsed>1</U_AssetUsed>
    <U_PoundageKind>1</U_PoundageKind>
    <U_PurchaseQuality>1</U_PurchaseQuality>
    <U_PurOrderState>189</U_PurOrderState>
    <U_StpStatus>1</U_StpStatus>
    <U_DJZT>2</U_DJZT>
    <U_Fee>0.000000</U_Fee>
   </row>
  </Documents>
  <Document_Lines>
   <row>
    <LineNum>0</LineNum>
    <ItemCode>106764</ItemCode>
    <ItemDescription>索尼爱立信手机</ItemDescription>
    <Quantity>1.000000</Quantity>
    <ShipDate>20110906</ShipDate>
    <Price>1145.300000</Price>
    <PriceAfterVAT>1340.000000</PriceAfterVAT>
    <Currency>RMB</Currency>
    <Rate>0.000000</Rate>
    <DiscountPercent>0.000000</DiscountPercent>
    <WarehouseCode>010101</WarehouseCode>
    <SalesPersonCode>-1</SalesPersonCode>
    <CommisionPercent>0.000000</CommisionPercent>
    <TreeType>iNotATree</TreeType>
    <AccountCode>124301</AccountCode>
    <UseBaseUnits>tNO</UseBaseUnits>
    <BarCode>6948859201152</BarCode>
    <VatGroup>J1</VatGroup>
    <Height1>0.000000</Height1>
    <Height2>0.000000</Height2>
    <Lengh1>0.000000</Lengh1>
    <Lengh2>0.000000</Lengh2>
    <Weight1>0.350000</Weight1>
    <Weight1Unit>3</Weight1Unit>
    <Weight2>0.000000</Weight2>
    <Factor1>1.000000</Factor1>
    <Factor2>1.000000</Factor2>
    <Factor3>1.000000</Factor3>
    <Factor4>1.000000</Factor4>
    <BaseType>-1</BaseType>
    <Volume>0.000000</Volume>
    <VolumeUnit>2</VolumeUnit>
    <Width1>0.000000</Width1>
    <Width2>0.000000</Width2>
    <Address></Address>
    <TaxType>tt_Yes</TaxType>
    <TaxLiable>tYES</TaxLiable>
    <ShippingMethod>-1</ShippingMethod>
    <CorrectionInvoiceItem>ciis_ShouldBe</CorrectionInvoiceItem>
    <CorrInvAmountToStock>0.000000</CorrInvAmountToStock>
    <CorrInvAmountToDiffAcct>0.000000</CorrInvAmountToDiffAcct>
    <WTLiable>tNO</WTLiable>
    <DeferredTax>tNO</DeferredTax>
    <LineTotal>1145.300000</LineTotal>
    <TaxPercentagePerRow>17.000000</TaxPercentagePerRow>
    <ConsumerSalesForecast>tNO</ConsumerSalesForecast>
    <ExciseAmount>0.000000</ExciseAmount>
    <SWW>1545.000000</SWW>
    <DistributeExpense>tYES</DistributeExpense>
    <RowTotalFC>0.000000</RowTotalFC>
    <TaxOnly>tNO</TaxOnly>
    <UnitPrice>1145.300000</UnitPrice>
    <LineStatus>bost_Open</LineStatus>
    <LineType>dlt_Regular</LineType>
    <ItemDetails></ItemDetails>
    <U_StupStatus>N</U_StupStatus>
    <U_ProductPrice>0.000000</U_ProductPrice>
    <U_RelievePrice>0.000000</U_RelievePrice>
    <U_WentPrice>0.000000</U_WentPrice>
    <U_PeriodNumber>0</U_PeriodNumber>
    <U_UnitPrice>0.000000</U_UnitPrice>
    <U_BankRates>0.000000</U_BankRates>
    <U_CarriesFee>0.000000</U_CarriesFee>
    <U_ConsumptionTax>0.000000</U_ConsumptionTax>
    <U_IsSwitch>N</U_IsSwitch>
    <U_Handmoney>0.000000</U_Handmoney>
    <U_Charges>0.000000</U_Charges>
    <U_AssetAmt>0.000000</U_AssetAmt>
    <U_ReqSum>0.000000</U_ReqSum>
   </row>
   <row>
    <LineNum>1</LineNum>
    <ItemCode>106765</ItemCode>
    <ItemDescription>索尼爱立信手机</ItemDescription>
    <Quantity>1.000000</Quantity>
    <ShipDate>20110906</ShipDate>
    <Price>1145.300000</Price>
    <PriceAfterVAT>1340.000000</PriceAfterVAT>
    <Currency>RMB</Currency>
    <Rate>0.000000</Rate>
    <DiscountPercent>0.000000</DiscountPercent>
    <WarehouseCode>010101</WarehouseCode>
    <SalesPersonCode>-1</SalesPersonCode>
    <CommisionPercent>0.000000</CommisionPercent>
    <TreeType>iNotATree</TreeType>
    <AccountCode>124301</AccountCode>
    <UseBaseUnits>tNO</UseBaseUnits>
    <BarCode>6948859200865</BarCode>
    <VatGroup>J1</VatGroup>
    <Height1>0.000000</Height1>
    <Height2>0.000000</Height2>
    <Lengh1>0.000000</Lengh1>
    <Lengh2>0.000000</Lengh2>
    <Weight1>0.350000</Weight1>
    <Weight1Unit>3</Weight1Unit>
    <Weight2>0.000000</Weight2>
    <Factor1>1.000000</Factor1>
    <Factor2>1.000000</Factor2>
    <Factor3>1.000000</Factor3>
    <Factor4>1.000000</Factor4>
    <BaseType>-1</BaseType>
    <Volume>0.000000</Volume>
    <VolumeUnit>2</VolumeUnit>
    <Width1>0.000000</Width1>
    <Width2>0.000000</Width2>
    <Address></Address>
    <TaxType>tt_Yes</TaxType>
    <TaxLiable>tYES</TaxLiable>
    <ShippingMethod>-1</ShippingMethod>
    <CorrectionInvoiceItem>ciis_ShouldBe</CorrectionInvoiceItem>
    <CorrInvAmountToStock>0.000000</CorrInvAmountToStock>
    <CorrInvAmountToDiffAcct>0.000000</CorrInvAmountToDiffAcct>
    <WTLiable>tNO</WTLiable>
    <DeferredTax>tNO</DeferredTax>
    <LineTotal>1145.300000</LineTotal>
    <TaxPercentagePerRow>17.000000</TaxPercentagePerRow>
    <ConsumerSalesForecast>tNO</ConsumerSalesForecast>
    <ExciseAmount>0.000000</ExciseAmount>
    <SWW>1545.000000</SWW>
    <DistributeExpense>tYES</DistributeExpense>
    <RowTotalFC>0.000000</RowTotalFC>
    <TaxOnly>tNO</TaxOnly>
    <UnitPrice>1145.300000</UnitPrice>
    <LineStatus>bost_Open</LineStatus>
    <LineType>dlt_Regular</LineType>
    <ItemDetails></ItemDetails>
    <U_StupStatus>N</U_StupStatus>
    <U_ProductPrice>0.000000</U_ProductPrice>
    <U_RelievePrice>0.000000</U_RelievePrice>
    <U_WentPrice>0.000000</U_WentPrice>
    <U_PeriodNumber>0</U_PeriodNumber>
    <U_UnitPrice>0.000000</U_UnitPrice>
    <U_BankRates>0.000000</U_BankRates>
    <U_CarriesFee>0.000000</U_CarriesFee>
    <U_ConsumptionTax>0.000000</U_ConsumptionTax>
    <U_IsSwitch>N</U_IsSwitch>
    <U_Handmoney>0.000000</U_Handmoney>
    <U_Charges>0.000000</U_Charges>
    <U_AssetAmt>0.000000</U_AssetAmt>
    <U_ReqSum>0.000000</U_ReqSum>
   </row>
   <row>
    <LineNum>2</LineNum>
    <ItemCode>105042</ItemCode>
    <ItemDescription>诺基亚手机</ItemDescription>
    <Quantity>6.000000</Quantity>
    <ShipDate>20110906</ShipDate>
    <Price>1752.140000</Price>
    <PriceAfterVAT>2050.000000</PriceAfterVAT>
    <Currency>RMB</Currency>
    <Rate>0.000000</Rate>
    <DiscountPercent>0.000000</DiscountPercent>
    <WarehouseCode>010101</WarehouseCode>
    <SalesPersonCode>-1</SalesPersonCode>
    <CommisionPercent>0.000000</CommisionPercent>
    <TreeType>iNotATree</TreeType>
    <AccountCode>124301</AccountCode>
    <UseBaseUnits>tNO</UseBaseUnits>
    <BarCode>6907384020089</BarCode>
    <VatGroup>J1</VatGroup>
    <Height1>0.000000</Height1>
    <Height2>0.000000</Height2>
    <Lengh1>0.000000</Lengh1>
    <Lengh2>0.000000</Lengh2>
    <Weight1>3.900000</Weight1>
    <Weight1Unit>3</Weight1Unit>
    <Weight2>0.000000</Weight2>
    <Factor1>1.000000</Factor1>
    <Factor2>1.000000</Factor2>
    <Factor3>1.000000</Factor3>
    <Factor4>1.000000</Factor4>
    <BaseType>-1</BaseType>
    <Volume>0.000000</Volume>
    <VolumeUnit>2</VolumeUnit>
    <Width1>0.000000</Width1>
    <Width2>0.000000</Width2>
    <Address></Address>
    <TaxType>tt_Yes</TaxType>
    <TaxLiable>tYES</TaxLiable>
    <ShippingMethod>-1</ShippingMethod>
    <CorrectionInvoiceItem>ciis_ShouldBe</CorrectionInvoiceItem>
    <CorrInvAmountToStock>0.000000</CorrInvAmountToStock>
    <CorrInvAmountToDiffAcct>0.000000</CorrInvAmountToDiffAcct>
    <WTLiable>tNO</WTLiable>
    <DeferredTax>tNO</DeferredTax>
    <LineTotal>10512.820000</LineTotal>
    <TaxPercentagePerRow>17.000000</TaxPercentagePerRow>
    <ConsumerSalesForecast>tNO</ConsumerSalesForecast>
    <ExciseAmount>0.000000</ExciseAmount>
    <SWW>2384.000000</SWW>
    <DistributeExpense>tYES</DistributeExpense>
    <RowTotalFC>0.000000</RowTotalFC>
    <TaxOnly>tNO</TaxOnly>
    <UnitPrice>1752.140000</UnitPrice>
    <LineStatus>bost_Open</LineStatus>
    <LineType>dlt_Regular</LineType>
    <ItemDetails></ItemDetails>
    <U_StupStatus>N</U_StupStatus>
    <U_ProductPrice>0.000000</U_ProductPrice>
    <U_RelievePrice>0.000000</U_RelievePrice>
    <U_WentPrice>0.000000</U_WentPrice>
    <U_PeriodNumber>0</U_PeriodNumber>
    <U_UnitPrice>0.000000</U_UnitPrice>
    <U_BankRates>0.000000</U_BankRates>
    <U_CarriesFee>0.000000</U_CarriesFee>
    <U_ConsumptionTax>0.000000</U_ConsumptionTax>
    <U_IsSwitch>N</U_IsSwitch>
    <U_Handmoney>0.000000</U_Handmoney>
    <U_Charges>0.000000</U_Charges>
    <U_AssetAmt>0.000000</U_AssetAmt>
    <U_ReqSum>0.000000</U_ReqSum>
   </row>
   <row>
    <LineNum>3</LineNum>
    <ItemCode>111874</ItemCode>
    <ItemDescription>三星手机</ItemDescription>
    <Quantity>1.000000</Quantity>
    <ShipDate>20110906</ShipDate>
    <Price>2726.500000</Price>
    <PriceAfterVAT>3190.000000</PriceAfterVAT>
    <Currency>RMB</Currency>
    <Rate>0.000000</Rate>
    <DiscountPercent>0.000000</DiscountPercent>
    <WarehouseCode>010101</WarehouseCode>
    <SalesPersonCode>-1</SalesPersonCode>
    <CommisionPercent>0.000000</CommisionPercent>
    <TreeType>iNotATree</TreeType>
    <AccountCode>124301</AccountCode>
    <UseBaseUnits>tNO</UseBaseUnits>
    <BarCode>111874</BarCode>
    <VatGroup>J1</VatGroup>
    <Height1>0.000000</Height1>
    <Height2>0.000000</Height2>
    <Lengh1>0.000000</Lengh1>
    <Lengh2>0.000000</Lengh2>
    <Weight1>0.000000</Weight1>
    <Weight2>0.000000</Weight2>
    <Factor1>1.000000</Factor1>
    <Factor2>1.000000</Factor2>
    <Factor3>1.000000</Factor3>
    <Factor4>1.000000</Factor4>
    <BaseType>-1</BaseType>
    <Volume>0.000000</Volume>
    <VolumeUnit>2</VolumeUnit>
    <Width1>0.000000</Width1>
    <Width2>0.000000</Width2>
    <Address></Address>
    <TaxType>tt_Yes</TaxType>
    <TaxLiable>tYES</TaxLiable>
    <ShippingMethod>1</ShippingMethod>
    <CorrectionInvoiceItem>ciis_ShouldBe</CorrectionInvoiceItem>
    <CorrInvAmountToStock>0.000000</CorrInvAmountToStock>
    <CorrInvAmountToDiffAcct>0.000000</CorrInvAmountToDiffAcct>
    <WTLiable>tNO</WTLiable>
    <DeferredTax>tNO</DeferredTax>
    <LineTotal>2726.500000</LineTotal>
    <TaxPercentagePerRow>17.000000</TaxPercentagePerRow>
    <ConsumerSalesForecast>tNO</ConsumerSalesForecast>
    <ExciseAmount>0.000000</ExciseAmount>
    <DistributeExpense>tYES</DistributeExpense>
    <RowTotalFC>0.000000</RowTotalFC>
    <TaxOnly>tNO</TaxOnly>
    <UnitPrice>2726.500000</UnitPrice>
    <LineStatus>bost_Open</LineStatus>
    <LineType>dlt_Regular</LineType>
    <ItemDetails>由DM系统中导入</ItemDetails>
    <U_StupStatus>N</U_StupStatus>
    <U_ProductPrice>0.000000</U_ProductPrice>
    <U_RelievePrice>0.000000</U_RelievePrice>
    <U_WentPrice>0.000000</U_WentPrice>
    <U_PeriodNumber>0</U_PeriodNumber>
    <U_UnitPrice>0.000000</U_UnitPrice>
    <U_BankRates>0.000000</U_BankRates>
    <U_CarriesFee>0.000000</U_CarriesFee>
    <U_ConsumptionTax>0.000000</U_ConsumptionTax>
    <U_IsSwitch>N</U_IsSwitch>
    <U_Handmoney>0.000000</U_Handmoney>
    <U_Charges>0.000000</U_Charges>
    <U_AssetAmt>0.000000</U_AssetAmt>
    <U_ReqSum>0.000000</U_ReqSum>
   </row>
  </Document_Lines>
  <TaxExtension>
   <row>
    <NetWeight>0.000000</NetWeight>
    <GrossWeight>0.000000</GrossWeight>
    <BuildingS></BuildingS>
    <BuildingB></BuildingB>
   </row>
  </TaxExtension>
 </BO>
</BOM>