Ejemplo n.º 1
0
        private PLFUnitClass LoadLogBook(READCYCLE.readcycle readcycle)
        {
            PLFUnitClass plf = new PLFUnitClass();
            plf.START_PERIOD.systemTime = readcycle.TIMEFROM.ToString("yy:MM:dd HH:mm:ss");
            plf.END_PERIOD.systemTime = readcycle.TIMETO.ToString("yy:MM:dd HH:mm:ss");
            plf.TIME_STEP = readcycle.TIMESTEP.ToString();
            plf.installedSensors = readcycle.installedSensors;

            fb_con.Open();
            string sql = "SELECT * FROM LOGBOOK WHERE READCYCLEID=@READCYCLEID ORDER BY ID";
            FbCommand cmd = new FbCommand(sql, fb_con);
            cmd.Parameters.AddWithValue("@READCYCLEID", readcycle.ID);
            int i = 0;
            PLFRecord onerecord = new PLFRecord();
            DateTime previewDate = new DateTime();
            string gettedValue;
            using (FbDataReader r = cmd.ExecuteReader())
            {
                while (r.Read())
                {
                    onerecord = new PLFRecord();

                    if (plf.installedSensors.SYSTEM_TIME.systemTime != null)
                    {
                        gettedValue = r["READTIME"].ToString();
                        if (previewDate == new DateTime())
                        {
                            onerecord.SYSTEM_TIME.systemTime = DateTime.Parse(gettedValue).ToString("yy:MM:dd HH:mm:ss");
                            previewDate = DateTime.Parse(gettedValue);
                        }
                        else
                        {
                            if (DateTime.Parse(gettedValue) == previewDate)
                            {
                                onerecord.SYSTEM_TIME.systemTime = (DateTime.Parse(gettedValue).AddSeconds(Convert.ToInt32(plf.TIME_STEP))).ToString("yy:MM:dd HH:mm:ss");
                                previewDate = DateTime.Parse(gettedValue);
                            }
                            else
                            {
                                onerecord.SYSTEM_TIME.systemTime = DateTime.Parse(gettedValue).ToString("yy:MM:dd HH:mm:ss");
                                previewDate = DateTime.Parse(gettedValue);
                            }
                        }

                    }
                    if (plf.installedSensors.FUEL_CONSUMPTION != null)
                        onerecord.FUEL_CONSUMPTION = r["FUEL0"].ToString();
                    if (plf.installedSensors.FUEL_VOLUME1 != null)
                        onerecord.FUEL_VOLUME1 = r["FUEL1"].ToString();
                    if (plf.installedSensors.FUEL_VOLUME2 != null)
                        onerecord.FUEL_VOLUME2 = r["FUEL2"].ToString();
                    //FUELPH
                    if (plf.installedSensors.VOLTAGE != null)
                        onerecord.VOLTAGE = r["BATTERY"].ToString();
                    if (plf.installedSensors.ENGINE_RPM != null)
                        onerecord.ENGINE_RPM = r["ENGINERPM"].ToString();
                    if (plf.installedSensors.TEMPERATURE1 != null)
                        onerecord.TEMPERATURE1 = r["TEMPERATURE1"].ToString();
                    if (plf.installedSensors.TEMPERATURE2 != null)
                        onerecord.TEMPERATURE2 = r["TEMPERATURE2"].ToString();
                    if (plf.installedSensors.WEIGHT1 != null)
                        onerecord.WEIGHT1 = r["WEIGHT1"].ToString();
                    if (plf.installedSensors.WEIGHT2 != null)
                        onerecord.WEIGHT2 = r["WEIGHT2"].ToString();
                    if (plf.installedSensors.WEIGHT3 != null)
                        onerecord.WEIGHT3 = r["WEIGHT3"].ToString();
                    if (plf.installedSensors.WEIGHT4 != null)
                        onerecord.WEIGHT4 = r["WEIGHT4"].ToString();
                    if (plf.installedSensors.WEIGHT5 != null)
                        onerecord.WEIGHT5 = r["WEIGHT5"].ToString();
                    if (plf.installedSensors.ADDITIONAL_SENSORS != null)
                        onerecord.ADDITIONAL_SENSORS = r["SENSOR1"].ToString();
                    if (plf.installedSensors.RESERVED_3 != null)
                        onerecord.RESERVED_3 = r["SENSOR3"].ToString();
                    if (plf.installedSensors.RESERVED_4 != null)
                        onerecord.RESERVED_4 = r["SENSOR4"].ToString();
                    if (plf.installedSensors.RESERVED_5 != null)
                        onerecord.RESERVED_5 = r["SENSOR5"].ToString();
                    //IGNITION
                    //ENGWORKTIME
                    //REFUEL
                    //FUELDELTA
                    //REFUELTIME
                    //REFUELTIME
                    if (plf.installedSensors.SPEED != null)
                        onerecord.SPEED = r["SPEED"].ToString();
                    if (plf.installedSensors.DISTANCE_COUNTER != null)
                        onerecord.DISTANCE_COUNTER = r["RACE"].ToString();
                    //MOVETIME
                    //IDLETIME
                    if (plf.installedSensors.LATITUDE != null)
                        onerecord.LATITUDE = r["LATITUDE"].ToString();
                    if (plf.installedSensors.LONGITUDE != null)
                        onerecord.LONGITUDE = r["LONGITUDE"].ToString();
                    if (plf.installedSensors.ALTITUDE != null)
                        onerecord.ALTITUDE = r["ALTITUDE"].ToString();
                    if (plf.installedSensors.FUEL_COUNTER != null)
                        onerecord.FUEL_COUNTER = r["FUEL"].ToString();

                    plf.Records.Add(onerecord);
                }
            }
            fb_con.Close();
            return plf;
        }
Ejemplo n.º 2
0
        public void LoadAllInfo()
        {
            Console.WriteLine("Conerting starts");
            DateTime startLoadTime = DateTime.Now;


            PLFUnit.PLFUnitClass plf;

            CARS cars = new CARS(fb_con);

            cars.LoadAllCars();

            DEPARTMENTS depar = new DEPARTMENTS(fb_con);

            depar.LoadAllDepartments();

            WORKERS workers = new WORKERS(fb_con);

            workers.LoadAllWorkers();

            DEVICES devices = new DEVICES(fb_con);

            devices.LoadAllDevices();

            READCYCLE readcycle = new READCYCLE(fb_con);

            readcycle.LoadAllReadCycles();

            DataBlock datablock = new DataBlock(connectionStringMysql, currentLanguage);

            try
            {
                List <KeyValuePair <int, int> > orgOldNewIds  = new List <KeyValuePair <int, int> >();
                List <KeyValuePair <int, int> > workOldNewIds = new List <KeyValuePair <int, int> >();
                List <KeyValuePair <int, int> > carsOldNewIds = new List <KeyValuePair <int, int> >();
                List <KeyValuePair <READCYCLE.readcycle, int> > readCycleAndorgIdList = new List <KeyValuePair <READCYCLE.readcycle, int> >();

                List <int> allIds      = new List <int>();
                int        newDeviceId = -1;
                int        userInfoId;
                KeyValuePair <int, int> tempOldNewIds;
                List <int> addedWorkers = new List <int>();
                datablock.OpenConnection();
                datablock.OpenTransaction();
                //Создание организация, работников и ТС
                foreach (DEPARTMENTS.department department in depar.departments)
                {
                    addedWorkers = new List <int>();
                    int orgId = datablock.organizationTable.AddNewOrganization(department.DEPARTMENT, 1, 1, 1);
                    tempOldNewIds = new KeyValuePair <int, int>(department.ID, orgId);
                    orgOldNewIds.Add(tempOldNewIds);
                    int carId = -1;
                    #region "cars"
                    IEnumerable <CARS.car> carsList =
                        from car in cars.carsArray
                        where car.DEPARTMENTID == department.ID
                        select car;

                    foreach (CARS.car car in carsList)
                    {
                        IEnumerable <int> scoreQuery =
                            from devId in readcycle.cycles
                            where devId.CARID == car.ID
                            select devId.DEVICEID;
                        allIds = scoreQuery.ToList();

                        if (allIds.Count > 0)
                        {
                            IEnumerable <DEVICES.device> oneDevice =
                                from devId in devices.devices
                                where devId.ID == allIds[0]
                                select devId;

                            if (oneDevice.ToList().Count > 0)
                            {
                                DEVICES.device NewDevice = oneDevice.ToList()[0];
                                newDeviceId = datablock.deviceTable.AddNewDevice(1, NewDevice.DEVICE, NewDevice.VERSION, DateTime.Now, 1, 23442324);
                            }
                            else
                            {
                                newDeviceId = datablock.deviceTable.AddNewDevice(1, "UndefinedDevice", "UndefinedVersion", DateTime.Now, 1, 23442324);
                            }
                        }
                        else
                        {
                            newDeviceId = datablock.deviceTable.AddNewDevice(1, "UndefinedDevice", "UndefinedVersion", DateTime.Now, 1, 23442324);
                        }

                        if (car.DEPARTMENTID == department.ID)
                        {
                            int cardId = datablock.cardsTable.CreateNewCard(car.REGNUMBER, "Unknown", datablock.cardsTable.vehicleCardTypeId, orgId, 0, "Created from FIREBIRD database", 0, 1);
                            carId         = datablock.vehiclesTables.AddNewVehicle(car.REGNUMBER, car.CARMODEL, "Unknown", 1, newDeviceId, cardId, DateTime.Now, 1);
                            tempOldNewIds = new KeyValuePair <int, int>(car.ID, carId);
                            carsOldNewIds.Add(tempOldNewIds);
                        }
                    }
                    #endregion
                    #region "workers"
                    IEnumerable <WORKERS.worker> workersList =
                        from worker in workers.workers
                        where worker.DEPARTMENTID == department.ID
                        select worker;

                    foreach (WORKERS.worker workerForAdd in workersList)
                    {
                        int newWId = datablock.cardsTable.CreateNewCard(workerForAdd.FIRSTNAME + " " + workerForAdd.SURNAME, workerForAdd.WORKERINTID.ToString(), datablock.cardsTable.driversCardTypeId,
                                                                        orgId, 0, "Created from firebird", 0, 1);

                        /*userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Patronimic);
                         * datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.MIDDLENAME);
                         * userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Name);
                         * datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.FIRSTNAME);
                         * userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Surname);
                         * datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.SURNAME);
                         * userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Birthday);
                         * datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.BIRTHDAY.ToShortDateString());
                         * userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_DriversCertificate);
                         * datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.LICENCE);*/
                        addedWorkers.Add(workerForAdd.ID);
                        tempOldNewIds = new KeyValuePair <int, int>(workerForAdd.ID, newWId);
                        workOldNewIds.Add(tempOldNewIds);
                    }
                    #endregion
                    #region "set orgId to READCYCLES"
                    if (addedWorkers.Count > 0)
                    {
                        for (int i = 0; i < readcycle.cycles.Count; i++)
                        {
                            if (addedWorkers.Contains(readcycle.cycles[i].WORKER1ID) || addedWorkers.Contains(readcycle.cycles[i].WORKER2ID))
                            {
                                KeyValuePair <READCYCLE.readcycle, int> readCycleAndorgId = new KeyValuePair <READCYCLE.readcycle, int>(readcycle.cycles[i], orgId);
                                readCycleAndorgIdList.Add(readCycleAndorgId);
                            }
                        }
                    }
                    #endregion
                }
                Console.WriteLine("Added workers, departmens, cars");

                if (readCycleAndorgIdList.Count != readcycle.cycles.Count)
                {
                    if (false) //база фигово связана
                    {
                        throw new Exception("Куда-то пропала часть инфы");
                    }
                }
                //Загрузка файлов ПЛФ в ранее созданные организации.
                foreach (KeyValuePair <READCYCLE.readcycle, int> readedcycle in readCycleAndorgIdList)
                {
                    SQLDB                     sqlDb     = datablock.sqlDb;
                    SQLDB_Records             sqlDB_rec = new SQLDB_Records(connectionStringMysql, sqlDb.GETMYSQLCONNECTION());
                    ReflectObjectToTableClass reflectedItemsList;
                    byte[]                    bytes = Guid.NewGuid().ToByteArray();
                    int    orgId         = readedcycle.Value;
                    Type   type          = null;
                    object myParseObject = new object();
                    plf          = new PLFUnitClass();
                    plf          = LoadLogBook(readedcycle.Key);
                    plf.cardType = 2;

                    IEnumerable <string> selCar =
                        from car in cars.carsArray
                        where car.ID == readedcycle.Key.CARID
                        select car.REGNUMBER;
                    if (selCar.ToList().Count > 0)
                    {
                        plf.VEHICLE = selCar.ToList()[0];
                    }


                    IEnumerable <string> selDeviceName =
                        from dev in devices.devices
                        where dev.ID == readedcycle.Key.DEVICEID
                        select dev.DEVICE;
                    if (selDeviceName.ToList().Count > 0)
                    {
                        plf.ID_DEVICE = selDeviceName.ToList()[0];
                    }


                    int driverId = -1;
                    foreach (KeyValuePair <int, int> oldNew in workOldNewIds)
                    {
                        if (oldNew.Key == readedcycle.Key.WORKER1ID)
                        {
                            driverId = oldNew.Value;
                        }
                    }
                    int dataBlockId = datablock.AddPlfTypeData(orgId, bytes,
                                                               "AutoGenerated " + plf.VEHICLE + " " + plf.START_PERIOD.ToString() + " - " + plf.END_PERIOD.ToString(),
                                                               driverId);
                    DataRecords dataRecord = new DataRecords(connectionString, dataBlockId, currentLanguage, sqlDb);

                    //////////////////////устанавливаем PLF карту нужного водителя. Незнаю почему именно здесь, но так получилось.
                    int plfDriversCardType = sqlDB_rec.Get_DataBlockCardType(dataBlockId);
                    sqlDb.SetDataBlock_CardId(dataBlockId, plfDriversCardType);
                    // sqlDB.OpenConnection();
                    int cardTypeParamId = sqlDb.AddParam("cardType", 0, 255);
                    //sqlDB.OpenConnection();
                    sqlDb.DeleteDataRecord(dataBlockId, cardTypeParamId);
                    // sqlDB.CloseConnection();
                    //////////////////////
                    type          = plf.GetType();
                    myParseObject = plf;

                    //sqlDB.OpenConnection();
                    SetParseBDate(sqlDb, dataBlockId);
                    //sqlDB.CloseConnection();

                    List <ReflectObjectToTableClass> allRecordsToAdd = new List <ReflectObjectToTableClass>();

                    foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        reflectedItemsList = new ReflectObjectToTableClass();
                        string fieldName = pi.Name;
                        object field2    = pi.GetValue(myParseObject, null);

                        if (field2 != null)
                        {
                            reflectedItemsList.ReflectObjectToTable(fieldName, field2); //Не удалять!
                            allRecordsToAdd.Add(AddRecords(reflectedItemsList, sqlDb)); //не удалять
                        }
                    }

                    foreach (ReflectObjectToTableClass recordList in allRecordsToAdd)
                    {
                        dataRecord.AddDataArray(recordList.reflectedItemsList);
                    }

                    //sqlDB.OpenConnection();
                    SetParseEDate(sqlDb, dataBlockId);
                    sqlDb.SetDataBlockState(dataBlockId, 2);
                    int dataBlockParseRecords = sqlDb.SetDataBlockParseRecords(dataBlockId);
                    Console.WriteLine("" + dataBlockParseRecords.ToString() + " records added");
                }

                Console.WriteLine("\n\r" + "Время начала импорта " + startLoadTime.ToShortDateString() + " " + startLoadTime.ToShortTimeString());
                Console.WriteLine("\n\r" + "Время окончания импорта " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
                //throw new Exception();
                datablock.CommitTransaction();
                datablock.CloseConnection();
            }
            catch (Exception ex)
            {
                datablock.RollbackConnection();
                datablock.CloseConnection();
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void LoadAllInfo()
        {
            Console.WriteLine("Conerting starts");
            DateTime startLoadTime = DateTime.Now;

            PLFUnit.PLFUnitClass plf;

            CARS cars = new CARS(fb_con);
            cars.LoadAllCars();

            DEPARTMENTS depar = new DEPARTMENTS(fb_con);
            depar.LoadAllDepartments();

            WORKERS workers = new WORKERS(fb_con);
            workers.LoadAllWorkers();

            DEVICES devices = new DEVICES(fb_con);
            devices.LoadAllDevices();

            READCYCLE readcycle = new READCYCLE(fb_con);
            readcycle.LoadAllReadCycles();

            DataBlock datablock = new DataBlock(connectionStringMysql, currentLanguage);
            try
            {
                List<KeyValuePair<int, int>> orgOldNewIds = new List<KeyValuePair<int, int>>();
                List<KeyValuePair<int, int>> workOldNewIds = new List<KeyValuePair<int, int>>();
                List<KeyValuePair<int, int>> carsOldNewIds = new List<KeyValuePair<int, int>>();
                List<KeyValuePair<READCYCLE.readcycle, int>> readCycleAndorgIdList = new List<KeyValuePair<READCYCLE.readcycle, int>>();

                List<int> allIds = new List<int>();
                int newDeviceId = -1;
                int userInfoId;
                KeyValuePair<int, int> tempOldNewIds;
                List<int> addedWorkers = new List<int>();
                datablock.OpenConnection();
                datablock.OpenTransaction();
                //Создание организация, работников и ТС
                foreach (DEPARTMENTS.department department in depar.departments)
                {
                    addedWorkers = new List<int>();
                    int orgId = datablock.organizationTable.AddNewOrganization(department.DEPARTMENT, 1, 1, 1);
                    tempOldNewIds = new KeyValuePair<int, int>(department.ID, orgId);
                    orgOldNewIds.Add(tempOldNewIds);
                    int carId = -1;
                    #region "cars"
                    IEnumerable<CARS.car> carsList =
                       from car in cars.carsArray
                       where car.DEPARTMENTID == department.ID
                       select car;

                    foreach (CARS.car car in carsList)
                    {
                        IEnumerable<int> scoreQuery =
                        from devId in readcycle.cycles
                        where devId.CARID == car.ID
                        select devId.DEVICEID;
                        allIds = scoreQuery.ToList();

                        if (allIds.Count > 0)
                        {
                            IEnumerable<DEVICES.device> oneDevice =
                            from devId in devices.devices
                            where devId.ID == allIds[0]
                            select devId;

                            if (oneDevice.ToList().Count > 0)
                            {
                                DEVICES.device NewDevice = oneDevice.ToList()[0];
                                newDeviceId = datablock.deviceTable.AddNewDevice(1, NewDevice.DEVICE, NewDevice.VERSION, DateTime.Now, 1, 23442324);
                            }
                            else
                                newDeviceId = datablock.deviceTable.AddNewDevice(1, "UndefinedDevice", "UndefinedVersion", DateTime.Now, 1, 23442324);
                        }
                        else
                            newDeviceId = datablock.deviceTable.AddNewDevice(1, "UndefinedDevice", "UndefinedVersion", DateTime.Now, 1, 23442324);

                        if (car.DEPARTMENTID == department.ID)
                        {
                            int cardId = datablock.cardsTable.CreateNewCard(car.REGNUMBER, "Unknown", datablock.cardsTable.vehicleCardTypeId, orgId, 0, "Created from FIREBIRD database", 0, 1);
                            carId = datablock.vehiclesTables.AddNewVehicle(car.REGNUMBER, car.CARMODEL, "Unknown", 1, newDeviceId, cardId, DateTime.Now, 1);
                            tempOldNewIds = new KeyValuePair<int, int>(car.ID, carId);
                            carsOldNewIds.Add(tempOldNewIds);
                        }
                    }
                    #endregion
                    #region "workers"
                    IEnumerable<WORKERS.worker> workersList =
                         from worker in workers.workers
                         where worker.DEPARTMENTID == department.ID
                         select worker;

                    foreach (WORKERS.worker workerForAdd in workersList)
                    {
                        int newWId = datablock.cardsTable.CreateNewCard(workerForAdd.FIRSTNAME + " " + workerForAdd.SURNAME, workerForAdd.WORKERINTID.ToString(), datablock.cardsTable.driversCardTypeId,
                            orgId, 0, "Created from firebird", 0, 1);
                        /*userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Patronimic);
                        datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.MIDDLENAME);
                        userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Name);
                        datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.FIRSTNAME);
                        userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Surname);
                        datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.SURNAME);
                        userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Birthday);
                        datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.BIRTHDAY.ToShortDateString());
                        userInfoId = datablock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_DriversCertificate);
                        datablock.usersTable.EditUserInfo(newWId, userInfoId, workerForAdd.LICENCE);*/
                        addedWorkers.Add(workerForAdd.ID);
                        tempOldNewIds = new KeyValuePair<int, int>(workerForAdd.ID, newWId);
                        workOldNewIds.Add(tempOldNewIds);
                    }
                    #endregion
                    #region "set orgId to READCYCLES"
                    if(addedWorkers.Count>0)
                        for(int i=0;i<readcycle.cycles.Count;i++)
                        {
                            if(addedWorkers.Contains(readcycle.cycles[i].WORKER1ID) || addedWorkers.Contains(readcycle.cycles[i].WORKER2ID))
                            {
                                KeyValuePair<READCYCLE.readcycle, int> readCycleAndorgId = new KeyValuePair<READCYCLE.readcycle, int>(readcycle.cycles[i], orgId);
                                readCycleAndorgIdList.Add(readCycleAndorgId);
                            }
                        }
                    #endregion
                }
                Console.WriteLine("Added workers, departmens, cars");

                if (readCycleAndorgIdList.Count != readcycle.cycles.Count)
                {
                    if (false) //база фигово связана
                        throw new Exception("Куда-то пропала часть инфы");
                }
                //Загрузка файлов ПЛФ в ранее созданные организации.
                foreach (KeyValuePair<READCYCLE.readcycle, int> readedcycle in readCycleAndorgIdList)
                {
                    SQLDB sqlDb = datablock.sqlDb;
                    SQLDB_Records sqlDB_rec = new SQLDB_Records(connectionStringMysql, sqlDb.GETMYSQLCONNECTION());
                    ReflectObjectToTableClass reflectedItemsList;
                    byte[] bytes = Guid.NewGuid().ToByteArray();
                    int orgId = readedcycle.Value;
                    Type type = null;
                    object myParseObject = new object();
                    plf = new PLFUnitClass();
                    plf = LoadLogBook(readedcycle.Key);
                    plf.cardType = 2;

                    IEnumerable<string> selCar =
                            from car in cars.carsArray
                            where car.ID == readedcycle.Key.CARID
                            select car.REGNUMBER;
                    if(selCar.ToList().Count>0)
                        plf.VEHICLE = selCar.ToList()[0];

                    IEnumerable<string> selDeviceName =
                            from dev in devices.devices
                            where dev.ID == readedcycle.Key.DEVICEID
                            select dev.DEVICE;
                    if (selDeviceName.ToList().Count > 0)
                        plf.ID_DEVICE = selDeviceName.ToList()[0];

                    int driverId = -1;
                    foreach (KeyValuePair<int, int> oldNew in workOldNewIds)
                    {
                        if (oldNew.Key == readedcycle.Key.WORKER1ID)
                            driverId = oldNew.Value;
                    }
                    int dataBlockId = datablock.AddPlfTypeData(orgId, bytes,
                        "AutoGenerated " + plf.VEHICLE + " " + plf.START_PERIOD.ToString() + " - " + plf.END_PERIOD.ToString(),
                        driverId);
                    DataRecords dataRecord = new DataRecords(connectionString, dataBlockId, currentLanguage, sqlDb);

                        //////////////////////устанавливаем PLF карту нужного водителя. Незнаю почему именно здесь, но так получилось.
                    int plfDriversCardType = sqlDB_rec.Get_DataBlockCardType(dataBlockId);
                    sqlDb.SetDataBlock_CardId(dataBlockId, plfDriversCardType);
                       // sqlDB.OpenConnection();
                        int cardTypeParamId = sqlDb.AddParam("cardType", 0, 255);
                        //sqlDB.OpenConnection();
                        sqlDb.DeleteDataRecord(dataBlockId, cardTypeParamId);
                       // sqlDB.CloseConnection();
                        //////////////////////
                        type = plf.GetType();
                        myParseObject = plf;

                    //sqlDB.OpenConnection();
                    SetParseBDate(sqlDb, dataBlockId);
                    //sqlDB.CloseConnection();

                    List<ReflectObjectToTableClass> allRecordsToAdd = new List<ReflectObjectToTableClass>();

                    foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        reflectedItemsList = new ReflectObjectToTableClass();
                        string fieldName = pi.Name;
                        object field2 = pi.GetValue(myParseObject, null);

                        if (field2 != null)
                        {
                            reflectedItemsList.ReflectObjectToTable(fieldName, field2);//Не удалять!
                            allRecordsToAdd.Add(AddRecords(reflectedItemsList, sqlDb));//не удалять
                        }
                    }

                    foreach (ReflectObjectToTableClass recordList in allRecordsToAdd)
                    {
                        dataRecord.AddDataArray(recordList.reflectedItemsList);
                    }

                    //sqlDB.OpenConnection();
                    SetParseEDate(sqlDb,dataBlockId);
                    sqlDb.SetDataBlockState(dataBlockId, 2);
                    int dataBlockParseRecords = sqlDb.SetDataBlockParseRecords(dataBlockId);
                    Console.WriteLine("" + dataBlockParseRecords.ToString()+" records added");
                }

                Console.WriteLine("\n\r" + "Время начала импорта " + startLoadTime.ToShortDateString() + " " + startLoadTime.ToShortTimeString());
                Console.WriteLine("\n\r" + "Время окончания импорта " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
                //throw new Exception();
                datablock.CommitTransaction();
                datablock.CloseConnection();

            }
            catch (Exception ex)
            {
                datablock.RollbackConnection();
                datablock.CloseConnection();
                Console.WriteLine(ex.Message);
            }
        }