FormStandardLibraryInformation.cs 12 KB

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