Esempio n. 1
0
        public ListViewPanel CreateDataViewPanel(DBDataProvider dataProvider, ConfigEntry entry, bool showList = true)
		{
            string deviceKey = entry.DeviceKey;
            string displayName = entry.DisplayName;
            if (this.panelDict.ContainsKey(deviceKey))
            {
                ListViewPanel panel = this.panelDict[deviceKey];
                if (this.currentPanel != panel)
                {
                    this.currentPanel.Visibility = Visibility.Hidden;
                }
                panel.Visibility = Visibility.Visible;
                this.currentPanel = panel;
                return panel;
            }
            else
            {
                // !
                ListViewPanel panel = new ListViewPanel(dataProvider, entry);
                DataListener dataListener = dataProvider.GetDataListener(deviceKey);
                panel.SetIcon(entry.Icon);
                panel.AddDataListener(dataListener);
                if (showList)
                {
                    panel.ListView = this.ShowListView(panel, dataListener);
                    panel.SearchView = this.ShowListView(panel, dataListener);
                    panel.GraphView = this.ShowGraphView(panel, dataListener);
                    panel.GraphSearchView = this.ShowSearchGraphView(panel, dataListener);

                    // Notice; Comment 4-7.
                    // panel.ListRecentData();
                    // 是否显示 控制面板
                    if (deviceKey == DataProvider.DeviceKey_MDS)
                    {
                        panel.ControlPanel = this.ShowControlView(DataProvider.DeviceKey_MDS);
                    }
                    else if (deviceKey == DataProvider.DeviceKey_AIS)
                    {
                        panel.ControlPanel = this.ShowControlView(DataProvider.DeviceKey_AIS);
                    }
                    else if (deviceKey == DataProvider.DeviceKey_NaI)
                    {
                        panel.SetupContextMenu((ListView)panel.ListView);
                        panel.SetupContextMenu((ListView)panel.SearchView);
                        panel.EnergyPanel = this.ShowEnergyView(DataProvider.DeviceKey_NaI);
                    }
                }

                if (this.currentPanel != null)
                {
                    this.currentPanel.Visibility = Visibility.Hidden;
                }
                this.currentPanel = panel;

                this.panelDict.Add(deviceKey, panel);
                return panel;
            }
		}
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="displayName">Display Name</param>
        /// <param name="interval">In Seconds</param>
        public ListViewPanel(DataProvider dataProvider, ConfigEntry entry)
		{
			InitializeComponent();
            this.deviceKey = entry.DeviceKey;
            this.DisplayName = entry.DisplayName;
            this.dataProvider = dataProvider;

            this.refreshDataTimer = new System.Windows.Forms.Timer();
            this.refreshDataTimer.Interval = (entry.Interval * 1000);
            this.refreshDataTimer.Tick += RefreshDataTimerTick;
            this.refreshDataTimer.Start();
		}
Esempio n. 3
0
        public ListViewPanel CreateDataViewPanel(DataProvider dataProvider, ConfigEntry entry, bool showList = true)
		{
            string deviceKey = entry.DeviceKey;
            string displayName = entry.DisplayName;
            if (this.panelDict.ContainsKey(deviceKey))
            {
                ListViewPanel panel = this.panelDict[deviceKey];
                if (this.currentPanel != panel)
                {
                    this.currentPanel.Visibility = Visibility.Hidden;
                }
                panel.Visibility = Visibility.Visible;
                this.currentPanel = panel;
                return panel;
            }
            else
            {
                // !
                ListViewPanel panel = new ListViewPanel(dataProvider, entry);
                DataListener dataListener = dataProvider.GetDataListener(deviceKey);
                panel.AddDataListener(dataListener);
                if (showList)
                {
                    panel.ListView = this.ShowListView(panel, dataListener);
                    panel.SearchView = this.ShowListView(panel, dataListener);
                    panel.GraphView = this.ShowGraphView(panel, dataListener, true);
                    panel.GraphSearchView = this.ShowSearchGraphView(panel, dataListener, false);

                    panel.ListRecentData();
                    // 是否显示 控制面板
                    if (deviceKey == DataProvider.DeviceKey_HvSampler)
                    {
                        panel.ControlPanel = this.ShowControlView(DataProvider.DeviceKey_HvSampler);
                    }
                    else if (deviceKey == DataProvider.DeviceKey_ISampler)
                    {
                        panel.ControlPanel = this.ShowControlView(DataProvider.DeviceKey_ISampler);
                    }
                }

                if (this.currentPanel != null)
                {
                    this.currentPanel.Visibility = Visibility.Hidden;
                }
                this.currentPanel = panel;

                this.panelDict.Add(deviceKey, panel);
                return panel;
            }
		}
 private List<ColumnInfo> ToColumnInfoList(ConfigEntry entry)
 {
     List<ColumnInfo> ret = new List<ColumnInfo>();
     foreach (ConfigItem ci in entry.ConfigItems)
     {
         ret.Add(new ColumnInfo()
         {   Header = ci.ColumnName,
             BindingName = ci.Key,
             Width = 120,
             DisplayInChart = ci.DisplayInChart
         });
     }
     return ret;
 }
Esempio n. 5
0
        private void ProcessLine(string key, string value, ConfigEntry entry)
        {
            int cp = value.IndexOf('#');
            if (cp > 0)
            {
                value = value.Substring(0, cp - 1);
            }
            string[] v = value.Split(';');
            int c = v.Length;

            string columnName = v[0].Trim();

            bool dynamicDataDisplay = false;
            bool alarm = false;
            double min = 0.0;
            double max = 100.0;
            double height = 100.0;
            double yellow = double.MaxValue;
            double red = double.MaxValue;
            if (v.Length > 1)
            {
                string e2 = v[1].Trim();
                if (e2.StartsWith("("))
                {
                    dynamicDataDisplay = true;
                    this.ParseDisplayParams(e2, out min, out max, out height);
                }

                if (v.Length > 2)
                {
                    string e3 = v[2].Trim();
                    if (e3.StartsWith("alarm"))
                    {
                        alarm = true;
                        e3 = e3.Substring(5);
                        this.ParseAlarmParams(e3, out yellow, out red);
                    }
                }
                else
                {
                    if (e2.StartsWith("alarm"))
                    {
                        alarm = true;
                        e2 = e2.Substring(5);
                        this.ParseAlarmParams(e2, out yellow, out red);
                    }
                }

                string dynDataDisplay = v[1].Trim();
                if (dynDataDisplay.StartsWith("("))
                {
                    dynamicDataDisplay = true;
                    this.ParseDisplayParams(dynDataDisplay, out min, out max, out height);
                }
            }

            var item = new ConfigItem(key);
            item.ColumnName = columnName;
            item.Unit = this.GetUnit(columnName);
            item.Max = max;
            item.Min = min;
            item.Height = height;

            item.DisplayInChart = dynamicDataDisplay;

            item.Alarm = alarm;
            if (alarm)
            {
                item.Yellow = yellow;
                item.Red = red;
            }
            entry.Add(item);
        }
Esempio n. 6
0
        private void ParseItems(string keyValueItems, ConfigEntry entry)
        {
            string[] keyValArray = keyValueItems.Split(';').Select(x => x.Trim()).ToArray();
            foreach (var keyValue in keyValArray)
            {
                string[] kv = keyValue.Split('=');
                if (kv.Length == 2)
                {
                    string key = kv[0].Trim().ToLower();
                    string val = kv[1];
                    if (key == "displayname")
                    {
                        entry.DisplayName = val;
                    }
                    else if (key == "tablename")
                    {
                        entry.TableName = val;
                    }
                    else if (key == "interval")
                    {
                        int interval = int.Parse(val);
                        entry.Interval = interval;
                    }
                    else if (key == "datafilter")
                    {
                        Assembly assembly = Assembly.Load("Scada.MainVision");
                        Type dataFilterType = assembly.GetType("Scada.MainVision." + val);

                        entry.DataFilter = (DataFilter)Activator.CreateInstance(dataFilterType, new object[] { });
                    }
                    else if (key == "datafilterparam")
                    {
                        if (entry.DataFilter != null)
                        {
                            entry.DataFilter.Parameter = val;
                        }
                        else
                        {
                            throw new Exception("DataFilter should be set first!");
                        }
                    }
                    else if (key == "icon")
                    {
                        entry.Icon = string.Format("Images/{0}.png", val);
                    }
                }

            }
        }
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="displayName">Display Name</param>
        /// <param name="interval">In Seconds</param>
        public ListViewPanel(DBDataProvider dataProvider, ConfigEntry entry)
        {
            InitializeComponent();
            this.deviceKey = entry.DeviceKey;
            this.DisplayName = entry.DisplayName;
            this.dataProvider = dataProvider;

            this.dbConn = this.dataProvider.GetMySqlConnection();

            var dbCmd = this.dbConn.CreateCommand();
            var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += (s, evt) =>
            {
                if (this.Shown && this.deviceKey != currentDeviceKey)
                {
                    currentDeviceKey = this.deviceKey;
                    this.ListRecentData(dbCmd);
                }
            };
            dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
            dispatcherTimer.Start();

        }
Esempio n. 8
0
        public ListViewPanel CreateDataViewPanel(DBDataProvider dataProvider, ConfigEntry entry, bool showList = true)
        {
            string deviceKey   = entry.DeviceKey;
            string displayName = entry.DisplayName;

            if (this.panelDict.ContainsKey(deviceKey))
            {
                ListViewPanel panel = this.panelDict[deviceKey];
                if (this.currentPanel != panel)
                {
                    this.currentPanel.Visibility = Visibility.Hidden;
                }
                panel.Visibility  = Visibility.Visible;
                this.currentPanel = panel;
                return(panel);
            }
            else
            {
                // !
                ListViewPanel panel        = new ListViewPanel(dataProvider, entry);
                DataListener  dataListener = dataProvider.GetDataListener(deviceKey);
                panel.SetIcon(entry.Icon);
                panel.AddDataListener(dataListener);
                if (showList)
                {
                    panel.ListView   = this.ShowListView(panel, dataListener);
                    panel.SearchView = this.ShowListView(panel, dataListener);

                    if (deviceKey != DataProvider.DeviceKey_Dwd && deviceKey != DataProvider.DeviceKey_Shelter)
                    {
                        panel.HasSerachDataChart = true;
                        if (deviceKey == DataProvider.DeviceKey_Hpic)
                        {
                            panel.GraphSearchView = this.ShowSearchHpicGraphView(panel, dataListener);
                        }
                        else
                        {
                            panel.GraphSearchView = this.ShowSearchGraphView(panel, dataListener);
                        }
                    }

                    if (deviceKey == DataProvider.DeviceKey_MDS)
                    {
                        panel.HasRealTimeChart = true;
                        panel.GraphView        = this.ShowGraphView(panel, dataListener);
                        panel.selectedField    = "flow";
                        panel.ControlPanel     = this.ShowControlView(DataProvider.DeviceKey_MDS);
                        panel.SttPanel         = this.ShowSttView(DataProvider.DeviceKey_MDS);
                    }
                    else if (deviceKey == DataProvider.DeviceKey_AIS)
                    {
                        panel.HasRealTimeChart = true;
                        panel.GraphView        = this.ShowGraphView(panel, dataListener);
                        panel.selectedField    = "flow";
                        panel.ControlPanel     = this.ShowControlView(DataProvider.DeviceKey_AIS);
                        panel.SttPanel         = this.ShowSttView(DataProvider.DeviceKey_AIS);
                    }
                    else if (deviceKey == DataProvider.DeviceKey_Weather)
                    {
                        panel.FieldSelect.Visibility    = Visibility.Visible;
                        panel.FieldSelect.SelectedIndex = 0;
                        panel.selectedField             = "temperature";
                    }
                    else if (deviceKey == DataProvider.DeviceKey_Hpic)
                    {
                        // panel.IntervalSelect.Visibility = Visibility.Visible;
                        panel.IntervalSelect.SelectedIndex = 0;
                        panel.selectedField = "doserate";
                    }
                    else if (deviceKey == DataProvider.DeviceKey_NaI)
                    {
                        panel.SetupContextMenu((ListView)panel.ListView);
                        panel.SetupContextMenu((ListView)panel.SearchView);
                        panel.EnergyPanel   = this.ShowEnergyView(DataProvider.DeviceKey_NaI);
                        panel.selectedField = "doserate";
                    }
                    else if (deviceKey == DataProvider.DeviceKey_Shelter)
                    {
                        panel.DoorPanel = this.ShowDoorView();
                    }
                }

                if (this.currentPanel != null)
                {
                    this.currentPanel.Visibility = Visibility.Hidden;
                }
                this.currentPanel = panel;

                this.panelDict.Add(deviceKey, panel);
                return(panel);
            }
        }
Esempio n. 9
0
        private void ParseLine(string line, ConfigEntry entry, Dictionary<string, object> data)
        {
            string[] a = line.Split(' ');
            foreach (var i in entry.ConfigItems)
            {
                if (i.FieldIndex > 1)
                {
                    string v = a[i.FieldIndex + 1];
                    data.Add(i.Key, v);
                }
                else if (i.FieldIndex == 1)
                {
                    string v = a[1] + " " + a[2];
                    data.Add(i.Key, v);
                }

            }

        }
Esempio n. 10
0
        /// <summary>
        /// Implements
        /// </summary>
        /// <param name="deviceKey"></param>
        /// <param name="current"></param>
        /// <param name="count"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        private List <Dictionary <string, object> > Refresh(string deviceKey, bool current, int count, DateTime beginTime, DateTime endTime, DateTime fromTime, DateTime toTime, MySqlCommand cmd)
        {
            // Return values
            var ret = new List <Dictionary <string, object> >();

            Config      cfg   = Config.Instance();
            ConfigEntry entry = cfg[deviceKey];

            if (current)
            {
                // Dead Branch
                cmd.CommandText = this.GetSelectStatement(entry.TableName, count);
            }
            else
            {
                cmd.CommandText = this.GetSelectStatement(entry.TableName, beginTime, endTime, fromTime, toTime);
            }

            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                int index = 0;

                List <string> keys = new List <string>();
                foreach (var i in entry.ConfigItems)
                {
                    string key = i.Key.ToLower();
                    if (deviceKey == DataProvider.DeviceKey_NaI && key.IndexOf('-') > 0)
                    {
                        continue;
                    }

                    keys.Add(key);
                }

                if (deviceKey == DataProvider.DeviceKey_Hpic || deviceKey == DataProvider.DeviceKey_Weather)
                {
                    keys.Add("ifrain");
                }

                string[] keyArray = keys.ToArray();

                Dictionary <string, object> data = null;// new Dictionary<string, object>(10);
                while (reader.Read())
                {
                    data = new Dictionary <string, object>(keyArray.Length);
                    foreach (var key in keyArray)
                    {
                        try
                        {
                            // -----------------------------
                            int i = reader.GetOrdinal(key);
                            if (!reader.IsDBNull(i))
                            {
                                string v = reader.GetString(i);
                                if (key == "ifrain")
                                {
                                    if (v == "0")
                                    {
                                        data.Add(key, false);
                                    }
                                    else
                                    {
                                        data.Add(key, true);
                                    }
                                }
                                else if (key == "doserate")
                                {
                                    double dv;
                                    if (double.TryParse(v, out dv))
                                    {
                                        data.Add(key, dv.ToString("0.0"));
                                    }
                                    else
                                    {
                                        data.Add(key, v);
                                    }
                                }
                                else if (key == "nuclidefound")
                                {
                                    data.Add(key, v == "1" ? "发现" : "未发现");
                                }
                                else if (key.IndexOf("alarm") >= 0)
                                {
                                    data.Add(key, v);
                                }
                                else
                                {
                                    double d;
                                    if (double.TryParse(v, out d))
                                    {
                                        data.Add(key, d.ToString("0.0"));
                                    }
                                    else
                                    {
                                        data.Add(key, d.ToString(v));
                                    }
                                }
                            }
                            else
                            {
                                if (key == "ifrain")
                                {
                                    data.Add(key, false);
                                }
                            }
                        }
                        catch (SqlNullValueException)
                        {
                            // TODO: Has Null Value
                            if (!data.ContainsKey(key))
                            {
                                data.Add(key, string.Empty);
                            }
                        }
                        catch (Exception e)
                        {
                            // break;
                            // No this field.
                        }
                    }

                    /*
                     * if (entry.DataFilter != null)
                     * {
                     *  entry.DataFilter.Fill(data);
                     * }
                     */
                    ret.Add(data);

                    index++;
                }
            }

            return(ret);
        }
Esempio n. 11
0
        public Dictionary <string, object> RefreshTimeNow(string deviceKey, MySqlCommand cmd)
        {
            // Return values
            const int MaxItemCount = 20;
            var       ret          = new Dictionary <string, object>(MaxItemCount);

            Config      cfg   = Config.Instance();
            ConfigEntry entry = cfg[deviceKey];

            cmd.CommandText = this.GetSelectStatement(entry.TableName, 1);

            try
            {
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        return(ret);
                    }
                    foreach (var i in entry.ConfigItems)
                    {
                        string key = i.Key.ToLower();
                        if (deviceKey == DataProvider.DeviceKey_NaI && key.IndexOf('-') > 0)
                        {
                            continue;
                        }

                        try
                        {
                            int index = reader.GetOrdinal(key);
                            if (!reader.IsDBNull(index))
                            {
                                string v = reader.GetString(index);
                                if (key == "doserate")
                                {
                                    double dv;
                                    if (double.TryParse(v, out dv))
                                    {
                                        ret.Add(key, dv.ToString("0.0"));
                                    }
                                    else
                                    {
                                        ret.Add(key, v);
                                    }
                                }
                                else if (key == "nuclidefound")
                                {
                                    ret.Add(key, v == "1" ? "发现" : "未发现");
                                }
                                else if (key.IndexOf("alarm") >= 0 || key == "direction")
                                {
                                    ret.Add(key, v);
                                }
                                else
                                {
                                    ret.Add(key, v);
                                }
                            }
                        }
                        catch (SqlNullValueException)
                        {
                            // TODO: Has Null Value
                            ret.Add(key, null);
                        }
                        catch (Exception)
                        {
                            // No this field.
                        }
                    }

                    if (entry.DataFilter != null)
                    {
                        entry.DataFilter.Fill(ret);
                    }
                }
            }
            catch (Exception)
            {
            }

            if (deviceKey == "scada.weather")
            {
                var d = new List <Dictionary <string, object> >();
                d.Add(ret);
                ReviseIfRainForWeather(cmd, d);
                return(d[0]);
            }
            return(ret);
        }
Esempio n. 12
0
        private void ProcessLine(string key, string value, ConfigEntry entry)
        {
            int cp = value.IndexOf('#');
            if (cp > 0)
            {
                value = value.Substring(0, cp - 1);
            }
            string[] v = value.Split(';');
            int c = v.Length;

            string columnName = v[0].Trim();

            bool dynamicDataDisplay = false;
            double min = 0.0;
            double max = 100.0;
            double height = 100.0;
            if (v.Length > 1)
            {
                string dynDataDisplay = v[1].Trim();
                if (dynDataDisplay.StartsWith("("))
                {
                    dynamicDataDisplay = true;
                    this.ParseDisplayParams(dynDataDisplay, out min, out max, out height);
                }
            }

            var item = new ConfigItem(key);
            item.ColumnName = columnName;
            item.Unit = this.GetUnit(columnName);
            item.Max = max;
            item.Min = min;
            item.Height = height;

            item.DisplayInChart = dynamicDataDisplay;
            entry.Add(item);
        }