Exemplo n.º 1
0
        private void RellenarTabla(ref DataTable myDataTable)
        {
            int[] numeroColumnas;
            string[] columnsName = null;
            int num;
            int numeroCampos;
            if (((this.Columnas == null) && (this.ColumnsName == null)) && !this.NoColumn)
            {
                numeroColumnas = this.numeroColumnas;
                numeroCampos = this.numeroCampos;
            }
            else if (this.Columns != null)
            {
                numeroColumnas = this.Columnas;
                numeroCampos = this.Columnas.Length;
            }
            else
            {
                numeroCampos = this.ColumnsName.Length;
                columnsName = this.ColumnsName;
                numeroColumnas = new int[numeroCampos];
                for (num = 0; num < numeroCampos; num++)
                {
                    numeroColumnas[num] = this.numeroColumna(columnsName[num]);
                }
            }
            this.conexion.SelectLatestVersion();
            CFrontRecordset recordset = this.conexion.OpenTable(this.Tabla);
            NavisionFieldType[] typeArray = new NavisionFieldType[numeroCampos];
            for (num = 0; num < numeroCampos; num++)
            {
                string str;
                string typeName = "";
                if (columnsName == null)
                {
                    str = this.nombreColumna(numeroColumnas[num]);
                }
                else
                {
                    str = columnsName[num];
                }
                switch (recordset.FieldType(numeroColumnas[num], ref typeArray[num]))
                {
                    case "Code":
                        typeName = "System.String";
                        break;

                    case "Decimal":
                        typeName = "System.Decimal";
                        break;

                    case "Binary":
                        typeName = "System.String";
                        break;

                    case "Blob":
                        typeName = "System.String";
                        break;

                    case "Boolean":
                        typeName = "System.Boolean";
                        break;

                    case "Date":
                        typeName = "System.DateTime";
                        break;

                    case "DateFormula":
                        typeName = "System.String";
                        break;

                    case "DateTime":
                        typeName = "System.DateTime";
                        break;

                    case "Duration":
                        typeName = "System.String";
                        break;

                    case "Guid":
                        typeName = "System.String";
                        break;

                    case "Option":
                        typeName = "System.String";
                        break;

                    case "RecordId":
                        typeName = "System.String";
                        break;

                    case "Integer":
                        typeName = "System.Int32";
                        break;

                    case "BigInteger":
                        typeName = "System.Int64";
                        break;

                    case "TableFilter":
                        typeName = "System.String";
                        break;

                    case "Time":
                        typeName = "System.DateTime";
                        break;

                    case "Text":
                        typeName = "System.String";
                        break;

                    default:
                        throw new Exception("Error: Unknown data type -> " + recordset.FieldType(numeroColumnas[num], ref typeArray[num]).ToString());
                }
                DataColumn column = new DataColumn(str, Type.GetType(typeName));
                myDataTable.Columns.Add(column);
            }
            myDataTable.AcceptChanges();
            recordset.FreeRec();
            recordset.Close();
        }
Exemplo n.º 2
0
 public static bool PonerComillas(string Cadena, NavisionFieldType fieldType)
 {
     if (Cadena == "")
     {
         return false;
     }
     if (fieldType == NavisionFieldType.Boolean)
     {
         return false;
     }
     if (Cadena.IndexOf("<>") > -1)
     {
         return false;
     }
     if (Cadena.IndexOf("..") > -1)
     {
         return false;
     }
     for (int i = 0; i < Cadena.Length; i++)
     {
         if (((Cadena[i] == '<') || (Cadena[i] == '>')) || (((Cadena[i] == '=') || (Cadena[i] == '|')) || (Cadena[i] == '&')))
         {
             if (((Cadena[i] == '<') || (Cadena[i] == '>')) && ((fieldType != NavisionFieldType.Text) && (fieldType != NavisionFieldType.Code)))
             {
                 return false;
             }
             if (((Cadena[i] == '|') || (Cadena[i] == '&')) && ((fieldType == NavisionFieldType.Text) || (fieldType == NavisionFieldType.Code)))
             {
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 3
0
        private static byte[] GetBytesByType(NavisionFieldType type, object value, int tableHandle, int fieldNo)
        {
            NavisionFieldType type2 = type;
            if (type2 <= NavisionFieldType.Blob)
            {
                switch (type2)
                {
                    case NavisionFieldType.TableFilter:
                        return NavisionTableFilter.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.RecordId:
                        return NavisionRecordId.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.Text:
                        return NavisionText.Parse((string) value).GetBytes();

                    case NavisionFieldType.Binary:
                        return NavisionBinary.Parse(Convert.ToString(value)).GetBytes();

                    case ((NavisionFieldType) 0x8401):
                        goto Label_0322;

                    case NavisionFieldType.Blob:
                        return new byte[0];

                    case NavisionFieldType.Decimal:
                        return NavisionDecimal.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.Date:
                    {
                        NavisionDate date = new NavisionDate();
                        if (value.ToString() != "")
                        {
                            date = NavisionDate.Parse(Convert.ToDateTime(value).ToShortDateString());
                        }
                        return date.GetBytes();
                    }
                    case NavisionFieldType.Time:
                        return NavisionTime.Parse(Convert.ToDateTime(value).ToShortTimeString()).GetBytes();

                    case NavisionFieldType.DateFormula:
                        return NavisionDateFormula.Parse(Convert.ToString(value)).GetBytes();
                }
            }
            else
            {
                switch (type2)
                {
                    case NavisionFieldType.Code:
                        return NavisionCode.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.Option:
                    {
                        NavisionOption option = new NavisionOption(0);
                        if (value.GetType() != Type.GetType("System.String"))
                        {
                            option = new NavisionOption(Convert.ToInt32((string) value));
                        }
                        else
                        {
                            string[] strArray = FieldOptions(tableHandle, fieldNo);
                            for (int i = 0; i < strArray.Length; i++)
                            {
                                if (strArray[i] == ((string) value))
                                {
                                    option = new NavisionOption(i);
                                    break;
                                }
                            }
                        }
                        return option.GetBytes();
                    }
                    case NavisionFieldType.Boolean:
                        return NavisionBoolean.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.Integer:
                    {
                        NavisionInteger integer2 = new NavisionInteger(Convert.ToInt32(value));
                        return integer2.GetBytes();
                    }
                    case NavisionFieldType.BigInteger:
                        return NavisionBigInteger.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.Duration:
                        return NavisionDuration.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.Guid:
                        return NavisionGuid.Parse(Convert.ToString(value)).GetBytes();

                    case NavisionFieldType.DateTime:
                    {
                        NavisionDateTime time = new NavisionDateTime();
                        if (value.ToString() != "")
                        {
                            time = NavisionDateTime.Parse(Convert.ToDateTime(value).ToString());
                        }
                        return time.GetBytes();
                    }
                }
            }
            Label_0322:
            return new byte[0];
        }
Exemplo n.º 4
0
 public static string fieldType(int hTable, int fieldNo, ref NavisionFieldType fieldType)
 {
     fieldType = Cfront.FieldType(hTable, fieldNo);
     return ((NavisionFieldType) fieldType).ToString();
 }
Exemplo n.º 5
0
        private static string ValidateField(int hTable, int fieldNo, NavisionFieldType fieldType, string filter)
        {
            if (filter.Length > 250)
            {
                return "ERROR: Filter size exceeds the maximun length allowed";
            }
            char[] separator = new char[] { '|', '&' };
            string[] strArray = filter.Split(separator);
            int length = 0;
            for (int i = 0; i < strArray.Length; i++)
            {
                string str;
                int num4;
                length = eliminateFilterOperators(strArray[i]).Length;
                NavisionFieldType type = fieldType;
                if (type <= NavisionFieldType.Blob)
                {
                    switch (type)
                    {
                        case NavisionFieldType.TableFilter:
                            return "";

                        case NavisionFieldType.RecordId:
                            goto Label_0417;

                        case NavisionFieldType.Text:
                            goto Label_046F;

                        case NavisionFieldType.Binary:
                            goto Label_0181;

                        case ((NavisionFieldType) 0x8401):
                        {
                            continue;
                        }
                        case NavisionFieldType.Blob:
                            return ("ERROR: Cannot filter a BLOB field. Field n\x00ba " + fieldNo.ToString());

                        case NavisionFieldType.Decimal:
                            try
                            {
                                Convert.ToDecimal(eliminateFilterOperators(strArray[i]));
                                continue;
                            }
                            catch
                            {
                                return ("ERROR: Data type not match in field n\x00ba " + fieldNo.ToString());
                            }
                            goto Label_0181;

                        case NavisionFieldType.Date:
                            goto Label_019F;

                        case NavisionFieldType.Time:
                            goto Label_04A0;

                        case NavisionFieldType.DateFormula:
                            goto Label_03FF;
                    }
                }
                else
                {
                    switch (type)
                    {
                        case NavisionFieldType.Boolean:
                            return "";

                        case NavisionFieldType.Integer:
                            goto Label_0443;

                        case NavisionFieldType.Code:
                            goto Label_04CC;

                        case NavisionFieldType.Guid:
                            return "";

                        case NavisionFieldType.DateTime:
                            goto Label_019F;

                        case NavisionFieldType.Option:
                            return "";

                        case NavisionFieldType.Duration:
                            return "";
                    }
                }
                continue;
            Label_0181:
                return "";
            Label_019F:
                str = "  ... ";
                if ((strArray[i] == " ") || (strArray[i] == "''"))
                {
                    strArray[i] = "''";
                    continue;
                }
                try
                {
                    int num3 = strArray[i].IndexOf("..");
                    if (num3 != -1)
                    {
                        string str2 = strArray[i].Substring(0, num3);
                        string str3 = strArray[i].Substring(num3 + 2, (strArray[i].Length - num3) - 2);
                        if (str2 != "")
                        {
                            if (str2.IndexOf("/") != -1)
                            {
                                str = str + "substr1:" + str2;
                                Convert.ToDateTime(str2);
                                str = str + "...";
                            }
                            else
                            {
                                str2 = str2.Insert(2, "/").Insert(5, "/");
                                str = str + "substr1(2):" + str2;
                                Convert.ToDateTime(str2);
                                str = str + "...";
                            }
                        }
                        if (str3 != "")
                        {
                            if (str3.IndexOf("/") != -1)
                            {
                                str = str + "substr2:" + str3;
                                Convert.ToDateTime(str3);
                                str = str + "...";
                            }
                            else
                            {
                                str3 = str3.Insert(2, "/").Insert(5, "/");
                                str = str + "substr2(2):" + str3;
                                Convert.ToDateTime(str3);
                                str = str + "...";
                            }
                        }
                    }
                    else
                    {
                        strArray[i] = strArray[i].Replace("<", "").Replace(">", "").Replace("=", "");
                        if (strArray[i].IndexOf("/") != -1)
                        {
                            str = str + "granulos[i]:" + strArray[i];
                            Convert.ToDateTime(strArray[i]);
                            str = str + "...";
                        }
                        else
                        {
                            strArray[i] = strArray[i].Insert(2, "/").Insert(5, "/");
                            str = str + "granulos[i](2):" + strArray[i];
                            Convert.ToDateTime(strArray[i]);
                            str = str + "...";
                        }
                    }
                    continue;
                }
                catch (Exception exception)
                {
                    string message = exception.Message;
                    return ("ERROR(2): Data type not match in field n\x00ba " + fieldNo.ToString() + str);
                }
            Label_03FF:
                return "";
            Label_0417:
                try
                {
                    Convert.ToInt32(eliminateFilterOperators(strArray[i]));
                    continue;
                }
                catch
                {
                    return ("ERROR: Data type not match in field n\x00ba " + fieldNo.ToString());
                }
            Label_0443:
                try
                {
                    Convert.ToInt32(eliminateFilterOperators(strArray[i]));
                    continue;
                }
                catch
                {
                    return ("ERROR: Data type not match in field n\x00ba " + fieldNo.ToString());
                }
            Label_046F:
                if ((Cfront.FieldLength(hTable, fieldNo) + 1) >= length)
                {
                    continue;
                }
                return ("ERROR: Filter size in field n\x00ba " + fieldNo.ToString() + " exceeds the field size");
            Label_04A0:
                try
                {
                    Convert.ToDateTime(eliminateFilterOperators(strArray[i]));
                    continue;
                }
                catch
                {
                    return ("ERROR: Data type not match in field n\x00ba " + fieldNo.ToString());
                }
            Label_04CC:
                num4 = Cfront.FieldLength(hTable, fieldNo);
                int index = strArray[i].IndexOf("..");
                if (index != -1)
                {
                    string str4 = strArray[i].Substring(0, index);
                    string str5 = strArray[i].Substring(index + 2, (strArray[i].Length - index) - 2);
                    if ((str4 != "") && (str4.Length > num4))
                    {
                        return ("ERROR: Filter size in field n\x00ba " + fieldNo.ToString() + " ( " + str4 + ") exceeds the field size");
                    }
                    if ((str5 != "") && (str5.Length > num4))
                    {
                        return ("ERROR: Filter size in field n\x00ba " + fieldNo.ToString() + " ( " + str5 + ") exceeds the field size");
                    }
                }
                else if (strArray[i].Length > num4)
                {
                    return ("ERROR: Filter size in field n\x00ba " + fieldNo.ToString() + " ( " + strArray[i] + ") exceeds the field size");
                }
                return "";
            }
            return "";
        }
Exemplo n.º 6
0
 public string FieldType(int fieldNo, ref NavisionFieldType fieldType)
 {
     return CFrontDll.fieldType(this.hTable, fieldNo, ref fieldType);
 }
Exemplo n.º 7
0
        public NavisionDBDataReader ExecuteReader(bool LockTable)
        {
            NavisionDBDataReader reader;
            DataRow row;
            int[] fieldNumbers;
            int num;
            int fieldCount;
            CFrontRecordset recordset = this.PrepararConsulta(LockTable);
            if (recordset.EOF)
            {
                reader = new NavisionDBDataReader();
                goto Label_03B0;
            }
            DataTable tabla = new DataTable(this.Tabla.TableName);
            string[] columnsName = null;
            if (((this.Tabla.Columns == null) && (this.Tabla.ColumnsName == null)) && !this.Tabla.NoColumn)
            {
                fieldNumbers = this.Tabla.FieldNumbers;
                fieldCount = this.Tabla.FieldCount;
            }
            else
            {
                fieldCount = this.Tabla.Columns.Length;
                fieldNumbers = this.Tabla.Columns;
                columnsName = this.Tabla.ColumnsName;
            }
            NavisionFieldType[] typeArray = new NavisionFieldType[fieldCount];
            for (num = 0; num < fieldCount; num++)
            {
                string str;
                string typeName = "";
                if (columnsName == null)
                {
                    str = recordset.FieldName(fieldNumbers[num]);
                }
                else
                {
                    str = columnsName[num];
                }
                switch (recordset.FieldType(fieldNumbers[num], ref typeArray[num]))
                {
                    case "Code":
                        typeName = "System.String";
                        break;

                    case "Decimal":
                        typeName = "System.Decimal";
                        break;

                    case "Binary":
                        typeName = "System.String";
                        break;

                    case "Blob":
                        typeName = "System.String";
                        break;

                    case "Boolean":
                        typeName = "System.Boolean";
                        break;

                    case "Date":
                        typeName = "System.DateTime";
                        break;

                    case "DateFormula":
                        typeName = "System.String";
                        break;

                    case "DateTime":
                        typeName = "System.DateTime";
                        break;

                    case "Duration":
                        typeName = "System.String";
                        break;

                    case "Guid":
                        typeName = "System.String";
                        break;

                    case "Option":
                        typeName = "System.String";
                        break;

                    case "RecordId":
                        typeName = "System.String";
                        break;

                    case "Integer":
                        typeName = "System.Int32";
                        break;

                    case "BigInteger":
                        typeName = "System.Int64";
                        break;

                    case "TableFilter":
                        typeName = "System.String";
                        break;

                    case "Time":
                        typeName = "System.DateTime";
                        break;

                    case "Text":
                        typeName = "System.String";
                        break;

                    default:
                        throw new Exception("Error: Unknown data type -> " + recordset.FieldType(fieldNumbers[num], ref typeArray[num]).ToString());
                }
                DataColumn column = new DataColumn(str, Type.GetType(typeName));
                tabla.Columns.Add(column);
            }
            Label_0335:
            row = tabla.NewRow();
            for (num = 0; num < fieldCount; num++)
            {
                row[num] = recordset[fieldNumbers[num]];
            }
            tabla.Rows.Add(row);
            if (!this.Tabla.firstRow)
            {
                if (this.Tabla.Reverse)
                {
                    if (recordset.MovePrevious())
                    {
                        goto Label_0335;
                    }
                }
                else if (recordset.MoveNext())
                {
                    goto Label_0335;
                }
            }
            tabla.AcceptChanges();
            reader = new NavisionDBDataReader(tabla);
            Label_03B0:
            recordset.FreeRec();
            recordset.Close();
            return reader;
        }
Exemplo n.º 8
0
        private void RellenarTablaGeneral(ref DataTable myDataTable, NavisionDBTable tabla, bool distinct)
        {
            DataRow row;
            int[] fieldNumbers;
            string[] columnsName = null;
            int num;
            int fieldCount;
            if (((tabla.Columns == null) && (tabla.ColumnsName == null)) && !tabla.NoColumn)
            {
                fieldNumbers = tabla.FieldNumbers;
                fieldCount = tabla.FieldCount;
            }
            else
            {
                fieldCount = tabla.Columns.Length;
                fieldNumbers = tabla.Columns;
                columnsName = tabla.ColumnsName;
            }
            tabla.ConnectionDB.SelectLatestVersion();
            CFrontRecordset recordset = tabla.ConnectionDB.OpenTable(tabla.TableNo);
            NavisionFieldType[] typeArray = new NavisionFieldType[fieldCount];
            for (num = 0; num < fieldCount; num++)
            {
                string str;
                string typeName = "";
                if (columnsName == null)
                {
                    str = tabla.FieldName(fieldNumbers[num]);
                }
                else
                {
                    str = columnsName[num];
                }
                switch (recordset.FieldType(fieldNumbers[num], ref typeArray[num]))
                {
                    case "Code":
                        typeName = "System.String";
                        break;

                    case "Decimal":
                        typeName = "System.Decimal";
                        break;

                    case "Binary":
                        typeName = "System.String";
                        break;

                    case "Blob":
                        typeName = "System.String";
                        break;

                    case "Boolean":
                        typeName = "System.Boolean";
                        break;

                    case "Date":
                        typeName = "System.DateTime";
                        break;

                    case "DateFormula":
                        typeName = "System.String";
                        break;

                    case "DateTime":
                        typeName = "System.DateTime";
                        break;

                    case "Duration":
                        typeName = "System.String";
                        break;

                    case "Guid":
                        typeName = "System.String";
                        break;

                    case "Option":
                        typeName = "System.String";
                        break;

                    case "RecordId":
                        typeName = "System.String";
                        break;

                    case "Integer":
                        typeName = "System.Int32";
                        break;

                    case "BigInteger":
                        typeName = "System.Int64";
                        break;

                    case "TableFilter":
                        typeName = "System.String";
                        break;

                    case "Time":
                        typeName = "System.DateTime";
                        break;

                    case "Text":
                        typeName = "System.String";
                        break;

                    default:
                        throw new Exception("Error: Unknown data type -> " + recordset.FieldType(fieldNumbers[num], ref typeArray[num]).ToString());
                }
                DataColumn column = new DataColumn(str, Type.GetType(typeName));
                myDataTable.Columns.Add(column);
            }
            if (tabla.Key != null)
            {
                recordset.SetCurrentKey(tabla.Key);
            }
            object[,] filters = tabla.Filters;
            if (filters != null)
            {
                for (num = 0; num < (filters.Length / 2); num++)
                {
                    recordset.SetFilter(Convert.ToInt32(filters[num, 0]), Convert.ToString(filters[num, 1]));
                }
            }
            if (tabla.Reverse)
            {
                recordset.MoveLast();
            }
            else
            {
                recordset.MoveFirst();
            }
            if (recordset.EOF)
            {
                goto Label_03E0;
            }
            Label_0380:
            row = myDataTable.NewRow();
            for (num = 0; num < fieldCount; num++)
            {
                row[num] = recordset[fieldNumbers[num]];
            }
            myDataTable.Rows.Add(row);
            if (!distinct && !tabla.firstRow)
            {
                if (tabla.Reverse)
                {
                    if (recordset.MovePrevious())
                    {
                        goto Label_0380;
                    }
                }
                else if (recordset.MoveNext())
                {
                    goto Label_0380;
                }
            }
            Label_03E0:
            myDataTable.AcceptChanges();
            recordset.FreeRec();
            recordset.Close();
        }