示例#1
0
 public Running_Data(DataTable dt)
 {
     foreach (DataRow dr in dt.Rows)
     {
         string station_name = dr[0].ToString();
         int    Int_Num      = int.Parse(dr[1].ToString());
         int    Double_Num   = int.Parse(dr[2].ToString());
         int    Switch_Num   = int.Parse(dr[3].ToString());
         string com_type     = dr[4].ToString();
         string station_num  = dr[5].ToString();
         Running_Data_Struct running_data_struct = new Running_Data_Struct(station_name, Int_Num, Double_Num, Switch_Num, com_type, station_num);
         Station_Info_List.Add(running_data_struct);
     }
 }
示例#2
0
 public void Set_Value_Switch(string Station_Name, int address, bool value)
 {
     foreach (object myobject in Station_Info_List)
     {
         Running_Data_Struct mystruct = (Running_Data_Struct)myobject;
         if (mystruct.Get_Name() == Station_Name)
         {
             bool[] data = mystruct.Get_SwitchData();
             if (address >= 0 && address < data.Length)
             {
                 data[address] = value;
                 // 这里加入触发事件
                 Value_Change(new EventArgs());
             }
             break;
         }
     }
 }
示例#3
0
        private static void Gengxin_Tick(object sender, EventArgs e)
        {
            // 将来要改成事件驱动的变化,就是相应的时实库变化,本数据也发生变化
            if (gengxin == false)
            {
                gengxin = true;
                try
                {
                    foreach (object mylabel in ALLMyLabel_List)
                    {
                        try
                        {
                            MyLabel label      = (MyLabel)mylabel;
                            string  Value_Name = label.Value_Name;
                            string  where_cmd  = "Value_Name = '" + Value_Name + "'";

                            //DataTable dt = sqlbuilder.Select_Table("Value_Table", where_cmd);
                            DataRow[] rows = ValueTable.Select(where_cmd);

                            DataRow dr         = rows[0];
                            string  value_type = dr[1].ToString();
                            string  mode       = dr[4].ToString();
                            // 0 模式 直接显示文字模式
                            #region
                            if (mode == "0")
                            {
                                // 0 直接显示模式
                                if (dr[2].ToString() == "")
                                {
                                    label.Dispatcher.BeginInvoke(new Action(() => { label.Content = " " + dr[3].ToString() + " "; }));
                                    continue;
                                }
                                string station_name = dr[2].ToString();
                                int    address      = int.Parse(dr[3].ToString());
                                for (int i = 0; i < mydata.Station_Info_List.Count; i++)
                                {
                                    Running_Data_Struct mystruct = (Running_Data_Struct)mydata.Station_Info_List[i];
                                    //string myname = mystruct.Get_Name();
                                    if (mystruct.Get_Name() == station_name)
                                    {
                                        // 当站的名与结构的站名相同
                                        if (value_type == "Int")
                                        {
                                            int[] num = mystruct.Get_IntData();
                                            label.Dispatcher.BeginInvoke(new Action(() => { label.Content = " " + num[address].ToString() + " "; }));
                                        }

                                        if (value_type == "Double")
                                        {
                                        }

                                        if (value_type == "Bool")
                                        {
                                        }
                                        break;
                                    }
                                }
                            }
                            #endregion

                            // 1 模式 条件显示文字模式
                            #region
                            if (mode == "1")
                            {
                                if (dr[2].ToString() == "" || dr[3].ToString() == "")
                                {
                                    continue;      // 如果站名或者地址有一个为空,那么就不能用条件显示模式
                                }
                                string station_name = dr[2].ToString();
                                int    address      = 0;
                                try
                                {
                                    address = int.Parse(dr[3].ToString());
                                }
                                catch { continue; }
                                for (int i = 0; i < mydata.Station_Info_List.Count; i++)
                                {
                                    Running_Data_Struct mystruct = (Running_Data_Struct)mydata.Station_Info_List[i];
                                    //string myname = mystruct.Get_Name();
                                    if (mystruct.Get_Name() == station_name)
                                    {
                                        // 当站的名与结构的站名相同
                                        if (value_type == "Int")
                                        {
                                            int[]  num        = mystruct.Get_IntData();
                                            int    getvalue   = num[address];
                                            string condition1 = dr[5].ToString();
                                            string condition2 = dr[8].ToString();
                                            string condition3 = dr[11].ToString();
                                            int    value1     = -1;
                                            int    value2     = -1;
                                            int    value3     = -1;
                                            try
                                            {
                                                value1 = int.Parse(dr[6].ToString());
                                            }
                                            catch { }
                                            try
                                            {
                                                value2 = int.Parse(dr[9].ToString());
                                            }
                                            catch { }
                                            try
                                            {
                                                value3 = int.Parse(dr[12].ToString());
                                            }
                                            catch { }
                                            string Return_Value1 = dr[7].ToString();
                                            string Return_Value2 = dr[10].ToString();
                                            string Return_Value3 = dr[13].ToString();
                                            string result1       = Condition_Int(getvalue, condition1, value1, Return_Value1);
                                            string result2       = Condition_Int(getvalue, condition2, value2, Return_Value2);
                                            string result3       = Condition_Int(getvalue, condition3, value3, Return_Value3);
                                            if (result1 != null)
                                            {
                                                label.Dispatcher.BeginInvoke(new Action(() => { label.Content = " " + result1 + " "; })); continue;
                                            }
                                            if (result2 != null)
                                            {
                                                label.Dispatcher.BeginInvoke(new Action(() => { label.Content = " " + result2 + " "; })); continue;
                                            }
                                            if (result3 != null)
                                            {
                                                label.Dispatcher.BeginInvoke(new Action(() => { label.Content = " " + result3 + " "; })); continue;
                                            }
                                            label.Content = "标签设置有错误!";
                                        }

                                        if (value_type == "Double")
                                        {
                                        }

                                        if (value_type == "Bool")
                                        {
                                        }
                                        break;
                                    }
                                }
                            }
                            #endregion

                            // 2 模式 直接显示标签颜色
                            #region
                            if (mode == "2")
                            {
                                if (dr[2].ToString() == "" || dr[3].ToString() == "")
                                {
                                    continue;
                                }
                                string station_name = dr[2].ToString();
                                int    address      = 0;
                                try
                                {
                                    address = int.Parse(dr[3].ToString());
                                }
                                catch { continue; }
                                for (int i = 0; i < mydata.Station_Info_List.Count; i++)
                                {
                                    Running_Data_Struct mystruct = (Running_Data_Struct)mydata.Station_Info_List[i];
                                    if (mystruct.Get_Name() == station_name)
                                    {
                                        if (value_type == "Int")
                                        {
                                        }
                                        if (value_type == "Double")
                                        {
                                        }
                                        if (value_type == "Bool")
                                        {
                                            bool[] bool_num   = mystruct.Get_SwitchData();
                                            bool   getvalue   = bool_num[address];
                                            string condition1 = dr[5].ToString();
                                            string condition2 = dr[8].ToString();
                                            string condition3 = dr[11].ToString();
                                            bool   value1     = false;
                                            bool   value2     = false;
                                            bool   value3     = false;
                                            try
                                            {
                                                value1 = bool.Parse(dr[6].ToString());
                                            }
                                            catch { }
                                            try
                                            {
                                                value2 = bool.Parse(dr[9].ToString());
                                            }
                                            catch { }
                                            try
                                            {
                                                value3 = bool.Parse(dr[12].ToString());
                                            }
                                            catch { }
                                            string Return_Value1 = dr[7].ToString();
                                            string Return_Value2 = dr[10].ToString();
                                            string Return_Value3 = dr[13].ToString();
                                            string color1        = Condition_Bool(getvalue, condition1, value1, Return_Value1);
                                            string color2        = Condition_Bool(getvalue, condition2, value2, Return_Value2);
                                            string color3        = Condition_Bool(getvalue, condition3, value3, Return_Value3);
                                            if (color1 != null)
                                            {
                                                label.Dispatcher.BeginInvoke(new Action(() => { label.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color1)); })); continue;
                                            }
                                            if (color2 != null)
                                            {
                                                label.Dispatcher.BeginInvoke(new Action(() => { label.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color2)); })); continue;
                                            }
                                            if (color3 != null)
                                            {
                                                label.Dispatcher.BeginInvoke(new Action(() => { label.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color3)); })); continue;
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            #endregion
                        }
                        catch { }
                    }
                    gengxin = false;
                }
                catch { gengxin = false; }
            }
        }