FormStandardLibraryInformation.cs 13 KB

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