/// <summary>
 /// 斷線偵測畫面
 /// </summary>
 /// <param name="ewatch_MySqlComponent">資料庫方法</param>
 public EwatchConnectionUserControl(Ewatch_MySqlComponent ewatch_MySqlComponent)
 {
     Ewatch_MySqlComponent = ewatch_MySqlComponent;
     CaseSettings          = ewatch_MySqlComponent.CaseSettings;
     AiSettings            = ewatch_MySqlComponent.AiSettings;
     ElectricSettings      = ewatch_MySqlComponent.ElectricSettings;
     InitializeComponent();
     #region AI斷線資訊
     AigridControl.DataSource           = AiSettings;
     gridView1.OptionsBehavior.Editable = false;
     gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
     for (int i = 0; i < gridView1.Columns.Count; i++)
     {
         gridView1.Columns[i].BestFit();
     }
     gridView1.Columns["PK"].Visible             = false;
     gridView1.Columns["NotifyFlag"].Visible     = false;
     gridView1.Columns["CaseNo"].Caption         = "案場名稱";
     gridView1.Columns["AiNo"].Caption           = "Ai編號";
     gridView1.Columns["AiName"].Caption         = "Ai名稱";
     gridView1.Columns["NotifyFlag"].Visible     = false;
     gridView1.Columns["TimeoutSpan"].Visible    = false;
     gridView1.Columns["MTimeoutSpan"].Visible   = false;
     gridView1.Columns["SendTime"].Visible       = false;
     gridView1.Columns["ConnectionFlag"].Caption = "連線狀態";
     #region 案場名稱顯示功能
     gridView1.CustomColumnDisplayText += (s, e) =>
     {
         if (e.Column.FieldName.ToString() == "CaseNo")
         {
             string cellValue = e.Value.ToString();
             var    data      = CaseSettings.SingleOrDefault(g => g.CaseNo == cellValue);
             if (data != null)
             {
                 e.DisplayText = data.TitleName;
             }
         }
     };
     #endregion
     #region 斷線燈號顯示功能
     gridView1.CustomDrawCell += (s, e) =>
     {
         e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
         e.Appearance.Options.UseTextOptions = true;
         e.DefaultDraw();
         if (e.Column.FieldName == "ConnectionFlag")
         {
             Color  color;
             string cellValue = e.CellValue.ToString();
             if (cellValue == "不使用")
             {
                 color = normalPriority;
             }
             else if (cellValue == "斷線")
             {
                 color = highPriority;
             }
             else
             {
                 color = lowPriority;
             }
             e.Cache.FillEllipse(e.Bounds.X + 204, e.Bounds.Y + 1, markWidth, markWidth, color);
         }
     };
     #endregion
     #endregion
     #region 電表斷線資訊
     ElectricgridControl.DataSource     = ElectricSettings;
     gridView2.OptionsBehavior.Editable = false;
     gridView2.OptionsSelection.EnableAppearanceFocusedCell = false;
     for (int i = 0; i < gridView2.Columns.Count; i++)
     {
         gridView2.Columns[i].BestFit();
     }
     gridView2.Columns["PK"].Visible             = false;
     gridView2.Columns["CaseNo"].Caption         = "案場編號";
     gridView2.Columns["ElectricNo"].Caption     = "電表編號";
     gridView2.Columns["PhaseTypeEnum"].Caption  = "相位類型";
     gridView2.Columns["ElectricName"].Caption   = "電表名稱";
     gridView2.Columns["NotifyFlag"].Visible     = false;
     gridView2.Columns["TimeoutSpan"].Visible    = false;
     gridView2.Columns["MTimeoutSpan"].Visible   = false;
     gridView2.Columns["SendTime"].Visible       = false;
     gridView2.Columns["ConnectionFlag"].Caption = "連線狀態";
     #region 相位類型顯示功能
     gridView2.CustomColumnDisplayText += (s, e) =>
     {
         if (e.Column.FieldName.ToString() == "PhaseTypeEnum")
         {
             int cellValue = Convert.ToInt32(e.Value);
             if (cellValue == 0)
             {
                 e.DisplayText = "三相";
             }
             else if (cellValue == 1)
             {
                 e.DisplayText = "單相";
             }
         }
         else if (e.Column.FieldName.ToString() == "CaseNo")
         {
             string cellValue = e.Value.ToString();
             var    data      = CaseSettings.SingleOrDefault(g => g.CaseNo == cellValue);
             if (data != null)
             {
                 e.DisplayText = data.TitleName;
             }
         }
     };
     #endregion
     #region 斷線燈號顯示功能
     gridView2.CustomDrawCell += (s, e) =>
     {
         e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
         e.Appearance.Options.UseTextOptions = true;
         e.DefaultDraw();
         if (e.Column.FieldName == "ConnectionFlag")
         {
             Color  color;
             string cellValue = e.CellValue.ToString();
             if (cellValue == "不使用")
             {
                 color = normalPriority;
             }
             else if (cellValue == "斷線")
             {
                 color = highPriority;
             }
             else
             {
                 color = lowPriority;
             }
             e.Cache.FillEllipse(e.Bounds.X + 150, e.Bounds.Y + 1, markWidth, markWidth, color);
         }
     };
     #endregion
     #endregion
 }
コード例 #2
0
        public Form1()
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\log\\log-.txt",
                                       rollingInterval: RollingInterval.Day,
                                       outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger(); //宣告Serilog初始化

            MySqlSetting  = InitialMethod.MySqlLoad();
            ButtonSetting = InitialMethod.InitialButtonLoad();
            InitializeComponent();
            NavigationFrame = new NavigationFrame()
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.Parent = DisPlaypanelControl;

            ButtonMethod = new ButtonMethod()
            {
                Form1 = this, navigationFrame = NavigationFrame
            };
            ButtonMethod.AccordionLoad(accordionControl1, ButtonSetting);

            #region Ewatch平台
            Ewatch_MySqlMethod                = new Ewatch_MySqlMethod(MySqlSetting);
            Ewatch_MySqlComponent             = new Ewatch_MySqlComponent(Ewatch_MySqlMethod);
            Ewatch_MySqlComponent.MyWorkState = true;
            Ewatch_Field4Component.Add(Ewatch_MySqlComponent);
            Ewatch_AlarmComponent             = new Ewatch_AlarmComponent(Ewatch_MySqlMethod);
            Ewatch_AlarmComponent.MyWorkState = true;
            Ewatch_Field4Component.Add(Ewatch_AlarmComponent);

            EwatchConnectionUserControl ewatchConnectionUserControl = new EwatchConnectionUserControl(Ewatch_MySqlComponent)
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(ewatchConnectionUserControl);
            Ewatch_Field4UserControl.Add(ewatchConnectionUserControl);

            CaseUserControl caseUserControl = new CaseUserControl(Ewatch_MySqlMethod)
            {
                Form1 = this, Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(caseUserControl);
            Ewatch_Field4UserControl.Add(caseUserControl);

            AiSettingUserControl aiSettingUserControl = new AiSettingUserControl(Ewatch_MySqlMethod)
            {
                Form1 = this, Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(aiSettingUserControl);
            Ewatch_Field4UserControl.Add(aiSettingUserControl);

            AiConfigUserControl aiConfigUserControl = new AiConfigUserControl(Ewatch_MySqlMethod)
            {
                Form1 = this, Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(aiConfigUserControl);
            Ewatch_Field4UserControl.Add(aiConfigUserControl);

            ElectricSettingUserControl electricSettingUserControl = new ElectricSettingUserControl(Ewatch_MySqlMethod)
            {
                Form1 = this, Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(electricSettingUserControl);
            Ewatch_Field4UserControl.Add(electricSettingUserControl);

            StateSettingUserControl stateSettingUserControl = new StateSettingUserControl(Ewatch_MySqlMethod)
            {
                Form1 = this, Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(stateSettingUserControl);
            Ewatch_Field4UserControl.Add(stateSettingUserControl);
            #endregion

            #region ChungHsin平台
            ChungHsin_MySqlMethod                = new ChungHsin_MySqlMethod(MySqlSetting);
            ChungHsin_MySqlComponent             = new ChungHsin_MySqlComponent(ChungHsin_MySqlMethod);
            ChungHsin_MySqlComponent.MyWorkState = true;
            ChungHsin_Field4Component.Add(ChungHsin_MySqlComponent);

            ChumgHsinConnectionUserControl chumgHsinConnectionUserControl = new ChumgHsinConnectionUserControl(ChungHsin_MySqlComponent)
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(chumgHsinConnectionUserControl);
            ChungHsin_Field4UserControl.Add(chumgHsinConnectionUserControl);

            DeviceConfigUserControl deviceConfigUserControl = new DeviceConfigUserControl(ChungHsin_MySqlMethod)
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(deviceConfigUserControl);
            ChungHsin_Field4UserControl.Add(deviceConfigUserControl);

            CH_CaseSettingUserControl cH_CaseSettingUserControl = new CH_CaseSettingUserControl(ChungHsin_MySqlMethod)
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(cH_CaseSettingUserControl);
            ChungHsin_Field4UserControl.Add(cH_CaseSettingUserControl);

            ReceiveSettingUserControl receiveSettingUserControl = new ReceiveSettingUserControl(ChungHsin_MySqlMethod)
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.AddPage(receiveSettingUserControl);
            ChungHsin_Field4UserControl.Add(receiveSettingUserControl);
            #endregion

            timer1.Interval = 1000;
            timer1.Enabled  = true;
        }