|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using CnasSynchronousCommon;
-
- namespace CNAS_RunSync
- {
- public partial class ucSynchrousMain : UserControl
- {
- private string delayDays = FileOperation.GetSystemFormatConfigData().ShowDelayDays;
- private SyncInstrumentItemInfo syncInstrumentItem = new SyncInstrumentItemInfo();
- //private Dictionary<string, DataTable> dictSourceTables = new Dictionary<string, DataTable>();
- private DataTable dtSource = new DataTable(); //当前显示数据源
- private Dictionary<string, DataRow> dictSource = new Dictionary<string, DataRow>();
- private Dictionary<string, Type> DictComboBox = new Dictionary<string, Type>(); //ComboBox数据源
- private List<string> lstIntOrDouble = new List<string>() { "等于", "不等于", "大于", "小于", "不大于", "不小于" };
- private List<string> lstText = new List<string>() { "等于", "不等于", "包含", "不包含" };
- private Color FinedBackColor = Color.LightCyan; //查询后选中项
- Dictionary<string, string> DictField = new Dictionary<string, string>();
-
- public ucSynchrousMain()
- {
- InitializeComponent();
- }
-
- //需要存在一个仪器才能正常显示数据
- public ucSynchrousMain(SyncInstrumentItemInfo syncInstrumentItem)
- {
- InitializeComponent();
-
- dgvSyncData.AutoGenerateColumns = false;
- dgvSyncData.RowHeadersVisible = false;
- //dgvSyncData.RowsDefaultCellStyle.BackColor = Color.Bisque;
- dgvSyncData.AlternatingRowsDefaultCellStyle.BackColor = Color.WhiteSmoke;
-
- this.syncInstrumentItem = syncInstrumentItem;
- }
- /// <summary>
- /// 控件加载时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ucSynchrousMain_Load(object sender, EventArgs e)
- {
- BindData();
- }
-
- /// <summary>
- /// 绑定数据
- /// </summary>
- public void BindData()
- {
- if (this.syncInstrumentItem == null) return;
-
- this.lblTitle.Text = string.Format("当前仪器:【{0}】", syncInstrumentItem.Code);
-
- if (syncInstrumentItem.LstSyncPramas == null) return;
- if (syncInstrumentItem.SyncInstrumentDSInfo == null) return;
- //if (syncInstrumentItem.SyncInstrumentDSInfo.Path == null) return;
- if (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType == DataSourceType.None) return;
-
- this.lblTitleMsg.Text= string.Format("类型:{0} 路径:{1}", syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString(),syncInstrumentItem.SyncInstrumentDSInfo.Path);
-
- //清空现有绑定
- DictComboBox.Clear();
- dictSource.Clear();
-
- //加载相关数据
- //1.1根据仪器类型加载本地存储的中英文字段说明映射
- //if (syncInstrumentItem.LstSyncPramas.Count > 0)
- //{
- //InstrumentDescribeZH describeZH = new InstrumentDescribeZH(syncInstrumentItem.InstruType, syncInstrumentItem.LstSyncPramas[0].SourceTable);
- //describeZH.GetFieldDescribe();
- //DictField = describeZH.DictField;
- //}
-
- //2.datagridview中绑定数据(绑定的是从数据源中读取的数据)
- //2.1 根据映射表,创建datagridviewcolumn/和绑定数据列
- if (syncInstrumentItem.LstSyncPramas.Count <= 0) return;
-
- //创建选择列
- AddCheckBoxColumn(dgvSyncData, "selectedColumn", "选择", 80, true);
-
- //创建数据列
- foreach (var item in syncInstrumentItem.LstSyncPramas)
- {
- string strColumnName = item.SourceField;
- if (DictField.ContainsKey(strColumnName))
- strColumnName = DictField[strColumnName];
- AddDatagridColumn(dgvSyncData, item.SourceField, strColumnName, 150);
- }
- //创建GUID列
- AddDatagridColumn(dgvSyncData, "GridGuid", "GridGuid", 50, false);
-
- //2.2 获取数据源数据,构建datagridviewcell
- //2.2.1 获取数据源数据
- var query = syncInstrumentItem.LstSyncPramas.Where(s => s.IfDateField == true).ToList<SyncParamasInfo>();
- if (query.Count == 1)
- {
- object[] obj = new object[]
- {
- syncInstrumentItem.LstSyncPramas[0].SourceTable,
- query[0].SourceField,
- DateTime.Now.AddDays(Convert.ToInt32(delayDays)).ToString("yyyy-MM-dd HH:mm:ss")
- };
- InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrumentItem.SyncInstrumentDSInfo, obj);
- dtSource = instrumentData.GetInstrumentDataByDate();
- }
-
- //2.2.2 构建datagridviewcell
- foreach (DataRow dr in dtSource.Rows)
- {
- DataGridViewRow dataGridViewRow = new DataGridViewRow();
- foreach (DataGridViewColumn dataGridViewColumn in dgvSyncData.Columns)
- {
- if (dataGridViewColumn.Index == 0)
- {
- dataGridViewRow.Cells.Add(new DataGridViewCheckBoxCell());
- }
-
- if (dtSource.Columns.Contains(dataGridViewColumn.Name))
- AddDataTextCell(dataGridViewRow, dataGridViewColumn, dr);
- }
- //添加GUID值
- string strGuid = Guid.NewGuid().ToString();
- DataGridViewTextBoxCell txtCell = new DataGridViewTextBoxCell
- {
- Value = strGuid
- };
- dataGridViewRow.Cells.Add(txtCell);
-
- dgvSyncData.Rows.Add(dataGridViewRow);
-
- dictSource.Add(strGuid, dr);
- }
-
- //3.初始化查询相关内容
- //3.1 绑定Combobox数据源
- foreach (DataColumn dc in dtSource.Columns)
- {
- if (syncInstrumentItem.LstSyncPramas.Where(s => s.SourceField == dc.ColumnName.ToUpper()).LongCount<SyncParamasInfo>() > 0)
- {
- string strColumnName = dc.ColumnName.ToUpper();
- if (DictField.ContainsKey(strColumnName))
- strColumnName = DictField[strColumnName];
- DictComboBox.Add(strColumnName, dc.DataType);
- }
- }
- if (DictComboBox.Count > 0)
- {
- BindingSource bsComboBox = new BindingSource
- {
- DataSource = DictComboBox
- };
- cmbColumns.DataSource = bsComboBox;
- cmbColumns.ValueMember = "Key";
- cmbColumns.DisplayMember = "Key";
- }
- }
-
- /// <summary>
- /// 添加datagridview的列
- /// </summary>
- /// <param name="dgvShow"></param>
- /// <param name="strColumnName"></param>
- /// <param name="strColumnHeaderText"></param>
- /// <param name="Width"></param>
- /// <param name="bVisible"></param>
- private void AddDatagridColumn(DataGridView dgvShow, string strColumnName, string strColumnHeaderText, int Width, bool bVisible = true)
- {
- DataGridViewColumn Column = new DataGridViewColumn()
- {
- Name = strColumnName,
- HeaderText = strColumnHeaderText,
- Width = Width,
- Visible = bVisible,
- CellTemplate = new DataGridViewTextBoxCell(),
- ReadOnly = true
- };
-
- //设置文本对齐方式
- Column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- Column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
-
- //设置该列背景颜色
- dgvShow.Columns.Add(Column);
- }
-
- private void AddCheckBoxColumn(DataGridView dgvShow, string strColumnName, string strColumnHeaderText, int Width, bool bVisible = true)
- {
- DataGridViewCheckBoxColumn selectedColumn = new DataGridViewCheckBoxColumn()
- {
- HeaderText = strColumnHeaderText,
- Name = strColumnName,
- Visible = bVisible,
- Width = Width,
- ReadOnly = false
- };
-
- //设置文本对齐方式
- selectedColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- selectedColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
-
- //设置该列背景颜色
- dgvShow.Columns.Add(selectedColumn);
- }
-
- /// <summary>
- /// 添加datagridview的单元格
- /// </summary>
- /// <param name="dataGridViewRow"></param>
- /// <param name="dataGridViewColumn"></param>
- /// <param name="dr"></param>
- private void AddDataTextCell(DataGridViewRow dataGridViewRow, DataGridViewColumn dataGridViewColumn, DataRow dr)
- {
- DataGridViewTextBoxCell txtCell = new DataGridViewTextBoxCell();
- txtCell.Value = Convert.ToString(dr[dataGridViewColumn.Name]);
- dataGridViewRow.Cells.Add(txtCell);
- }
-
- private void btnRunData_Click(object sender, EventArgs e)
- {
- //组织上传数据
- if (dgvSyncData.Columns.Count <= 0) return;
-
- DataTable dtReadySource = dtSource.Clone();
- GetUpLoadData(ref dtReadySource);
- if (dtReadySource.Rows.Count <= 0)
- {
- string strMsg = "未能获得上传数据,请查询筛选后重试!";
- MessageBox.Show(strMsg);
- WriteMsgToRichTextBox(strMsg);
- }
-
- //执行上传
- RunUpLoad(dtReadySource);
- }
-
- /// <summary>
- /// 获取上传数据
- /// </summary>
- /// <param name="dtReadySource">准备上传的数据</param>
- private void GetUpLoadData(ref DataTable dtReadySource)
- {
- foreach (DataGridViewRow dgvRow in dgvSyncData.Rows)
- {
- if (dgvRow.DefaultCellStyle.BackColor == FinedBackColor)
- {
- string strGuid = dgvRow.Cells["GridGuid"].Value.ToString();
- if (!dictSource.ContainsKey(strGuid)) continue;
- DataRow dr = dictSource[strGuid];
-
- DataRow drReady = dtReadySource.NewRow();
- foreach (DataColumn dc in dtReadySource.Columns)
- {
- if (dr.Table.Columns.Contains(dc.ColumnName))
- drReady[dc.ColumnName] = dr[dc.ColumnName];
- }
- dtReadySource.Rows.Add(drReady);
- }
- }
- }
-
- private void RunUpLoad(DataTable dtReadySource)
- {
- //根据映射字段获取准备上传的所有数据
- if (dtReadySource == null || dtReadySource.Rows.Count <= 0) return;
-
- //构建准备插入的数据
- DataTable dtTarget = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(syncInstrumentItem.LstSyncPramas[0].TargetTable, syncInstrumentItem.SyncTargetDBInfo);
- if (dtTarget.Columns.Count <= 0)
- {
- MessageBox.Show("未能成功读取CNAS数据库列,请检查数据库配置。");
- WriteMsgToRichTextBox("未能成功读取CNAS数据库列,请检查数据库配置。");
- return;
- }
-
- //创建插入操作类
- CnasInsertOperation insertOperation = new CnasInsertOperation { syncInstrumentItem = syncInstrumentItem };
-
- //逐行插入数据到内存表
- string strErrorMsg = insertOperation.CreateInputData(dtReadySource, ref dtTarget);
- if (strErrorMsg != "")
- {
- MessageBox.Show(strErrorMsg);
- return;
- }
- if (dtTarget.Rows.Count <= 0)
- {
- MessageBox.Show("未能获取到符合要求的数据,请检查配置或联系管理员。");
- WriteMsgToRichTextBox("未能获取到符合要求的数据,请检查配置或联系管理员。");
- return;
- }
-
- //检查数据合法性
- insertOperation.CheckInsertDataFormat(dtTarget, ref strErrorMsg);
- if (strErrorMsg != "")
- {
- MessageBox.Show(strErrorMsg);
- return;
- }
-
- //逐行执行插入内存表数据到数据库中
- int ErrorCount = 0;
- int SuccessCount = 0;
- int OtherCount = 0;
- List<DataRow> lstError = new List<DataRow>();
- foreach (DataRow dr in dtTarget.Rows)
- {
-
- if (dr[11].ToString().Length > 1)
- {
- AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[11]}");
- dr[11] = kxjsf(dr[11].ToString());
-
- }
- if (dr[12].ToString().Length > 1)
- {
- AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[12]}");
- }
- if (dr[13].ToString().Length > 1)
- {
- AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[13]}");
- }
- if (dr[14].ToString().Length > 1)
- {
- AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[14]}");
- }
- if (dr[15].ToString().Length > 1)
- {
- AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[15]}");
- }
- if (dr[16].ToString().Length > 1)
- {
- AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[16]}");
- }
-
- dr.AcceptChanges();
- int iReturn = CnasDataOperationFact.CnasDataOperation().InsertDataToCNASTable(GlobalCommonOperation.ConvertDataRowToTable(dr), syncInstrumentItem.SyncTargetDBInfo, syncInstrumentItem.LstSyncPramas, syncInstrumentItem.CnasInstrumentColumn, syncInstrumentItem.lstFixedValue);
- if (iReturn <= 0) //此时出现问题
- {
- if (iReturn == -1)
- {
- AppLog.ServiceInfo("数据库连接中断,终止本次上传。");
- WriteMsgToRichTextBox("数据库连接中断,终止本次上传。");
- break; //此时数据库连接中断,直接跳出循环,结束本次数据同步传输
- }
- else if (iReturn == -2) //等于-2表示插入准备更新时发现数据一致,不再执行
- {
- OtherCount++;
- }
- else
- {
- ErrorCount++;
- /*需要转换一下,否则会将整个dt全部写入日志*/
- lstError.Add(GlobalCommonOperation.ConvertDataRowToTable(dr).Rows[0]);
- }
- }
- else
- {
- SuccessCount++;
- }
- }
-
- ////判断返回结果
- //if (lstError.Count <= 0)
- //{
- // MessageBox.Show("上传完成!");
- //}
- //else
- //{
- // AppLog.Error($"未成功上传的数据如下:{TransConvert.ListToString(lstError)}");
- // MessageBox.Show("上传过程中发生异常,存在部分数据未成功上传,请联系管理员!");
- //}
- MessageBox.Show($"上传操作完成!其中成功{SuccessCount}条,失败{ErrorCount}条,其他{OtherCount}条。");
- WriteMsgToRichTextBox($"上传操作完成!其中成功{SuccessCount}条,失败{ErrorCount}条,其他{OtherCount}条。");
- if (lstError.Count > 0)
- {
- AppLog.Error($"未成功上传的数据如下:{TransConvert.ListToString(lstError)}");
- WriteMsgToRichTextBox($"未成功上传的数据如下:{TransConvert.ListToString(lstError)}");
- }
- }
-
- private string kxjsf(string sss)
- {
- double sd = Convert.ToDouble(sss);
-
- //double sd = 123.123456;
- string temps2 = "0";
- string temps3 = "0";
- string temps4 = "0";
-
- int tempi2 = 0;
- int tempi3 = 0;
- int tempi4 = 0;
- if (sss.Contains('.'))
- {
- string[] s1 = sss.Split('.');
-
- if (s1[1].Length > 2)
- {
-
- if (s1[1].Length > 2)
- {
- temps2 = s1[1].Substring(1, 1);
- temps3 = s1[1].Substring(2, 1);
- }
- tempi2 = int.Parse(temps2);
- tempi3 = int.Parse(temps3);
-
- if (s1[1].Length > 3)
- {
- temps4 = s1[1].Substring(3, 1);
- }
- tempi4 = int.Parse(temps4);
-
- if (tempi3 > 5 || tempi3 < 5)
- {
- return sd.ToString("0.00");
- }
- else
- {
- if (tempi4 != 0)
- {
- return sd.ToString("0.00");
- }
- else
- {
- if (tempi2 == 0 || tempi2 == 2 || tempi2 == 4 || tempi2 == 6 || tempi2 == 8)
- {
- return sss.Substring(0, 5);
- }
- else
- {
- return sd.ToString("0.00");
- }
- }
- }
- }
- }
- return sss;
-
- }
-
- private void cmbColumns_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cmbColumns.SelectedItem == null) return;
- KeyValuePair<string, Type> obj = (KeyValuePair<string, Type>)cmbColumns.SelectedItem;
- if (DictComboBox.ContainsKey(obj.Key))
- {
- Type selectType = DictComboBox[obj.Key];
-
- switch (selectType.ToString())
- {
- case "System.DateTime":
- UseDateTimeControl();
- break;
- case "System.Double":
- case "System.Int64":
- case "System.Int32":
- UseNormalControl();
- //绑定条件ComboBox
- combCondition.DataSource = lstIntOrDouble;
- break;
- case "System.Byte[]":
- case "System.String":
- default:
- UseNormalControl();
- //绑定条件ComboBox
- combCondition.DataSource = lstText;
- break;
- }
- }
- }
- /// <summary>
- /// 使用时间类型专用的查询控件组
- /// </summary>
- private void UseDateTimeControl()
- {
- if (pnlCheck.Controls.Contains(pnlText))
- pnlCheck.Controls.Remove(pnlText);
- if (!pnlCheck.Controls.Contains(pnlDate))
- {
- pnlCheck.Controls.Add(pnlDate);
- pnlDate.Visible = true;
- pnlDate.Dock = DockStyle.Fill;
- }
- }
-
- /// <summary>
- /// 使用标准的查询控件组
- /// </summary>
- private void UseNormalControl()
- {
- if (pnlCheck.Controls.Contains(pnlDate))
- pnlCheck.Controls.Remove(pnlDate);
- if (!pnlCheck.Controls.Contains(pnlText))
- {
- pnlCheck.Controls.Add(pnlText);
- pnlText.Visible = true;
- pnlText.Dock = DockStyle.Fill;
- }
- }
-
- private void btnFind_Click(object sender, EventArgs e)
- {
- if (cmbColumns.SelectedValue == null) return;
- //1.合法性检测
- if (DictComboBox[cmbColumns.SelectedValue.ToString()].ToString().Equals("System.DateTime"))
- {
- if (dtpTarget.Value < dtpSource.Value)
- {
- MessageBox.Show("查询时间需要一个有效的时间范围!");
- return;
- }
- }
- else
- {
- if (this.txtFind.Text.Trim() == "") //为空 认为是取消查询
- {
- btnCancelFind_Click(sender, e);
- return;
- }
- }
-
-
- //2.将datagridview中满足条件的项修改背景色
- //2.1 判断当前显示的datagridview是否含有旧的查询数据
- //2.2 将满足条件的项背景色改为特殊颜色
- foreach (DataGridViewRow dgvrow in dgvSyncData.Rows)
- {
- dgvrow.DefaultCellStyle.BackColor = Color.White;
-
- //查询列的当前值
- string strGuid = dgvrow.Cells["GridGuid"].Value.ToString();
- if (DictField.Count > 0)
- {
- var query = DictField.Where(s => s.Value == cmbColumns.SelectedValue.ToString());
- if (query.Count() == 1)
- {
- string strValue = dgvrow.Cells[query.ElementAtOrDefault(0).Key].Value.ToString();
- //判断是否满足条件
- if (CheckMatchCondition(strValue))
- {
- dgvrow.DefaultCellStyle.BackColor = FinedBackColor;
- }
- }
- }
- else
- {
- string strValue = dgvrow.Cells[cmbColumns.SelectedValue.ToString()].Value.ToString();
- //判断是否满足条件
- if (CheckMatchCondition(strValue))
- {
- dgvrow.DefaultCellStyle.BackColor = FinedBackColor;
- }
- }
- }
- }
- private bool CheckMatchCondition(string strValue)
- {
- if (DictComboBox[cmbColumns.SelectedValue.ToString()].ToString().Equals("System.DateTime"))
- {
- DateTime dt = DateTime.Now;
- if (!DateTime.TryParse(strValue, out dt)) return false;
-
- DateTime dtSource = dtpSource.Value;
- DateTime dtTarget = dtpTarget.Value;
- DateTime dtValue = dt;
- if (dt >= dtSource && dt <= dtTarget)
- return true;
- else
- return false;
- }
- else
- {
- string strFindText = this.txtFind.Text.ToString();
- bool bReturn = false;
- try
- {
- switch (combCondition.SelectedValue.ToString())
- {
- case "等于":
- bReturn = strValue == strFindText ? true : false;
- break;
- case "不等于":
- bReturn = strValue != strFindText ? true : false;
- break;
- case "包含":
- bReturn = strValue.Contains(strFindText) ? true : false;
- break;
- case "不包含":
- bReturn = !strValue.Contains(strFindText) ? true : false;
- break;
- case "大于":
- bReturn = Convert.ToDouble(strValue) > Convert.ToDouble(strFindText) ? true : false;
- break;
- case "不小于":
- bReturn = Convert.ToDouble(strValue) >= Convert.ToDouble(strFindText) ? true : false;
- break;
- case "小于":
- bReturn = Convert.ToDouble(strValue) < Convert.ToDouble(strFindText) ? true : false;
- break;
- case "不大于":
- bReturn = Convert.ToDouble(strValue) <= Convert.ToDouble(strFindText) ? true : false;
- break;
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- bReturn = false;
- }
- return bReturn;
- }
- }
-
-
- /// <summary>
- /// 获得查询语句(非日期类型)
- /// </summary>
- /// <param name="strColumnName"></param>
- /// <param name="strColumnType"></param>
- /// <param name="strCondition"></param>
- /// <param name="strValue"></param>
- /// <returns></returns>
- private string GetSelectString(string strColumnName, string strCondition, string strValue)
- {
- string strCondi = "";
- switch (strCondition)
- {
- case "等于":
- strCondi = "=";
- break;
- case "不等于":
- strCondi = "<>";
- break;
- case "包含":
- strCondi = "like";
- break;
- case "不包含":
- strCondi = "not like";
- break;
- case "大于":
- strCondi = ">";
- break;
- case "不小于":
- strCondi = ">=";
- break;
- case "小于":
- strCondi = "<";
- break;
- case "不大于":
- strCondi = "<=";
- break;
- }
- if (strCondi == "like" || strCondi == "not like")
- return string.Format("{0} {1} '%{2}%'", strColumnName, strCondi, strValue);
- else
- return string.Format("{0} {1} '{2}'", strColumnName, strCondi, strValue);
- }
- private void btnCancelFind_Click(object sender, EventArgs e)
- {
- foreach (DataGridViewRow dgvrow in dgvSyncData.Rows)
- {
- if (dgvrow.Cells[0].Value != null && dgvrow.Cells[0].Value.ToString() == "True")
- dgvrow.Cells[0].Value = false;
-
- if (dgvrow.Index % 2 == 1)
- {
- dgvrow.DefaultCellStyle.BackColor = Color.WhiteSmoke;
- }
- else
- {
- dgvrow.DefaultCellStyle.BackColor = Color.White;
- }
-
- }
- }
-
- private void dgvSyncData_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- //只有第一列“选择列”时触发
- if (e.ColumnIndex == 0)
- {
- if (dgvSyncData.Rows[e.RowIndex].Cells[0].Value.ToString() == "True")
- dgvSyncData.Rows[e.RowIndex].DefaultCellStyle.BackColor = FinedBackColor;
- else
- {
- if (e.RowIndex % 2 == 1)
- {
- dgvSyncData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.WhiteSmoke;
- }
- else
- {
- dgvSyncData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
- }
- }
- }
- }
-
- public void WriteMsgToRichTextBox(string strMsg)
- {
- Invoke(new MethodInvoker(delegate ()
- {
- this.rtxtLog.Text += string.Format("{0} 日期: {1}\n", strMsg,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- }));
- }
- }
- }
|