public static bool CheckFieldExists(string TableName, string FieldName) { SAPbobsCOM.Company SBO_Company = Conexion.oCompany; SAPbobsCOM.UserFieldsMD oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */; bool ret = false; try { FieldName = FieldName.Replace("U_", ""); oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); int FieldID = getFieldidByName(TableName, FieldName); // ‘TableName = TableName.Replace(“@”, “”) if (oUserFieldsMD.GetByKey(TableName, FieldID)) { ret = true; } else { ret = false; } } catch (Exception ex) { ret = false; } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD); oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */; GC.Collect(); } return(ret); }
private static void LoadUserFieldMDToXmlFile(string prefix) { SAPbobsCOM.UserFieldsMD userFieldsMD = null; XmlDocument documentoFinal = null; SAPbobsCOM.Recordset RS = (SAPbobsCOM.Recordset)sbo_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); if (sbo_company.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB) { RS.DoQuery(string.Format(@"select ""TableID"", ""FieldID"" from CUFD where (CUFD.""TableID"" like '@{0}%' or CUFD.""AliasID"" like '{0}%') and CUFD.""TableID"" not like 'A%'", prefix)); } if (RS.RecordCount > 0) { while (!RS.EoF) { int fieldID = int.Parse(RS.Fields.Item("FieldID").Value.ToString()); string tableID = RS.Fields.Item("TableID").Value.ToString(); userFieldsMD = (SAPbobsCOM.UserFieldsMD)sbo_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); if (userFieldsMD.GetByKey(tableID, fieldID)) { XmlDocument documento = new XmlDocument(); sbo_company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode; documento.LoadXml(userFieldsMD.GetAsXML()); if (documentoFinal == null) { documentoFinal = new XmlDocument(); documentoFinal.LoadXml(userFieldsMD.GetAsXML()); } else { XmlNode nodeBO = documento.DocumentElement.FirstChild; string stringContenidoNodeBO = nodeBO.InnerXml; try { XmlNode nuevoNodeBO = documentoFinal.CreateElement("BO"); nuevoNodeBO.InnerXml = stringContenidoNodeBO; documentoFinal.DocumentElement.AppendChild(nuevoNodeBO); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } RS.MoveNext(); } if (documentoFinal != null) { documentoFinal.Save(UserFieldsFile); } sbo_application.StatusBar.SetText("UDF export completed", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } }