Esempio n. 1
0
        public bool writeData(List <typeRec> typeRecs, string key, string logID)
        {
            string        connectionString;
            SqlConnection cnn;

            connectionString = ConfigurationManager.ConnectionStrings["LoggerDB"].ConnectionString;
            cnn = new SqlConnection(connectionString);
            try
            {
                cnn.Open();

                SqlCommand     command;
                SqlDataAdapter dataAdapter = new SqlDataAdapter();

                int loadNum     = 0;
                int configCount = typeRecs.Count / 3;
                int count       = 0;
                while (loadNum < configCount)
                {
                    typeRec      r     = typeRecs[count];
                    configParams parms = new configParams();

                    parms.camera          = r.typeContent.Substring(0, 1);
                    parms.cardReaderError = r.typeContent.Substring(1, 3);
                    parms.reserved1       = r.typeContent.Substring(4, 3);
                    parms.reserved2       = r.typeContent.Substring(7, 3);
                    parms.trackWriteError = r.typeContent.Substring(10, 3);
                    parms.supply          = r.typeContent.Substring(13, 3);
                    parms.reserved3       = r.typeContent.Substring(16, 9);

                    count++;
                    r          = typeRecs[count];
                    parms.luno = r.typeContent;

                    count++;
                    r = typeRecs[count];
                    int timersNum = r.typeContent.Length / 5;

                    parms.timers = new timerRec[timersNum];

                    for (int x = 0, y = 0; y < timersNum; x = x + 5, y++)
                    {
                        parms.timers[y].timerNum  = r.typeContent.Substring(x, 2);
                        parms.timers[y].timerTics = r.typeContent.Substring(x + 2, 3);
                    }

                    count++;
                    loadNum++;

                    // childs of configParamsInfo
                    string sql = "";
                    for (int y = 0; y < timersNum; y++)
                    {
                        sql = @"INSERT INTO configParamsTimers([logkey],[rectype],[timerNum],[timerTics],[logID]) ";
                        sql = sql + @" VALUES('" + r.typeIndex + "','C',";
                        sql = sql + "'" + parms.timers[y].timerNum + "',";
                        sql = sql + "'" + parms.timers[y].timerTics + "'," + logID + ")";

                        command = new SqlCommand(sql, cnn);
                        dataAdapter.InsertCommand = new SqlCommand(sql, cnn);
                        dataAdapter.InsertCommand.ExecuteNonQuery();
                        command.Dispose();
                    }

                    // save the timers parent record

                    sql = @"INSERT INTO configParamsInfo([logkey],[rectype],[camera],[cardReaderError],[reserved1]," +
                          "[reserved2],[trackWriteError],[supply],[reserved3],[luno],[timersCount],[load],[prjkey],[logID])" +
                          " VALUES('" + r.typeIndex + "','" + // key
                          'C' + "','" +                       // record type
                          parms.camera + "','" +
                          parms.cardReaderError + "','" +
                          parms.reserved1 + "','" +
                          parms.reserved2 + "','" +
                          parms.trackWriteError + "','" +
                          parms.supply + "','" +
                          parms.reserved3 + "','" +
                          parms.luno + "','" +
                          timersNum.ToString() + "','" +
                          loadNum.ToString() + "','" +
                          key + "'," +
                          logID + ")";

                    command = new SqlCommand(sql, cnn);
                    dataAdapter.InsertCommand = new SqlCommand(sql, cnn);
                    dataAdapter.InsertCommand.ExecuteNonQuery();
                    command.Dispose();
                    // cnn.Close();
                }
                cnn.Close();
                return(true);
            }

            catch (Exception dbEx)
            {
                Console.WriteLine(dbEx.ToString());
                return(false);
            }
        }
Esempio n. 2
0
        public bool writeData(List <typeRec> typeRecs, string key, string logID)
        {
            string        connectionString;
            SqlConnection cnn;

            connectionString = ConfigurationManager.ConnectionStrings["LoggerDB"].ConnectionString;
            cnn = new SqlConnection(connectionString);
            try
            {
                cnn.Open();

                SqlCommand     command;
                SqlDataAdapter dataAdapter = new SqlDataAdapter();

                int loadNum = 0;
                int count   = 0;

                while (count < typeRecs.Count)
                {
                    typeRec        r     = typeRecs[count];
                    enhancedParams parms = new enhancedParams();

                    parms.luno = r.typeContent;
                    count++;

                    int optionsCount = 0;

                    if (typeRecs[count - 1].typeIndex == typeRecs[count].typeIndex)
                    {
                        r            = typeRecs[count];
                        optionsCount = r.typeContent.Length / 5;

                        parms.options = new parameterAndValue[optionsCount];

                        for (int x = 0, y = 0; y < optionsCount; x = x + 5, y++)
                        {
                            parms.options[y].paramName  = r.typeContent.Substring(x, 2);
                            parms.options[y].paramValue = r.typeContent.Substring(x + 2, 3);
                        }

                        count++;
                    }

                    int timersNum = 0;

                    if (typeRecs[count - 1].typeIndex == typeRecs[count].typeIndex)
                    {
                        r         = typeRecs[count];
                        timersNum = r.typeContent.Length / 5;

                        parms.timers = new timerRec[timersNum];

                        for (int x = 0, y = 0; y < timersNum; x = x + 5, y++)
                        {
                            parms.timers[y].timerNum  = r.typeContent.Substring(x, 2);
                            parms.timers[y].timerTics = r.typeContent.Substring(x + 2, 3);
                        }

                        count++;
                    }
                    loadNum++;

                    // childs of EnhanedParamsInfo

                    string sql = "";
                    for (int y = 0; y < optionsCount; y++)
                    {
                        sql = @"INSERT INTO enhancedParams([logkey],[rectype],[optionNum],[optionCode],[logID]) ";
                        sql = sql + @" VALUES('" + r.typeIndex + "','C',";
                        sql = sql + "'" + parms.options[y].paramName + "',";
                        sql = sql + "'" + parms.options[y].paramValue + "'," + logID + ")";

                        command = new SqlCommand(sql, cnn);
                        dataAdapter.InsertCommand = new SqlCommand(sql, cnn);
                        dataAdapter.InsertCommand.ExecuteNonQuery();
                        command.Dispose();
                    }

                    sql = "";
                    for (int y = 0; y < timersNum; y++)
                    {
                        sql = @"INSERT INTO enhancedTimers([logkey],[rectype],[timerNum],[timerSeconds],[logID]) ";
                        sql = sql + @" VALUES('" + r.typeIndex + "','C',";
                        sql = sql + "'" + parms.timers[y].timerNum + "',";
                        sql = sql + "'" + parms.timers[y].timerTics + "'," + logID + ")";

                        command = new SqlCommand(sql, cnn);
                        dataAdapter.InsertCommand = new SqlCommand(sql, cnn);
                        dataAdapter.InsertCommand.ExecuteNonQuery();
                        command.Dispose();
                    }

                    // save the timers parent record

                    sql = @"INSERT INTO enhancedParamsInfo([logkey],[rectype],[luno],[paramsCount],[timersCount],[load],[prjkey],[logID])" +
                          " VALUES('" + r.typeIndex + "','" + // key
                          'C' + "','" +                       // record type
                          parms.luno + "','" +
                          optionsCount.ToString() + "','" +
                          timersNum.ToString() + "','" +
                          loadNum.ToString() + "','" +
                          key + "'," + logID + ")";

                    command = new SqlCommand(sql, cnn);
                    dataAdapter.InsertCommand = new SqlCommand(sql, cnn);
                    dataAdapter.InsertCommand.ExecuteNonQuery();
                    command.Dispose();
                    // cnn.Close();
                }
                cnn.Close();
                return(true);
            }

            catch (Exception dbEx)
            {
                Console.WriteLine(dbEx.ToString());
                return(false);
            }
        }
Esempio n. 3
0
        public void getData(string regExStr, string recordType, string logID)
        {
            string sql = @"SELECT logkey,id,group8 from [logger].[dbo].[loginfo] " +
                         "WHERE group8 like '" + regExStr + "' " +
                         "AND logID =" + logID;
            Dictionary <string, string> data = readData(sql);

            string[]       dataTypes = null;
            List <typeRec> typeList  = new List <typeRec>();

            string[] tmpTypes;

            foreach (KeyValuePair <string, string> rec in data)
            {
                // tmpTypes = rec.Value.Split((char)0x1c);

                if (recordType == "00" || recordType == "01")
                {
                    typeRec r = new typeRec();
                    r.typeIndex   = rec.Key;
                    r.typeContent = rec.Value;
                    typeList.Add(r);
                }



                tmpTypes = rec.Value.Split((char)0x1c);

                if (tmpTypes[3] == recordType)
                {
                    int    myInd    = tmpTypes[0].Length + tmpTypes[1].Length + tmpTypes[2].Length + tmpTypes[3].Length;
                    string typeData = rec.Value.Substring(myInd + 4, rec.Value.Length - (myInd + 4));

                    dataTypes = typeData.Split((char)0x1c);

                    foreach (string item in dataTypes)
                    {
                        typeRec r = new typeRec();
                        r.typeIndex   = rec.Key;
                        r.typeContent = item;
                        typeList.Add(r);
                    }
                }
            }
            switch (recordType)
            {
            case "00":
                TRec tr = new TRec();
                if (tr.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }

                break;

            case "01":
                TReply treply = new TReply();
                if (treply.writeData(typeList, Key, logID))
                {
                    // set screen bit to true
                    setBitToTrue(recordType, logID);
                }
                break;

            case "11":
                screenRec scrRec = new screenRec();
                if (scrRec.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "12":
                stateRec staRec = new stateRec();
                if (staRec.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "13":
                configParamsRec cpRec = new configParamsRec();
                if (cpRec.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "15":
                FitRec fitRec = new FitRec();
                if (fitRec.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "16":
                ConfigIdRec cir = new ConfigIdRec();
                if (cir.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "1A":
                EnhancedParamsRec epRec = new EnhancedParamsRec();
                if (epRec.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "1B":
                //writeMAC(typeList);
                break;

            case "1C":
                DateAndTimeRec dt = new DateAndTimeRec();
                if (dt.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;

            case "1E":
                //writeDispenser(typeList);
                break;

            case "42":
                ExtEncryptionRec xer = new ExtEncryptionRec();
                if (xer.writeData(typeList, Key, logID))
                {
                    setBitToTrue(recordType, logID);
                }
                break;
            }
        }