Exemplo n.º 1
0
        public string querySensor(string tbim, string type)
        {
            string[] senType = new string[11];
            senType[0]  = "speedSensor";
            senType[1]  = "heightSensor";
            senType[2]  = "temperatureSensor";
            senType[3]  = "pressureSensor";
            senType[4]  = "FuelQuantitySensor";
            senType[5]  = "solidGague";
            senType[6]  = "accelerateSensor";
            senType[7]  = "VUSensor";
            senType[8]  = "switch";
            senType[9]  = "battery";
            senType[10] = "indicator";

            /*   long tick = DateTime.Now.Ticks;
             * Random ro = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
             * List<SensorDescription> list = new List<SensorDescription>();
             * for (int i = 1; i <= 20; i++) {
             *     SensorDescription f = new SensorDescription();
             *     f.tbim = i.ToString();
             *     f.alias = i.ToString();
             *     int iRan = ro.Next(0, 11);
             *     f.sensorType = senType[iRan];
             *     list.Add(f);
             * }
             */
            string        coonString = @"SERVER=tianmn-pc\sqlexpress;UID=tianmn2109;password=10000000;";
            SqlConnection connection = new SqlConnection(coonString);

            connection.Open();
            string queryStr = @"select * from dbo.testData";

            if (tbim != "ALL")
            {
                queryStr += @" and tbim='" + tbim + "'";
            }
            if (type != "ALL")
            {
                queryStr += @" and type ='" + type + "'";
            }
            SqlCommand     seleceCMD = new SqlCommand(queryStr, connection);
            SqlDataAdapter custDA    = new SqlDataAdapter();

            custDA.SelectCommand = seleceCMD;
            DataSet custDS = new DataSet();

            custDA.Fill(custDS);
            List <SensorDescription> list = new List <SensorDescription>();

            foreach (DataRow mDr in custDS.Tables[0].Rows)
            {
                SensorDescription f = new SensorDescription();
                f.tbim       = mDr["tbim"].ToString();
                f.alias      = mDr["alias"].ToString();
                f.sensorType = senType[int.Parse(mDr["sensorType"].ToString())];
                list.Add(f);
            }
            string json = new JavaScriptSerializer().Serialize(list);

            return(json);
        }
        public string querySensor(string tbim, string type)
        {
            string[] senType = new string[11];
            senType[0] = "speedSensor";
            senType[1] = "heightSensor";
            senType[2] = "temperatureSensor";
            senType[3] = "pressureSensor";
            senType[4] = "FuelQuantitySensor";
            senType[5] = "solidGague";
            senType[6] = "accelerateSensor";
            senType[7] = "VUSensor";
            senType[8] = "switch";
            senType[9] = "battery";
            senType[10] = "indicator";

            /*   long tick = DateTime.Now.Ticks;
               Random ro = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
               List<SensorDescription> list = new List<SensorDescription>();
               for (int i = 1; i <= 20; i++) {
                   SensorDescription f = new SensorDescription();
                   f.tbim = i.ToString();
                   f.alias = i.ToString();
                   int iRan = ro.Next(0, 11);
                   f.sensorType = senType[iRan];
                   list.Add(f);
               }
               */
            string coonString = @"SERVER=tianmn-pc\sqlexpress;UID=tianmn2109;password=10000000;";
            SqlConnection connection = new SqlConnection(coonString);
            connection.Open();
            string queryStr = @"select * from dbo.testData";
            if (tbim != "ALL") {
                queryStr += @" and tbim='" + tbim + "'";
            }
            if (type != "ALL") {
                queryStr += @" and type ='" + type + "'";
            }
            SqlCommand seleceCMD = new SqlCommand(queryStr, connection);
            SqlDataAdapter custDA = new SqlDataAdapter();
            custDA.SelectCommand = seleceCMD;
            DataSet custDS = new DataSet();
            custDA.Fill(custDS);
            List<SensorDescription> list = new List<SensorDescription>();
            foreach (DataRow mDr in custDS.Tables[0].Rows)
            {
                SensorDescription f = new SensorDescription();
                f.tbim = mDr["tbim"].ToString();
                f.alias = mDr["alias"].ToString();
                f.sensorType = senType[int.Parse(mDr["sensorType"].ToString())];
                list.Add(f);
            }
            string json = new JavaScriptSerializer().Serialize(list);
            return json;
        }