Esempio n. 1
0
        public void WritePrefix(DbConnect DbConnect)
        {
            DbConnect.ClearParameters();

            DbConnect.Query = "INSERT INTO prefix_reports (`session_time`,`prefix0`, `prefix1_3`, `prefix4_5`, `prefix8`, `prefix9_12`, `prefix13`, `prefix14`, `prefix15_22`, `prefix23_26`, `prefix31`, `crc_packet`, `crc_packet_ok`)"
                              + " VALUES (now(), @Id, @TextId, @Size, @Channel, @Serial, @Company, @Device, @Imei, @Phone, @Operation, @Crc, @CorrectCrc)";

            DbConnect.AddParameter("Id", Id);
            DbConnect.AddParameter("TextId", TextId);
            DbConnect.AddParameter("Size", Size);
            DbConnect.AddParameter("Channel", Channel);
            DbConnect.AddParameter("Serial", Serial);
            DbConnect.AddParameter("Company", Company);
            DbConnect.AddParameter("Device", Device);
            DbConnect.AddParameter("Imei", Imei);
            DbConnect.AddParameter("Phone", Phone);
            DbConnect.AddParameter("Operation", Operation);
            DbConnect.AddParameter("Crc", Crc.ToString("X4"));
            DbConnect.AddParameter("CorrectCrc", (CorrectCrc ? 1 : 0));

            DbConnect.ExecuteNonQuery();
        }
Esempio n. 2
0
        public void WriteTest(DbConnect DbConnect)
        {
            DbConnect.ClearParameters();

            DbConnect.AddParameter("Channel", Channel);
            DbConnect.AddParameter("Serial", Serial);
            DbConnect.AddParameter("Company", Company);
            DbConnect.AddParameter("Device", Device);

            DbConnect.AddParameter("Code", 5);
            DbConnect.AddParameter("Data", "");

            DbConnect.Query = "INSERT INTO receipt_requests (`ts`,`serNUM`, `mfDEV`, `typeDEV`, `chNUM`, `Status`, `CodeOp`, `Data`) VALUES (now(), @Serial, @Company, @Device, @Channel, 0, @Code, @Data)";

            try
            {
                DbConnect.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception((Properties.Settings.Default.DebugInfo ? e.Message : "Database write error"));
            }
        }
Esempio n. 3
0
        public void WriteData(DbConnect DbConnect, int Status)
        {
            if (Receipt == null)
            {
                return;
            }

            DbConnect.ClearParameters();

            DbConnect.AddParameter("Id", Receipt.Id);
            DbConnect.AddParameter("Status", Status);

            DbConnect.Query = "UPDATE receipt_requests SET `status` = @Status WHERE id = @Id";

            try
            {
                DbConnect.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception((Properties.Settings.Default.DebugInfo ? e.Message : "Database write error"));
            }
        }
Esempio n. 4
0
        public void Write(DbConnect DbConnect)
        {
            string FieldString     = "";
            string ParameterString = "";

            foreach (Protocol.StructValue CurrentValue in ChosenBlock.ValueList)
            {
                // сверяем значение флага
                if (!CurrentValue.CheckFlag(Data, Size))
                {
                    continue;
                }

                if (CurrentValue.Field.Length == 0)
                {
                    // неизвестное поле

                    throw new Exception("Unknown field: " + CurrentValue.Name);
                }
                else if (CurrentValue.Parameter.Length > 0)
                {
                    // поле из префикса

                    if (!DbConnect.CheckParameter(CurrentValue.Parameter))
                    {
                        throw new Exception("Unknown parameter: " + CurrentValue.Name);
                    }

                    FieldString += (FieldString.Length > 0 ? "," : "") + "`" + CurrentValue.Field + "`";

                    ParameterString += (ParameterString.Length > 0 ? "," : "") + "@" + CurrentValue.Parameter;
                }
                else if (CurrentValue.Type.Length > 0 && CurrentValue.Size > 0)
                {
                    // поле из блока, распознаем тип и длину

                    if (CurrentValue.Offset + CurrentValue.Size >= Size)
                    {
                        throw new Exception("Value is out of block limits: " + CurrentValue.Name);
                    }

                    if (CurrentValue.Type == "uint" && CurrentValue.Size == 1)
                    {
                        DbConnect.AddParameter("_" + CurrentValue.Field, Data[CurrentValue.Offset]);
                    }
                    else if (CurrentValue.Type == "uint" && CurrentValue.Size == 2)
                    {
                        DbConnect.AddParameter("_" + CurrentValue.Field, System.BitConverter.ToUInt16(Data, CurrentValue.Offset));
                    }
                    else if (CurrentValue.Type == "uint" && CurrentValue.Size == 4)
                    {
                        DbConnect.AddParameter("_" + CurrentValue.Field, System.BitConverter.ToUInt32(Data, CurrentValue.Offset));
                    }
                    else if (CurrentValue.Type == "uint" && CurrentValue.Size == 8)
                    {
                        DbConnect.AddParameter("_" + CurrentValue.Field, System.BitConverter.ToUInt64(Data, CurrentValue.Offset));
                    }
                    else if (CurrentValue.Type == "float" && CurrentValue.Size == 4)
                    {
                        if (BitConverter.ToString(Data, CurrentValue.Offset, 4) == "00-00-C0-7F")
                        {
                            continue;
                        }
                        DbConnect.AddParameter("_" + CurrentValue.Field, System.BitConverter.ToSingle(Data, CurrentValue.Offset));
                    }
                    else if (CurrentValue.Type == "datetime" && CurrentValue.Size == 4)
                    {
                        DbConnect.AddParameter("_" + CurrentValue.Field, Converter.ToDateTime32(Data, CurrentValue.Offset));
                    }
                    else if (CurrentValue.Type == "char" && CurrentValue.Size > 0)
                    {
                        DbConnect.AddParameter("_" + CurrentValue.Field, System.BitConverter.ToString(Data, CurrentValue.Offset, CurrentValue.Size).Replace("-", string.Empty));
                    }
                    else if (CurrentValue.Type == "byte" && CurrentValue.Size > 0)
                    {
                        byte[] arr = new byte[CurrentValue.Size];
                        Array.Copy(Data, CurrentValue.Offset, arr, 0, CurrentValue.Size);
                        DbConnect.AddParameter("_" + CurrentValue.Field, arr);
                    }
                    else
                    {
                        throw new Exception("Unknown type: " + CurrentValue.Type + " of " + CurrentValue.Size.ToString() + "bytes");
                    }

                    FieldString += (FieldString.Length > 0 ? "," : "") + "`" + CurrentValue.Field + "`";

                    ParameterString += (ParameterString.Length > 0 ? "," : "") + "@_" + CurrentValue.Field;
                }
                else
                {
                    // неизвестное поле

                    throw new Exception("Unknown value: " + CurrentValue.Name);
                }
            }

            if (FieldString.Length > 0)
            {
                DbConnect.Query = "INSERT INTO " + ChosenBlock.Table + " (" + FieldString + ") VALUES (" + ParameterString + ")";

                try
                {
                    DbConnect.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw new Exception((Properties.Settings.Default.DebugInfo ? e.Message : "Database write error"));
                }
            }
        }