private void SettingView_Load(object sender, EventArgs e) { gateWay = InitialMethod.GateWayLoad(); taiwan_DistricsSetting = InitialMethod.Taiwan_DistricsLoad(); #region 產生電錶填入欄位 for (int i = 0; i < 30; i++) //toggleSwitch = 啟動, toggleSwitch2 = 總錶 { DevExpress.XtraEditors.ToggleSwitch toggleSwitch = new DevExpress.XtraEditors.ToggleSwitch { Name = $"toggleSwitch{ 1 + i * 2}", Location = new Point(10, 8 + 25 * i), Size = new Size(48, 19), IsOn = false }; toggleSwitch.Properties.ShowText = false; xtraScrollableControl1.Controls.Add(toggleSwitch); DevExpress.XtraEditors.ToggleSwitch toggleSwitch2 = new DevExpress.XtraEditors.ToggleSwitch { Name = $"toggleSwitch{ 2 + i * 2}", Location = new Point(600, 8 + 25 * i), Size = new Size(48, 19), IsOn = false }; toggleSwitch2.Properties.ShowText = false; xtraScrollableControl1.Controls.Add(toggleSwitch2); toggleSwitches.Add(toggleSwitch); toggleSwitches2.Add(toggleSwitch2); } for (int i = 0; i < 30; i++) //設備名稱 { DevExpress.XtraEditors.TextEdit textEdit = new DevExpress.XtraEditors.TextEdit { Name = $"textEdit{1 + i}", Location = new Point(65, 6 + 25 * i), Size = new Size(105, 22) }; xtraScrollableControl1.Controls.Add(textEdit); textEdits.Add(textEdit); } for (int i = 0; i < 30; i++) //設備ID { DevExpress.XtraEditors.SpinEdit spinEdit = new DevExpress.XtraEditors.SpinEdit { Name = $"spinEdit{1 + i}", Location = new Point(185, 6 + 25 * i), Size = new Size(55, 20) }; spinEdit.Properties.MaxValue = 254; spinEdit.Properties.MinValue = 1; spinEdit.Properties.IsFloatValue = false; xtraScrollableControl1.Controls.Add(spinEdit); spinEdits.Add(spinEdit); } for (int i = 0; i < 30; i++) //電錶廠牌 { DevExpress.XtraEditors.ComboBoxEdit comboBoxEdit = new DevExpress.XtraEditors.ComboBoxEdit { Name = $"comboBoxEdit{1 + i * 4}", Location = new Point(250, 6 + 25 * i), Size = new Size(105, 22), Tag = i }; comboBoxEdit.SelectedIndexChanged += ComboBoxEdit1_SelectedIndexChanged; comboBoxEdit.Properties.Items.Add("PA310"); comboBoxEdit.Properties.Items.Add("HC6600"); comboBoxEdit.Properties.Items.Add("CPM6"); comboBoxEdit.Properties.Items.Add("PA60"); comboBoxEdit.Properties.Items.Add("ABBM2M"); comboBoxEdit.Properties.AllowFocused = false; comboBoxEdit.Properties.AllowMouseWheel = false; comboBoxEdit.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; xtraScrollableControl1.Controls.Add(comboBoxEdit); comboBoxEdits.Add(comboBoxEdit); } for (int i = 0; i < 30; i++) //comboBoxEdit2 = 電錶類型, comboBoxEdit3 = 迴路, comboBoxEdit4 = 相位 { DevExpress.XtraEditors.ComboBoxEdit comboBoxEdit2 = new DevExpress.XtraEditors.ComboBoxEdit { Name = $"comboBoxEdit{2 + i * 4}", Location = new Point(365, 6 + 25 * i), Size = new Size(68, 22), Tag = i }; comboBoxEdit2.SelectedIndexChanged += ComboBoxEdit2_SelectedIndexChanged; comboBoxEdit2.Properties.Items.Add("三相"); comboBoxEdit2.Properties.Items.Add("單相"); comboBoxEdit2.Properties.AllowFocused = false; comboBoxEdit2.Properties.AllowMouseWheel = false; comboBoxEdit2.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; xtraScrollableControl1.Controls.Add(comboBoxEdit2); DevExpress.XtraEditors.ComboBoxEdit comboBoxEdit3 = new DevExpress.XtraEditors.ComboBoxEdit { Name = $"comboBoxEdit{3 + i * 4}", Location = new Point(442, 6 + 25 * i), Size = new Size(68, 22), Tag = i }; comboBoxEdit3.Properties.Items.Add("迴路1"); comboBoxEdit3.Properties.Items.Add("迴路2"); comboBoxEdit3.Properties.Items.Add("迴路3"); comboBoxEdit3.Properties.Items.Add("迴路4"); comboBoxEdit3.Properties.AllowFocused = false; comboBoxEdit3.Properties.AllowMouseWheel = false; comboBoxEdit3.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; xtraScrollableControl1.Controls.Add(comboBoxEdit3); DevExpress.XtraEditors.ComboBoxEdit comboBoxEdit4 = new DevExpress.XtraEditors.ComboBoxEdit { Name = $"comboBoxEdit{4 + i * 4}", Location = new Point(518, 6 + 25 * i), Size = new Size(68, 22), Tag = i }; comboBoxEdit4.Properties.Items.Add("R相"); comboBoxEdit4.Properties.Items.Add("S相"); comboBoxEdit4.Properties.Items.Add("T相"); comboBoxEdit4.Properties.AllowFocused = false; comboBoxEdit4.Properties.AllowMouseWheel = false; comboBoxEdit4.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; xtraScrollableControl1.Controls.Add(comboBoxEdit4); comboBoxEdits2.Add(comboBoxEdit2); comboBoxEdits3.Add(comboBoxEdit3); comboBoxEdits4.Add(comboBoxEdit4); } #endregion #region 抓取原先設定 #region 層資料 ComtoggleSwitch.IsOn = gateWay.ControlFlag; RecordtoggleSwitch.IsOn = gateWay.RecordFlag; ATMtextEdit.Text = gateWay.GateWays[0].Authorization; if (gateWay.GateWays[0].GatewayEnumType == 0) { labelControl4.Visible = true; labelControl22.Visible = true; ComPortcomboBoxEdit.Visible = true; RTURatetextEdit.Visible = true; ComcomboBoxEdit.SelectedIndex = 0; ComPortcomboBoxEdit.Text = gateWay.GateWays[0].ModbusRTULocation; RTURatetextEdit.Text = Convert.ToString(gateWay.GateWays[0].ModbusRTURate); } else if (gateWay.GateWays[0].GatewayEnumType == 1) { labelControl19.Visible = true; labelControl21.Visible = true; ComTCPtextEdit.Visible = true; RatetextEdit.Visible = true; ComcomboBoxEdit.SelectedIndex = 1; ComTCPtextEdit.Text = gateWay.GateWays[0].ModbusTCPLocation; RatetextEdit.Text = Convert.ToString(gateWay.GateWays[0].ModbusTCPRate); } else if (gateWay.GateWays[0].GatewayEnumType == 2) { labelControl20.Visible = true; HTTPtextEdit.Visible = true; ComcomboBoxEdit.SelectedIndex = 2; HTTPtextEdit.Text = gateWay.GateWays[0].APILocation; } else if (gateWay.GateWays[0].GatewayEnumType == 3) { labelControl19.Visible = true; labelControl21.Visible = true; ComTCPtextEdit.Visible = true; RatetextEdit.Visible = true; ComcomboBoxEdit.SelectedIndex = 3; ComTCPtextEdit.Text = gateWay.GateWays[0].EMSLocation; RatetextEdit.Text = Convert.ToString(gateWay.GateWays[0].EMSRate); } #endregion #region 天氣 ATMtextEdit.Text = gateWay.GateWays[0].Authorization; CitycomboBoxEdit.Text = gateWay.GateWays[0].LocationName; ZonecomboBoxEdit.Text = gateWay.GateWays[0].DistrictName; DeviceTypecomboBoxEdit.SelectedIndex = gateWay.GateWays[0].GateWaySenserIDs[0].SenserEnumType; DeviceNametextEdit.Text = gateWay.GateWays[0].GateWaySenserIDs[0].DeviceName; IDspinEdit.Text = Convert.ToString(gateWay.GateWays[0].GateWaySenserIDs[0].DeviceID); #endregion #region 電表 for (int i = 0; i < gateWay.GateWays[0].GateWayElectricIDs.Count; i++) { toggleSwitches[i].IsOn = true; textEdits[i].Text = gateWay.GateWays[0].GateWayElectricIDs[i].DeviceName; spinEdits[i].Text = Convert.ToString(gateWay.GateWays[0].GateWayElectricIDs[i].DeviceID); comboBoxEdits[i].SelectedIndex = gateWay.GateWays[0].GateWayElectricIDs[i].ElectricEnumType; comboBoxEdits2[i].SelectedIndex = gateWay.GateWays[0].GateWayElectricIDs[i].PhaseEnumType; comboBoxEdits3[i].SelectedIndex = gateWay.GateWays[0].GateWayElectricIDs[i].LoopEnumType; comboBoxEdits4[i].SelectedIndex = gateWay.GateWays[0].GateWayElectricIDs[i].PhaseAngleEnumType; toggleSwitches2[i].IsOn = gateWay.GateWays[0].GateWayElectricIDs[i].TotalMeterFlag; } #endregion #endregion }