Пример #1
0
        /*public int EditAnySTRIDValueTEST(string newValue, string STRID_NAME, string Language, string tableName, string primaryName, int primaryValue)
        {
            DBI sqlDB = new SQLDB(connectionString);

            return sqlDB.EditAnySTRIDValue(newValue, STRID_NAME, Language, tableName, primaryName, primaryValue);
        }*/
        //------------------------static
        public static bool checkDataBlock(byte[] _bytes)
        {
            DDDParser parser = new DDDParser();
            byte[] twoLetters = HexBytes.arrayCopy(_bytes, 0, 2);
            bool isItRight = false;
            if (parser.checkWhatCardIsIt(twoLetters) != -1)
                isItRight = true;
            return isItRight;
        }
Пример #2
0
        /// <summary>
        /// Выгрузить из базы данных файл, из которого создан блок данных
        /// </summary>
        /// <param name="dataBlockId">ID блока данных</param>
        /// <returns>массив байт - файл ДДД или ПЛФ</returns>
        public byte[] GetDataBlock_BytesArray(int dataBlockId)
        {
            PARSER.DDDParser dddParser = new PARSER.DDDParser();

            byte[] blockDataBlob = sqlDb.GetDataBlock(dataBlockId);
            blockDataBlob = UnZipBytes(blockDataBlob);//АнЗипим файл!

            return blockDataBlob;
        }
Пример #3
0
        /// <summary>
        /// Парсить блок данных
        /// </summary>
        /// <param name="generateXML">генерировать ли XML файл</param>
        /// <param name="output">путь, куда XML сохранять</param>
        /// <param name="userId">ID пользователя, от имени которого вызывается этот метод</param>
        /// <returns>разобранный обьект</returns>
        public object ParseRecords(bool generateXML, string output, int userId)
        {
            Exception noOrg = new Exception("No organization entered");
            Exception CardVehicleError = new Exception("Ошибка в базе данных. Нет связи Карта - ТС!");

            if (organizationID == 0)
                throw noOrg;

            if (DATA_BLOCK_ID == -1)
                throw (new Exception("Can't find this Data Block"));
            else
            {
                //SQLDB sqlDB = new SQLDB(connectionString);
                SQLDB_Records sqlDB_rec = new SQLDB_Records(connectionString, sqlDb.GETMYSQLCONNECTION());
                ReflectObjectToTableClass reflectedItemsList;
                Type type = null;
                object myParseObject = new object();
                PARSER.DDDParser dddParser = new DDDParser();
                string fileName = "";

                try
                {

                    fileName = sqlDB_rec.Get_ParamValue(DATA_BLOCK_ID, "DataBlock_FileName");
                    byte[] blockDataBlob = sqlDb.GetDataBlock(DATA_BLOCK_ID);
                    blockDataBlob = UnZipBytes(blockDataBlob);//АнЗипим файл!
                    dddParser.ParseFile(blockDataBlob, fileName);

                    int cardType = dddParser.GetCardType();
                    currentCardType = cardType;

                    //test
                    //OpenConnection();
                    //OpenTransaction();
                    //

                    if (cardType == 0)// 0 - card(driver)
                    {
                        int cardId;
                        if (dddParser.cardUnitClass.ef_identification.driverCardHolderIdentification != null)
                        {
                            string drName = dddParser.cardUnitClass.ef_identification.driverCardHolderIdentification.cardHolderName.ToString();
                            string drNumber = dddParser.cardUnitClass.ef_identification.cardIdentification.cardNumber.ToString();
                            //sqlDB.OpenConnection();
                            cardId = cardsTable.GetCardId(drName, drNumber, cardsTable.driversCardTypeId);
                            if (cardId <= 0)
                            {
                                int grId = cardsTable.GetAllGroupIds(organizationID, 0)[0];
                                UserFromTable userData = new UserFromTable();
                                userData.name = "";
                                userData.pass = "";
                                int newUserId = usersTable.AddNewUser(userData, usersTable.DriverUserTypeId, 1, organizationID, userId);
                                string[] arr=drName.Split(' ');
                                usersTable.AddUserInfoValue(newUserId, DataBaseReference.UserInfo_Name, arr[0]);
                                usersTable.AddUserInfoValue(newUserId, DataBaseReference.UserInfo_Surname, arr[1]);
                                cardId = cardsTable.CreateNewCard(drName, drNumber, cardsTable.driversCardTypeId, organizationID, newUserId, "Init DataBlockId = " + DATA_BLOCK_ID, userId, grId);
                            }
                            sqlDb.SetDataBlock_CardId(DATA_BLOCK_ID, cardId);
                            //sqlDB.CloseConnection();
                        }
                        else
                        {
                            //sqlDB.OpenConnection();
                            sqlDb.SetDataBlockState(DATA_BLOCK_ID, 4);
                            //sqlDB.CloseConnection();
                            throw new Exception("Поддерживаются только водительские карты и информация с бортового устройства.");
                        }
                        type = dddParser.cardUnitClass.GetType();
                        myParseObject = dddParser.cardUnitClass;
                    }
                    else if (cardType == 1)//vehicle
                    {
                        /////////////////////////
                        int vehicleId;
                        if (dddParser.vehicleUnitClass.vehicleOverview.vehicleRegistrationIdentification != null)
                        {
                            int cardId;
                            string vehRegNumber = dddParser.vehicleUnitClass.vehicleOverview.vehicleRegistrationIdentification.vehicleRegistrationNumber.ToString();
                            string vin = dddParser.vehicleUnitClass.vehicleOverview.vehicleIdentificationNumber.ToString();
                            cardId = cardsTable.GetCardId(vehRegNumber, vin, cardsTable.vehicleCardTypeId);
                            vehicleId = vehiclesTables.GetVehicleId_byVinRegNumbers(vin, vehRegNumber);
                            if ((vehicleId <= 0 && cardId > 0) || (vehicleId > 0 && cardId <= 0))
                                throw CardVehicleError;

                            if (cardId <= 0)
                            {
                                string marka = "";
                                DateTime BLOCKED = dddParser.vehicleUnitClass.vehicleOverview.vuDownloadablePeriod.maxDownloadableTime.getTimeRealDate();
                                int grId = cardsTable.GetAllGroupIds(organizationID,0)[0];
                                cardId = cardsTable.CreateNewCard(vehRegNumber, vin, cardsTable.vehicleCardTypeId, organizationID, userId, "Init DataBlockId = " + DATA_BLOCK_ID, userId, grId);
                                //vehiclesTables.OpenConnection();
                                vehicleId = vehiclesTables.AddNewVehicle(vehRegNumber, marka, vin, 0, 1, cardId, BLOCKED, 1);
                                //vehiclesTables.CloseConnection();
                                // SetAllVehiclesIDS(vehicleId);
                            }
                            sqlDb.SetDataBlock_CardId(DATA_BLOCK_ID, cardId);
                        }
                        /////////////////////////
                        type = dddParser.vehicleUnitClass.GetType();
                        myParseObject = dddParser.vehicleUnitClass;
                    }
                    else if (cardType == 2)//plf
                    {
                        //////////////////////устанавливаем PLF карту нужного водителя. Незнаю почему именно здесь, но так получилось.
                        int plfDriversCardType = sqlDB_rec.Get_DataBlockCardType(DATA_BLOCK_ID);
                        sqlDb.SetDataBlock_CardId(DATA_BLOCK_ID, plfDriversCardType);
                        // sqlDB.OpenConnection();
                        int cardTypeParamId = sqlDb.AddParam("cardType", 0, 255);
                        //sqlDB.OpenConnection();
                        sqlDb.DeleteDataRecord(DATA_BLOCK_ID, cardTypeParamId);
                        // sqlDB.CloseConnection();
                        //////////////////////
                        type = dddParser.plfUnitClass.GetType();
                        myParseObject = dddParser.plfUnitClass;
                    }
                    else if (cardType == -1)
                        throw new Exception("Информация непригодна для разбора(не опознан тип карты");

                    //sqlDB.OpenConnection();
                    SetParseBDate(sqlDb);
                    //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));//не удалять
                        }
                    }

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

                    //sqlDB.OpenConnection();
                    SetParseEDate(sqlDb);
                    sqlDb.SetDataBlockState(DATA_BLOCK_ID, 2);
                    int dataBlockParseRecords = sqlDb.SetDataBlockParseRecords(DATA_BLOCK_ID);
                    Console.WriteLine("\n\r" + dataBlockParseRecords.ToString() + " records added");
                    //XML GENERATING
                    if (generateXML)
                        dddParser.GenerateXmlFile(output);
                    //
                    //Добавляем лог для каждого типа блока данных свой.
                    string logNote;
                    HistoryTable historyTable = new HistoryTable(connectionString, CurrentLanguage, sqlDb);
                    if (currentCardType == 0)//driver
                    {
                        string drName = dddParser.cardUnitClass.ef_identification.driverCardHolderIdentification.cardHolderName.ToString();
                        string drNumber = dddParser.cardUnitClass.ef_identification.cardIdentification.cardNumber.ToString();
                        logNote = "Driver: " + drName + "(" + drNumber + ")" + ", records number: " + dataBlockParseRecords.ToString();
                        historyTable.AddHistoryRecord("fn_data_block", "DATA_BLOCK_ID", DATA_BLOCK_ID, userId, historyTable.DDDDriversDataBlockLoaded, logNote, sqlDb);
                    }
                    if (currentCardType == 1)//vehicle
                    {
                        string logVehRegNumber = dddParser.vehicleUnitClass.vehicleOverview.vehicleRegistrationIdentification.vehicleRegistrationNumber.ToString();
                        string logVin = dddParser.vehicleUnitClass.vehicleOverview.vehicleIdentificationNumber.ToString();
                        logNote = "Vehicle: " + logVehRegNumber + "(" + logVin + ")" + ", records number: " + dataBlockParseRecords.ToString();
                        historyTable.AddHistoryRecord("fn_data_block", "DATA_BLOCK_ID", DATA_BLOCK_ID, userId, historyTable.DDDVehiclesDataBlockLoaded, logNote, sqlDb);
                    }
                    if (currentCardType == 2)//plf
                    {
                        string vehPlfIdent = dddParser.plfUnitClass.VEHICLE;
                        string plfDeviceId = dddParser.plfUnitClass.ID_DEVICE;
                        string period = dddParser.plfUnitClass.START_PERIOD.GetSystemTime().ToShortDateString() + " - " + dddParser.plfUnitClass.END_PERIOD.GetSystemTime().ToShortDateString();
                        logNote = "PLF File: " + vehPlfIdent + "(" + plfDeviceId + ")" + ", period: " + period + ", records number: " + dataBlockParseRecords.ToString();
                        historyTable.AddHistoryRecord("fn_data_block", "DATA_BLOCK_ID", DATA_BLOCK_ID, userId, historyTable.PLFDataBlockLoaded, logNote, sqlDb);
                    }
                    //
                    //sqlDb.CommitConnection();
                    //sqlDb.CloseConnection();
                }
                catch (Exception ex)
                {
                    //sqlDb.RollbackConnection();
                    //sqlDb.CloseConnection();
                    throw ex;
                }
                finally
                {
                }
                return myParseObject;
            }
        }