CNAS取数仪器端升级
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. using CnasSynchronousCommon;
  2. using CnasSynchronusClient;
  3. using CnasSynchrousModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Windows.Forms;
  14. using System.Xml.Linq;
  15. using System.Xml.Serialization;
  16. using static System.Runtime.CompilerServices.RuntimeHelpers;
  17. namespace CNAS_DBSync
  18. {
  19. public delegate void ReferenceChangeSyncParamHanlder(SyncInstrumentItemInfo syncInstrumentItem);
  20. public partial class frmSyncParams : Form
  21. {
  22. public List<SyncInstrumentItemInfo> lstSyncInstrument = new List<SyncInstrumentItemInfo>(); //本地存储的仪器数据源
  23. public SyncInstrumentItemInfo currentSyncItem = new SyncInstrumentItemInfo(); //当前正在操作的仪器项
  24. public Dictionary<string, DataTable> dictInstruTables = new Dictionary<string, DataTable>(); //当前仪器项的来源表结构
  25. private SyncInstrumentItemInfo syncInstrumentItem; //其他调用传递的仪器项
  26. public ReferenceChangeSyncParamHanlder ParamsChangedDelegate; //传递仪器参数委托
  27. private string strMode = "";
  28. private string strTableInfoMode = ""; //获取所有表信息的方式;0为自动获取,1为手动输入
  29. public frmSyncParams(SyncInstrumentItemInfo syncInstrumentItem = null)
  30. {
  31. InitializeComponent();
  32. dgvInstrument.AutoGenerateColumns = false;
  33. dgvInstrument.RowHeadersVisible = false;
  34. dgvInstruDS.AutoGenerateColumns = false;
  35. dgvInstruDS.RowHeadersVisible = false;
  36. dgvCnas.AutoGenerateColumns = false;
  37. dgvCnas.RowHeadersVisible = false;
  38. dgvMapping.AutoGenerateColumns = false;
  39. dgvMapping.RowHeadersVisible = false;
  40. if (syncInstrumentItem != null)
  41. {
  42. strMode = "Reference";
  43. this.syncInstrumentItem = syncInstrumentItem;
  44. this.btnAdd.Visible = false;
  45. this.btnDel.Visible = false;
  46. }
  47. }
  48. private void Option1_Click(object sender, EventArgs e)
  49. {
  50. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  51. frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument, strInstrumentCode);
  52. frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  53. {
  54. var lstInstrument = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
  55. if (lstInstrument.Count == 1)
  56. {
  57. lstInstrument[0].Code = Instrumentitem.Code;
  58. lstInstrument[0].InstruType = Instrumentitem.InstruType;
  59. }
  60. };
  61. if (frmSetting.ShowDialog() == DialogResult.OK)
  62. {
  63. //绑定数据
  64. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  65. }
  66. //frmSetting.ShowDialog();
  67. }
  68. private void Option2_Click(object sender, EventArgs e)
  69. {
  70. // 处理选项2的点击事件
  71. MessageBox.Show("选项2被点击");
  72. }
  73. private void frmSyncParams_Load(object sender, EventArgs e)
  74. {
  75. if (syncInstrumentItem == null)
  76. {
  77. lstSyncInstrument = FileOperation.GetLocalSyncInStrumentData();
  78. }
  79. else
  80. {
  81. lstSyncInstrument = new List<SyncInstrumentItemInfo>() { syncInstrumentItem };
  82. }
  83. //绑定数据源,填写相关内容
  84. if (lstSyncInstrument.Count != 0)
  85. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  86. }
  87. /// <summary>
  88. /// 保存当前设置到本地
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. private void btnSave_Click(object sender, EventArgs e)
  93. {
  94. //将配置好的信息存储到本地文件中
  95. try
  96. {
  97. bool bIfSaveSuccess = true;
  98. if (strMode == "Reference")
  99. {
  100. if (!CheckIfHaveDateField(new List<SyncInstrumentItemInfo>() { currentSyncItem }))
  101. {
  102. MessageBox.Show("日期字段不允许为空!");
  103. return;
  104. }
  105. if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument))
  106. {
  107. MessageBox.Show("关键字段不允许为空!");
  108. return;
  109. }
  110. //1.先加载所有数据 2.替换当前数据 3.重新保存
  111. List<SyncInstrumentItemInfo> lstDB = FileOperation.GetLocalSyncInStrumentData();
  112. var item = lstDB.Where(p => p.GUID == currentSyncItem.GUID).SingleOrDefault();
  113. if (item != null)
  114. {
  115. lstDB.Remove(item);
  116. lstDB.Add(currentSyncItem);
  117. }
  118. else
  119. {
  120. lstDB.Add(currentSyncItem);
  121. }
  122. //重新保存信息
  123. bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstDB);
  124. //委托发送参数
  125. this.ParamsChangedDelegate(syncInstrumentItem);
  126. }
  127. else
  128. {
  129. if (!CheckIfHaveDateField(lstSyncInstrument))
  130. {
  131. MessageBox.Show("日期字段不允许为空!");
  132. return;
  133. }
  134. if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument))
  135. {
  136. MessageBox.Show("关键字段不允许为空!");
  137. return;
  138. }
  139. bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
  140. }
  141. if (bIfSaveSuccess)
  142. MessageBox.Show("保存成功!");
  143. else
  144. MessageBox.Show("保存失败!");
  145. }
  146. catch (Exception ex)
  147. {
  148. MessageBox.Show("保存失败!错误信息为:" + ex.Message.ToString());
  149. AppLog.Error(ex.Message);
  150. }
  151. }
  152. private bool CheckIfHaveDateField(List<SyncInstrumentItemInfo> lstSyncInstrument)
  153. {
  154. bool bIfHave = true;
  155. foreach (var item in lstSyncInstrument)
  156. {
  157. if (item.LstSyncPramas == null) continue;
  158. if (item.LstSyncPramas.Count <= 0) continue;
  159. if (item.LstSyncPramas.Where(s => s.IfDateField == true).Count() != 1)
  160. {
  161. bIfHave = false;
  162. break;
  163. }
  164. }
  165. return bIfHave;
  166. }
  167. private bool CheckIfHaveKeyPrimaryField(List<SyncInstrumentItemInfo> lstSyncInstrument)
  168. {
  169. bool bIfHave = true;
  170. foreach (var item in lstSyncInstrument)
  171. {
  172. if (item.LstSyncPramas == null) continue;
  173. if (item.LstSyncPramas.Count <= 0) continue;
  174. if (item.LstSyncPramas.Where(s => s.IfPrimaryKey == true).Count() <= 0)
  175. {
  176. bIfHave = false;
  177. break;
  178. }
  179. }
  180. return bIfHave;
  181. }
  182. /// <summary>
  183. /// 新增仪器
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void btnAdd_Click(object sender, EventArgs e)
  188. {
  189. frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument);
  190. frmInstrumentCode frmCode = new frmInstrumentCode(lstSyncInstrument);
  191. frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  192. {
  193. lstSyncInstrument.Add(Instrumentitem);
  194. //绑定数据
  195. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  196. dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0];
  197. dgvInstrument_SelectionChanged(null, null);
  198. };
  199. frmSetting.ShowDialog();
  200. }
  201. /// <summary>
  202. /// 删除仪器
  203. /// </summary>
  204. /// <param name="sender"></param>
  205. /// <param name="e"></param>
  206. private void btnDel_Click(object sender, EventArgs e)
  207. {
  208. if (dgvInstrument.Rows.Count <= 0) return;
  209. //当前选中行
  210. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  211. //找到数据源中数据,删除
  212. var lstitem = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
  213. if (lstitem == null)
  214. return;
  215. else if (lstitem.Count >= 1)
  216. {
  217. foreach (var item in lstitem)
  218. {
  219. lstSyncInstrument.Remove(item);
  220. }
  221. }
  222. //绑定数据
  223. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>();
  224. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  225. //dgvInstrument.dgvInstrument_SelectionChanged()
  226. if (lstSyncInstrument.Count > 0)
  227. dgvInstrument_SelectionChanged(null, null);
  228. else
  229. {
  230. currentSyncItem = new SyncInstrumentItemInfo();
  231. dictInstruTables.Clear();
  232. cbxCnas.DataSource = null;
  233. cbxCnas.Items.Clear();
  234. cbxInstrument.DataSource = null;
  235. dgvInstruDS.DataSource = null;
  236. dgvCnas.DataSource = null;
  237. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  238. }
  239. }
  240. private void dgvInstrument_SelectionChanged(object sender, EventArgs e)
  241. {
  242. if (dgvInstrument.Rows.Count <= 0 || dgvInstrument.Rows[dgvInstrument.CurrentRow.Index].Cells[0].Value == null)
  243. {
  244. currentSyncItem = new SyncInstrumentItemInfo();
  245. return;
  246. }
  247. //清空绑定
  248. cbxCnas.DataSource = null;
  249. cbxInstrument.DataSource = null;
  250. dgvInstruDS.DataSource = null;
  251. dgvCnas.DataSource = null;
  252. //当前选中单元格
  253. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  254. var lstInstrument = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
  255. if (lstInstrument.Count == 1)
  256. {
  257. currentSyncItem = lstInstrument[0];
  258. if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn))
  259. txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
  260. else
  261. txtInstrumentColumn.Text = "";
  262. if (currentSyncItem.SyncInstrumentDSInfo != null && currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType != DataSourceType.None)
  263. {
  264. switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  265. {
  266. case DataSourceType.MySQL:
  267. case DataSourceType.Dm:
  268. case DataSourceType.Oracle:
  269. case DataSourceType.PostgreSQL:
  270. case DataSourceType.SQL:
  271. case DataSourceType.Kingbase:
  272. if (currentSyncItem.LstSyncPramas != null)
  273. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  274. if (currentSyncItem.SyncInstrumentDSInfo.ServerName != "")
  275. btnLoadDBData_Click(sender, e);
  276. break;
  277. default:
  278. if (currentSyncItem.LstSyncPramas != null)
  279. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  280. btnLoadDBData_Click(sender, e);
  281. break;
  282. }
  283. }
  284. else
  285. {
  286. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  287. }
  288. }
  289. else
  290. {
  291. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  292. }
  293. }
  294. /// <summary>
  295. /// 切换选中表时发生
  296. /// </summary>
  297. /// <param name="sender"></param>
  298. /// <param name="e"></param>
  299. private void cbxInstrument_SelectedIndexChanged(object sender, EventArgs e)
  300. {
  301. if (cbxInstrument.Text == null) return;
  302. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  303. // 使用LINQ查找匹配的数据
  304. SyncInstrumentItemInfo matchedInstrument = lstSyncInstrument.FirstOrDefault(x => x.Code == strInstrumentCode);
  305. InstrumentData instrumentDatas = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
  306. DataTable dtTableType = null;
  307. string strTableName_Instru = cbxInstrument.Text.ToString();
  308. if (matchedInstrument.SyncInstrumentDSInfo != null)
  309. {
  310. switch (matchedInstrument.SyncInstrumentDSInfo.InstrumentDataSourceType)
  311. {
  312. case DataSourceType.MySQL:
  313. dtTableType = SelectTableType.MySqlsec(strTableName_Instru);
  314. break;
  315. case DataSourceType.Dm:
  316. dtTableType = SelectTableType.DmSql(strTableName_Instru);
  317. break;
  318. case DataSourceType.Oracle:
  319. dtTableType = SelectTableType.OrcSql(strTableName_Instru, currentSyncItem);
  320. break;
  321. case DataSourceType.PostgreSQL:
  322. dtTableType = SelectTableType.PostgreSql(strTableName_Instru);
  323. break;
  324. case DataSourceType.SQL:
  325. dtTableType = SelectTableType.Sqlserversec(strTableName_Instru, currentSyncItem);
  326. break;
  327. case DataSourceType.Kingbase:
  328. dtTableType = SelectTableType.KingSql(strTableName_Instru);
  329. break;
  330. default:
  331. strTableName_Instru = matchedInstrument.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString();
  332. strTableName_Instru = currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString();
  333. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(matchedInstrument.SyncInstrumentDSInfo, new object[] { "", "", "" });
  334. dictInstruTables = instrumentData.GetInstrumentData();
  335. dictInstruTables = instrumentDatas.GetInstrumentData();
  336. if (dictInstruTables.ContainsKey(strTableName_Instru))
  337. dtTableType = dictInstruTables[strTableName_Instru];
  338. if (dictInstruTables.ContainsKey(cbxInstrument.Text))
  339. dtTableType = dictInstruTables[cbxInstrument.Text];
  340. break;
  341. }
  342. DataTable dtInstruShow = new DataTable();
  343. dtInstruShow.Columns.Add("InstruFieldName");
  344. dtInstruShow.Columns.Add("InstruDataType");
  345. dtInstruShow.Columns.Add("remark");
  346. if (dtTableType != null)
  347. {
  348. switch (matchedInstrument.SyncInstrumentDSInfo.InstrumentDataSourceType)
  349. {
  350. case DataSourceType.MySQL:
  351. case DataSourceType.Dm:
  352. case DataSourceType.PostgreSQL:
  353. case DataSourceType.SQL:
  354. case DataSourceType.Kingbase:
  355. for (int i = 0; i < dtTableType.Rows.Count; i++)
  356. {
  357. dtInstruShow.Rows.Add(new object[] { dtTableType.Rows[i]["ColumnName"], dtTableType.Rows[i]["DataType"], dtTableType.Rows[i]["remark"] });
  358. }
  359. break;
  360. case DataSourceType.Oracle:
  361. strTableName_Instru = cbxInstrument.Text.ToString();
  362. if (dictInstruTables.ContainsKey(strTableName_Instru))
  363. {
  364. DataTable dt = dictInstruTables[strTableName_Instru];
  365. if (dt != null)
  366. {
  367. dtInstruShow = new DataTable();
  368. dtInstruShow.Columns.Add("InstruFieldName");
  369. dtInstruShow.Columns.Add("InstruDataType");
  370. foreach (DataColumn dc in dt.Columns)
  371. {
  372. dtInstruShow.Rows.Add(new object[] { dc.ColumnName, dc.DataType });
  373. }
  374. dgvInstruDS.DataSource = dtInstruShow;
  375. }
  376. }
  377. break;
  378. default:
  379. foreach (DataColumn dc in dtTableType.Columns)
  380. {
  381. dtInstruShow.Rows.Add(new object[] { dc.ColumnName, dc.DataType, "" });
  382. }
  383. break;
  384. }
  385. }
  386. dgvInstruDS.DataSource = dtInstruShow;
  387. }
  388. }
  389. /// <summary>
  390. /// 切换表时发生
  391. /// </summary>
  392. /// <param name="sender"></param>
  393. /// <param name="e"></param>
  394. private void cbxCnas_SelectedIndexChanged(object sender, EventArgs e)
  395. {
  396. if (cbxCnas.Text == null) return;
  397. string strTableName_Cnas = cbxCnas.Text.ToString();
  398. DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Cnas, currentSyncItem.SyncTargetDBInfo);
  399. //从数据库中加载数据表结构
  400. //DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(strTableName_Cnas,currentSyncItem.SyncTargetDBInfo);
  401. if (dtTableStruct != null)
  402. {
  403. DataTable dtCnasShow = new DataTable();
  404. dtCnasShow.Columns.Add("CnasFieldName");
  405. dtCnasShow.Columns.Add("CnasDataType");
  406. dtCnasShow.Columns.Add("remark");
  407. for (int i = 0; i < dtTableStruct.Rows.Count; i++)
  408. {
  409. dtCnasShow.Rows.Add(new object[] { dtTableStruct.Rows[i]["ColumnName"], dtTableStruct.Rows[i]["DataType"], dtTableStruct.Rows[i]["remark"] });
  410. }
  411. dgvCnas.DataSource = null;
  412. dgvCnas.DataSource = dtCnasShow;
  413. //绑定数据
  414. cbxCNASColumn.DataSource = dtCnasShow.Copy();
  415. cbxCNASColumn.DisplayMember = "CnasFieldName";
  416. cbxCNASColumn.ValueMember = "CnasFieldName";
  417. if (dtTableStruct.Columns.Count > 0)
  418. {
  419. if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn) && dtTableStruct.Columns.Contains(currentSyncItem.CnasInstrumentColumn))
  420. {
  421. cbxCNASColumn.Text = this.txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
  422. }
  423. else
  424. {
  425. cbxCNASColumn.Text = this.txtInstrumentColumn.Text = "";
  426. }
  427. }
  428. }
  429. }
  430. //增加映射
  431. private void btnAddMapping_Click(object sender, EventArgs e)
  432. {
  433. if (cbxInstrument.Text == null) return;
  434. if (cbxCnas.Text == null) return;
  435. if (dgvInstruDS.Rows.Count <= 0) return;
  436. if (dgvCnas.Rows.Count <= 0) return;
  437. SyncParamasInfo syncParamas = new SyncParamasInfo();
  438. if (currentSyncItem.LstSyncPramas == null) currentSyncItem.LstSyncPramas = new List<SyncParamasInfo>();
  439. if (dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper() == "ID")
  440. {
  441. MessageBox.Show("该字段为CNAS数据库保留字段,不允许插入数据,请重新选择!");
  442. return;
  443. }
  444. //仪器表名和选中行
  445. syncParamas.SourceTable = cbxInstrument.Text.ToString();
  446. syncParamas.SourceField = dgvInstruDS.Rows[dgvInstruDS.CurrentCell.RowIndex].Cells[0].Value.ToString();
  447. syncParamas.DataType = dgvInstruDS.Rows[dgvInstruDS.CurrentCell.RowIndex].Cells[1].Value.ToString().ToUpper();
  448. //CNAS表名和选中行
  449. syncParamas.TargetTable = cbxCnas.Text.ToString();
  450. syncParamas.TargetField = dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString();
  451. //验证数据合法性
  452. SyncParamsOperation paramsOperation = new SyncParamsOperation();
  453. if (paramsOperation.CheckTableIfRepeat(currentSyncItem.LstSyncPramas, syncParamas.SourceTable, syncParamas.TargetTable))
  454. {
  455. MessageBox.Show("已存在不同表单映射数据,无法添加!");
  456. return;
  457. }
  458. //if (paramsOperation.CheckSourceFieldRepeat(currentSyncItem.LstSyncPramas, syncParamas.SourceTable, syncParamas.SourceField))
  459. //{
  460. // MessageBox.Show("仪器数据源字段已分配,请重新选择!");
  461. // return;
  462. //}
  463. if (paramsOperation.CheckTargetFieldRepeat(currentSyncItem.LstSyncPramas, syncParamas.TargetTable, syncParamas.TargetField))
  464. {
  465. MessageBox.Show("CNAS端数据字段已分配,请重新选择!");
  466. return;
  467. }
  468. if (paramsOperation.CheckTargetKeepField(syncParamas.TargetField))
  469. {
  470. MessageBox.Show("CNAS端数据字段为保留字段,请重新选择!");
  471. return;
  472. }
  473. //绑定数据
  474. currentSyncItem.LstSyncPramas.Add(syncParamas);
  475. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  476. //选中最后一行
  477. dgvMapping.CurrentCell = dgvMapping.Rows[dgvMapping.Rows.Count - 1].Cells[0];
  478. }
  479. /// <summary>
  480. /// 删除映射
  481. /// </summary>
  482. /// <param name="sender"></param>
  483. /// <param name="e"></param>
  484. private void btnDelMap_Click(object sender, EventArgs e)
  485. {
  486. //当前选中项
  487. if (dgvMapping.CurrentCell == null) return;
  488. string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
  489. string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
  490. var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
  491. if (lstDelItems.Count > 0)
  492. {
  493. foreach (var item in lstDelItems)
  494. {
  495. currentSyncItem.LstSyncPramas.Remove(item);
  496. }
  497. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  498. }
  499. }
  500. /// <summary>
  501. /// 配置数据库界面
  502. /// </summary>
  503. /// <param name="sender"></param>
  504. /// <param name="e"></param>
  505. private void btnDatabaseConfig_Click(object sender, EventArgs e)
  506. {
  507. frmDatabaseParams frmDatabase = new frmDatabaseParams(currentSyncItem);
  508. frmDatabase.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  509. {
  510. this.currentSyncItem = Instrumentitem;
  511. };
  512. frmDatabase.InstrumentItemData = delegate (Dictionary<string, DataTable> dict)
  513. {
  514. //this.dictInstruTables = dict;
  515. };
  516. frmDatabase.ShowDialog();
  517. //加载数据
  518. if ((currentSyncItem.SyncInstrumentDSInfo.Host != null && currentSyncItem.SyncInstrumentDSInfo.Host.Length > 0) || (currentSyncItem.SyncInstrumentDSInfo.Path != null && currentSyncItem.SyncInstrumentDSInfo.Path.Length > 0))
  519. btnLoadDBData_Click(null, null);
  520. }
  521. private void btnLoadDBData_Click(object sender, EventArgs e)
  522. {
  523. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  524. strTableInfoMode = FileOperation.GetSystemFormatConfigData(strInstrumentCode).TableInfoMode;
  525. if (strTableInfoMode == "1")
  526. {
  527. cbxInstrument.DropDownStyle = ComboBoxStyle.DropDown;
  528. //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
  529. }
  530. int iReturn = 0;
  531. if (strTableInfoMode == "0")
  532. iReturn = LoadSourceAndTargetData(true);
  533. else
  534. iReturn = LoadSourceAndTargetData();
  535. switch (iReturn)
  536. {
  537. case -1:
  538. MessageBox.Show("未能成功获取设备数据库配置信息,请配置后重试!");
  539. break;
  540. case -2:
  541. MessageBox.Show("未能成功获取CNAS数据库配置信息,请配置后重试!");
  542. break;
  543. case -3:
  544. MessageBox.Show("未能成功获取仪器数据信息,请配置后重试!");
  545. break;
  546. case -4:
  547. MessageBox.Show("未能成功获取CNAS数据信息,请配置后重试!");
  548. break;
  549. case -5:
  550. DialogResult dr = MessageBox.Show("检测到数据连接配置已经修改,是否全部删除已经分配的字段映射?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
  551. if (dr == DialogResult.Yes)
  552. {
  553. //此时将全部删除已经分配的映射字段
  554. currentSyncItem.LstSyncPramas.Clear();
  555. currentSyncItem.lstFixedValue.Clear();
  556. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  557. }
  558. break;
  559. case -6:
  560. MessageBox.Show("请先手动输入表名");
  561. break;
  562. case -7:
  563. MessageBox.Show("配置SQL查询没有结果,请检查SQL是否正确");
  564. break;
  565. default:
  566. break;
  567. }
  568. }
  569. /// <summary>
  570. /// 加载来源和目标数据的数据结构
  571. /// </summary>
  572. /// <param name="bIfLoading"></param>
  573. /// <returns></returns>
  574. public int LoadSourceAndTargetData(bool bIfLoading = false)
  575. {
  576. //检查配置信息
  577. if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
  578. if (currentSyncItem.SyncTargetDBInfo == null) return -2;
  579. bool bIfSameTable = true;
  580. //是否需要重新加载来源库
  581. if (bIfLoading)
  582. {
  583. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
  584. dictInstruTables = instrumentData.GetInstrumentData();
  585. }
  586. if (dictInstruTables.Count <= 0) return -3;
  587. //绑定ComboBox
  588. List<string> lstTableName = new List<string>();
  589. foreach (var item in dictInstruTables)
  590. {
  591. lstTableName.Add(item.Key);
  592. }
  593. cbxInstrument.DataSource = lstTableName;
  594. cbxInstrument.ValueMember = "";
  595. if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
  596. {
  597. if (lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable) || lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable.ToUpper()) || lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable.ToLower()))
  598. cbxInstrument.Text = currentSyncItem.LstSyncPramas[0].SourceTable;
  599. else
  600. bIfSameTable = false;
  601. }
  602. //获取CNAS配置的数据库连接信息
  603. DataTable dtCNAS = CnasDataOperationFact.CnasDataOperation().GetAllCNASTablesName(currentSyncItem.SyncTargetDBInfo);
  604. if (dtCNAS != null && dtCNAS.Rows.Count > 0)
  605. {
  606. List<string> lstCnasTables = new List<string>();
  607. foreach (DataRow dr in dtCNAS.Rows)
  608. {
  609. if (dtCNAS.Columns.Contains("TABNAME"))
  610. lstCnasTables.Add(dr["TABNAME"].ToString());
  611. else if (dtCNAS.Columns.Contains("table_name"))
  612. lstCnasTables.Add(dr["table_name"].ToString());
  613. }
  614. cbxCnas.DataSource = lstCnasTables;
  615. cbxCnas.ValueMember = "";
  616. if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
  617. {
  618. if (lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToUpper()) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToLower()))
  619. {
  620. cbxCnas.Text = currentSyncItem.LstSyncPramas[0].TargetTable;
  621. //cbxCnas_SelectedIndexChanged(null, null);
  622. }
  623. else
  624. bIfSameTable = false;
  625. }
  626. }
  627. else
  628. return -4;
  629. if (!bIfSameTable)
  630. {
  631. return -5;
  632. }
  633. return 1;
  634. }
  635. public AccessFormatConfig AccessFormat { get; set; }
  636. public ExcelFormatConfig ExcelFormat { get; set; }
  637. public FoxProFormatConfig FoxProFormat { get; set; }
  638. public SqliteFormatConfig SqliteFormat { get; set; }
  639. public SqlServerFormatConfig SqlServerFormat { get; set; }
  640. public OracleFormatConfig OracleFormat { get; set; }
  641. public MySqlFormatConfig MySqlFormat { get; set; }
  642. public NormalFileFormatConfig NormalFileFormat { get; set; }
  643. public PostgreSqlFormatConfig PostgreSqlFormat { get; set; }
  644. public KingbaseFormatConfig KingbaseFormat { get; set; }
  645. public DmFormatConfig DmFormat { get; set; }
  646. /// <summary>
  647. /// 手动输入表名时,获取该表的表信息
  648. /// </summary>
  649. /// <returns></returns>
  650. public int LoadSourceAndTargetData()
  651. {
  652. if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
  653. if (currentSyncItem.SyncTargetDBInfo == null) return -2;
  654. string sqlName = "";
  655. string sql = "";
  656. ExcelFormat = FileOperation.GetFormatConfigData<ExcelFormatConfig>("ExcelFormatConfig.xml");
  657. AccessFormat = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml");
  658. FoxProFormat = FileOperation.GetFormatConfigData<FoxProFormatConfig>("FoxProFormatConfig.xml");
  659. SqliteFormat = FileOperation.GetFormatConfigData<SqliteFormatConfig>("SqliteFormatConfig.xml");
  660. SqlServerFormat = FileOperation.GetFormatConfigData<SqlServerFormatConfig>("SqlServerFormatConfig.xml");
  661. OracleFormat = FileOperation.GetFormatConfigData<OracleFormatConfig>("OracleFormatConfig.xml");
  662. NormalFileFormat = FileOperation.GetFormatConfigData<NormalFileFormatConfig>("NormalFileFormatConfig.xml");
  663. switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  664. {
  665. case DataSourceType.MySQL:
  666. MySqlFormat = FileOperation.GetFormatConfigData<MySqlFormatConfig>("MySqlFormatConfig.xml");
  667. sqlName = MySqlFormat.AutoSql.MySqlViewName;
  668. sql = MySqlFormat.AutoSql.MySqlViewSql;
  669. break;
  670. case DataSourceType.Dm:
  671. DmFormat = FileOperation.GetFormatConfigData<DmFormatConfig>("DmFormatConfig.xml");
  672. sqlName = DmFormat.AutoSql.DmViewName;
  673. sql = DmFormat.AutoSql.DmViewSql;
  674. break;
  675. case DataSourceType.Oracle:
  676. OracleFormat = FileOperation.GetFormatConfigData<OracleFormatConfig>("OracleFormatConfig.xml");
  677. sqlName = OracleFormat.AutoSql.OracleViewName;
  678. sql = OracleFormat.AutoSql.OracleViewSql;
  679. break;
  680. case DataSourceType.PostgreSQL:
  681. PostgreSqlFormat = FileOperation.GetFormatConfigData<PostgreSqlFormatConfig>("PostgreSqlFormatConfig.xml");
  682. sqlName = PostgreSqlFormat.AutoSql.PostgreSqlViewName;
  683. sql = PostgreSqlFormat.AutoSql.PostgreSqlViewSql;
  684. break;
  685. case DataSourceType.SQL:
  686. SqlServerFormat = FileOperation.GetFormatConfigData<SqlServerFormatConfig>("SqlServerFormatConfig.xml");
  687. sqlName = SqlServerFormat.AutoSql.SqlServerViewName;
  688. sql = SqlServerFormat.AutoSql.SqlServerViewSql;
  689. break;
  690. case DataSourceType.Kingbase:
  691. KingbaseFormat = FileOperation.GetFormatConfigData<KingbaseFormatConfig>("KingbaseFormatConfig.xml");
  692. sqlName = KingbaseFormat.AutoSql.KingbaseViewName;
  693. sql = KingbaseFormat.AutoSql.KingbaseViewSql;
  694. break;
  695. default:
  696. break;
  697. }
  698. //cbxInstrument.Text = ExtractTableNames(sql);
  699. cbxInstrument.Text = sqlName;
  700. if (cbxInstrument.Text == "") return -6;
  701. int returnValue = 1;
  702. //根据手动输入来源库的表名加载字段
  703. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
  704. //dictInstruTables = instrumentData.GetInstrumentData();
  705. //dictInstruTables =
  706. DataTable dataTableStruct = null;
  707. string strTableName_Instru = cbxInstrument.Text.ToString();
  708. switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  709. {
  710. case DataSourceType.MySQL:
  711. dataTableStruct = SelectTableType.MySqlsecSD(sql);
  712. break;
  713. case DataSourceType.Dm:
  714. dataTableStruct = SelectTableType.DmSqlSD(sql);
  715. break;
  716. case DataSourceType.Oracle:
  717. dataTableStruct = SelectTableType.OrcSqlSD(sql, currentSyncItem);
  718. break;
  719. case DataSourceType.PostgreSQL:
  720. dataTableStruct = SelectTableType.PostgreSqlSD(sql);
  721. break;
  722. case DataSourceType.SQL:
  723. dataTableStruct = SelectTableType.SqlserversecSD(sql, currentSyncItem);
  724. break;
  725. case DataSourceType.Kingbase:
  726. if (cbxInstrument.Text.Contains('.'))
  727. cbxInstrument.Text = cbxInstrument.Text.Split('.')[1];
  728. dataTableStruct = SelectTableType.KingSql(sql);
  729. break;
  730. default:
  731. break;
  732. }
  733. DataTable dtInstruShow = new DataTable();
  734. dtInstruShow.Columns.Add("InstruFieldName");
  735. dtInstruShow.Columns.Add("InstruDataType");
  736. dtInstruShow.Columns.Add("remark");
  737. if (dataTableStruct != null)
  738. {
  739. for (int i = 0; i < dataTableStruct.Columns.Count; i++)
  740. {
  741. dtInstruShow.Rows.Add(new object[] { dataTableStruct.Columns[i].ColumnName, dataTableStruct.Columns[i].DataType });
  742. }
  743. }
  744. dgvInstruDS.DataSource = dtInstruShow;
  745. if (dataTableStruct != null && dataTableStruct.Columns.Count > 0)
  746. {
  747. dictInstruTables.Clear();
  748. dictInstruTables.Add(cbxInstrument.Text, dataTableStruct);
  749. //return 1;
  750. }
  751. else
  752. {
  753. returnValue = -7;
  754. return returnValue;
  755. }
  756. //获取CNAS配置的数据库连接信息
  757. DataTable dtCNAS = CnasDataOperationFact.CnasDataOperation().GetAllCNASTablesName(currentSyncItem.SyncTargetDBInfo);
  758. if (dtCNAS != null && dtCNAS.Rows.Count > 0)
  759. {
  760. List<string> lstCnasTables = new List<string>();
  761. foreach (DataRow dr in dtCNAS.Rows)
  762. {
  763. lstCnasTables.Add(dr["TABNAME"].ToString());
  764. }
  765. cbxCnas.DataSource = lstCnasTables;
  766. cbxCnas.ValueMember = "";
  767. if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
  768. {
  769. if (lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToUpper()) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToLower()))
  770. {
  771. cbxCnas.Text = currentSyncItem.LstSyncPramas[0].TargetTable;
  772. //cbxCnas_SelectedIndexChanged(null, null);
  773. }
  774. else
  775. returnValue = -5;
  776. }
  777. }
  778. else
  779. returnValue = -4;
  780. return returnValue;
  781. }
  782. public string ExtractTableNames(string sql)
  783. {
  784. // 预处理:去除注释、统一空格
  785. sql = Regex.Replace(sql, @"(--.*)|(\/\*[\s\S]*?\*\/)", "", RegexOptions.Multiline);
  786. sql = Regex.Replace(sql, @"\s+", " ");
  787. // 定义匹配模式
  788. var patterns = new Dictionary<string, string>
  789. {
  790. { "SELECT", @"(?:FROM|JOIN)\s+([\w\.]+)(?:\s+AS\s+\w+)?" },
  791. { "INSERT", @"INSERT\s+INTO\s+([\w\.]+)" },
  792. { "UPDATE", @"UPDATE\s+([\w\.]+)" },
  793. { "DELETE", @"DELETE\s+FROM\s+([\w\.]+)" }
  794. };
  795. var tables = new HashSet<string>();
  796. foreach (var pattern in patterns.Values)
  797. {
  798. var matches = Regex.Matches(sql, pattern, RegexOptions.IgnoreCase);
  799. foreach (Match match in matches)
  800. {
  801. if (match.Groups[1].Success)
  802. tables.Add(match.Groups[1].Value.Trim());
  803. }
  804. }
  805. if (tables.Count == 0)
  806. return "";
  807. else
  808. return tables.ToList()[0];
  809. }
  810. private void dgvMapping_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  811. {
  812. if (dgvMapping.CurrentCell == null) return;
  813. if (dgvMapping.CurrentCell.ColumnIndex == 2) //此时修改的主健列
  814. {
  815. string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
  816. string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
  817. string strPrimaryKey = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["PrimaryKey"].Value.ToString();
  818. var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
  819. if (lstDelItems.Count > 0)
  820. {
  821. foreach (var item in lstDelItems)
  822. {
  823. item.IfPrimaryKey = strPrimaryKey.ToLower() == "true" ? true : false;
  824. }
  825. }
  826. }
  827. if (dgvMapping.CurrentCell.ColumnIndex == 3) //此时修改的是日期字段列
  828. {
  829. string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
  830. string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
  831. string strDateKey = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["DateKey"].Value.ToString();
  832. var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
  833. if (lstDelItems.Count == 1)
  834. {
  835. if (strDateKey.ToLower() == "true")
  836. {
  837. //datagridview显示列(只能允许一条数据选择true,所以要把其他行的数据都置为false)
  838. foreach (DataGridViewRow dgvRow in dgvMapping.Rows)
  839. {
  840. if (dgvRow.Cells["DateKey"].Value.ToString().ToLower() == "true")
  841. dgvRow.Cells["DateKey"].Value = false;
  842. }
  843. //内存数据源
  844. foreach (var item in currentSyncItem.LstSyncPramas)
  845. {
  846. if (item.IfDateField)
  847. item.IfDateField = false;
  848. }
  849. lstDelItems[0].IfDateField = true;
  850. }
  851. else
  852. {
  853. lstDelItems[0].IfDateField = false;
  854. }
  855. }
  856. }
  857. }
  858. private void dgvMapping_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  859. {
  860. if (dgvMapping.IsCurrentCellDirty)
  861. {
  862. dgvMapping.CommitEdit(DataGridViewDataErrorContexts.Commit);
  863. }
  864. }
  865. private void btnCNASFieldConfig_Click(object sender, EventArgs e)
  866. {
  867. if (currentSyncItem == null || currentSyncItem.LstSyncPramas == null || currentSyncItem.LstSyncPramas.Count == 0)
  868. {
  869. MessageBox.Show("请先指定至少一个映射字段。");
  870. return;
  871. }
  872. frmCNASValue frmCNAS = new frmCNASValue(currentSyncItem);
  873. if (frmCNAS.ShowDialog() == DialogResult.OK)
  874. {
  875. this.currentSyncItem = frmCNAS.syncInstrument;
  876. }
  877. }
  878. private void btnSourceFilter_Click(object sender, EventArgs e)
  879. {
  880. if (currentSyncItem == null || currentSyncItem.LstSyncPramas == null || currentSyncItem.LstSyncPramas.Count == 0)
  881. {
  882. MessageBox.Show("请先指定至少一个映射字段。");
  883. return;
  884. }
  885. frmSourceFilter frm = new frmSourceFilter(currentSyncItem, strTableInfoMode);
  886. frm.sourceDataFilterHandler = delegate (SourceDataFilter dataFilter)
  887. {
  888. currentSyncItem.SourceFilter = dataFilter;
  889. };
  890. frm.ShowDialog();
  891. }
  892. private void dgvInstrument_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  893. {
  894. if (dgvInstrument.Rows.Count <= 0) return;
  895. //当前选中单元格
  896. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  897. frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument, strInstrumentCode);
  898. frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  899. {
  900. lstSyncInstrument.Add(Instrumentitem);
  901. //绑定数据
  902. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  903. dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0];
  904. dgvInstrument_SelectionChanged(null, null);
  905. };
  906. frmSetting.ShowDialog();
  907. }
  908. private void cbxCNASColumn_SelectedIndexChanged(object sender, EventArgs e)
  909. {
  910. if (cbxCNASColumn.Visible)
  911. {
  912. cbxCNASColumn.Visible = false;
  913. txtInstrumentColumn.Visible = true;
  914. currentSyncItem.CnasInstrumentColumn = txtInstrumentColumn.Text = cbxCNASColumn.Text;
  915. }
  916. }
  917. /// <summary>
  918. /// 当双击textBox时,显示ComboBOX用于选择
  919. /// </summary>
  920. /// <param name="sender"></param>
  921. /// <param name="e"></param>
  922. private void txtInstrumentColumn_DoubleClick(object sender, EventArgs e)
  923. {
  924. txtInstrumentColumn.Visible = false;
  925. cbxCNASColumn.Top = txtInstrumentColumn.Top;
  926. cbxCNASColumn.Height = txtInstrumentColumn.Height;
  927. cbxCNASColumn.Width = txtInstrumentColumn.Width;
  928. cbxCNASColumn.Location = txtInstrumentColumn.Location;
  929. cbxCNASColumn.Visible = true;
  930. }
  931. private void cbxCNASColumn_Leave(object sender, EventArgs e)
  932. {
  933. if (cbxCNASColumn.Visible)
  934. {
  935. txtInstrumentColumn.Visible = true;
  936. cbxCNASColumn.Visible = false;
  937. }
  938. }
  939. private void tsmServiceSetting_Click(object sender, EventArgs e)
  940. {
  941. frmServiceConfig frmServiceConfig = new frmServiceConfig();
  942. frmServiceConfig.ShowDialog();
  943. }
  944. private void tsmSystemSetting_Click(object sender, EventArgs e)
  945. {
  946. //frmSystemSetting frmSystem = new frmSystemSetting();
  947. //frmSystem.ShowDialog();
  948. //strTableInfoMode = FileOperation.GetSystemFormatConfigData().TableInfoMode;
  949. //if (strTableInfoMode == "1")
  950. //{
  951. // cbxInstrument.DropDownStyle = ComboBoxStyle.DropDown;
  952. // //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
  953. //}
  954. //else
  955. //{
  956. // cbxInstrument.DropDownStyle = ComboBoxStyle.DropDownList;
  957. //}
  958. }
  959. private void tsmSourceSetting_Click(object sender, EventArgs e)
  960. {
  961. frmSourceSetting frmSource = new frmSourceSetting();
  962. frmSource.ShowDialog();
  963. }
  964. private void tsmHelper_Click(object sender, EventArgs e)
  965. {
  966. string strHelpFilePath = FileHelper.getBasePath() + @"\Helper.CHM";
  967. //Help.ShowHelp(null, strHelpFilePath, HelpNavigator.TopicId, "1");
  968. //Help.ShowHelpIndex(this, strHelpFilePath);
  969. System.Diagnostics.Process.Start(strHelpFilePath);
  970. }
  971. /// <summary>
  972. /// 右键事件
  973. /// </summary>
  974. /// <param name="sender"></param>
  975. /// <param name="e"></param>
  976. private void dgvInstrument_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  977. {
  978. if (e.Button == MouseButtons.Right)
  979. {
  980. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  981. if (dgvInstrument.Rows.Count <= 0) return;
  982. //当前选中单元格
  983. if (strInstrumentCode != "")
  984. {
  985. // 显示上下文菜单
  986. ContextMenuStrip contextMenu = new ContextMenuStrip();
  987. contextMenu.Items.Add("编辑", null, new EventHandler(Option1_Click));
  988. contextMenu.Show(dgvInstrument, new Point(e.X, e.Y));
  989. }
  990. }
  991. }
  992. }
  993. }