private static bool CheckFieldExists(String tableName, String fieldName) { SAPbobsCOM.IUserFieldsMD oUserFieldsMD = null; bool blnFlag = false; try { fieldName = fieldName.Replace("U_", ""); oUserFieldsMD = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); int fieldID = GetFieldIDByName(tableName, fieldName); if (oUserFieldsMD.GetByKey(tableName, fieldID)) { blnFlag = true; } } catch (Exception ex) { blnFlag = false; AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD); oUserFieldsMD = null; GC.Collect(); } return(blnFlag); }
public static void CreateUDT(String udtName, String udtDesc, SAPbobsCOM.BoUTBTableType udtType) { if (!CheckTableExists(udtName)) { //SDK -> UserTableMD Object -> Fields Required SAPbobsCOM.IUserTablesMD oUDTMD = null; try { // 1. Get Company Object oUDTMD = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables); // 2. Set Table Properties oUDTMD.TableName = udtName; oUDTMD.TableDescription = udtDesc; oUDTMD.TableType = udtType; // 3. Add AddOnUtilities.IRetCode = oUDTMD.Add(); // 4. Error Handling AddOnUtilities.DIErrorHandler(String.Format("UDT {0} Created.", udtName)); } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace, Enum.MsgBoxType.B1StatusBar, SAPbouiCOM.BoMessageTime.bmt_Short, true); } finally { //Important - release COM Object System.Runtime.InteropServices.Marshal.ReleaseComObject(oUDTMD); GC.Collect(); oUDTMD = null; } } }
private static bool CheckUDOExists(String udoName) { SAPbobsCOM.UserObjectsMD oUdtMD = null; bool blnFlag = false; try { oUdtMD = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD); if (oUdtMD.GetByKey(udoName)) { blnFlag = true; } } catch (Exception ex) { blnFlag = false; AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD); oUdtMD = null; GC.Collect(); } return(blnFlag); }
public void SetValueViaDBS(ref SAPbouiCOM.Form oForm, String table, String field, Object value) { try { SAPbouiCOM.DBDataSource oDBS = oForm.DataSources.DBDataSources.Item(table); oDBS.SetValue(field, 0, value.ToString()); } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } }
public static void CreateUDV() { string formId, itemId, colId, queryName; int queryId, controlType, lRetCode = 0; Recordset oRecordSet = oCompany.GetBusinessObject(BoObjectTypes.BoRecordset); oRecordSet = AccessMatrixEngine.GetAllConfiguration(); while (!oRecordSet.EoF) { formId = oRecordSet.Fields.Item("U_FormId").Value.ToString(); itemId = oRecordSet.Fields.Item("U_ItemId").Value.ToString(); colId = oRecordSet.Fields.Item("U_ColumnId").Value.ToString(); queryName = oRecordSet.Fields.Item("U_QueryName").Value.ToString(); controlType = Convert.ToInt32(oRecordSet.Fields.Item("U_ControlType").Value.ToString()); if (formId == "UDO_FT_UserProject") { string zz = "asd"; } if (queryName == "") { oRecordSet.MoveNext(); continue; } queryId = GetQueryId(queryName); ClearUDVIfExist(formId, itemId, (controlType == 1 ? "-1" : colId));//If control is textbox, SAP return the colUID value as "1". But UDV only works as "-1". FormattedSearches oFormattedSearches = (FormattedSearches)oCompany.GetBusinessObject(BoObjectTypes.oFormattedSearches); oFormattedSearches.FormID = formId; oFormattedSearches.ItemID = itemId; oFormattedSearches.ColumnID = (controlType == 1 ? "-1" : colId); //If control is textbox, SAP return the colUID value as "1". But UDV only works as "-1". oFormattedSearches.Action = BoFormattedSearchActionEnum.bofsaQuery; oFormattedSearches.QueryID = queryId; lRetCode = oFormattedSearches.Add(); if (lRetCode != 0) { string errMsg = AddOnUtilities.oCompany.GetLastErrorDescription(); AddOnUtilities.MsgBoxWrapper(errMsg, MsgBoxType.B1StatusBar, BoMessageTime.bmt_Short, true); } oRecordSet.MoveNext(); } }
public static void CreateUDF(String udt, //can put business object as well String udfName, String udfDesc, SAPbobsCOM.BoFieldTypes udfType, SAPbobsCOM.BoFldSubTypes udfSubType, int udfEditSize, Dictionary <string, string> udfValidValues = null, SAPbobsCOM.BoYesNoEnum udfMandatory = SAPbobsCOM.BoYesNoEnum.tNO) { if (!CheckFieldExists(udt, udfName)) { SAPbobsCOM.UserFieldsMD oUDFMD = null; try { oUDFMD = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUDFMD.TableName = udt; oUDFMD.Name = udfName; oUDFMD.Description = udfDesc; oUDFMD.Type = udfType; oUDFMD.SubType = udfSubType; oUDFMD.EditSize = udfEditSize; oUDFMD.Mandatory = udfMandatory; //foreach(var udfValidValue in udfValidValues) //{ // oUDFMD.ValidValues.Value = udfValidValue.Key; // oUDFMD.ValidValues.Value = udfValidValue.Key; // oUDFMD.ValidValues.Add(); //} AddOnUtilities.IRetCode = oUDFMD.Add(); AddOnUtilities.DIErrorHandler(String.Format("UDF {0} Created.", udfName)); } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } finally { //Important - release COM Object System.Runtime.InteropServices.Marshal.ReleaseComObject(oUDFMD); GC.Collect(); oUDFMD = null; } } }
public SAPbouiCOM.Form CreateFormViaXML(String xmlData) { SAPbouiCOM.Form oForm = null; try { SAPbouiCOM.FormCreationParams oFCP = AddOnUtilities.oApplication.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams); oFCP.XmlData = xmlData; // Option 1 - to load the file //AddOn.oApplication.LoadBatchActions(xmlData); // Option 2 - to load the file oForm = AddOnUtilities.oApplication.Forms.AddEx(oFCP); } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } return(oForm); }
public SAPbouiCOM.Form CreateFormXmlFile(String filePath) { SAPbouiCOM.Form oForm = null; try { if (!File.Exists(filePath)) { AddOnUtilities.MsgBoxWrapper(String.Format("File does not exist.", filePath)); return(null); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filePath); oForm = CreateFormViaXML(xmlDoc.InnerXml); } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } return(oForm); }
private static int GetFieldIDByName(String tableName, String fieldName) { int index = -1; SAPbobsCOM.Recordset ors = null; try { ors = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); if (AddOnUtilities.oCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB) { ors.DoQuery("SELECT \"FieldID\" FROM \"CUFD\" WHERE \"TableID\" = '" + tableName + "' AND \"AliasID\" = '" + fieldName + "'"); } else { ors.DoQuery("SELECT FieldID FROM CUFD WHERE TableID = '" + tableName + "' AND AliasID = '" + fieldName + "'"); } if (!ors.EoF) { index = ors.Fields.Item("FieldID").Value; } } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(ors); ors = null; GC.Collect(); } return(index); }
private static void oApplication_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent) { //For UDOs, FormType is 0 and FormUID starts with UDO. if (pVal.FormType != 0 || FormUID.Contains("UDO")) { SAPbouiCOM.BoEventTypes EventEnum = 0; EventEnum = pVal.EventType; // To prevent an endless loop of MessageBoxes, // we'll not notify et_FORM_ACTIVATE and et_FORM_LOAD events //if ( ( EventEnum != SAPbouiCOM.BoEventTypes.et_FORM_ACTIVATE ) & ( EventEnum != SAPbouiCOM.BoEventTypes.et_FORM_LOAD ) ) if (pVal.BeforeAction) { string input = ""; //if FormType is 0, it's UDO and use FormType as FormUID (Variable) string formType = pVal.FormType.ToString() == "0" ? FormUID : pVal.FormType.ToString(); if (EventEnum == SAPbouiCOM.BoEventTypes.et_VALIDATE || EventEnum == BoEventTypes.et_CHOOSE_FROM_LIST) { SAPbobsCOM.Recordset rsConfigData = AccessMatrixEngine.GetConfiguration(formType, pVal.ItemUID, pVal.ColUID, (int)pVal.EventType); string accessMatrixKey = String.Empty, controlType = String.Empty; if (rsConfigData.RecordCount > 0) { accessMatrixKey = rsConfigData.Fields.Item("U_AccessMatrixKey").Value.ToString(); controlType = rsConfigData.Fields.Item("U_ControlType").Value.ToString(); string controlName = rsConfigData.Fields.Item("U_ControlName").Value.ToString(); string itemId = rsConfigData.Fields.Item("U_ItemId").Value.ToString(); string colId = rsConfigData.Fields.Item("U_ColumnId").Value.ToString(); string result = AccessMatrixEngine.CheckIfValidOrNot(rsConfigData); input = AccessMatrixEngine.GetInputValue(itemId, colId, controlType); if (input != "" && result != "") { BubbleEvent = false; AddOnUtilities.oApplication.ActivateMenuItem("7425"); return; } if (result != "") { BubbleEvent = false; AddOnUtilities.MsgBoxWrapper(result, Enum.MsgBoxType.B1StatusBar, BoMessageTime.bmt_Short, true); return; } //Set Names from Codes in UDOs. string relatedColumn = rsConfigData.Fields.Item("U_RelatedColumn").Value.ToString(); string relatedItem = rsConfigData.Fields.Item("U_RelatedItem").Value.ToString(); if (input != "" && pVal.FormType.ToString() == "0") { if (relatedColumn != "" && relatedItem != "") { string strName = AccessMatrixEngine.GetNameByCode(input, accessMatrixKey); AccessMatrixEngine.SetValueToMatrix(relatedItem, relatedColumn, strName); } } BubbleEvent = true; return; } } else if (EventEnum == SAPbouiCOM.BoEventTypes.et_KEY_DOWN && pVal.CharPressed == 9) { SAPbobsCOM.Recordset rsConfigData = AccessMatrixEngine.GetConfiguration(formType, pVal.ItemUID, pVal.ColUID, (int)pVal.EventType); string accessMatrixKey = String.Empty, controlType = String.Empty; if (rsConfigData.RecordCount > 0) { accessMatrixKey = rsConfigData.Fields.Item("U_AccessMatrixKey").Value.ToString(); controlType = rsConfigData.Fields.Item("U_ControlType").Value.ToString(); string controlName = rsConfigData.Fields.Item("U_ControlName").Value.ToString(); string itemId = rsConfigData.Fields.Item("U_ItemId").Value.ToString(); string colId = rsConfigData.Fields.Item("U_ColumnId").Value.ToString(); string result = AccessMatrixEngine.CheckIfValidOrNot(rsConfigData); input = AccessMatrixEngine.GetInputValue(itemId, colId, controlType); if (input == "") { BubbleEvent = false; AddOnUtilities.oApplication.ActivateMenuItem("7425"); return; } if (result != "") { BubbleEvent = false; AddOnUtilities.oApplication.ActivateMenuItem("7425"); return; } BubbleEvent = true; return; } } else if (EventEnum == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) { SAPbobsCOM.Recordset rsConfigData = AccessMatrixEngine.GetConfigurationForLineLoop(formType, pVal.ItemUID, pVal.ColUID, (int)pVal.EventType); int recordCount = rsConfigData.RecordCount; string accessMatrixKey = String.Empty, controlType = String.Empty; while (!rsConfigData.EoF) { //To Do : Update following statement to be dynamic. // I = 1 (Item), S = 2 (Service) //Some Document do not have Item or Service Type. Those controls are always ComboBox. //Check if it is ComboBox and if it's ComboBox, assign ControlType as 3 which is not Item or Service. dynamic tmpControl = AddOnUtilities.oApplication.Forms.ActiveForm.Items.Item("3").Specific; string documentType = ""; if (tmpControl is SAPbouiCOM.ComboBox) { documentType = ((SAPbouiCOM.ComboBox)AddOnUtilities.oApplication.Forms.ActiveForm.Items.Item("3").Specific).Value; documentType = (documentType == "I" ? "1" : "2"); } else { documentType = "3"; } string configDocumentType = rsConfigData.Fields.Item("U_DocType").Value.ToString(); if (documentType != configDocumentType) { rsConfigData.MoveNext(); continue; } //if(rsConfigData.Fields.Item("U_DocType").Value.ToString() != documentType && !rsConfigData.EoF) //{ //rsConfigData.MoveNext(); //} string result = AccessMatrixEngine.CheckIfValidOrNotAllLine(rsConfigData, documentType); rsConfigData.MoveNext(); if (result != "") { BubbleEvent = false; AddOnUtilities.MsgBoxWrapper(result, Enum.MsgBoxType.B1StatusBar, BoMessageTime.bmt_Short, true); return; } } } } } BubbleEvent = true; }
public static bool CreateCustomQueries(string qryCategory) { Recordset oRecordSet = oCompany.GetBusinessObject(BoObjectTypes.BoRecordset); UserQueries oUserQueries = (SAPbobsCOM.UserQueries)AddOnUtilities.oCompany.GetBusinessObject(BoObjectTypes.oUserQueries); QueryCategories oQueryCategories = (SAPbobsCOM.QueryCategories)AddOnUtilities.oCompany.GetBusinessObject(BoObjectTypes.oQueryCategories); int lRetCode = 0, queryCategoryId = 0; try { string strQuery = "SELECT \"CategoryId\" FROM \"OQCN\" WHERE \"CatName\" = '" + qryCategory + "'"; oRecordSet = ((SAPbobsCOM.Recordset)(AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset))); oRecordSet.DoQuery(strQuery); if (oRecordSet.RecordCount < 1) { string tmp = oRecordSet.Fields.Item(0).Value.ToString(); bool isQueryCategoryExist = Convert.ToBoolean(oRecordSet.Fields.Item(0).Value); if (!isQueryCategoryExist) //Create only if query category is not created yet. { oQueryCategories.Name = qryCategory; oQueryCategories.Permissions = "YYYYYYYYYYYYYYY"; lRetCode = oQueryCategories.Add(); if (lRetCode != 0) { string errMsg = AddOnUtilities.oCompany.GetLastErrorDescription(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(oQueryCategories); } } List <string[]> lstQueryList = AddOnUtilities.ReadQueries(); queryCategoryId = Convert.ToInt32(oRecordSet.Fields.Item(0).Value); foreach (string[] query in lstQueryList) { string queryDescription = query[0]; strQuery = "SELECT \"QName\" FROM OUQR WHERE \"QCategory\" = (SELECT \"CategoryId\" FROM OQCN WHERE \"CatName\" = '" + qryCategory + "') AND \"QName\" = '" + queryDescription + "'"; oRecordSet.DoQuery(strQuery); if (oRecordSet.RecordCount == 0) { oUserQueries.QueryDescription = queryDescription; oUserQueries.Query = query[1]; oUserQueries.QueryType = UserQueryTypeEnum.uqtWizard; oUserQueries.QueryCategory = queryCategoryId; lRetCode = oUserQueries.Add(); if (lRetCode != 0) { string errMsg = AddOnUtilities.oCompany.GetLastErrorDescription(); AddOnUtilities.MsgBoxWrapper(errMsg, MsgBoxType.B1StatusBar, BoMessageTime.bmt_Short, true); } } } } catch (Exception ex) { throw; } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(oQueryCategories); } return(lRetCode == 0); }