Exemplo n.º 1
0
        public void LoadToDb(FileInfo dbfFile, string TableName, SqlConnection connection)
        {
            NDbfReader.Table  dbfTable  = NDbfReader.Table.Open(dbfFile.Open(FileMode.Open));
            NDbfReader.Reader dbfReader = dbfTable.OpenReader(Encoding.GetEncoding(866));
            SqlTransaction    TRA       = connection.BeginTransaction(("Bulk" + TableName));
            SqlBulkCopy       da        = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, TRA);

            da.BulkCopyTimeout      = 60000;
            da.DestinationTableName = string.Concat(SchemaName, ".", TableName);
            DataTable      servertable = ds.Tables[TableName];
            List <DataRow> rows        = new List <DataRow>();

            while (dbfReader.Read())
            {
                DataRow newrow = servertable.NewRow();
                foreach (NDbfReader.Column c in dbfTable.Columns)
                {
                    newrow.SetField(c.Name, dbfReader.GetValue(c.Name));
                }
                rows.Add(newrow);
            }
            da.WriteToServer(rows.ToArray());
            TRA.Commit();
            dbfTable.Dispose();
            dbfFile.Delete();
        }
Exemplo n.º 2
0
        public void LoadDBFToDb_House(FileInfo dbfFile, SqlConnection connection)
        {
            NDbfReader.Table    dbfTable  = NDbfReader.Table.Open(dbfFile.Open(FileMode.Open));
            NDbfReader.Reader   dbfReader = dbfTable.OpenReader(Encoding.GetEncoding(866));
            QueriesTableAdapter qta       = new QueriesTableAdapter();
            int       c  = 1;
            guidparse gp = (string x) => { if (x == null)
                                           {
                                               return(null);
                                           }
                                           else
                                           {
                                               return(Guid.Parse(x));
                                           } };

            while (dbfReader.Read())
            {
                int ESTSTATUS;
                int.TryParse(dbfReader.GetValue("ESTSTATUS").ToString(), out ESTSTATUS);
                if (!(bool)qta.CanInsert_tmpHouse_Query(Guid.Parse(dbfReader.GetValue("HOUSEID").ToString())) &&
                    (bool)qta.CanInsert_tmpHouseAO_Query(Guid.Parse(dbfReader.GetValue("AOGUID").ToString()))
                    )
                {
                    qta.Insert_tmpHouse_Query(
                        dbfReader.GetString("POSTALCODE"),
                        dbfReader.GetString("IFNSFL"),
                        dbfReader.GetString("TERRIFNSFL"),
                        dbfReader.GetString("IFNSUL"),
                        dbfReader.GetString("TERRIFNSUL"),
                        dbfReader.GetString("OKATO"),
                        dbfReader.GetString("OKTMO"),
                        dbfReader.GetDate("UPDATEDATE"),
                        dbfReader.GetString("HOUSENUM"),
                        int.Parse(dbfReader.GetValue("ESTSTATUS").ToString()),
                        dbfReader.GetString("BUILDNUM"),
                        dbfReader.GetString("STRUCNUM"),
                        int.Parse(dbfReader.GetValue("STRSTATUS").ToString()),
                        Guid.Parse(dbfReader.GetValue("HOUSEID").ToString()),
                        Guid.Parse(dbfReader.GetValue("HOUSEGUID").ToString()),
                        Guid.Parse(dbfReader.GetValue("AOGUID").ToString()),
                        dbfReader.GetDate("STARTDATE").Value,
                        dbfReader.GetDate("ENDDATE").Value,
                        int.Parse(dbfReader.GetValue("STATSTATUS").ToString()),
                        gp(dbfReader.GetString("NORMDOC")),
                        int.Parse(dbfReader.GetValue("COUNTER").ToString()),
                        dbfReader.GetString("CADNUM"),
                        int.Parse(dbfReader.GetValue("DIVTYPE").ToString()));
                }
                c++;
                LogInfo(c.ToString() + ". " + Guid.Parse(dbfReader.GetValue("HOUSEID").ToString()));
            }
            dbfTable.Dispose();
            dbfFile.Delete();
        }