CNAS取数仪器端升级
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

718 lines
28KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CnasSynchronusClient;
  10. using CnasSynchrousModel;
  11. using CnasSynchronousCommon;
  12. namespace CNAS_RunSync
  13. {
  14. public partial class ucSynchrousMain : UserControl
  15. {
  16. private string delayDays = FileOperation.GetSystemFormatConfigData().ShowDelayDays;
  17. private SyncInstrumentItemInfo syncInstrumentItem = new SyncInstrumentItemInfo();
  18. //private Dictionary<string, DataTable> dictSourceTables = new Dictionary<string, DataTable>();
  19. private DataTable dtSource = new DataTable(); //当前显示数据源
  20. private Dictionary<string, DataRow> dictSource = new Dictionary<string, DataRow>();
  21. private Dictionary<string, Type> DictComboBox = new Dictionary<string, Type>(); //ComboBox数据源
  22. private List<string> lstIntOrDouble = new List<string>() { "等于", "不等于", "大于", "小于", "不大于", "不小于" };
  23. private List<string> lstText = new List<string>() { "等于", "不等于", "包含", "不包含" };
  24. private Color FinedBackColor = Color.LightCyan; //查询后选中项
  25. Dictionary<string, string> DictField = new Dictionary<string, string>();
  26. public ucSynchrousMain()
  27. {
  28. InitializeComponent();
  29. }
  30. //需要存在一个仪器才能正常显示数据
  31. public ucSynchrousMain(SyncInstrumentItemInfo syncInstrumentItem)
  32. {
  33. InitializeComponent();
  34. dgvSyncData.AutoGenerateColumns = false;
  35. dgvSyncData.RowHeadersVisible = false;
  36. //dgvSyncData.RowsDefaultCellStyle.BackColor = Color.Bisque;
  37. dgvSyncData.AlternatingRowsDefaultCellStyle.BackColor = Color.WhiteSmoke;
  38. this.syncInstrumentItem = syncInstrumentItem;
  39. }
  40. /// <summary>
  41. /// 控件加载时发生
  42. /// </summary>
  43. /// <param name="sender"></param>
  44. /// <param name="e"></param>
  45. private void ucSynchrousMain_Load(object sender, EventArgs e)
  46. {
  47. BindData();
  48. }
  49. /// <summary>
  50. /// 绑定数据
  51. /// </summary>
  52. public void BindData()
  53. {
  54. if (this.syncInstrumentItem == null) return;
  55. this.lblTitle.Text = string.Format("当前仪器:【{0}】", syncInstrumentItem.Code);
  56. if (syncInstrumentItem.LstSyncPramas == null) return;
  57. if (syncInstrumentItem.SyncInstrumentDSInfo == null) return;
  58. //if (syncInstrumentItem.SyncInstrumentDSInfo.Path == null) return;
  59. if (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType == DataSourceType.None) return;
  60. this.lblTitleMsg.Text= string.Format("类型:{0} 路径:{1}", syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString(),syncInstrumentItem.SyncInstrumentDSInfo.Path);
  61. //清空现有绑定
  62. DictComboBox.Clear();
  63. dictSource.Clear();
  64. //加载相关数据
  65. //1.1根据仪器类型加载本地存储的中英文字段说明映射
  66. //if (syncInstrumentItem.LstSyncPramas.Count > 0)
  67. //{
  68. //InstrumentDescribeZH describeZH = new InstrumentDescribeZH(syncInstrumentItem.InstruType, syncInstrumentItem.LstSyncPramas[0].SourceTable);
  69. //describeZH.GetFieldDescribe();
  70. //DictField = describeZH.DictField;
  71. //}
  72. //2.datagridview中绑定数据(绑定的是从数据源中读取的数据)
  73. //2.1 根据映射表,创建datagridviewcolumn/和绑定数据列
  74. if (syncInstrumentItem.LstSyncPramas.Count <= 0) return;
  75. //创建选择列
  76. AddCheckBoxColumn(dgvSyncData, "selectedColumn", "选择", 80, true);
  77. //创建数据列
  78. foreach (var item in syncInstrumentItem.LstSyncPramas)
  79. {
  80. string strColumnName = item.SourceField;
  81. if (DictField.ContainsKey(strColumnName))
  82. strColumnName = DictField[strColumnName];
  83. AddDatagridColumn(dgvSyncData, item.SourceField, strColumnName, 150);
  84. }
  85. //创建GUID列
  86. AddDatagridColumn(dgvSyncData, "GridGuid", "GridGuid", 50, false);
  87. //2.2 获取数据源数据,构建datagridviewcell
  88. //2.2.1 获取数据源数据
  89. var query = syncInstrumentItem.LstSyncPramas.Where(s => s.IfDateField == true).ToList<SyncParamasInfo>();
  90. if (query.Count == 1)
  91. {
  92. object[] obj = new object[]
  93. {
  94. syncInstrumentItem.LstSyncPramas[0].SourceTable,
  95. query[0].SourceField,
  96. DateTime.Now.AddDays(Convert.ToInt32(delayDays)).ToString("yyyy-MM-dd HH:mm:ss")
  97. };
  98. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrumentItem.SyncInstrumentDSInfo, obj);
  99. dtSource = instrumentData.GetInstrumentDataByDate();
  100. }
  101. //2.2.2 构建datagridviewcell
  102. foreach (DataRow dr in dtSource.Rows)
  103. {
  104. DataGridViewRow dataGridViewRow = new DataGridViewRow();
  105. foreach (DataGridViewColumn dataGridViewColumn in dgvSyncData.Columns)
  106. {
  107. if (dataGridViewColumn.Index == 0)
  108. {
  109. dataGridViewRow.Cells.Add(new DataGridViewCheckBoxCell());
  110. }
  111. if (dtSource.Columns.Contains(dataGridViewColumn.Name))
  112. AddDataTextCell(dataGridViewRow, dataGridViewColumn, dr);
  113. }
  114. //添加GUID值
  115. string strGuid = Guid.NewGuid().ToString();
  116. DataGridViewTextBoxCell txtCell = new DataGridViewTextBoxCell
  117. {
  118. Value = strGuid
  119. };
  120. dataGridViewRow.Cells.Add(txtCell);
  121. dgvSyncData.Rows.Add(dataGridViewRow);
  122. dictSource.Add(strGuid, dr);
  123. }
  124. //3.初始化查询相关内容
  125. //3.1 绑定Combobox数据源
  126. foreach (DataColumn dc in dtSource.Columns)
  127. {
  128. if (syncInstrumentItem.LstSyncPramas.Where(s => s.SourceField == dc.ColumnName.ToUpper()).LongCount<SyncParamasInfo>() > 0)
  129. {
  130. string strColumnName = dc.ColumnName.ToUpper();
  131. if (DictField.ContainsKey(strColumnName))
  132. strColumnName = DictField[strColumnName];
  133. DictComboBox.Add(strColumnName, dc.DataType);
  134. }
  135. }
  136. if (DictComboBox.Count > 0)
  137. {
  138. BindingSource bsComboBox = new BindingSource
  139. {
  140. DataSource = DictComboBox
  141. };
  142. cmbColumns.DataSource = bsComboBox;
  143. cmbColumns.ValueMember = "Key";
  144. cmbColumns.DisplayMember = "Key";
  145. }
  146. }
  147. /// <summary>
  148. /// 添加datagridview的列
  149. /// </summary>
  150. /// <param name="dgvShow"></param>
  151. /// <param name="strColumnName"></param>
  152. /// <param name="strColumnHeaderText"></param>
  153. /// <param name="Width"></param>
  154. /// <param name="bVisible"></param>
  155. private void AddDatagridColumn(DataGridView dgvShow, string strColumnName, string strColumnHeaderText, int Width, bool bVisible = true)
  156. {
  157. DataGridViewColumn Column = new DataGridViewColumn()
  158. {
  159. Name = strColumnName,
  160. HeaderText = strColumnHeaderText,
  161. Width = Width,
  162. Visible = bVisible,
  163. CellTemplate = new DataGridViewTextBoxCell(),
  164. ReadOnly = true
  165. };
  166. //设置文本对齐方式
  167. Column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  168. Column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  169. //设置该列背景颜色
  170. dgvShow.Columns.Add(Column);
  171. }
  172. private void AddCheckBoxColumn(DataGridView dgvShow, string strColumnName, string strColumnHeaderText, int Width, bool bVisible = true)
  173. {
  174. DataGridViewCheckBoxColumn selectedColumn = new DataGridViewCheckBoxColumn()
  175. {
  176. HeaderText = strColumnHeaderText,
  177. Name = strColumnName,
  178. Visible = bVisible,
  179. Width = Width,
  180. ReadOnly = false
  181. };
  182. //设置文本对齐方式
  183. selectedColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  184. selectedColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  185. //设置该列背景颜色
  186. dgvShow.Columns.Add(selectedColumn);
  187. }
  188. /// <summary>
  189. /// 添加datagridview的单元格
  190. /// </summary>
  191. /// <param name="dataGridViewRow"></param>
  192. /// <param name="dataGridViewColumn"></param>
  193. /// <param name="dr"></param>
  194. private void AddDataTextCell(DataGridViewRow dataGridViewRow, DataGridViewColumn dataGridViewColumn, DataRow dr)
  195. {
  196. DataGridViewTextBoxCell txtCell = new DataGridViewTextBoxCell();
  197. txtCell.Value = Convert.ToString(dr[dataGridViewColumn.Name]);
  198. dataGridViewRow.Cells.Add(txtCell);
  199. }
  200. private void btnRunData_Click(object sender, EventArgs e)
  201. {
  202. //组织上传数据
  203. if (dgvSyncData.Columns.Count <= 0) return;
  204. DataTable dtReadySource = dtSource.Clone();
  205. GetUpLoadData(ref dtReadySource);
  206. if (dtReadySource.Rows.Count <= 0)
  207. {
  208. string strMsg = "未能获得上传数据,请查询筛选后重试!";
  209. MessageBox.Show(strMsg);
  210. WriteMsgToRichTextBox(strMsg);
  211. }
  212. //执行上传
  213. RunUpLoad(dtReadySource);
  214. }
  215. /// <summary>
  216. /// 获取上传数据
  217. /// </summary>
  218. /// <param name="dtReadySource">准备上传的数据</param>
  219. private void GetUpLoadData(ref DataTable dtReadySource)
  220. {
  221. foreach (DataGridViewRow dgvRow in dgvSyncData.Rows)
  222. {
  223. if (dgvRow.DefaultCellStyle.BackColor == FinedBackColor)
  224. {
  225. string strGuid = dgvRow.Cells["GridGuid"].Value.ToString();
  226. if (!dictSource.ContainsKey(strGuid)) continue;
  227. DataRow dr = dictSource[strGuid];
  228. DataRow drReady = dtReadySource.NewRow();
  229. foreach (DataColumn dc in dtReadySource.Columns)
  230. {
  231. if (dr.Table.Columns.Contains(dc.ColumnName))
  232. drReady[dc.ColumnName] = dr[dc.ColumnName];
  233. }
  234. dtReadySource.Rows.Add(drReady);
  235. }
  236. }
  237. }
  238. private void RunUpLoad(DataTable dtReadySource)
  239. {
  240. //根据映射字段获取准备上传的所有数据
  241. if (dtReadySource == null || dtReadySource.Rows.Count <= 0) return;
  242. //构建准备插入的数据
  243. DataTable dtTarget = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(syncInstrumentItem.LstSyncPramas[0].TargetTable, syncInstrumentItem.SyncTargetDBInfo);
  244. if (dtTarget.Columns.Count <= 0)
  245. {
  246. MessageBox.Show("未能成功读取CNAS数据库列,请检查数据库配置。");
  247. WriteMsgToRichTextBox("未能成功读取CNAS数据库列,请检查数据库配置。");
  248. return;
  249. }
  250. //创建插入操作类
  251. CnasInsertOperation insertOperation = new CnasInsertOperation { syncInstrumentItem = syncInstrumentItem };
  252. //逐行插入数据到内存表
  253. string strErrorMsg = insertOperation.CreateInputData(dtReadySource, ref dtTarget);
  254. if (strErrorMsg != "")
  255. {
  256. MessageBox.Show(strErrorMsg);
  257. return;
  258. }
  259. if (dtTarget.Rows.Count <= 0)
  260. {
  261. MessageBox.Show("未能获取到符合要求的数据,请检查配置或联系管理员。");
  262. WriteMsgToRichTextBox("未能获取到符合要求的数据,请检查配置或联系管理员。");
  263. return;
  264. }
  265. //检查数据合法性
  266. insertOperation.CheckInsertDataFormat(dtTarget, ref strErrorMsg);
  267. if (strErrorMsg != "")
  268. {
  269. MessageBox.Show(strErrorMsg);
  270. return;
  271. }
  272. //逐行执行插入内存表数据到数据库中
  273. int ErrorCount = 0;
  274. int SuccessCount = 0;
  275. int OtherCount = 0;
  276. List<DataRow> lstError = new List<DataRow>();
  277. foreach (DataRow dr in dtTarget.Rows)
  278. {
  279. if (dr[11].ToString().Length > 1)
  280. {
  281. AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[11]}");
  282. dr[11] = kxjsf(dr[11].ToString());
  283. }
  284. if (dr[12].ToString().Length > 1)
  285. {
  286. AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[12]}");
  287. }
  288. if (dr[13].ToString().Length > 1)
  289. {
  290. AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[13]}");
  291. }
  292. if (dr[14].ToString().Length > 1)
  293. {
  294. AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[14]}");
  295. }
  296. if (dr[15].ToString().Length > 1)
  297. {
  298. AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[15]}");
  299. }
  300. if (dr[16].ToString().Length > 1)
  301. {
  302. AppLog.Error($"逐行插入目标数据,最终准备插入(更新)数据行{dr[16]}");
  303. }
  304. dr.AcceptChanges();
  305. int iReturn = CnasDataOperationFact.CnasDataOperation().InsertDataToCNASTable(GlobalCommonOperation.ConvertDataRowToTable(dr), syncInstrumentItem.SyncTargetDBInfo, syncInstrumentItem.LstSyncPramas, syncInstrumentItem.CnasInstrumentColumn, syncInstrumentItem.lstFixedValue);
  306. if (iReturn <= 0) //此时出现问题
  307. {
  308. if (iReturn == -1)
  309. {
  310. AppLog.ServiceInfo("数据库连接中断,终止本次上传。");
  311. WriteMsgToRichTextBox("数据库连接中断,终止本次上传。");
  312. break; //此时数据库连接中断,直接跳出循环,结束本次数据同步传输
  313. }
  314. else if (iReturn == -2) //等于-2表示插入准备更新时发现数据一致,不再执行
  315. {
  316. OtherCount++;
  317. }
  318. else
  319. {
  320. ErrorCount++;
  321. /*需要转换一下,否则会将整个dt全部写入日志*/
  322. lstError.Add(GlobalCommonOperation.ConvertDataRowToTable(dr).Rows[0]);
  323. }
  324. }
  325. else
  326. {
  327. SuccessCount++;
  328. }
  329. }
  330. ////判断返回结果
  331. //if (lstError.Count <= 0)
  332. //{
  333. // MessageBox.Show("上传完成!");
  334. //}
  335. //else
  336. //{
  337. // AppLog.Error($"未成功上传的数据如下:{TransConvert.ListToString(lstError)}");
  338. // MessageBox.Show("上传过程中发生异常,存在部分数据未成功上传,请联系管理员!");
  339. //}
  340. MessageBox.Show($"上传操作完成!其中成功{SuccessCount}条,失败{ErrorCount}条,其他{OtherCount}条。");
  341. WriteMsgToRichTextBox($"上传操作完成!其中成功{SuccessCount}条,失败{ErrorCount}条,其他{OtherCount}条。");
  342. if (lstError.Count > 0)
  343. {
  344. AppLog.Error($"未成功上传的数据如下:{TransConvert.ListToString(lstError)}");
  345. WriteMsgToRichTextBox($"未成功上传的数据如下:{TransConvert.ListToString(lstError)}");
  346. }
  347. }
  348. private string kxjsf(string sss)
  349. {
  350. double sd = Convert.ToDouble(sss);
  351. //double sd = 123.123456;
  352. string temps2 = "0";
  353. string temps3 = "0";
  354. string temps4 = "0";
  355. int tempi2 = 0;
  356. int tempi3 = 0;
  357. int tempi4 = 0;
  358. if (sss.Contains('.'))
  359. {
  360. string[] s1 = sss.Split('.');
  361. if (s1[1].Length > 2)
  362. {
  363. if (s1[1].Length > 2)
  364. {
  365. temps2 = s1[1].Substring(1, 1);
  366. temps3 = s1[1].Substring(2, 1);
  367. }
  368. tempi2 = int.Parse(temps2);
  369. tempi3 = int.Parse(temps3);
  370. if (s1[1].Length > 3)
  371. {
  372. temps4 = s1[1].Substring(3, 1);
  373. }
  374. tempi4 = int.Parse(temps4);
  375. if (tempi3 > 5 || tempi3 < 5)
  376. {
  377. return sd.ToString("0.00");
  378. }
  379. else
  380. {
  381. if (tempi4 != 0)
  382. {
  383. return sd.ToString("0.00");
  384. }
  385. else
  386. {
  387. if (tempi2 == 0 || tempi2 == 2 || tempi2 == 4 || tempi2 == 6 || tempi2 == 8)
  388. {
  389. return sss.Substring(0, 5);
  390. }
  391. else
  392. {
  393. return sd.ToString("0.00");
  394. }
  395. }
  396. }
  397. }
  398. }
  399. return sss;
  400. }
  401. private void cmbColumns_SelectedIndexChanged(object sender, EventArgs e)
  402. {
  403. if (cmbColumns.SelectedItem == null) return;
  404. KeyValuePair<string, Type> obj = (KeyValuePair<string, Type>)cmbColumns.SelectedItem;
  405. if (DictComboBox.ContainsKey(obj.Key))
  406. {
  407. Type selectType = DictComboBox[obj.Key];
  408. switch (selectType.ToString())
  409. {
  410. case "System.DateTime":
  411. UseDateTimeControl();
  412. break;
  413. case "System.Double":
  414. case "System.Int64":
  415. case "System.Int32":
  416. UseNormalControl();
  417. //绑定条件ComboBox
  418. combCondition.DataSource = lstIntOrDouble;
  419. break;
  420. case "System.Byte[]":
  421. case "System.String":
  422. default:
  423. UseNormalControl();
  424. //绑定条件ComboBox
  425. combCondition.DataSource = lstText;
  426. break;
  427. }
  428. }
  429. }
  430. /// <summary>
  431. /// 使用时间类型专用的查询控件组
  432. /// </summary>
  433. private void UseDateTimeControl()
  434. {
  435. if (pnlCheck.Controls.Contains(pnlText))
  436. pnlCheck.Controls.Remove(pnlText);
  437. if (!pnlCheck.Controls.Contains(pnlDate))
  438. {
  439. pnlCheck.Controls.Add(pnlDate);
  440. pnlDate.Visible = true;
  441. pnlDate.Dock = DockStyle.Fill;
  442. }
  443. }
  444. /// <summary>
  445. /// 使用标准的查询控件组
  446. /// </summary>
  447. private void UseNormalControl()
  448. {
  449. if (pnlCheck.Controls.Contains(pnlDate))
  450. pnlCheck.Controls.Remove(pnlDate);
  451. if (!pnlCheck.Controls.Contains(pnlText))
  452. {
  453. pnlCheck.Controls.Add(pnlText);
  454. pnlText.Visible = true;
  455. pnlText.Dock = DockStyle.Fill;
  456. }
  457. }
  458. private void btnFind_Click(object sender, EventArgs e)
  459. {
  460. if (cmbColumns.SelectedValue == null) return;
  461. //1.合法性检测
  462. if (DictComboBox[cmbColumns.SelectedValue.ToString()].ToString().Equals("System.DateTime"))
  463. {
  464. if (dtpTarget.Value < dtpSource.Value)
  465. {
  466. MessageBox.Show("查询时间需要一个有效的时间范围!");
  467. return;
  468. }
  469. }
  470. else
  471. {
  472. if (this.txtFind.Text.Trim() == "") //为空 认为是取消查询
  473. {
  474. btnCancelFind_Click(sender, e);
  475. return;
  476. }
  477. }
  478. //2.将datagridview中满足条件的项修改背景色
  479. //2.1 判断当前显示的datagridview是否含有旧的查询数据
  480. //2.2 将满足条件的项背景色改为特殊颜色
  481. foreach (DataGridViewRow dgvrow in dgvSyncData.Rows)
  482. {
  483. dgvrow.DefaultCellStyle.BackColor = Color.White;
  484. //查询列的当前值
  485. string strGuid = dgvrow.Cells["GridGuid"].Value.ToString();
  486. if (DictField.Count > 0)
  487. {
  488. var query = DictField.Where(s => s.Value == cmbColumns.SelectedValue.ToString());
  489. if (query.Count() == 1)
  490. {
  491. string strValue = dgvrow.Cells[query.ElementAtOrDefault(0).Key].Value.ToString();
  492. //判断是否满足条件
  493. if (CheckMatchCondition(strValue))
  494. {
  495. dgvrow.DefaultCellStyle.BackColor = FinedBackColor;
  496. }
  497. }
  498. }
  499. else
  500. {
  501. string strValue = dgvrow.Cells[cmbColumns.SelectedValue.ToString()].Value.ToString();
  502. //判断是否满足条件
  503. if (CheckMatchCondition(strValue))
  504. {
  505. dgvrow.DefaultCellStyle.BackColor = FinedBackColor;
  506. }
  507. }
  508. }
  509. }
  510. private bool CheckMatchCondition(string strValue)
  511. {
  512. if (DictComboBox[cmbColumns.SelectedValue.ToString()].ToString().Equals("System.DateTime"))
  513. {
  514. DateTime dt = DateTime.Now;
  515. if (!DateTime.TryParse(strValue, out dt)) return false;
  516. DateTime dtSource = dtpSource.Value;
  517. DateTime dtTarget = dtpTarget.Value;
  518. DateTime dtValue = dt;
  519. if (dt >= dtSource && dt <= dtTarget)
  520. return true;
  521. else
  522. return false;
  523. }
  524. else
  525. {
  526. string strFindText = this.txtFind.Text.ToString();
  527. bool bReturn = false;
  528. try
  529. {
  530. switch (combCondition.SelectedValue.ToString())
  531. {
  532. case "等于":
  533. bReturn = strValue == strFindText ? true : false;
  534. break;
  535. case "不等于":
  536. bReturn = strValue != strFindText ? true : false;
  537. break;
  538. case "包含":
  539. bReturn = strValue.Contains(strFindText) ? true : false;
  540. break;
  541. case "不包含":
  542. bReturn = !strValue.Contains(strFindText) ? true : false;
  543. break;
  544. case "大于":
  545. bReturn = Convert.ToDouble(strValue) > Convert.ToDouble(strFindText) ? true : false;
  546. break;
  547. case "不小于":
  548. bReturn = Convert.ToDouble(strValue) >= Convert.ToDouble(strFindText) ? true : false;
  549. break;
  550. case "小于":
  551. bReturn = Convert.ToDouble(strValue) < Convert.ToDouble(strFindText) ? true : false;
  552. break;
  553. case "不大于":
  554. bReturn = Convert.ToDouble(strValue) <= Convert.ToDouble(strFindText) ? true : false;
  555. break;
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. AppLog.Error(ex.Message);
  561. bReturn = false;
  562. }
  563. return bReturn;
  564. }
  565. }
  566. /// <summary>
  567. /// 获得查询语句(非日期类型)
  568. /// </summary>
  569. /// <param name="strColumnName"></param>
  570. /// <param name="strColumnType"></param>
  571. /// <param name="strCondition"></param>
  572. /// <param name="strValue"></param>
  573. /// <returns></returns>
  574. private string GetSelectString(string strColumnName, string strCondition, string strValue)
  575. {
  576. string strCondi = "";
  577. switch (strCondition)
  578. {
  579. case "等于":
  580. strCondi = "=";
  581. break;
  582. case "不等于":
  583. strCondi = "<>";
  584. break;
  585. case "包含":
  586. strCondi = "like";
  587. break;
  588. case "不包含":
  589. strCondi = "not like";
  590. break;
  591. case "大于":
  592. strCondi = ">";
  593. break;
  594. case "不小于":
  595. strCondi = ">=";
  596. break;
  597. case "小于":
  598. strCondi = "<";
  599. break;
  600. case "不大于":
  601. strCondi = "<=";
  602. break;
  603. }
  604. if (strCondi == "like" || strCondi == "not like")
  605. return string.Format("{0} {1} '%{2}%'", strColumnName, strCondi, strValue);
  606. else
  607. return string.Format("{0} {1} '{2}'", strColumnName, strCondi, strValue);
  608. }
  609. private void btnCancelFind_Click(object sender, EventArgs e)
  610. {
  611. foreach (DataGridViewRow dgvrow in dgvSyncData.Rows)
  612. {
  613. if (dgvrow.Cells[0].Value != null && dgvrow.Cells[0].Value.ToString() == "True")
  614. dgvrow.Cells[0].Value = false;
  615. if (dgvrow.Index % 2 == 1)
  616. {
  617. dgvrow.DefaultCellStyle.BackColor = Color.WhiteSmoke;
  618. }
  619. else
  620. {
  621. dgvrow.DefaultCellStyle.BackColor = Color.White;
  622. }
  623. }
  624. }
  625. private void dgvSyncData_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  626. {
  627. //只有第一列“选择列”时触发
  628. if (e.ColumnIndex == 0)
  629. {
  630. if (dgvSyncData.Rows[e.RowIndex].Cells[0].Value.ToString() == "True")
  631. dgvSyncData.Rows[e.RowIndex].DefaultCellStyle.BackColor = FinedBackColor;
  632. else
  633. {
  634. if (e.RowIndex % 2 == 1)
  635. {
  636. dgvSyncData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.WhiteSmoke;
  637. }
  638. else
  639. {
  640. dgvSyncData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
  641. }
  642. }
  643. }
  644. }
  645. public void WriteMsgToRichTextBox(string strMsg)
  646. {
  647. Invoke(new MethodInvoker(delegate ()
  648. {
  649. this.rtxtLog.Text += string.Format("{0} 日期: {1}\n", strMsg,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  650. }));
  651. }
  652. }
  653. }