コード例 #1
0
        /// <summary>
        /// Funcion que permite crear los campos sus respectivas tablas
        /// </summary>
        /// <param name="nombretabla">Se especifica la tabla del campo a crear</param>
        /// <param name="nombrecampo">Se especifica el campo a crear</param>
        /// <param name="descripcion">Se especifica la descripción del campo a crear</param>
        /// <param name="longitud">Se especifica la longitud del campo a crear</param>
        /// <param name="tipo">Se especifica el tipo de dato del campo </param>
        /// <param name="subtipo">Se especifica el subtipo de dato del campo. Solo apliaca para tipo de datos Float</param>
        public static void CreaCampoMD(String nombretabla, String nombrecampo, String descripcion, int longitud, SAPbobsCOM.BoFieldTypes tipo, SAPbobsCOM.BoFldSubTypes subtipo, SAPbobsCOM.BoYesNoEnum mandatory, String defaultValue, ValorValido[] valores, String linkTable)
        {
            SAPbobsCOM.UserFieldsMD oUserFieldsMD;
            try
            {
                oUserFieldsMD             = (SAPbobsCOM.UserFieldsMD)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
                oUserFieldsMD.TableName   = nombretabla; //Se obtiene el nombre de la tabla de usario
                oUserFieldsMD.Name        = nombrecampo; //Se asigna el nombre del campo de usuario
                oUserFieldsMD.Description = descripcion; //Se asigna una descripcion al campo de usuario
                oUserFieldsMD.Mandatory   = mandatory;
                if (longitud > 0)
                {
                    oUserFieldsMD.EditSize = longitud; //Se define una longitud al campo de usuario
                }
                oUserFieldsMD.Type    = tipo;          //Se asigna el tipo de dato al campo de usuario
                oUserFieldsMD.SubType = subtipo;

                if (defaultValue != null)
                {
                    oUserFieldsMD.DefaultValue = defaultValue;
                }

                if (valores != null && valores.Length > 0)
                {
                    foreach (ValorValido vv in valores)
                    {
                        oUserFieldsMD.ValidValues.Value       = vv.valor;
                        oUserFieldsMD.ValidValues.Description = vv.descripcion;
                        oUserFieldsMD.ValidValues.Add();
                    }
                }

                oUserFieldsMD.LinkedTable = linkTable;

                ret = oUserFieldsMD.Add();    //Se agrega el campo de usuario

                if (ret != 0 && ret != -2035) //&& ret != -5002)
                {
                    Conexion_SBO.m_oCompany.GetLastError(out ret, out errMsg);
                    Msj_Appl.Errores(8, "CargarTabla -> " + errMsg);
                }

                Comunes.FuncionesComunes.LiberarObjetoGenerico(oUserFieldsMD);
            }
            catch
            {
            }
        }
コード例 #2
0
 /// <summary>
 /// A method for adding new field to B1 table
 /// </summary>
 /// <param name="name">Field Name</param>
 /// <param name="description">Field description</param>
 /// <param name="tableName">Table the field will be added to</param>
 /// <param name="fieldType">Field Type</param>
 /// <param name="size">Field size in the database</param>
 /// <param name="mandatory">bool: if the value is mandatory to be filled</param>
 /// <param name="subType">Sub field type</param>
 public void AddField(string name, string description, string tableName, SAPbobsCOM.BoFieldTypes fieldType, SAPbobsCOM.BoYesNoEnum mandatory, SAPbobsCOM.BoFldSubTypes subType, bool addedToUDT)
 {
     AddField(name, description, tableName, fieldType, null, mandatory, subType, addedToUDT);
 }
コード例 #3
0
        /// <summary>
        /// A method for adding new field to B1 table
        /// </summary>
        /// <param name="name">Field Name</param>
        /// <param name="description">Field description</param>
        /// <param name="tableName">Table the field will be added to</param>
        /// <param name="fieldType">Field Type</param>
        /// <param name="size">Field size in the database</param>
        /// <param name="subType"></param>
        /// <param name="mandatory"></param>
        /// <param name="addedToUDT">If this field will be added to system table or User defined table</param>
        /// <param name="valiedValue">The default selected value</param>
        /// <param name="validValues">Add the values seperated by comma "," for value and description ex:(Value,Description)</param>
        public void AddField(string name, string description, string tableName, SAPbobsCOM.BoFieldTypes fieldType, Nullable <int> size, SAPbobsCOM.BoYesNoEnum mandatory, SAPbobsCOM.BoFldSubTypes subType, bool addedToUDT, string validValue, params string[] validValues)
        {
            var objUserFieldMD = B1Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields) as SAPbobsCOM.UserFieldsMD;

            try
            {
                if (addedToUDT)
                {
                    tableName = string.Format("@{0}", tableName);
                }
                if (!IsFieldExists(name, tableName))
                {
                    objUserFieldMD.TableName   = tableName;
                    objUserFieldMD.Name        = name;
                    objUserFieldMD.Description = description;
                    objUserFieldMD.Type        = fieldType;
                    objUserFieldMD.Mandatory   = mandatory;

                    if (size == null || size <= 0)
                    {
                        size = 50;
                    }

                    if (fieldType != SAPbobsCOM.BoFieldTypes.db_Numeric)
                    {
                        objUserFieldMD.Size = (int)size;
                    }
                    else
                    {
                        objUserFieldMD.EditSize = 10;
                    }

                    if (fieldType == BoFieldTypes.db_Float && subType == BoFldSubTypes.st_None)
                    {
                        objUserFieldMD.SubType = BoFldSubTypes.st_Quantity;
                    }
                    else
                    {
                        objUserFieldMD.SubType = subType;
                    }

                    if (validValue != null)
                    {
                        objUserFieldMD.DefaultValue = validValue;
                    }

                    if (validValues != null)
                    {
                        foreach (string s in validValues)
                        {
                            var valuesAttributes = s.Split(',');
                            if (valuesAttributes.Length == 2)
                            {
                                objUserFieldMD.ValidValues.Description = valuesAttributes[1];
                            }
                            objUserFieldMD.ValidValues.Value = valuesAttributes[0];
                            objUserFieldMD.ValidValues.Add();
                        }
                    }

                    if (objUserFieldMD.Add() != 0)
                    {
                        var test = _oCompany.GetLastErrorDescription();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                objUserFieldMD.ReleaseObject();
            }
        }
コード例 #4
0
        public void AddField(string TableName, string FieldName, string FieldDescription, SAPbobsCOM.BoFieldTypes FieldType, SAPbobsCOM.BoFldSubTypes FieldSubType, Int32 FieldSize)
        {
            var oUserFieldsMD = (SAPbobsCOM.UserFieldsMD) this.sapCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);

            oUserFieldsMD.TableName   = TableName;
            oUserFieldsMD.Name        = FieldName;
            oUserFieldsMD.Description = FieldDescription;
            oUserFieldsMD.Type        = FieldType;
            oUserFieldsMD.SubType     = FieldSubType;
            if (System.Convert.ToInt32(FieldSize) > 0)
            {
                oUserFieldsMD.EditSize = System.Convert.ToInt32(FieldSize);
            }

            var lRetCode = oUserFieldsMD.Add();

            oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */;
            GC.Collect();
            if (lRetCode != 0)
            {
                var error = this.sapCompany.GetLastErrorDescription();
                if (error != "")
                {
                    //Console.WriteLine($"Error Adding UDF {TableName} {FieldName} : {error}");
                }
            }
            //else
            //Console.WriteLine($"Table:  {TableName} successfully added column: { FieldName}");
        }
コード例 #5
0
        public bool AddColumns(string TableName, string Name, string Description, SAPbobsCOM.BoFieldTypes Type, int Size = 0, SAPbobsCOM.BoFldSubTypes SubType = SAPbobsCOM.BoFldSubTypes.st_None, string LinkedTable = "", string[,] LOV = null, string DefV = "")
        {
            bool outResult = false;

            try
            {
                SAPbobsCOM.UserFieldsMD v_UserField = default(SAPbobsCOM.UserFieldsMD);

                if (TableName.StartsWith("@") == true)
                {
                    if (!ColumnExists(TableName, Name))
                    {
                        v_UserField           = (SAPbobsCOM.UserFieldsMD)oDiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
                        v_UserField.TableName = TableName;
                        v_UserField.Name      = Name;
                        if (!string.IsNullOrEmpty(DefV))
                        {
                            v_UserField.DefaultValue = DefV;
                        }

                        if (LOV == null)
                        {
                        }
                        else
                        {
                            for (int k = 0; k <= LOV.Length - 1; k++)
                            {
                                v_UserField.ValidValues.Value = LOV[k, 0];
                                v_UserField.ValidValues.Value = LOV[k, 1];
                                v_UserField.ValidValues.Add();
                            }
                        }

                        v_UserField.Description = Description;
                        v_UserField.Type        = Type;
                        if (Type != SAPbobsCOM.BoFieldTypes.db_Date)
                        {
                            if (Size != 0)
                            {
                                v_UserField.Size     = Convert.ToInt16(Size);
                                v_UserField.EditSize = Convert.ToInt16(Size);
                            }
                        }
                        if (SubType != SAPbobsCOM.BoFldSubTypes.st_None)
                        {
                            v_UserField.SubType = SubType;
                        }
                        if (!string.IsNullOrEmpty(LinkedTable))
                        {
                            v_UserField.LinkedTable = LinkedTable;
                        }
                        v_RetVal = v_UserField.Add();
                        if (v_RetVal != 0)
                        {
                            oDiCompany.GetLastError(out v_ErrCode, out v_ErrMsg);
                            Program.objHrmsUI.oApplication.SetStatusBarMessage("Failed to add UserField " + Description + " - " + v_ErrCode + " " + v_ErrMsg);
                            return(false);
                        }
                        else
                        {
                            Program.objHrmsUI.oApplication.SetStatusBarMessage("[@" + TableName + "] - " + Description + " added successfully!!!");
                            outResult = true;
                            return(true);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(v_UserField);
                        v_UserField = null;
                    }
                    else
                    {
                        return(false);
                    }
                }


                if (TableName.StartsWith("@") == false)
                {
                    if (!UDFExists(TableName, Name))
                    {
                        v_UserField           = (SAPbobsCOM.UserFieldsMD)oDiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
                        v_UserField.TableName = TableName;
                        v_UserField.Name      = Name;
                        if (!string.IsNullOrEmpty(DefV))
                        {
                            v_UserField.DefaultValue = DefV;
                        }

                        if (LOV == null)
                        {
                        }
                        else
                        {
                            for (int k = 0; k <= LOV.Length / 2 - 1; k++)
                            {
                                v_UserField.ValidValues.Value       = LOV[k, 0];
                                v_UserField.ValidValues.Description = LOV[k, 1];
                                v_UserField.ValidValues.Add();
                            }
                        }
                        v_UserField.Description = Description;
                        v_UserField.Type        = Type;
                        if (Type != SAPbobsCOM.BoFieldTypes.db_Date)
                        {
                            if (Size != 0)
                            {
                                v_UserField.Size     = Size;
                                v_UserField.EditSize = Size;
                            }
                        }
                        if (SubType != SAPbobsCOM.BoFldSubTypes.st_None)
                        {
                            v_UserField.SubType = SubType;
                        }
                        if (!string.IsNullOrEmpty(LinkedTable))
                        {
                            v_UserField.LinkedTable = LinkedTable;
                        }
                        v_RetVal = v_UserField.Add();
                        if (v_RetVal != 0)
                        {
                            oDiCompany.GetLastError(out v_ErrCode, out v_ErrMsg);
                            Program.objHrmsUI.oApplication.SetStatusBarMessage("Failed to add UserField " + Description + " - " + v_ErrCode + " " + v_ErrMsg);
                            return(false);
                        }
                        else
                        {
                            Program.objHrmsUI.oApplication.SetStatusBarMessage("Udf Created " + Description, SAPbouiCOM.BoMessageTime.bmt_Short, false);

                            outResult = true;
                            return(true);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(v_UserField);
                        v_UserField = null;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to Add Columns : " + ex.Message);
            }
            finally
            {
            }
            return(outResult);
        }
コード例 #6
0
        public void CreateUserField(string TableName, string FieldName, string FieldDescription, SAPbobsCOM.BoFieldTypes oType, SAPbobsCOM.BoFldSubTypes oSubType, int FieldSize, bool MandatoryYN = false, string DefaultValue = "")
        {
            if (FieldDescription.Length > 30)
            {
                FieldDescription = FieldDescription.Substring(0, 30);
            }
            if (FindColumns != null)
            {
                FindColumns.Fields.Add(FieldName, FieldDescription);
            }

            Log.AppendFormat(Environment.NewLine + "Criação/Atualização do Campo {0}.{1}: ", TableName, FieldName);
            SAPbobsCOM.UserFieldsMD oUserFieldsMD = ((SAPbobsCOM.UserFieldsMD)(SBOApp.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)));
            bool bUpdate;

            string Sql = " SELECT FieldId FROM CUFD WHERE TableID = '{0}' AND AliasID = '{1}' ";

            Sql = String.Format(Sql, TableName, FieldName);
            string FieldId = QueryForValue(Sql);

            if (FieldId != null)
            {
                bUpdate = oUserFieldsMD.GetByKey(TableName, Convert.ToInt32(FieldId));
            }
            else
            {
                bUpdate = false;
            }

            oUserFieldsMD.TableName   = TableName;
            oUserFieldsMD.Name        = FieldName;
            oUserFieldsMD.Description = FieldDescription;
            oUserFieldsMD.Type        = oType;
            oUserFieldsMD.SubType     = oSubType;
            oUserFieldsMD.Mandatory   = GetSapBoolean(MandatoryYN);
            if (!String.IsNullOrEmpty(DefaultValue))
            {
                oUserFieldsMD.DefaultValue = DefaultValue;
            }

            if (FieldSize > 0)
            {
                oUserFieldsMD.EditSize = FieldSize;
            }

            if (bUpdate)
            {
                //CodErro = oUserFieldsMD.Update();
                CodErro = 0;
            }
            else
            {
                CodErro = oUserFieldsMD.Add();
            }
            this.ValidateAction();

            Marshal.ReleaseComObject(oUserFieldsMD);
            oUserFieldsMD = null;
        }