public static string GetUserGauges(XmlElement cmdEl)
    {
        decimal userId = decimal.Parse(cmdEl.GetAttribute("USERID"));

        IDashboardSystemDA dacObj = DataAccessFactory.Instance.GetDashboardSystemDA();
        FIDataTable        dt     = dacObj.GetUserGauges(userId);

        XmlDocument doc    = new XmlDocument();
        XmlElement  rootEl = (XmlElement)doc.AppendChild(doc.CreateElement("GAUGES"));

        if (dt != null && dt.Rows.Count != 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                XmlElement el = (XmlElement)rootEl.AppendChild(doc.CreateElement("GAUGE"));
                el.SetAttribute("ID", dr["id"].ToString());
                el.SetAttribute("USERID", dr["user_id"].ToString());
                el.SetAttribute("NAME", dr["name"].ToString());
                el.SetAttribute("TYPE", dr["type"].ToString());
                el.SetAttribute("X", dr["x"].ToString());
                el.SetAttribute("Y", dr["y"].ToString());
                el.SetAttribute("WIDTH", dr["width"].ToString());
                el.SetAttribute("HEIGHT", dr["height"].ToString());
                el.SetAttribute("VISIBLE", dr["visible"].ToString());
            }
        }
        return(doc.OuterXml);
    }
    public static void DeleteUserGaugeConfig(XmlElement cmdEl)
    {
        IDashboardSystemDA dacObj = DataAccessFactory.Instance.GetDashboardSystemDA();

        decimal userId = decimal.Parse(cmdEl.GetAttribute("USERID"));

        foreach (XmlElement el in cmdEl.SelectNodes("GAUGE"))
        {
            dacObj.DeleteUserGaugeConfig(
                new Guid(el.GetAttribute("ID")),
                userId
                );
        }
    }
    public static string GetUserGaugeConfig(XmlElement cmdEl)
    {
        decimal userId = decimal.Parse(cmdEl.GetAttribute("USERID"));

        IDashboardSystemDA dacObj = DataAccessFactory.Instance.GetDashboardSystemDA();
        XmlDocument        doc    = new XmlDocument();
        XmlElement         rootEl = (XmlElement)doc.AppendChild(doc.CreateElement("GAUGES"));

        foreach (XmlElement reqEl in cmdEl.SelectNodes("GAUGE"))
        {
            Guid gaugeId     = new Guid(reqEl.GetAttribute("ID"));
            bool queryDef    = (reqEl.GetAttribute("QUERYDEF") == "1");
            bool execQueries = (reqEl.GetAttribute("QUERYRESULT") == "1");

            FIDataTable dt = dacObj.GetUserGaugeConfig(userId, gaugeId);
            XmlElement  el = (XmlElement)rootEl.AppendChild(doc.CreateElement("GAUGE"));
            if (dt != null && dt.Rows.Count != 0)
            {
                DataRow dr = dt.Rows[0];
                el.SetAttribute("ID", dr["id"].ToString());
                el.SetAttribute("USERID", dr["user_id"].ToString());
                el.SetAttribute("NAME", dr["name"].ToString());
                el.SetAttribute("TYPE", dr["type"].ToString());
                el.SetAttribute("X", dr["x"].ToString());
                el.SetAttribute("Y", dr["y"].ToString());
                el.SetAttribute("WIDTH", dr["width"].ToString());
                el.SetAttribute("HEIGHT", dr["height"].ToString());
                el.SetAttribute("VISIBLE", dr["visible"].ToString());
                el.SetAttribute("REFRESH", dr["refresh"].ToString());

                // config, parse and execute if needed
                el.InnerXml = dr["config"].ToString();
                if (execQueries)
                {
                    foreach (XmlElement queryEl in el.SelectNodes("VAL[@TYPE='QUERY']"))
                    {
                        ExecuteQueries(queryEl, queryDef);
                    }
                }
            }
        }
        return(doc.OuterXml);
    }
    public static void SaveUserGaugeConfig(XmlElement cmdEl)
    {
        IDashboardSystemDA dacObj = DataAccessFactory.Instance.GetDashboardSystemDA();

        decimal userId = decimal.Parse(cmdEl.GetAttribute("USERID"));

        foreach (XmlElement el in cmdEl.SelectNodes("GAUGE"))
        {
            dacObj.SaveUserGaugeConfig(
                new Guid(el.GetAttribute("ID")),
                userId,
                (!el.HasAttribute("NAME") ? null : el.GetAttribute("NAME")),
                (!el.HasAttribute("TYPE") ? null : el.GetAttribute("TYPE")),
                (!el.HasAttribute("X") ? -1 : int.Parse(el.GetAttribute("X"))),
                (!el.HasAttribute("Y") ? -1 : int.Parse(el.GetAttribute("Y"))),
                (!el.HasAttribute("WIDTH") ? -1 : int.Parse(el.GetAttribute("WIDTH"))),
                (!el.HasAttribute("HEIGHT") ? -1 : int.Parse(el.GetAttribute("HEIGHT"))),
                (!el.HasAttribute("VISIBLE") ? -1 : int.Parse(el.GetAttribute("WIDTH"))),
                (!el.HasAttribute("REFRESH") ? -1 : int.Parse(el.GetAttribute("REFRESH"))),
                (el.InnerXml == "" ? null : el.InnerXml)
                );
        }
    }