private void UpdateValue(Device sd, ZibaseDll.ZiBase.SensorInfo si, SensorType st)
        {
            DeviceValue dv = null;

            var q = sd.Values.Where(x => x.ValueType == st);
            if (q.Any())
            {
                dv = q.First();
                dv.Value = si.sHTMLValue;

                if (st == SensorType.ENERGY_KW || st == SensorType.ENERGY_KWH)
                {
                    String[] splitted = si.sValue.Split(new char[] { ' ' });
                    if (splitted.Length == 2)
                    {
                        float val = Convert.ToSingle(dv.Value,System.Globalization.CultureInfo.InvariantCulture); // Convert.ToInt32(splitted[0]);
                        //val /= 1000.0F;
                        dv.DisplayValue = val + " " + splitted[1];
                    }
                }
                else
                    dv.DisplayValue = si.sValue;
            }
            else
            {
                dv = new DeviceValue {Value = si.sHTMLValue, ValueType = st};
                if (st == SensorType.ENERGY_KW || st == SensorType.ENERGY_KWH)
                {
                    String[] splitted = si.sValue.Split(new char[] { ' ' });
                    if (splitted.Length == 2)
                    {
                        //float val = Convert.ToInt32(splitted[0]);
                        //val /= 1000.0F;
                        float val = Convert.ToSingle(dv.Value, System.Globalization.CultureInfo.InvariantCulture); // Convert.ToInt32(splitted[0]);
                        dv.DisplayValue = val + " " + splitted[1];
                    }
                }
                else
                    dv.DisplayValue = si.sValue;
                sd.Values.Add(dv);
            }

            // if no HSDevice associated,look for the current device in HS
            // IOMisc contains the ID followed by the SensorType
            if (dv.HSDevice == null)
            {
                var q2 = HSDevice.Where(x => x.iomisc.Contains(si.sID) && x.iomisc.Contains(st.ToString()));

                if (q2.Any())
                {
                    dv.AlreadyInHS = true;
                    dv.HSDevice = q2.First();
                }
            }
            dv.DwValue = si.dwValue;
            dv.HSUpdate();
        }
 private void Update(Device sd, ZiBase.SensorInfo se)
 {
     /*  if (se.sType == "lev") // common value for all sensor
         sd.RXLevel = se.sValue;
     else if (se.sType == "bat")// common value for all sensor
         sd.BatLevel = se.sValue;
     else
     {*/
         UpdateValue(sd, se, Device.EnumConverter(se.sType));
     //}
 }
        public void UpdateSensorData(ZiBase.SensorInfo se)
        {
            var q = from c in SensorList where c.ID.Contains(se.sID) select c;
            if (q.Any())
            {
                foreach (Device sd in q)
                {
                    //SensorData sd = q.First();
                    Update(sd, se);
                }
            }
            else
            {
                Device sd = new Device(se.sID) {ID = se.sID, Name = se.sName};

                Update(sd, se);
                SensorList.Add(sd);
            }
        }
        public string DisplaySensorInfo(Device se)
        {
            StringBuilder p = new StringBuilder();

            //string classname = "tableroweven"; // ((m_iUnitNumber % 2) == 0 ? "tableroweven" : "tablerowodd");

            //HsObjet.getInstance().WriteLog("Debug", "Device : " + se.ID + " " + se.Name);
            bool firstTime = true;
            foreach (DeviceValue dv in se.Values)
            {
                string classname = ((cnt % 2) == 0 ? "tableroweven" : "tablerowodd");
                //HsObjet.getInstance().WriteLog("Debug", "Value : " + dv.DisplayValue + " " + dv.ValueType + " inhs:" + dv.AlreadyInHS + " HSDevice null? :" + (dv.HSDevice==null));

                p.Append("<tr>\n");
                if (firstTime)
                {
                    p.Append("<td  noWrap class=\"" + classname + "\" align=center valign=middle>" + se.Name + "</td>\n");
                    p.Append("<td  noWrap class=\"" + classname + "\" align=center valign=middle>" + se.ID + "</td>\n");
                    firstTime = false;
                }
                else
                {
                    p.Append("<td  noWrap class=\"" + classname + "\" align=center valign=middle></td>\n");
                    p.Append("<td  noWrap class=\"" + classname + "\" align=center valign=middle></td>\n");
                }

                p.Append("<td  class=\"" + classname + "\" align=center>\n");
                p.Append(dv.ValueType.GetStringValue());
                p.Append("</td>\n");

                p.Append("<td  class=\"" + classname + "\" align=center>\n");
                p.Append(dv.DisplayValue);
                p.Append("</td>\n");

                p.Append("<td  class=\"" + classname + "\" align=center>\n");
                p.Append(dv.DwValue);
                p.Append("</td>\n");

                /*
                p.Append("<td  class=\"" + classname + "\" align=center>\n");
                p.Append(se.RXLevel);
                p.Append("</td>\n");

                p.Append("<td class=\"" + classname + "\" align=center>\n");
                p.Append(se.BatLevel);
                p.Append("</td>\n");
                 */

                p.Append("<td class=\"" + classname + "\" align=center>\n");
                p.Append("<input type=\"checkbox\" onClick=\"return false\"" + (dv.AlreadyInHS ? " checked " : "") + "\" name=\"AlreadyInHS\">" + (dv.AlreadyInHS ? " (" + dv.HSDevice.hc + dv.HSDevice.dc + ")" : "") + "</input>\n");
                p.Append("</td>\n");

                p.Append("<td class=\"" + classname + "\" align=middle>\n");
                p.Append("<form name='frmMain" + se.ID + "' method='POST'><br>\n");
                p.Append("<input type=\"hidden\" name=\"ref_page\" value=\"" + link + "\">\n");
                //p.Append("<input type='submit' name='AddDeviceId' value='"+ se.ID + "'>\n");
                p.Append("<input type=\"hidden\" name=\"Action\" value=\"\">\n");
                p.Append("<input type=\"hidden\" name=\"dc\" value=\"\">\n");
                p.Append("<input type=\"hidden\" name=\"hc\" value=\"\">\n");
                p.Append("<input type=\"hidden\" name=\"SensorType\" value=\"" + (int)dv.ValueType + "\">\n");
                p.Append("<input type=\"hidden\" name=\"Device\" value=\"\">\n");
                p.Append("<input class=\"formbutton\" id=\"AddUnit\" onclick=\"DoAddDevice('" + se.ID + "', 'DoAddDevice',this.form)\" type=\"button\"value=\"Add Device \" name=\"AddDevice\">\n");

                p.Append("</form>\n");
                p.Append("</td>\n");

                p.Append("</tr>\n");
            }
            return p.ToString();
        }