FormStandardLibraryInformation.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using DevExpress.Utils;
  2. using DevExpress.XtraDiagram.Bars;
  3. using OTS.WinFormsUI.Docking;
  4. using OTSCommon.DBOperate;
  5. using OTSIncAReportApp.OTSRstMgrFunction;
  6. using OTSIncAReportApp.OTSSampleReportInfo;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. using static OTSIncAReportApp.OTSReport_Export;
  19. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  20. namespace OTSIncAReportApp._1_UI
  21. {
  22. public partial class FormStandardLibraryInformation : DockContent
  23. {
  24. //测量结果
  25. frmReportApp m_frmReportApp = null;
  26. frmReportConditionChoose m_condition;
  27. public List<string[]> LibraryName = new List<string[]>();
  28. private bool isExport = true;
  29. public c_TemplateClass m_mbszclass = null;
  30. DataTable m_data=new DataTable();
  31. public FormStandardLibraryInformation(frmReportApp frmReportApp)
  32. {
  33. InitializeComponent();
  34. m_frmReportApp = frmReportApp;
  35. m_condition = frmReportApp.m_conditionChoose;
  36. m_mbszclass = new c_TemplateClass();
  37. }
  38. private void FormStandardLibraryInformation_Load(object sender, EventArgs e)
  39. {
  40. label1.Text = " ";
  41. label2.Text = " ";
  42. label3.Text = " ";
  43. // 设置ListView为详细视图
  44. listView1.View = View.Details;
  45. listView1.FullRowSelect = true; // 可选,设置是否选择整行
  46. listView1.GridLines = true; // 可选,设置是否显示网格线
  47. listView1.Columns.Clear();
  48. listView1.Columns.Add(" ", 90, HorizontalAlignment.Left);
  49. listView1.Columns.Add(" ", 130, HorizontalAlignment.Left);
  50. listView1.Columns.Add(" ", 70, HorizontalAlignment.Left);
  51. listView1.Items.Clear();
  52. DataLoad();
  53. }
  54. private void GetDBData(ResultFile resultFile)
  55. {
  56. ResultFile resfile = resultFile;
  57. string Name = "";
  58. string rstSTD = resfile.GetSTDName();
  59. string strSTDType = resfile.GetSTDEngineType();
  60. string[] result = Regex.Split(strSTDType, ":");
  61. if (result[0] == "0")
  62. {
  63. Name = "OTSIncASysSTD";
  64. return;
  65. }
  66. else
  67. {
  68. string input1 = rstSTD;
  69. string[] fruits1 = input1.Split('.');
  70. if ("NoSTDDB" == fruits1[0] ||
  71. "NoSTDDB.db" == fruits1[0])
  72. {
  73. Name = "OTSIncASysSTD";
  74. return;
  75. }
  76. else
  77. {
  78. Name = fruits1[0];
  79. }
  80. }
  81. try
  82. {
  83. ReadClassification();
  84. }
  85. catch (Exception ex) { return; }
  86. for (int i=0;i< LibraryName.Count;i++)
  87. {
  88. string input = LibraryName[i][0];
  89. string[] fruits = input.Split('.');
  90. if ( Name== fruits[0])
  91. {
  92. listView1.Items.Clear();
  93. DataTable dt_stl = new DataTable();
  94. DataTable Dt_grouping = new DataTable();
  95. if (result[0] == "3")
  96. {
  97. SqLiteHelper sh = new SqLiteHelper("data source='" + LibraryName[i][1] + "'");
  98. if (!sh.SearchTable("SELECT COUNT(*) FROM STDMinerals"))
  99. {
  100. return;
  101. }
  102. dt_stl = sh.ExecuteQuery("select * from STDMinerals");
  103. m_data = dt_stl.Copy();
  104. for (int a = 0; a < dt_stl.Rows.Count; a++)
  105. {
  106. ListViewItem item1 = new ListViewItem(dt_stl.Rows[a]["name"].ToString());
  107. item1.SubItems.Add("#"+ Convert.ToInt64(dt_stl.Rows[a]["color"]).ToString("X6"));//颜色
  108. item1.UseItemStyleForSubItems = false; // 允许为每个 SubItem 设置不同的样式
  109. item1.SubItems[1].BackColor = Color.LightBlue; // 这将不会生效,除非我们处理 OwnerDraw
  110. listView1.Items.Add(item1);
  111. }
  112. break ;
  113. }
  114. else
  115. {
  116. SqLiteHelper sh = new SqLiteHelper("data source='" + LibraryName[i][1] + "'");
  117. if (!sh.SearchTable("SELECT COUNT(*) FROM ClassifySTD"))
  118. {
  119. return;
  120. }
  121. dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
  122. Dt_grouping= sh.ExecuteQuery("select * from STDGroups");
  123. m_data = dt_stl.Copy();
  124. for (int a = 0; a < dt_stl.Rows.Count; a++)
  125. {
  126. string grouping = "";
  127. for (int b = 0; b < Dt_grouping.Rows.Count; b++)
  128. {
  129. if (dt_stl.Rows[a]["GroupId"].ToString() == Dt_grouping.Rows[b]["id"].ToString())
  130. {
  131. grouping = Dt_grouping.Rows[b]["name"].ToString();
  132. }
  133. }
  134. ListViewItem item1 = new ListViewItem(grouping/*,dt_stl.Rows[a]["StrName"].ToString()*/);
  135. item1.SubItems.Add(dt_stl.Rows[a]["StrName"].ToString());
  136. item1.SubItems.Add(dt_stl.Rows[a]["Color"].ToString());
  137. item1.UseItemStyleForSubItems = false; // 允许为每个 SubItem 设置不同的样式
  138. item1.SubItems[2].BackColor = Color.LightBlue; // 这将不会生效,除非我们处理 OwnerDraw
  139. listView1.Items.Add(item1);
  140. }
  141. break;
  142. }
  143. }
  144. }
  145. label1.Text = "分类名";
  146. label2.Text = "颜色";
  147. label3.Text = "分组名";
  148. // 由于 ListViewItem 不直接支持为 SubItem 设置背景色,我们需要启用 OwnerDrawFixed 模式
  149. listView1.OwnerDraw = true;
  150. listView1.DrawItem += new DrawListViewItemEventHandler(ListView1_DrawItem);
  151. listView1.DrawSubItem += new DrawListViewSubItemEventHandler(ListView1_DrawSubItem);
  152. }
  153. static List<string> GetDbFilesInDirectory(string directoryPath)
  154. {
  155. List<string> files = new List<string>();
  156. // 使用搜索模式 "*.db" 来查找所有.db文件
  157. string[] allDbFiles = Directory.GetFiles(directoryPath, "*.db");
  158. // 将找到的文件名添加到列表中
  159. files.AddRange(allDbFiles.Select(Path.GetFileName)); // 如果只需要文件名,而不是完整路径
  160. // 如果你需要文件的完整路径,可以直接返回 allDbFiles 数组(转换为List<string>)
  161. // return allDbFiles.ToList();
  162. return files;
  163. }
  164. private void ListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
  165. {
  166. // 这里可以自定义绘制整个 ListViewItem
  167. // 但由于我们只关心 SubItem 的颜色,所以主要逻辑将在 DrawSubItem 中
  168. e.DrawDefault = true; // 默认情况下使用标准绘制
  169. }
  170. private void ListView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
  171. {
  172. // 检查是否是我们要自定义颜色的那一列
  173. if (e.ColumnIndex == 2) // 第二列的索引是 1
  174. {
  175. Color color = ColorTranslator.FromHtml(e.SubItem.Text);
  176. // 自定义绘制 SubItem
  177. e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds);
  178. TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, e.Bounds, color, TextFormatFlags.Left);
  179. // 告诉 ListView 我们已经处理了绘制
  180. e.DrawDefault = false;
  181. }
  182. else
  183. {
  184. // 对于其他列,使用默认绘制
  185. e.DrawDefault = true;
  186. }
  187. }
  188. private void ReadClassificationNo()
  189. {
  190. LibraryName.Clear();
  191. string MeasurementFiles = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData";
  192. // 获取文件夹中的所有文件信息
  193. List<string> getNameM = GetDbFilesInDirectory(MeasurementFiles);
  194. // 遍历文件信息数组并打印出文件名
  195. for (int i = 0; i < getNameM.Count; i++)
  196. {
  197. string[] vs = new string[] { getNameM[i], MeasurementFiles + "\\" + getNameM[i] };
  198. LibraryName.Add(vs);
  199. }
  200. if (m_mbszclass.M_SY.StandardLibraryName == "NoSTDDB.db")
  201. {
  202. m_mbszclass.M_SY.StandardLibraryName = "";
  203. }
  204. }
  205. private void ReadClassification()
  206. {
  207. LibraryName.Clear();
  208. string fullPathM = "";
  209. string fullPathR = "";
  210. ResultFile resfile = m_frmReportApp.m_rstDataMgr.ResultFilesList[m_frmReportApp.m_rstDataMgr.GetWorkingResultId()];
  211. string str_libraryName = resfile.GetSTDName();
  212. bool endsWithDb = str_libraryName.EndsWith(".db", StringComparison.OrdinalIgnoreCase);
  213. if (!endsWithDb)
  214. {
  215. str_libraryName = str_libraryName + ".db";
  216. }
  217. try
  218. {
  219. fullPathM = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData\\" + str_libraryName /*+ ".db"*/;
  220. string MeasurementFiles = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData";
  221. // 获取文件夹中的所有文件信息
  222. List<string> getNameM = GetDbFilesInDirectory(MeasurementFiles);
  223. // 遍历文件信息数组并打印出文件名
  224. for (int i = 0; i < getNameM.Count; i++)
  225. {
  226. string[] vs = new string[] { getNameM[i], MeasurementFiles + "\\" + getNameM[i] };
  227. LibraryName.Add(vs);
  228. }
  229. }
  230. catch
  231. {
  232. }
  233. try
  234. {
  235. fullPathR = m_frmReportApp.m_rstDataMgr.CurResultFile.FilePath + "\\" + str_libraryName /*+ ".db"*/;
  236. string ReportFile = m_frmReportApp.m_rstDataMgr.CurResultFile.FilePath;
  237. // 获取文件夹中的所有文件信息
  238. List<string> getNameR = GetDbFilesInDirectory(ReportFile);
  239. for (int i = 0; i < getNameR.Count; i++)
  240. {
  241. string[] vs = new string[] { getNameR[i], ReportFile + "\\" + getNameR[i] };
  242. LibraryName.Add(vs);
  243. }
  244. }
  245. catch
  246. {
  247. }
  248. if (str_libraryName == "NoSTDDB.db" || m_mbszclass.M_SY.StandardLibraryName == "NoSTDDB.db")
  249. {
  250. m_mbszclass.M_SY.StandardLibraryName = "";
  251. }
  252. else
  253. {
  254. if (System.IO.File.Exists(fullPathR))
  255. {
  256. return;
  257. }
  258. else if (System.IO.File.Exists(fullPathM))
  259. {
  260. return;
  261. }
  262. else
  263. {
  264. //MessageBox.Show(table["library_does_not_match"].ToString());
  265. }
  266. }
  267. }
  268. private void FormStandardLibraryInformation_Activated(object sender, EventArgs e)
  269. {
  270. //DataLoad();
  271. }
  272. public void DataRefresh()
  273. {
  274. DataLoad();
  275. listView1.View = View.Details;
  276. listView1.FullRowSelect = true; // 可选,设置是否选择整行
  277. listView1.GridLines = true; // 可选,设置是否显示网格线
  278. }
  279. public void DataDeletion()
  280. {
  281. listView1.Items.Clear();
  282. }
  283. private void DataLoad()
  284. {
  285. if (m_condition.m_CurrentConditions.Count == 0)
  286. {
  287. return;
  288. }
  289. listView1.Items.Clear();
  290. string sou = m_condition.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  291. if (sou.Contains("+"))
  292. {
  293. for (int i = 0; i < sou.Split('+').Length; i++)
  294. {
  295. ResultFile resultFile = m_frmReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  296. if (resultFile != null)
  297. {
  298. GetDBData(resultFile);
  299. }
  300. }
  301. }
  302. else
  303. {
  304. for (int i = 0; i < m_frmReportApp.m_rstDataMgr.ResultFilesList.Count; i++)
  305. {
  306. if (sou == m_frmReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString())
  307. {
  308. GetDBData(m_frmReportApp.m_rstDataMgr.ResultFilesList[i]);
  309. }
  310. }
  311. }
  312. ////根据标签索引 显示默认的数据图表
  313. //if (m_frmReportApp.m_ChartsWindow.Controls != null)
  314. //{
  315. // if (m_frmReportApp.m_ChartsWindow.Controls.Count == 0)
  316. // {
  317. // m_frmReportApp.m_conditionChoose.tabIndex = DisplayPicutureType.AnalyzeStandardLibrary;
  318. // m_frmReportApp.m_conditionChoose.ShowsTheDefaultPic();
  319. // }
  320. //}
  321. //m_frmReportApp.m_RstWindow.SelectWorkSampleNode();
  322. ////设置每个功能模块限制菜单的显示
  323. //if (this.Controls.Count != 0)
  324. //{
  325. // m_frmReportApp.m_RibbonFun.SetRibbonButnStatu_ByModule(DisplayPicutureType.AnalyzeStandardLibrary);
  326. //}
  327. ////判断样品属性与样品窗口在主窗体的位置
  328. //if (m_frmReportApp.m_conditionChoose.DockState != m_frmReportApp.m_RstWindow.DockState)
  329. //{
  330. // m_frmReportApp.m_RstWindow.Activate();
  331. //}
  332. //else
  333. //{
  334. // if (!m_frmReportApp.m_conditionChoose.Focus())
  335. // {
  336. // m_frmReportApp.m_RstWindow.Activate();
  337. // }
  338. //}
  339. }
  340. }
  341. }