Ejemplo n.º 1
0
 private Cell GetCellValue(SqlCeDataReader reader, int col)
 {
     if (reader.GetFieldType(col).Name == "DateTime")
     {
         return(new Cell(reader[col].ToString()));
     }
     else
     {
         return(new Cell(reader[col]));
     }
 }
Ejemplo n.º 2
0
        public void FillListViewRows(ListView listView, string sql, List <SqlCeParameter> parameters)
        {
            try
            {
                using (SqlCeConnection conn = new SqlCeConnection(connString.ConnectionString))
                {
                    conn.Open();

                    using (SqlCeCommand command = new SqlCeCommand(sql, conn))
                    {
                        if (parameters != null)
                        {
                            command.Parameters.AddRange(parameters.ToArray());
                        }

                        using (SqlCeDataReader reader = command.ExecuteReader())
                        {
                            listView.Items.Clear();

                            while (reader.Read())
                            {
                                ListViewItem lvItem = new ListViewItem(reader[0].ToString());

                                for (int i = 1; i < reader.FieldCount; i++)
                                {
                                    if (!reader.IsDBNull(i))
                                    {
                                        if (reader.GetFieldType(i).FullName == typeof(DateTime).FullName)
                                        {
                                            lvItem.SubItems.Add(reader.GetDateTime(i).ToString("d"));
                                        }
                                        else
                                        {
                                            lvItem.SubItems.Add(reader.GetString(i));
                                        }
                                    }
                                    else
                                    {
                                        lvItem.SubItems.Add(string.Empty);
                                    }
                                }

                                listView.Items.Add(lvItem);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Выбрать в таблицу</summary>
        /// <param name="command">Комманда</param>
        /// <param name="formatDic">Словать форматирования данных</param>
        /// <returns>Таблица данных</returns>
        public static DataTable SelectToTable(this SqlCeCommand command, Dictionary <string, Enum> formatDic)
        {
            SqlCeDataReader reader      = command.ExecuteReader();
            DataTable       schemaTable = reader.GetSchemaTable();
            DataTable       table       = new DataTable();
            int             index       = 0;

            if (schemaTable != null)
            {
                foreach (DataRow row in schemaTable.Rows)
                {
                    Type type = reader.GetFieldType(index++);

                    if (type == typeof(DateTime))
                    {
                        type = typeof(string);
                    }

                    DataColumn column = new DataColumn(row["ColumnName"].ToString(), type);
                    table.Columns.Add(column);
                }

                while (reader.Read())
                {
                    DataRow row = table.NewRow();

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        Type type = reader[i].GetType();

                        switch (type.FullName)
                        {
                        case BaseFormatName.DBNull:
                            row[i] = string.Empty;
                            break;

                        case BaseFormatName.DateTime:
                            row[i] = GetDateTimeInFormat(reader.GetDateTime(i), formatDic);
                            break;

                        default:
                            row[i] = reader[i];
                            break;
                        }
                    }

                    table.Rows.Add(row);
                }
            }

            return(table);
        }
Ejemplo n.º 4
0
        public string GetSerializedData(ListQuerysDescarga QueryList, IEstadoCarga Estado)
        {
            StringBuilder   sb  = new StringBuilder();
            SqlCeDataReader dr  = null;
            SqlCeCommand    cmd = new SqlCeCommand();
            int             I   = 0;
            int             J   = 0;
            int             nIndexRowCountReplace = 0;
            int             nTableCount           = 0;
            int             nRowCount             = 0;
            int             nTotalRowsCount       = 0;

            // Se adicionan las 2 primeras lineas con tags para poder remplazarlos al final
            sb.Append("TABLECOUNT: <<TABLECOUNT>>" + "\r\n");
            sb.Append("TOTALROWCOUNT: <<TOTALROWCOUNT>>" + "\r\n");
            nTableCount     = 0;
            nTotalRowsCount = 0;
            try
            {
                this.OpenConnection();
                for (I = 0; I < QueryList.Count; I++)
                {
                    if (Estado.Cancelado)
                    {
                        break;
                    }
                    Estado.IniciarTabla(QueryList[I].TableName.ToUpper());
                    cmd.Connection  = (SqlCeConnection)this.Connection;
                    cmd.CommandText = QueryList[I].Query;
                    if (cmd.CommandText.StartsWith("SELECT", StringComparison.CurrentCultureIgnoreCase))
                    {
                        cmd.CommandType = CommandType.Text;
                    }
                    else
                    {
                        cmd.CommandType = CommandType.TableDirect;
                    }
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        nTableCount += 1;
                        sb.Append("TABLE: " + QueryList[I].TableName + "\r\n");
                        nIndexRowCountReplace = sb.Length;
                        sb.Append("ROWCOUNT: <<ROWCOUNT>> " + "\r\n");

                        // Se agrega una primer linea con los nombres de los campos
                        for (J = 0; J < dr.FieldCount; J++)
                        {
                            sb.Append(dr.GetName(J) + "|");
                        }
                        sb.Append("\r\n");

                        // Se agrega una segunda linea con los tipos de datos
                        for (J = 0; J < dr.FieldCount; J++)
                        {
                            sb.Append(dr.GetFieldType(J).ToString() + "|");
                        }
                        sb.Append("\r\n");

                        // Se agregan lineas con los datos de todos los registros
                        nRowCount = 0;
                        do
                        {
                            if (Estado.Cancelado)
                            {
                                break;
                            }
                            for (J = 0; J < dr.FieldCount; J++)
                            {
                                if (dr.IsDBNull(J))
                                {
                                    sb.Append("(null)|");
                                }
                                else
                                {
                                    if (dr.GetFieldType(J) == typeof(System.DateTime))
                                    {
                                        sb.Append(dr.GetDateTime(J).ToString("yyyy/MM/dd HH:mm:ss") + "|");
                                    }
                                    else
                                    {
                                        sb.Append(System.Convert.ToString(dr.GetValue(J)) + "|");
                                    }
                                }
                            }
                            sb.Append("\r\n");
                            nRowCount       += 1;
                            nTotalRowsCount += 1;
                        } while (dr.Read());
                        dr.Close();
                        sb.Replace("<<ROWCOUNT>>", nRowCount.ToString(), nIndexRowCountReplace, 40);
                        sb.Append("\r\n"); // Se agrega una linea adicional para delimitar los datos de la tabla
                    }
                }
                sb.Replace("<<TABLECOUNT>>", nTableCount.ToString(), 0, 40);
                if (sb.Length < 60)
                {
                    sb.Replace("<<TOTALROWCOUNT>>", nTotalRowsCount.ToString(), 0, sb.Length);
                }
                else
                {
                    sb.Replace("<<TOTALROWCOUNT>>", nTotalRowsCount.ToString(), 0, 60);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (this.Connection.State == ConnectionState.Open)
                {
                    this.CloseConnection();
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        public Tuple <LinkedList <int>, LinkedList <double[]>, LinkedList <double[]>, LinkedList <String[]>, LinkedList <String[]> > limbCoordinates(int ScanID)
        {
            LinkedList <int> scanID = new LinkedList <int>();

            double[] d = new double[3];
            LinkedList <double[]> joint1 = new LinkedList <double[]>();
            LinkedList <double[]> joint2 = new LinkedList <double[]>();

            String[] s = new String[3];
            LinkedList <String[]> joint3 = new LinkedList <String[]>();
            LinkedList <String[]> joint4 = new LinkedList <String[]>();

            SqlCeCommand selectQuery = this.con.CreateCommand();

            selectQuery.CommandText = "Select * from limbCoordinates where scanID = @ScanID";
            selectQuery.Parameters.Clear();
            selectQuery.Parameters.Add("@ScanID", ScanID);
            SqlCeDataReader reader = selectQuery.ExecuteReader();

            while (reader.Read())
            {
                scanID.AddLast(reader.GetInt32(0));
                d[0] = reader.GetDouble(1);
                d[1] = reader.GetDouble(2);
                d[2] = reader.GetDouble(3);
                joint1.AddLast(d);
                d[0] = reader.GetDouble(4);
                d[1] = reader.GetDouble(5);
                d[2] = reader.GetDouble(6);
                joint2.AddLast(d);
                System.Type type = reader.GetFieldType(4);

                if (Type.GetTypeCode(type) == TypeCode.String)
                {
                    s[0] = reader.GetString(7);
                    s[1] = reader.GetString(8);
                    s[2] = reader.GetString(9);
                    joint3.AddLast(s);
                }
                else if (Type.GetTypeCode(type) == TypeCode.Double)
                {
                    s[0] = reader.GetDouble(7).ToString();
                    s[1] = reader.GetDouble(8).ToString();
                    s[2] = reader.GetDouble(9).ToString();
                    joint3.AddLast(s);
                }
                type = reader.GetFieldType(10);
                if (Type.GetTypeCode(type) == TypeCode.String)
                {
                    s[0] = reader.GetString(10);
                    s[1] = reader.GetString(11);
                    s[2] = reader.GetString(12);
                    joint3.AddLast(s);
                }
                else if (Type.GetTypeCode(type) == TypeCode.Double)
                {
                    s[0] = reader.GetDouble(10).ToString();
                    s[1] = reader.GetDouble(11).ToString();
                    s[2] = reader.GetDouble(12).ToString();
                    joint3.AddLast(s);
                }
            }
            reader.Close();

            return(Tuple.Create(scanID, joint1, joint2, joint3, joint4));
        }