public void loadDocument() { SAPbobsCOM.Documents oDraft = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts); try { string path = ""; FileDialog dlg = new OpenFileDialog(); dlg.Filter = "xml files (*.xml)|*.xml"; DialogResult result = dlg.ShowDialog(); if (result == DialogResult.OK) { path = dlg.FileName; } oDraft = (SAPbobsCOM.Documents)oCompany.GetBusinessObjectFromXML(path, 0); string i = oDraft.GetType().ToString(); if (manageError(oDraft.Add(), true)) { MessageBox.Show("Document inserted correctly"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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); } }
private static void LoadUserFieldMDFromXmlFile(string xmlFileName) { SAPbobsCOM.UserFieldsMD userFieldsMD = null; GC.Collect(); xmlFileName = AppDomain.CurrentDomain.BaseDirectory + xmlFileName; int lErrCode = 0; int recordCount = sbo_company.GetXMLelementCount(xmlFileName); for (int iCounter = 0; iCounter <= recordCount - 1; iCounter++) { sbo_company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode; userFieldsMD = ((SAPbobsCOM.UserFieldsMD)(sbo_company.GetBusinessObjectFromXML(xmlFileName, Convert.ToInt32(iCounter)))); lErrCode = userFieldsMD.Add(); if (lErrCode != 0 && lErrCode != -1120 && lErrCode != -5002) { if (lErrCode == -2035) { lErrCode = userFieldsMD.Update(); if (lErrCode == 0) { sbo_application.StatusBar.SetText($"UDF {userFieldsMD.Name} updated", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } } else { sbo_application.StatusBar.SetText($"UDF {userFieldsMD.Name} not created | {sbo_company.GetLastErrorDescription()}", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } } if (lErrCode == 0) { sbo_application.StatusBar.SetText($"UDF {userFieldsMD.Name} created", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } GC.Collect(); } }