예제 #1
0
        private void btnXml_Click(object sender, EventArgs e)
        {
            try
            {
                oCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;
                SAPbobsCOM.Documents oInv;

                oInv = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);

                oInv.CardCode       = "C20000";
                oInv.DocDueDate     = DateTime.Today;
                oInv.Comments       = "invoice saved as xml";
                oInv.Lines.ItemCode = "A00001";
                oInv.Lines.Quantity = 2;
                oInv.Lines.Price    = 100;
                oInv.Lines.Add();
                oInv.Lines.ItemCode = "A00002";
                oInv.Lines.Quantity = 1;
                oInv.Lines.Price    = 50;

                oInv.Add();
                oCompany.GetNewObjectCode(out MySalesInvoice);

                if (oInv.GetByKey(Int32.Parse(MySalesInvoice)) == true)
                {
                    oInv.SaveXML("c:\\temp\\invoice_" + MySalesInvoice + ".xml");
                    MessageBox.Show("Invoice " + MySalesInvoice + " exported to XML");
                }

                else
                {
                    MessageBox.Show("Get Invoice failed: " + MySalesInvoice + " - " + oCompany.GetLastErrorDescription());
                }

                string schema;
                schema = oCompany.GetBusinessObjectXmlSchema(SAPbobsCOM.BoObjectTypes.oInvoices);
                //MessageBox.Show(schema);

                oInv          = oCompany.GetBusinessObjectFromXML("c:\\temp\\invoice_" + MySalesInvoice + ".xml", 0);
                oInv.Comments = "invoice loaded from xml";
                int ret = oInv.Add();

                if (ret == 0)
                {
                    oCompany.GetNewObjectCode(out MySalesInvoice);
                    MessageBox.Show("Invoice " + MySalesInvoice + " added from xml.");
                }

                else
                {
                    MessageBox.Show("Adding invoice " + MySalesInvoice + " from XML failed: " + oCompany.GetLastErrorDescription());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
            }
        }