FormStandardLibraryInformation.cs 13 KB

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