private bool CreaUDOMD(string sCode, string sName, string sTableName, string[] sFindColumns, string[] sChildTables, SAPbobsCOM.BoYesNoEnum eCanCancel, SAPbobsCOM.BoYesNoEnum eCanClose, SAPbobsCOM.BoYesNoEnum eCanDelete, SAPbobsCOM.BoYesNoEnum eCanCreateDefaultForm, string[] sFormColumns, SAPbobsCOM.BoYesNoEnum eCanFind, SAPbobsCOM.BoYesNoEnum eCanLog, SAPbobsCOM.BoUDOObjType eObjectType, SAPbobsCOM.BoYesNoEnum eManageSeries, SAPbobsCOM.BoYesNoEnum eEnableEnhancedForm, SAPbobsCOM.BoYesNoEnum eRebuildEnhancedForm, string[] sChildFormColumns) { SAPbobsCOM.UserObjectsMD oUserObjectMD = null; int i_Result = 0; string s_Result = ""; try { oUserObjectMD = (SAPbobsCOM.UserObjectsMD)Conexion.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD); if (!oUserObjectMD.GetByKey(sCode)) { oUserObjectMD.Code = sCode; oUserObjectMD.Name = sName; oUserObjectMD.ObjectType = eObjectType; oUserObjectMD.TableName = sTableName; oUserObjectMD.CanCancel = eCanCancel; oUserObjectMD.CanClose = eCanClose; oUserObjectMD.CanDelete = eCanDelete; oUserObjectMD.CanCreateDefaultForm = eCanCreateDefaultForm; oUserObjectMD.EnableEnhancedForm = eEnableEnhancedForm; oUserObjectMD.RebuildEnhancedForm = eRebuildEnhancedForm; oUserObjectMD.CanFind = eCanFind; oUserObjectMD.CanLog = eCanLog; oUserObjectMD.ManageSeries = eManageSeries; if (sFindColumns != null) { for (int i = 0; i < sFindColumns.Length; i++) { oUserObjectMD.FindColumns.ColumnAlias = sFindColumns[i]; oUserObjectMD.FindColumns.Add(); } } if (sChildTables != null) { for (int i = 0; i < sChildTables.Length; i++) { oUserObjectMD.ChildTables.TableName = sChildTables[i]; oUserObjectMD.ChildTables.Add(); } } if (sFormColumns != null) { oUserObjectMD.UseUniqueFormType = SAPbobsCOM.BoYesNoEnum.tYES; for (int i = 0; i < sFormColumns.Length; i++) { oUserObjectMD.FormColumns.FormColumnAlias = sFormColumns[i]; oUserObjectMD.FormColumns.Add(); } } if (sChildFormColumns != null) { if (sChildTables != null) { for (int i = 0; i < sChildFormColumns.Length; i++) { oUserObjectMD.FormColumns.SonNumber = 1; oUserObjectMD.FormColumns.FormColumnAlias = sChildFormColumns[i]; oUserObjectMD.FormColumns.Add(); } } } i_Result = oUserObjectMD.Add(); if (i_Result != 0) { Conexion.company.GetLastError(out i_Result, out s_Result); StatusMessageError("Error: EstructuraDatos.cs > CreaUDOMD(): " + s_Result + ", creando el UDO " + sCode + "."); return(false); } } return(true); } catch (Exception ex) { StatusMessageError("Error: EstructuraDatos.cs > CreaUDOMD():" + ex.Message); return(false); } finally { LiberarObjetoGenerico(oUserObjectMD); } }
public static bool CreateUdo(string udoName, string description, string tableName, SAPbobsCOM.BoUDOObjType nObjectType, List <string> findFields, params string[] childTables) { var oUserObjectMD = B1Helper.DiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD) as SAPbobsCOM.UserObjectsMD; try { if (!oUserObjectMD.GetByKey(udoName)) { oUserObjectMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tYES; oUserObjectMD.CanClose = SAPbobsCOM.BoYesNoEnum.tYES; oUserObjectMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO; oUserObjectMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tYES; oUserObjectMD.CanFind = SAPbobsCOM.BoYesNoEnum.tYES; oUserObjectMD.FindColumns.ColumnAlias = "DocEntry"; if (findFields != null) { for (int i = 0; i < findFields.Count; i++) { if (i + 1 != findFields.Count) { oUserObjectMD.FindColumns.Add(); } oUserObjectMD.FindColumns.SetCurrentLine(i); oUserObjectMD.FindColumns.ColumnAlias = findFields[i]; } } oUserObjectMD.CanLog = SAPbobsCOM.BoYesNoEnum.tNO; oUserObjectMD.LogTableName = string.Empty; oUserObjectMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tNO; oUserObjectMD.ExtensionName = string.Empty; if (childTables != null) { for (int i = 0; i < childTables.Length; i++) { //oUserObjectMD.ChildTables.TableName = childTables[i]; if (i + 1 != childTables.Length) { oUserObjectMD.ChildTables.Add(); } oUserObjectMD.ChildTables.SetCurrentLine(i); oUserObjectMD.ChildTables.TableName = childTables[i]; } } oUserObjectMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tNO; oUserObjectMD.Code = udoName; oUserObjectMD.Name = description; oUserObjectMD.ObjectType = nObjectType; oUserObjectMD.TableName = tableName; if (oUserObjectMD.Add() != 0) { var err = Utilities.GetErrorMessage(); returnValue = false; } else { returnValue = true; } } } catch (Exception ex) { Utilities.LogException(ex); } finally { oUserObjectMD.ReleaseObject(); } return(returnValue); }
/// <summary> /// Method to create UDO /// </summary> /// <param name="udoCode"></param> /// <param name="udoName"></param> /// <param name="udoType"></param> /// <param name="mainTable"></param> /// <param name="oCanFind"></param> /// <param name="oCanDelete"></param> /// <param name="oCanCancel"></param> /// <param name="oCanClose"></param> /// <param name="oCanLog"></param> /// <param name="oManageSeries"></param> /// <param name="oYearTransfer"></param> /// <param name="oCanArchive"></param> /// <param name="oCanApprove"></param> /// <param name="oCreateDeafaultForm"></param> /// <param name="isEnhancedForm"></param> /// <param name="isMenuItem"></param> /// <param name="menuCaption"></param> /// <param name="FathermenuID"></param> /// <param name="position"></param> /// <param name="MenuUId"></param> /// <param name="formColumnList"></param> /// <param name="findColumnList"></param> /// <param name="childTableList"></param> /// <param name="enchancedFormColumnList"></param> /// <param name="isUniqueForm"></param> public void Create(/*Basic Setting*/ string udoCode, string udoName, SAPbobsCOM.BoUDOObjType udoType, string mainTable /*Setting Services*/, SAPbobsCOM.BoYesNoEnum oCanFind, SAPbobsCOM.BoYesNoEnum oCanDelete, SAPbobsCOM.BoYesNoEnum oCanCancel, SAPbobsCOM.BoYesNoEnum oCanClose, SAPbobsCOM.BoYesNoEnum oCanLog, SAPbobsCOM.BoYesNoEnum oManageSeries, SAPbobsCOM.BoYesNoEnum oYearTransfer, SAPbobsCOM.BoYesNoEnum oCanArchive, SAPbobsCOM.BoYesNoEnum oCanApprove /*UI Setting*/, SAPbobsCOM.BoYesNoEnum oCreateDeafaultForm, SAPbobsCOM.BoYesNoEnum isEnhancedForm, SAPbobsCOM.BoYesNoEnum isMenuItem, string menuCaption, int FathermenuID, int position, string MenuUId /*Set Form Columns*/, IList <Models.FormColumnValues> formColumnList /*Setting the Fields for the find columns*/, IList <Models.FindColumnValues> findColumnList /*Linking child user tables*/, IList <Models.ChildTableValues> childTableList /*Setting the fields for Enhance Column*/, IList <Models.EnhancedColumnValues> enchancedFormColumnList /*Set enhanced Column service value*/, SAPbobsCOM.BoYesNoEnum isUniqueForm) { SAPbobsCOM.IUserObjectsMD oUDOMD = null; SAPbobsCOM.IUserObjectMD_FindColumns oUDOFind = null; SAPbobsCOM.IUserObjectMD_FormColumns oUDOForm = null; SAPbobsCOM.IUserObjectMD_EnhancedFormColumns oEnhancedForm = null; SAPbobsCOM.IUserObjectMD_ChildTables oChild = null; PublicVariable.lRetCode = 0; try { oUDOMD = (SAPbobsCOM.IUserObjectsMD)PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD); oUDOFind = oUDOMD.FindColumns; oUDOForm = oUDOMD.FormColumns; oEnhancedForm = oUDOMD.EnhancedFormColumns; oChild = oUDOMD.ChildTables; //Basic Settings oUDOMD.Code = udoCode; oUDOMD.Name = udoName; oUDOMD.ObjectType = udoType; oUDOMD.TableName = mainTable; //Setting Services oUDOMD.CanFind = oCanFind; oUDOMD.CanDelete = oCanDelete; oUDOMD.CanCancel = oCanCancel; oUDOMD.CanClose = oCanClose; oUDOMD.CanLog = oCanLog; oUDOMD.ManageSeries = oManageSeries; oUDOMD.CanYearTransfer = oYearTransfer; oUDOMD.CanArchive = oCanArchive; oUDOMD.CanApprove = oCanApprove; //UI Settings oUDOMD.CanCreateDefaultForm = oCreateDeafaultForm; oUDOMD.EnableEnhancedForm = isEnhancedForm; if (isMenuItem == SAPbobsCOM.BoYesNoEnum.tYES) { oUDOMD.MenuItem = isMenuItem; oUDOMD.FatherMenuID = FathermenuID; oUDOMD.MenuCaption = menuCaption; oUDOMD.MenuUID = MenuUId; } else { oUDOMD.MenuItem = isMenuItem; } //Setting fields for default form if (formColumnList.Count != 0) { SAPbobsCOM.IUserObjectMD_FormColumns formColumns = oUDOMD.FormColumns; foreach (Models.FormColumnValues fColumn in formColumnList) { formColumns.FormColumnAlias = fColumn.ColumnAlias; formColumns.FormColumnDescription = fColumn.ColumnDescription; formColumns.Add(); } } //Find Columns if (oCanFind == SAPbobsCOM.BoYesNoEnum.tYES && findColumnList.Count != 0) { SAPbobsCOM.IUserObjectMD_FindColumns findColumns = oUDOMD.FindColumns; foreach (Models.FindColumnValues fColumn in findColumnList) { findColumns.ColumnAlias = fColumn.ColumnAlias; findColumns.ColumnDescription = fColumn.ColumnDescription; findColumns.Add(); } } //Child Table property if (childTableList.Count != 0) { foreach (Models.ChildTableValues fChildTable in childTableList) { oUDOMD.ChildTables.ObjectName = fChildTable.ObjectName; oUDOMD.ChildTables.TableName = fChildTable.TableName; oUDOMD.ChildTables.Add(); } } //Enhanced Column if (enchancedFormColumnList.Count != 0) { SAPbobsCOM.IUserObjectMD_EnhancedFormColumns enhanceFormColumns = oUDOMD.EnhancedFormColumns; foreach (Models.EnhancedColumnValues eColumn in enchancedFormColumnList) { enhanceFormColumns.ColumnAlias = eColumn.ColumnAlias; enhanceFormColumns.ColumnDescription = eColumn.ColumnDescription; enhanceFormColumns.ColumnIsUsed = eColumn.ColumnIsUsed; enhanceFormColumns.Editable = eColumn.Editable; enhanceFormColumns.ChildNumber = eColumn.ChildNumber; enhanceFormColumns.Add(); } oUDOMD.UseUniqueFormType = isUniqueForm; } //Add UDO PublicVariable.lRetCode = oUDOMD.Add(); if (PublicVariable.lRetCode == 0) { //Program.oApplication.StatusBar.SetText(String.Format("UDO {0}, {1} Registration", udoCode, udoName), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } else if (PublicVariable.lRetCode == -2035) { //Do Nothing string error = PublicVariable.oCompany.GetLastErrorDescription(); } else if (PublicVariable.lRetCode == -5002) { //Do Nothing string error = PublicVariable.oCompany.GetLastErrorDescription(); } else { string error = PublicVariable.oCompany.GetLastErrorDescription(); PublicVariable.oApplication.StatusBar.SetText(error, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } } catch (Exception ex) { PublicVariable.oApplication.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } finally { if (oUDOMD != null) { Marshal.FinalReleaseComObject(oUDOMD); oUDOMD = null; GC.Collect(); } } }