public static string CreateUDF(string tableName, string fieldName, string desc, SAPbobsCOM.BoFieldTypes fieldType, int Size, string LinkTab, SAPbobsCOM.BoFldSubTypes SubType = SAPbobsCOM.BoFldSubTypes.st_None) { SAPbobsCOM.Company SBO_Company = Conexion.oCompany; //get company service if (!SBO_Company.Connected) { Conexion.Conectar_Aplicacion(); } try { SAPbobsCOM.UserFieldsMD oUserFieldsMD; oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUserFieldsMD.TableName = tableName; oUserFieldsMD.Name = fieldName; oUserFieldsMD.Description = desc; oUserFieldsMD.Type = fieldType; if (Size != 0) { oUserFieldsMD.EditSize = Size; } oUserFieldsMD.SubType = SubType; int lRetCode; lRetCode = oUserFieldsMD.Add(); System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD); GC.Collect(); oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */; if (lRetCode != 0) { if ((lRetCode == -2035 | lRetCode == -1120)) { return(System.Convert.ToString(lRetCode)); } return(SBO_Company.GetLastErrorDescription()); } return(""); } catch (Exception ex) { return(ex.Message); } }
public static string CreateUDT(string tableName, string tableDesc, SAPbobsCOM.BoUTBTableType tableType) { SAPbobsCOM.Company SBO_Company = Conexion.oCompany; //get company service if (!SBO_Company.Connected) { Conexion.Conectar_Aplicacion(); } SAPbobsCOM.UserTablesMD oUdtMD = null /* TODO Change to default(_) if this is not a reference type */; try { oUdtMD = (SAPbobsCOM.UserTablesMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables); if (oUdtMD.GetByKey(tableName) == false) { oUdtMD.TableName = tableName; oUdtMD.TableDescription = tableDesc; oUdtMD.TableType = tableType; int lRetCode; lRetCode = oUdtMD.Add(); System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD); oUdtMD = null /* TODO Change to default(_) if this is not a reference type */; GC.Collect(); if ((lRetCode != 0)) { if ((lRetCode == -2035)) { return("-2035"); } return(SBO_Company.GetLastErrorDescription()); } return(""); } else { return(""); } } catch (Exception ex) { return(ex.Message); } }
public static string LoadObjectInfoFromRecordset(ref object Objeto, string Table, string WhereCondition) { string rpta = "N"; SAPbobsCOM.Company SBO_Company = Conexion.oCompany; try { //get company service if (!SBO_Company.Connected) { Conexion.Conectar_Aplicacion(); } SAPbobsCOM.Recordset oRecordSet = (SAPbobsCOM.Recordset)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); string sql = "select * from [" + Table + "] " + WhereCondition; oRecordSet.DoQuery(sql); if (oRecordSet.RecordCount > 0) { rpta = "S"; oRecordSet.MoveFirst(); foreach (PropertyInfo propiedad in Objeto.GetType().GetProperties()) { try { string tipoPropiedad = propiedad.PropertyType.Name; string NombrePropiedad = propiedad.Name; object valorPropiedad = propiedad.GetValue(Objeto, null); propiedad.SetValue(Objeto, Convert.ChangeType(oRecordSet.Fields.Item(NombrePropiedad).Value, propiedad.PropertyType), null); } catch (Exception) { rpta = "N"; } } } } catch (Exception) { } return(rpta); }
public static int GetNextCode(string UDO_Name) { int nProx = 0; SAPbobsCOM.Company SBO_Company = Conexion.oCompany; try { //get company service if (!SBO_Company.Connected) { Conexion.Conectar_Aplicacion(); } SAPbobsCOM.Recordset oRecorset = (SAPbobsCOM.Recordset)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); string sql = "select isnull(max(CAST(Code as int)),0)+1 as Proximo from [@" + UDO_Name + "]"; oRecorset.DoQuery(sql); nProx = (int)oRecorset.Fields.Item("Proximo").Value; } catch (Exception) { } return(nProx); }
public static string InsertRecord(string UDO_Name, Object Objeto, string UDO_Child, List <Object> DetalleObjeto) { SAPbobsCOM.Company SBO_Company = Conexion.oCompany; SAPbobsCOM.GeneralService oGeneralService; SAPbobsCOM.GeneralData oGeneralData; SAPbobsCOM.GeneralData oChild; SAPbobsCOM.GeneralDataCollection oChildren; //SAPbobsCOM.GeneralDataParams oGeneralParams; SAPbobsCOM.CompanyService oCompService; string rpta = "N"; try { //get company service if (!SBO_Company.Connected) { Conexion.Conectar_Aplicacion(); } oCompService = SBO_Company.GetCompanyService(); //SBO_Company.StartTransaction(); oGeneralService = oCompService.GetGeneralService(UDO_Name); oGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData); //Setting Data to Master Data Table Fields oGeneralData.SetProperty("Code", FuncionesUDO.GetNextCode(UDO_Name).ToString()); //Recorrer el Objeto y tomar Nombre y Valor de propiedades y asignarlas foreach (PropertyInfo propiedad in Objeto.GetType().GetProperties()) { try { string tipoPropiedad = propiedad.PropertyType.Name; string NombrePropiedad = propiedad.Name; var valorPropiedad = propiedad.GetValue(Objeto, null); oGeneralData.SetProperty(NombrePropiedad, valorPropiedad); } catch (Exception) { } } // Handle child rows if (DetalleObjeto.Any()) { oChildren = oGeneralData.Child(UDO_Child); foreach (Object det in DetalleObjeto) { // Create data for rows in the child table oChild = oChildren.Add(); foreach (PropertyInfo dPropiedad in det.GetType().GetProperties()) { try { string tipoPropiedad = dPropiedad.PropertyType.Name; string NombrePropiedad = dPropiedad.Name; var valorPropiedad = dPropiedad.GetValue(det, null); oChild.SetProperty(NombrePropiedad, valorPropiedad); } catch (Exception) { } } } } //if(!DT_CHILD.IsEmpty) //{ // oChildren = oGeneralData.Child("SM_MOR1"); // for (int i = 0; i <= DT_CHILD.Rows.Count - 1; i++) // { // // Create data for rows in the child table // oChild = oChildren.Add(); // for (int j = 0; j <= DT_CHILD.Columns.Count - 1; j++) // { // string nombreColumna = DT_CHILD.Columns.Item(j).Name; // var valorColumna = DT_CHILD.GetValue(j, i); // oChild.SetProperty(nombreColumna, valorColumna); // } // } //} //Attempt to Add the Record oGeneralService.Add(oGeneralData); rpta = "S"; } catch (Exception) { } finally { if (SBO_Company.InTransaction) { SBO_Company.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit); } } return(rpta); //try //{ // Type c_typo = Objeto.GetType(); // PropertyInfo[] c_propiedades = c_typo.GetProperties(); // //var valor = c_propiedades.GetValue(Objeto); // foreach (PropertyInfo propiedad in Objeto.GetType().GetProperties()) // { // string tipoPropiedad = propiedad.PropertyType.Name; // string NombrePropiedad = propiedad.Name; // var valorPropiedad = propiedad.GetValue(Objeto, null); // } //} //catch (Exception){} }