using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using tpDomeWinAPP.Models; using tpDomeWinAPP.Service; namespace tpDomeWinAPP { public partial class fmDB2Niagara : Form { public List ds { get; set; } public string building { get; set; } procCompare svcCompar = new procCompare(); public fmDB2Niagara() { InitializeComponent(); } private void btTagCompare_Click(object sender, EventArgs e) { building = ((fmCheckTagName)this.Parent.Parent.Parent.Parent.Parent).building; int i = svcCompar.updateNiagaraTag_forDBTags(building); if (i > 0) { lbMsg.Text = "共更新 " + i.ToString() + " 筆資料 " + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } else if(i == -1) { lbMsg.Text = "更新失敗! " + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } } private void btSearch_N4vsDB_Click(object sender, EventArgs e) { building = ((fmCheckTagName)this.Parent.Parent.Parent.Parent.Parent).building; if (string.IsNullOrEmpty(building)) { MessageBox.Show("請選擇棟別!"); return; } StringBuilder sb = new StringBuilder(); foreach (Control c in tableLayoutPanel1.Controls) { if (c is TextBox) { if (c.Text.Trim().Length > 0) { string num = c.Name.Substring(c.Name.Length - 1, 1);//取出最後的數字 switch (num) { // case "1": sb.Append($@" and device_building_tag like '%{c.Text.Trim()}%' "); break; case "2": sb.Append($@" and device_system_tag like '%{c.Text.Trim()}%' "); break; case "3": sb.Append($@" and device_floor_tag like '%{c.Text.Trim()}%' "); break; case "4": sb.Append($@" and device_name_tag like '%{c.Text.Trim()}%' "); break; case "5": sb.Append($@" and device_serial_tag like '%{c.Text.Trim()}%' "); break; } } } } sb.Insert(0, $@"select * from import_dbTag_niagaraTag where device_building_tag = '{building}' "); if (cbShowEmpty.Checked) { sb.Append($@" and niagaraTag = ''"); } sb.Append($@" order by device_number"); ds = svcCompar.filterDBTags(sb.ToString()); dataGridView2.DataSource = ds; lbMsg.Text = "共 " + ds.Count.ToString() + " 筆資料 " + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } private void dataGridView2_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { int index = 0; int spliteCell = 1;//每三行換一個顏色 DataGridView dg = (sender as DataGridView); //foreach (DataGridViewRow dgv in dataGridView1.Rows) foreach (DataGridViewRow dgv in dg.Rows) { if (index % 2 == 0) dgv.DefaultCellStyle.BackColor = SystemColors.GradientActiveCaption; //改row的顏色 else dgv.DefaultCellStyle.BackColor = Color.White; //改row的顏色 index++; } } } }