frmReportApp.cs 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642
  1. 
  2. using OTS.WinFormsUI.Docking;
  3. using OTSCommon.DBOperate.Model;
  4. using OTSIncAReportApp._1_UI;
  5. using OTSIncAReportApp.OTSRibbon;
  6. using OTSIncAReportApp.OTSRstMgrFunction;
  7. using OTSIncAReportApp.OTSSampleReportInfo;
  8. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  9. using OTSIncAReprotCharts;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.Drawing;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Runtime.InteropServices;
  17. using System.Windows.Forms;
  18. using OTSCommon;
  19. using NLog.Fluent;
  20. namespace OTSIncAReportApp
  21. {
  22. public struct PostLogMsg
  23. {
  24. public int logLevel;//1 trace 2 debug 3info 4 warn 5 error 6 fatal
  25. [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)2000)]
  26. public char[] logMessage;
  27. };
  28. /// <summary>
  29. /// 报告主窗体类
  30. /// </summary>
  31. public partial class frmReportApp : Form
  32. {
  33. #region 共享窗体对象--------------------------------------------------------------------------------------
  34. public frmMeasureRstMgr m_RstWindow = null; //测量结果,树控件窗体,属性Grid窗体
  35. public frmReportConditionChoose m_conditionChoose = null; //属性Grid窗体
  36. public frmSampleImage m_SImageWindow = null; //BSE窗体
  37. public frmTables m_TablesWindowandChart = null; //统计分析窗体
  38. public frmTables m_ParticlesListWindow = null; //颗粒列表窗体
  39. public frmTables m_OverviewWindow = null; //结果概况窗体
  40. public FormStandardLibraryInformation m_StandardLibrary = null; //标准库窗体
  41. public frmReportSysConfig m_ReportSysConfigForm; //配置参数窗体
  42. #endregion //-----------------------------------------------------------------------------------------------
  43. #region 报告类结构相关------------------------------------------------------------------------------------
  44. NLog.Logger log;
  45. private PostLogMsg m_LogMsg;
  46. public const int MsgID = 0x0464;
  47. public const int LogMsgID = 0x0465;
  48. public OutputNlog m_OutputNlog; //日志类对象
  49. public ResultDataMgr m_rstDataMgr = null; //DataMgrFun 对象, 此类是和调用C++ DataMGR交互数据
  50. public OTSRibbonFun m_RibbonFun = null; //报告菜单相关操作类
  51. //当前工作结果
  52. public static RectangleF selectedRegion = new RectangleF();
  53. public RptConfigFile m_RptConfigFile;
  54. public string MoreSource = "";
  55. public string savePathName = "FIELD_FILES_REMEASURE"; //二次采集图像目录名
  56. Hashtable table; //国际化表
  57. string[] m_str_resultfilepaths;
  58. #endregion //-----------------------------------------------------------------------------------------------
  59. #region EChart相关变量------------------------------------------------------------------------------------
  60. //定义浏览器
  61. //public CefSharp.WinForms.ChromiumWebBrowser browser;
  62. //public CefSharp.WinForms.ChromiumWebBrowser browsermore;//多测量结果对比时使用
  63. public bool more = false;
  64. public bool trans = false;
  65. //定义浏览器
  66. //public CefSharp.WinForms.ChromiumWebBrowser browser_trio;
  67. //public CefSharp.WinForms.ChromiumWebBrowser browser_triomore;//多测量结果对比时使用
  68. public class JsEvent
  69. {
  70. public string MessageText { set; get; }
  71. public void ShowTest()
  72. {
  73. MessageBox.Show(MessageText);
  74. }
  75. }
  76. public JsEvent js = new JsEvent();
  77. public string m_reportname;
  78. public string data;
  79. public string dataCombin;
  80. public string type;
  81. public bool timerKG;
  82. #endregion //------------------------------------------------------------------------------------------------
  83. #region 各功能模块窗体 -----------------------------------------------------------------------------------
  84. /// <summary>
  85. /// 颗粒分布图
  86. /// </summary>
  87. public OTSIncAReportGraph.Controls.Control_DrawDistrbutionImageAndBSE im_Control_DrawDistrbutionImageAndBSE = null;
  88. /// <summary>
  89. /// 颗粒排序图
  90. /// </summary>
  91. public OTSIncAReportGraph.Controls.Control_DrawDistrbutionSortImage im_Control_DrawDistrbutionSortImage = null;
  92. /// <summary>
  93. /// 颗粒列表_分页
  94. /// </summary>
  95. public OTSIncAReportGrids.ParticlesGridDevidePage im_ParticlesGridDevidePage = null;
  96. /// <summary>
  97. /// 颗粒成份分布表
  98. /// </summary>
  99. public OTSIncAReportGrids.CompositionDistributionGrid im_CompositionDistributionGrid = null;
  100. /// <summary>
  101. /// 平均元素含量表
  102. /// </summary>
  103. public OTSIncAReportGrids.ElementCompositionAvgGrid im_ElementCompositionAvgGrid = null;
  104. /// <summary>
  105. /// 颗粒尺寸表
  106. /// </summary>
  107. public OTSIncAReportGrids.ParticlesSizeGrid im_ParticlesSizeGrid = null;
  108. /// <summary>
  109. /// 测量结果概况
  110. /// </summary>
  111. public OTSIncAReportGrids.ResultGrid im_ResultGrid = null;
  112. /// <summary>
  113. /// 颗粒成份图EChart
  114. /// </summary>
  115. public Control_ECharts.DEVChart_ParticlesComposition im_EChart_ParticlesComposition = null;
  116. /// <summary>
  117. /// 三元相图EChart
  118. /// </summary>
  119. public Control_ECharts.DEVChart_Trianglediagram im_EChart_Trianglediagram = null;
  120. /// <summary>
  121. /// 国标信息表方法一
  122. /// </summary>
  123. public OTSIncAReportGB.ChineseStandardABCDDS im_ChineseStandardABCDDS = null;
  124. /// <summary>
  125. /// 国标信息表方法二
  126. /// </summary>
  127. public OTSIncAReportGB.NationalStandardMethodTwo im_NationalStandardMethodTwo = null;
  128. /// <summary>
  129. /// 美标
  130. /// </summary>
  131. public OTSIncAReportGB.ASTMStandardABCDDS im_ASTMStandardABCDDS = null;
  132. /// <summary>
  133. /// 德标
  134. /// </summary>
  135. public OTSIncAReportGB.DINStandardABCDDS im_DINStandardABCDDS = null;
  136. /// <summary>
  137. /// yb/t 6156-2023
  138. /// </summary>
  139. public OTSIncAReportGB.YB6156ABCD im_YB6156ABCD = null;
  140. public List<Particle> GetSelectedParticles()
  141. {
  142. List<Particle> Particles = new List<Particle>();
  143. int tabIndex = (int)(m_conditionChoose.tabIndex);
  144. switch (tabIndex)
  145. {
  146. case (int)DisplayPicutureType.AnalyzeImg:
  147. foreach (var field in im_Control_DrawDistrbutionImageAndBSE.m_list_allDfield)
  148. {
  149. foreach (var dp in field.List_DParticle)
  150. {
  151. if (dp.IsSelect)
  152. {
  153. Particle particle = new Particle();
  154. particle.FieldId = ((OTSIncAReportGraph.DisplayParticle)dp).FieldId;
  155. particle.ParticleId = ((OTSIncAReportGraph.DisplayParticle)dp).ParticleId;
  156. Particles.Add(particle);
  157. }
  158. }
  159. }
  160. break;
  161. case (int)DisplayPicutureType.AnalyzeDataTable:
  162. Particles = im_ParticlesGridDevidePage.GetParticleslist_select();
  163. break;
  164. default:
  165. break;
  166. }
  167. return Particles;
  168. }
  169. #endregion //--------------------------------------------------------------------------------------------
  170. #region 拖拽提示面板相关字段
  171. private Panel dropHintPanel;
  172. private PictureBox dropIconBox;
  173. private Label dropHintLabel;
  174. private Label dropSubLabel;
  175. #endregion
  176. #region 窗体初始化及构造函数
  177. /// <summary>
  178. /// 窗体构造函数
  179. /// </summary>
  180. public frmReportApp()
  181. {
  182. m_OutputNlog = new OutputNlog();
  183. m_OutputNlog.Visible = true;
  184. log = NLog.LogManager.GetCurrentClassLogger();
  185. InitializeComponent();
  186. //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
  187. m_RibbonFun = new OTSRibbonFun(this);
  188. //和DataMgr进行数据交互类
  189. m_rstDataMgr = new ResultDataMgr();
  190. //配置文件管理窗体
  191. m_ReportSysConfigForm = new frmReportSysConfig(this);
  192. //属性窗口
  193. m_conditionChoose = new frmReportConditionChoose(this);
  194. //树窗口
  195. m_RstWindow = new frmMeasureRstMgr(this);
  196. //分布图,排列图窗体
  197. m_SImageWindow = new frmSampleImage(this);
  198. //grid表格窗体
  199. m_TablesWindowandChart = new frmTables(this);
  200. m_ParticlesListWindow=new frmTables(this);
  201. m_OverviewWindow = new frmTables(this);
  202. //标准库窗体
  203. m_StandardLibrary = new FormStandardLibraryInformation (this);
  204. m_StandardLibrary = new FormStandardLibraryInformation(this);
  205. m_StandardLibrary.Visible = true;
  206. SetTag();
  207. #region 国际化语言
  208. Language lan = new Language(this);
  209. table = lan.GetNameTable(this.Name);
  210. #endregion
  211. // 初始化拖拽功能
  212. InitializeDragDropFeatures();
  213. }
  214. /// <summary>
  215. /// 为生成后没有Name的控件添加标签,为了国际化语言设置时可以找到这个控件
  216. /// </summary>
  217. protected void SetTag()
  218. {
  219. ribbonPanel3.Tag = "ribbonPanel3";
  220. ribbonPanel2.Tag = "ribbonPanel2";
  221. rbSelTool.Tag = "rbSelTool";
  222. rbChoiceTools.Tag = "rbChoiceTools";
  223. ribbonPanelOthers.Tag = "ribbonPanelOthers";
  224. ribbonTab1.Tag = "ribbonTab1";
  225. rbMenu.Tag = "rbMenu";
  226. dpbOpen.Tag = "dpbOpen";
  227. ribbonOrbMenuItem_Extremum.Tag = "ribbonOrbMenuItem_Extremum";
  228. dpbExport.Tag = "dpbExport";
  229. dpbTemplateEditing.Tag = "dpbTemplateEditing";
  230. ribbonOrbOptionButton1.Tag = "ribbonOrbOptionButton1";
  231. ribbonOrbMenuItem_InclusionsTraceability.Tag = "ribbonOrbMenuItem_InclusionsTraceability";
  232. ribbonOrbMenuItem_purity.Tag = "ribbonOrbMenuItem_purity";
  233. rbClose.Tag = "rbClose";
  234. rbChoiceParticle.Tag = "rbChoiceParticle";
  235. //dpbTemplateEditing.Tag = "dpbTemplateEditing";
  236. }
  237. /// <summary>
  238. /// 窗体构造函数,可接收多个测量结果文件
  239. /// </summary>
  240. public frmReportApp(string[] str_resultfilepaths)
  241. {
  242. m_OutputNlog = new OutputNlog();
  243. m_OutputNlog.Visible = true;
  244. Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath);
  245. log = NLog.LogManager.GetCurrentClassLogger();
  246. m_str_resultfilepaths = str_resultfilepaths;
  247. InitializeComponent();
  248. //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
  249. m_RibbonFun = new OTSRibbonFun(this);
  250. //和DataMgr进行数据交互类
  251. m_rstDataMgr = new ResultDataMgr();//必须放在new frmReportSysConfig(this)前
  252. //配置文件管理窗体
  253. m_ReportSysConfigForm = new frmReportSysConfig(this);
  254. //属性窗口
  255. m_conditionChoose = new frmReportConditionChoose(this);
  256. //树窗口
  257. m_RstWindow = new frmMeasureRstMgr(this);
  258. //分布图,排列图窗体
  259. m_SImageWindow = new frmSampleImage(this);
  260. //grid表格窗体
  261. m_TablesWindowandChart = new frmTables(this);
  262. m_ParticlesListWindow=new frmTables(this);
  263. m_OverviewWindow =new frmTables(this);
  264. //标准库窗体
  265. m_StandardLibrary = new FormStandardLibraryInformation(this);
  266. m_StandardLibrary = new FormStandardLibraryInformation(this);
  267. m_StandardLibrary.Visible = true;
  268. SetTag();
  269. #region 国际化语言
  270. Language lan = new Language(this);
  271. table = lan.GetNameTable(this.Name);
  272. #endregion
  273. // 初始化拖拽功能
  274. InitializeDragDropFeatures();
  275. }
  276. /// <summary>
  277. /// 报告主窗体加载事件
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void OTSReportApp_Load(object sender, EventArgs e)
  282. {
  283. log = NLog.LogManager.GetCurrentClassLogger();
  284. //------------- initialize the HMI of the main form.
  285. //if (Cef.IsInitialized == false)
  286. //{
  287. // var lib = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"CefSharp\libcef.dll");
  288. // var browser = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"CefSharp\CefSharp.BrowserSubprocess.exe");
  289. // var locales = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"CefSharp\locales\");
  290. // var res = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"CefSharp\");
  291. // var libraryLoader = new CefLibraryHandle(lib);
  292. // var isValid = !libraryLoader.IsInvalid;
  293. // if (isValid)
  294. // {
  295. // //InitializeCef();
  296. // var settings = new CefSettings
  297. // {
  298. // BrowserSubprocessPath = browser,
  299. // LocalesDirPath = locales,
  300. // ResourcesDirPath = res
  301. // };
  302. // settings.Locale = "zh-CN";
  303. // settings.CefCommandLineArgs.Add("disable-gpu", "1");
  304. // Cef.Initialize(settings);
  305. // }
  306. //}
  307. //加载配置文件
  308. m_rstDataMgr.m_RptConfigFile.LoadDataFromFile();
  309. //设置菜单按钮,都为true状态
  310. m_RibbonFun.SetAllRibbonButnStatu(false);
  311. //激活标准库窗体
  312. this.m_StandardLibrary.Activate();
  313. //创建,树窗口,属性grid窗口,分布图,grid,chart窗体等。
  314. CreateNewWorkspaceWindow();
  315. this.m_OverviewWindow.Activate();
  316. //----------------end the initialization
  317. if (m_str_resultfilepaths != null)
  318. {
  319. string path = m_str_resultfilepaths[0].Replace("^", " ");
  320. if (Path.GetExtension(path) == ".rst")
  321. {
  322. //构造函数直接接收传入的测量结果文件,并加载
  323. for (int i = 0; i < m_str_resultfilepaths.Length; i++)
  324. {
  325. this.m_RstWindow.AddSampleResult(m_str_resultfilepaths[i].Replace("^", " "));
  326. }
  327. }
  328. else if (Path.GetExtension(path) == ".prj")
  329. {
  330. this.Cursor = Cursors.WaitCursor;
  331. string strFilePath = System.IO.Path.GetDirectoryName(path);
  332. System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(strFilePath);
  333. foreach (System.IO.DirectoryInfo directory in folder.GetDirectories())
  334. {
  335. foreach (System.IO.FileInfo file in directory.GetFiles("*.rst"))
  336. {
  337. this.m_RstWindow.AddSampleResult(file.FullName);
  338. this.m_StandardLibrary.DataRefresh();
  339. }
  340. }
  341. this.Cursor = Cursors.Default;
  342. }
  343. }
  344. if (Language.ReadDefaultLanguage() == "EN")
  345. {
  346. rbHelp.Enabled = false;
  347. }
  348. else
  349. {
  350. rbHelp.Enabled = true;
  351. }
  352. m_RptConfigFile =RptConfigFile.GetRptConfig(); //报表程序的配置文件
  353. this.Text = "ReportApp(" + m_rstDataMgr.m_RptConfigFile.Systype.ToString() + ")";
  354. }
  355. #endregion
  356. #region Ribbon菜单按钮及菜单相关按按钮事件
  357. /// <summary>
  358. /// 新建按钮事件
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void ribTitleNewFile_Click(object sender, EventArgs e)
  363. {
  364. InitReportProState();
  365. }
  366. /// <summary>
  367. /// 初始伦报告加载
  368. /// </summary>
  369. public void InitReportProState()
  370. {
  371. //清除树窗体
  372. m_RstWindow.treeView1.Nodes.Clear();
  373. //清除属性Grid
  374. m_conditionChoose.m_sourceGrid = new OTSSourceGrid(m_conditionChoose);
  375. m_rstDataMgr.ResultFilesList.Clear();
  376. //清除各模块报表文件
  377. //m_ChartsWindow.Controls.Clear();
  378. m_TablesWindowandChart.Controls.Clear();
  379. m_ParticlesListWindow.Controls.Clear();
  380. m_OverviewWindow.Controls.Clear();
  381. m_SImageWindow.Controls.Clear();
  382. //再重新初始化下拉菜单和ribbon菜单中的按钮状态
  383. m_RibbonFun.SetAllRibbonButnStatu(false);
  384. im_Control_DrawDistrbutionImageAndBSE = null;
  385. im_Control_DrawDistrbutionSortImage = null;
  386. im_ParticlesGridDevidePage = null;
  387. im_CompositionDistributionGrid = null;
  388. im_ElementCompositionAvgGrid = null;
  389. im_ParticlesSizeGrid = null;
  390. im_ResultGrid = null;
  391. }
  392. /// <summary>
  393. /// 程序管理按钮点击事件
  394. /// </summary>
  395. /// <param name="sender"></param>
  396. /// <param name="e"></param>
  397. private void RibbonOrbOptionButton1_Click(object sender, EventArgs e)
  398. {
  399. //程序管理
  400. m_ReportSysConfigForm.ShowDialog();
  401. }
  402. /// <summary>
  403. /// 打开报告项目文件按钮事件
  404. /// </summary>
  405. /// <param name="sender"></param>
  406. /// <param name="e"></param>
  407. private void rbOpen_Click(object sender, EventArgs e)
  408. {
  409. string path = "";
  410. OpenFileDialog fileDialog = new OpenFileDialog();
  411. fileDialog.Filter = "text File|*.rst";
  412. fileDialog.RestoreDirectory = true;
  413. if (fileDialog.ShowDialog() == DialogResult.OK)
  414. {
  415. path = System.IO.Path.GetFullPath(fileDialog.FileName);
  416. log.Info("begin to load the result!");
  417. Cursor = Cursors.WaitCursor;
  418. this.m_RstWindow.AddSampleResult(path);
  419. Cursor = Cursors.Default;
  420. this.m_StandardLibrary.DataRefresh();
  421. }
  422. }
  423. /// <summary>
  424. /// 全图匹配按钮事件
  425. /// </summary>
  426. /// <param name="sender"></param>
  427. /// <param name="e"></param>
  428. private void rbAllImage_Click(object sender, EventArgs e)
  429. {
  430. int tabIndex = (int)(m_conditionChoose.tabIndex);
  431. switch (tabIndex)
  432. {
  433. case (int)DisplayPicutureType.AnalyzeImg:
  434. int imgDisType=m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  435. if (imgDisType == 0)
  436. {
  437. if (im_Control_DrawDistrbutionImageAndBSE != null)
  438. {
  439. //分布图
  440. im_Control_DrawDistrbutionImageAndBSE.FullGraphMatch();
  441. im_Control_DrawDistrbutionImageAndBSE.Invalidate();
  442. }
  443. }
  444. else
  445. {
  446. if (im_Control_DrawDistrbutionSortImage != null)
  447. {
  448. //排列图
  449. im_Control_DrawDistrbutionSortImage.FullGraphMatch();
  450. im_Control_DrawDistrbutionSortImage.Invalidate();
  451. }
  452. }
  453. break;
  454. case (int)DisplayPicutureType.AnalyzeDataTable:
  455. break;
  456. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  457. break;
  458. default:
  459. break;
  460. }
  461. }
  462. /// <summary>
  463. /// 帧图边框按钮事件
  464. /// </summary>
  465. /// <param name="sender"></param>
  466. /// <param name="e"></param>
  467. private void rbFrame_Click(object sender, EventArgs e)
  468. {
  469. int tabIndex = (int)(m_conditionChoose.tabIndex);
  470. switch (tabIndex)
  471. {
  472. case (int)DisplayPicutureType.AnalyzeImg:
  473. int imgDisType = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  474. if (imgDisType == 0)
  475. {
  476. if (im_Control_DrawDistrbutionImageAndBSE != null)
  477. {
  478. //分布图
  479. im_Control_DrawDistrbutionImageAndBSE.ShowGridLine();
  480. im_Control_DrawDistrbutionImageAndBSE.Invalidate();
  481. }
  482. }
  483. else
  484. {
  485. if (im_Control_DrawDistrbutionSortImage != null)
  486. {
  487. }
  488. }
  489. break;
  490. case (int)DisplayPicutureType.AnalyzeDataTable:
  491. break;
  492. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  493. break;
  494. default:
  495. break;
  496. }
  497. }
  498. /// <summary>
  499. /// 标尺按钮事件
  500. /// </summary>
  501. /// <param name="sender"></param>
  502. /// <param name="e"></param>
  503. private void rbStaff_Click(object sender, EventArgs e)
  504. {
  505. int tabIndex = (int)(m_conditionChoose.tabIndex);
  506. switch (tabIndex)
  507. {
  508. case (int)DisplayPicutureType.AnalyzeImg:
  509. int imgDisType = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  510. if (imgDisType == 0)
  511. {
  512. if (im_Control_DrawDistrbutionImageAndBSE != null)
  513. {
  514. //分布图
  515. im_Control_DrawDistrbutionImageAndBSE.ShowRulerControl();
  516. im_Control_DrawDistrbutionImageAndBSE.Invalidate();
  517. }
  518. }
  519. else
  520. {
  521. if (im_Control_DrawDistrbutionSortImage != null)
  522. {
  523. im_Control_DrawDistrbutionSortImage.ShowRulerControl();
  524. im_Control_DrawDistrbutionSortImage.Invalidate();
  525. }
  526. }
  527. break;
  528. case (int)DisplayPicutureType.AnalyzeDataTable:
  529. break;
  530. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  531. break;
  532. default:
  533. break;
  534. }
  535. }
  536. /// <summary>
  537. /// 恢复按钮事件
  538. /// </summary>
  539. /// <param name="sender"></param>
  540. /// <param name="e"></param>
  541. private void rbRenew_Click(object sender, EventArgs e)
  542. {
  543. rbRenewFun(false, 0, 0);
  544. }
  545. public void rbRenewFun(bool isReview, int FieldId, int ParticleId)
  546. {
  547. int tabIndex = (int)m_conditionChoose.tabIndex;
  548. int DisType = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  549. switch (tabIndex)
  550. {
  551. case (int)DisplayPicutureType.AnalyzeImg:
  552. if (DisType == (int)IMAGE_DISPLAY_TYPE.DISTRIBUTION)
  553. {
  554. if (im_Control_DrawDistrbutionImageAndBSE != null)
  555. {
  556. //分布图
  557. im_Control_DrawDistrbutionImageAndBSE.ShowRulerControl(false);
  558. im_Control_DrawDistrbutionImageAndBSE.ShowGridLine(false);
  559. im_Control_DrawDistrbutionImageAndBSE.Invalidate();
  560. m_SImageWindow.Controls.Clear();
  561. im_Control_DrawDistrbutionImageAndBSE = new OTSIncAReportGraph.Controls.Control_DrawDistrbutionImageAndBSE(this);
  562. im_Control_DrawDistrbutionImageAndBSE.isReView = isReview;
  563. im_Control_DrawDistrbutionImageAndBSE.reViewFieldId = FieldId;
  564. im_Control_DrawDistrbutionImageAndBSE.reViewParticleId = ParticleId;
  565. im_Control_DrawDistrbutionImageAndBSE.Dock = DockStyle.Fill;
  566. m_SImageWindow.Controls.Add(im_Control_DrawDistrbutionImageAndBSE);
  567. m_SImageWindow.Activate();
  568. im_Control_DrawDistrbutionImageAndBSE.ShowSourceName = "";
  569. im_Control_DrawDistrbutionImageAndBSE.DrawDistrbutionImageAndBSE_ByQuery(m_conditionChoose.m_conditionData);
  570. im_Control_DrawDistrbutionImageAndBSE.SetSelectParticle(GetSelectedParticles());
  571. ConditionItem imgType = m_conditionChoose.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.IMAGE_TYPE];
  572. //切换分布图显示方式
  573. DISTRIBUTION_IMAGE_SHOW_MODE t = (DISTRIBUTION_IMAGE_SHOW_MODE)imgType.itemVal;
  574. im_Control_DrawDistrbutionImageAndBSE.SetShowMode(t);
  575. //并删除排列图
  576. im_Control_DrawDistrbutionSortImage = null;
  577. }
  578. }
  579. if (DisType == (int)IMAGE_DISPLAY_TYPE.IMAGE_GRID)
  580. {
  581. if (im_Control_DrawDistrbutionSortImage != null)
  582. {
  583. //排序图
  584. im_Control_DrawDistrbutionSortImage.ShowRulerControl(false);
  585. im_Control_DrawDistrbutionSortImage.Invalidate();
  586. m_SImageWindow.Controls.Clear();
  587. im_Control_DrawDistrbutionSortImage = new OTSIncAReportGraph.Controls.Control_DrawDistrbutionSortImage(this);
  588. im_Control_DrawDistrbutionSortImage.Dock = DockStyle.Fill;
  589. m_SImageWindow.Controls.Add(im_Control_DrawDistrbutionSortImage);
  590. m_SImageWindow.Activate();
  591. im_Control_DrawDistrbutionSortImage.ShowSourceName = "";
  592. im_Control_DrawDistrbutionSortImage.GetDistrbutionSortimage_ByQuery(m_conditionChoose.m_CurrentConditions);
  593. im_Control_DrawDistrbutionSortImage.SetSelectParticle(GetSelectedParticles());
  594. }
  595. }
  596. break;
  597. case (int)DisplayPicutureType.AnalyzeDataTable:
  598. break;
  599. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  600. break;
  601. default:
  602. break;
  603. }
  604. }
  605. /// <summary>
  606. /// 反选操作按钮事件
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. private void rbReverseSelection_Click(object sender, EventArgs e)
  611. {
  612. int tabIndex = (int)(m_conditionChoose.tabIndex);
  613. switch (tabIndex)
  614. {
  615. case (int)DisplayPicutureType.AnalyzeImg:
  616. int imgDisType = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  617. if (imgDisType == 0)
  618. {
  619. if (im_Control_DrawDistrbutionImageAndBSE != null)
  620. {
  621. //分布图
  622. im_Control_DrawDistrbutionImageAndBSE.ReverseSelection();
  623. }
  624. }
  625. else
  626. {
  627. if (im_Control_DrawDistrbutionSortImage != null)
  628. {
  629. im_Control_DrawDistrbutionSortImage.ReverSeSelection();
  630. }
  631. }
  632. break;
  633. case (int)DisplayPicutureType.AnalyzeDataTable:
  634. break;
  635. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  636. break;
  637. default:
  638. break;
  639. }
  640. }
  641. /// <summary>
  642. /// 圆形工具按钮事件
  643. /// </summary>
  644. /// <param name="sender"></param>
  645. /// <param name="e"></param>
  646. private void rbCircular_Click(object sender, EventArgs e)
  647. {
  648. int tabIndex = (int)(m_conditionChoose.tabIndex);
  649. switch (tabIndex)
  650. {
  651. case (int)DisplayPicutureType.AnalyzeImg:
  652. IMAGE_DISPLAY_TYPE imgDisType = (IMAGE_DISPLAY_TYPE)m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  653. if (imgDisType == IMAGE_DISPLAY_TYPE.DISTRIBUTION)
  654. {
  655. if (im_Control_DrawDistrbutionImageAndBSE != null)
  656. {
  657. //分布图
  658. im_Control_DrawDistrbutionImageAndBSE.MultiSelect_Ellipse();
  659. }
  660. }
  661. else
  662. {
  663. if (im_Control_DrawDistrbutionSortImage != null)
  664. {
  665. im_Control_DrawDistrbutionSortImage.MultiSelect_Ellipse();
  666. }
  667. }
  668. break;
  669. case (int)DisplayPicutureType.AnalyzeDataTable:
  670. break;
  671. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  672. break;
  673. default:
  674. break;
  675. }
  676. }
  677. /// <summary>
  678. /// 矩形工具按钮事件
  679. /// </summary>
  680. /// <param name="sender"></param>
  681. /// <param name="e"></param>
  682. private void rbRectangle_Click(object sender, EventArgs e)
  683. {
  684. int tabIndex = (int)(m_conditionChoose.tabIndex);
  685. switch (tabIndex)
  686. {
  687. case (int)DisplayPicutureType.AnalyzeImg:
  688. int imgDisType = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  689. if (imgDisType == 0)
  690. {
  691. if (im_Control_DrawDistrbutionImageAndBSE != null)
  692. {
  693. //分布图
  694. im_Control_DrawDistrbutionImageAndBSE.MultiSelect_Rectangle();
  695. }
  696. }
  697. else
  698. {
  699. if (im_Control_DrawDistrbutionSortImage != null)
  700. {
  701. im_Control_DrawDistrbutionSortImage.MultiSelect_Rectangle();
  702. }
  703. }
  704. break;
  705. case (int)DisplayPicutureType.AnalyzeDataTable:
  706. break;
  707. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  708. break;
  709. default:
  710. break;
  711. }
  712. }
  713. /// <summary>
  714. /// 取消多边形选择工具按钮事件
  715. /// </summary>
  716. /// <param name="sender"></param>
  717. /// <param name="e"></param>
  718. private void rbCancel_Click(object sender, EventArgs e)
  719. {
  720. int tabIndex = (int)(m_conditionChoose.tabIndex);
  721. switch (tabIndex)
  722. {
  723. case (int)DisplayPicutureType.AnalyzeImg:
  724. int imgDisType = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.IMAGE_DISPLAY_TYPE);
  725. if (imgDisType == 0)
  726. {
  727. if (im_Control_DrawDistrbutionImageAndBSE != null)
  728. {
  729. //分布图
  730. im_Control_DrawDistrbutionImageAndBSE.DeselectAllParticle();
  731. }
  732. }
  733. else
  734. {
  735. if (im_Control_DrawDistrbutionSortImage != null)
  736. {
  737. im_Control_DrawDistrbutionSortImage.DeselectAllParticle();
  738. }
  739. }
  740. break;
  741. case (int)DisplayPicutureType.AnalyzeDataTable:
  742. break;
  743. case (int)DisplayPicutureType.AnalyzeSheetandChart:
  744. break;
  745. default:
  746. break;
  747. }
  748. }
  749. static OTSImageDisHelp ReportFun;
  750. public RptConfigFile RptConfigFile { get => m_RptConfigFile; set => m_RptConfigFile = value; }
  751. /// <summary>
  752. /// 二次采集按钮
  753. /// </summary>
  754. /// <param name="sender"></param>
  755. /// <param name="e"></param>
  756. private void rbReMeasure_Click(object sender, EventArgs e)
  757. {
  758. if (ReportFun == null)
  759. {
  760. //resultFile = m_rstDataMgr.CurResultFile;
  761. ReportFun = new OTSImageDisHelp(m_rstDataMgr.CurResultFile);
  762. }
  763. //二次测量参数页面
  764. frmReMeasure frmReMeasure = new frmReMeasure(ReportFun, this);
  765. frmReMeasure.ShowDialog();
  766. }
  767. #endregion
  768. #region 自定义封装相关方法
  769. /// <summary>
  770. /// 新建一个工作区域
  771. /// </summary>
  772. public void CreateNewWorkspaceWindow()
  773. {
  774. //创建测量数据窗口
  775. CreateCOverviewWindow();
  776. //创建测量数据窗口
  777. CreateCTablesWindow();
  778. //创建图表窗口
  779. CreateCSheetandChartWindow();
  780. //Show BSE图窗口
  781. CreateSampleWindow();
  782. //StandardLibraryWindow();
  783. m_OutputNlog.Show(DockWindowPanel, OTS.WinFormsUI.Docking.DockState.DockRight);
  784. m_OutputNlog.Visible = true;
  785. m_StandardLibrary.Show(DockWindowPanel, DockState.DockLeft);
  786. m_RstWindow.Show(DockWindowPanel, OTS.WinFormsUI.Docking.DockState.DockLeft);
  787. m_conditionChoose.Show(DockWindowPanel);
  788. DockWindowPanel.DockLeftPortion = 300;
  789. DockWindowPanel.DockRightPortion = 351;
  790. }
  791. /// <summary>
  792. /// 创建新的窗体
  793. /// </summary>
  794. /// <param name="WorkWindow"></param>
  795. /// <param name="iType"></param>
  796. /// <returns></returns>
  797. private OTS.WinFormsUI.Docking.DockContent CreateNewDocument(OTS.WinFormsUI.Docking.DockContent WorkWindow, DisplayPicutureType iType)
  798. {
  799. string text = "";
  800. if (iType == DisplayPicutureType.AnalyzeImg)
  801. {
  802. text = table["analysisdiagram"].ToString(); ;
  803. }
  804. else if (iType == DisplayPicutureType.AnalyzeDataTable)
  805. {
  806. text = table["analysisdatasheet"].ToString();
  807. }
  808. else if (iType == DisplayPicutureType.AnalyzeSheetandChart)
  809. {
  810. text = table["analysisdatasheetandchart"].ToString();
  811. }
  812. else if (iType == DisplayPicutureType.OverviewTable)
  813. {
  814. text = table["overviewtable"].ToString();
  815. }
  816. else
  817. {
  818. text = "标准库信息";
  819. }
  820. WorkWindow.Text = text;
  821. return WorkWindow;
  822. }
  823. /// <summary>
  824. /// 创建样品BSE图窗口
  825. /// </summary>
  826. public void CreateSampleWindow()
  827. {
  828. if (null == m_SImageWindow)
  829. {
  830. m_SImageWindow = new frmSampleImage(this);
  831. }
  832. m_SImageWindow = (frmSampleImage)CreateNewDocument(m_SImageWindow, DisplayPicutureType.AnalyzeImg);
  833. if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  834. {
  835. m_SImageWindow.MdiParent = this;
  836. m_SImageWindow.Show();
  837. }
  838. else
  839. {
  840. m_SImageWindow.Show(DockWindowPanel);
  841. }
  842. }
  843. private void StandardLibraryWindow()
  844. {
  845. if (null == m_StandardLibrary)
  846. {
  847. m_StandardLibrary = new FormStandardLibraryInformation(this);
  848. }
  849. m_StandardLibrary = (FormStandardLibraryInformation)CreateNewDocument(m_StandardLibrary, DisplayPicutureType.AnalyzeStandardLibrary);
  850. if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  851. {
  852. m_StandardLibrary.MdiParent = this;
  853. m_StandardLibrary.Show();
  854. }
  855. else
  856. {
  857. m_StandardLibrary.Show(DockWindowPanel);
  858. }
  859. //m_StandardLibrary.Text = "标准库数据";
  860. //if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  861. //{
  862. // m_StandardLibrary.MdiParent = this;
  863. // m_StandardLibrary.Show();
  864. //}
  865. //else
  866. //{
  867. // m_StandardLibrary.Show(DockWindowPanel);
  868. //}
  869. }
  870. /// <summary>
  871. /// 创建Grid表格窗体
  872. /// </summary>
  873. private void CreateCSheetandChartWindow()
  874. {
  875. if (null == m_TablesWindowandChart)
  876. {
  877. m_TablesWindowandChart = new frmTables(this);
  878. }
  879. m_TablesWindowandChart = (frmTables)CreateNewDocument(m_TablesWindowandChart, DisplayPicutureType.AnalyzeSheetandChart);
  880. if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  881. {
  882. m_TablesWindowandChart.MdiParent = this;
  883. m_TablesWindowandChart.Show();
  884. }
  885. else
  886. {
  887. m_TablesWindowandChart.Show(DockWindowPanel);
  888. }
  889. }
  890. /// <summary>
  891. /// 创建Grid表格窗体
  892. /// </summary>
  893. private void CreateCTablesWindow()
  894. {
  895. if (null == m_ParticlesListWindow)
  896. {
  897. m_ParticlesListWindow = new frmTables(this);
  898. }
  899. m_ParticlesListWindow = (frmTables)CreateNewDocument(m_ParticlesListWindow, DisplayPicutureType.AnalyzeDataTable);
  900. if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  901. {
  902. m_ParticlesListWindow.MdiParent = this;
  903. m_ParticlesListWindow.Show();
  904. }
  905. else
  906. {
  907. m_ParticlesListWindow.Show(DockWindowPanel);
  908. }
  909. }
  910. ///// <summary>
  911. ///// 创建chart图表窗体
  912. ///// </summary>
  913. //private void CreateChartsWindow()
  914. //{
  915. // if (null == m_ChartsWindow)
  916. // {
  917. // m_ChartsWindow = new frmCharts(this);
  918. // }
  919. // m_ChartsWindow = (frmCharts)CreateNewDocument(m_ChartsWindow, DisplayPicutureType.AnalyzeSheetandChart);
  920. // if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  921. // {
  922. // m_ChartsWindow.MdiParent = this;
  923. // m_ChartsWindow.Show();
  924. // }
  925. // else
  926. // {
  927. // m_ChartsWindow.Show(DockWindowPanel);
  928. // }
  929. //}
  930. /// <summary>
  931. /// 创建结果概况窗体
  932. /// </summary>
  933. private void CreateCOverviewWindow()
  934. {
  935. if (null == m_OverviewWindow)
  936. {
  937. m_OverviewWindow = new frmTables(this);
  938. }
  939. m_OverviewWindow = (frmTables)CreateNewDocument(m_OverviewWindow, DisplayPicutureType.OverviewTable);
  940. if (DockWindowPanel.DocumentStyle == DocumentStyle.SystemMdi)
  941. {
  942. m_OverviewWindow.MdiParent = this;
  943. m_OverviewWindow.Show();
  944. }
  945. else
  946. {
  947. m_OverviewWindow.Show(DockWindowPanel);
  948. }
  949. }
  950. /// <summary>
  951. /// 新建样品时提示保存样品信息Messagebox
  952. /// </summary>
  953. /// <returns></returns>
  954. public int ShowSaveInfoMsgBox()
  955. {
  956. //是否保存修改信息,保存样品信息提示
  957. int iRev = (int)MessageBox.Show("Save modification information", "Tips", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  958. if (iRev == (int)DialogResult.Yes)
  959. {
  960. return (int)MessageBoxRev.DIALOG_YES;
  961. }
  962. else if (iRev == (int)DialogResult.No)
  963. {
  964. return (int)MessageBoxRev.DIALOG_NO;
  965. }
  966. else
  967. {
  968. return (int)MessageBoxRev.DIALOG_CANCEL;
  969. }
  970. }
  971. #endregion
  972. #region 系统菜单相关功能
  973. private void ribbonOrbMenuItem4_Click(object sender, EventArgs e)
  974. {
  975. MemoryManagementClass.FlushMemory();
  976. //系统菜单,输出
  977. OTSReport_Export oe = new OTSReport_Export(this,true);
  978. oe.ShowDialog();
  979. oe.Dispose();
  980. oe = null;
  981. MemoryManagementClass.FlushMemory();
  982. }
  983. private void frmReportApp_FormClosed(object sender, FormClosedEventArgs e)
  984. {
  985. //string strDBpathGB =m_DataMgrFun. resultFilesList[0].FilePath + "\\" + "ReportGBDB.db";
  986. //File.Delete(strDBpathGB);
  987. //Process.GetCurrentProcess().Kill();
  988. //this.Hide();//打开EChar图后,回收浏览器资源暂卡,为达到操作流畅性,先隐藏窗体再回收资源
  989. //this.Invoke(new Action(() =>
  990. //{
  991. // if (Cef.IsInitialized)
  992. // Cef.Shutdown();
  993. //}));
  994. }
  995. #endregion
  996. private void dpbOpen_Click(object sender, EventArgs e)
  997. {
  998. OpenProFile();
  999. }
  1000. /// <summary>
  1001. /// 打开报告项目工程文件,封装方法
  1002. /// </summary>
  1003. /// <returns></returns>
  1004. private bool OpenProFile()
  1005. {
  1006. OpenFileDialog openFileDialog = new OpenFileDialog();
  1007. openFileDialog.Filter = "Measure Project Files((*.prj)|*.prj";
  1008. openFileDialog.ValidateNames = true;
  1009. openFileDialog.CheckPathExists = true;
  1010. openFileDialog.CheckFileExists = true;
  1011. openFileDialog.Multiselect = false;
  1012. CHistoryPrj historyPrj = new CHistoryPrj();
  1013. historyPrj.loadHistoryPath();
  1014. string strLatestPrjFolder = historyPrj.GetLatestPrjFolder();
  1015. openFileDialog.InitialDirectory = strLatestPrjFolder;
  1016. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1017. {
  1018. this.Cursor = Cursors.WaitCursor;
  1019. string strFilePath = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
  1020. System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(strFilePath);
  1021. foreach (System.IO.DirectoryInfo directory in folder.GetDirectories())
  1022. {
  1023. foreach (System.IO.FileInfo file in directory.GetFiles("*.rst"))
  1024. {
  1025. this.m_RstWindow.AddSampleResult(file.FullName);
  1026. this.m_StandardLibrary.DataRefresh();
  1027. }
  1028. }
  1029. this.Cursor = Cursors.Default;
  1030. return true;
  1031. }
  1032. else return false;
  1033. }
  1034. private void frmReportApp_FormClosing(object sender, FormClosingEventArgs e)
  1035. {
  1036. }
  1037. private void ribbonOrbMenuItem_Extremum_Click(object sender, EventArgs e)
  1038. {
  1039. try
  1040. {
  1041. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSExtremum.exe");
  1042. p.WaitForExit();
  1043. }
  1044. catch (Exception ex)
  1045. {
  1046. log.Error("OTSExtremum:" + ex.ToString());
  1047. }
  1048. }
  1049. protected override void DefWndProc(ref Message m)
  1050. {
  1051. switch (m.Msg)
  1052. {
  1053. case LogMsgID:
  1054. m_LogMsg = new PostLogMsg();
  1055. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1056. var log = NLog.LogManager.GetCurrentClassLogger();
  1057. string s = GetString(m_LogMsg.logMessage);
  1058. switch (m_LogMsg.logLevel)
  1059. {
  1060. case 1:
  1061. log.Trace(s);
  1062. break;
  1063. case 2:
  1064. log.Debug(s);
  1065. break;
  1066. case 3:
  1067. log.Info(s);
  1068. break;
  1069. case 4:
  1070. log.Warn(s);
  1071. break;
  1072. case 5:
  1073. log.Error(s);
  1074. break;
  1075. case 6:
  1076. log.Fatal(s);
  1077. break;
  1078. }
  1079. break;
  1080. default:
  1081. base.DefWndProc(ref m);
  1082. break;
  1083. }
  1084. }
  1085. private string GetString(char[] csStr)
  1086. {
  1087. int ilen = csStr.Length;
  1088. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1089. csName.IndexOf('\0');
  1090. csName = csName.Substring(0, csName.IndexOf('\0'));
  1091. return csName;
  1092. }
  1093. private void Backup_Click(object sender, EventArgs e)
  1094. {
  1095. //OTSImageDisHelp m_ReportFun = null;
  1096. //public OTSImageDisHelp ReportFun { get => m_ReportFun; set => m_ReportFun = value; }
  1097. //var ReportFun = new OTSImageDisHelp(m_rstDataMgr.CurResultFile);
  1098. if (BackupDatabase())
  1099. {
  1100. MessageBox.Show("Backup succeeded");
  1101. }
  1102. else
  1103. {
  1104. MessageBox.Show("Backup failed");
  1105. }
  1106. }
  1107. private bool BackupDatabase()
  1108. {
  1109. //创建备份数据库文件夹
  1110. string sourcePath = m_rstDataMgr.CurResultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  1111. string sourceName = "Inclusion.db";//源文件名称
  1112. string folderPath = m_rstDataMgr.CurResultFile.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  1113. string Fields = "";
  1114. for (int i = 1; i < 201; i++)
  1115. {
  1116. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  1117. {
  1118. Fields = folderPath + i.ToString();
  1119. continue;
  1120. }
  1121. else
  1122. {
  1123. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  1124. Fields = folderPath + i.ToString();
  1125. break;
  1126. }
  1127. }
  1128. if (Fields == "")
  1129. {
  1130. return false;
  1131. }
  1132. //复制数据库文件
  1133. string targetPath = Path.Combine(Fields, sourceName);
  1134. FileInfo file = new FileInfo(sourcePath);
  1135. if (file.Exists)
  1136. {
  1137. file.CopyTo(targetPath, true);
  1138. }
  1139. return true;
  1140. }
  1141. private void ribbonOrbMenuItem_InclusionsTraceability_Click(object sender, EventArgs e)
  1142. {
  1143. string sou = m_conditionChoose.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  1144. if(sou.Contains("+"))
  1145. {
  1146. MessageBox.Show("This function does not support multiple samples!");
  1147. return;
  1148. }
  1149. int index = m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  1150. try
  1151. {
  1152. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSInclusionsTraceability.exe", "\""+ m_rstDataMgr.ResultFilesList[index].FilePath+ "\"");
  1153. p.WaitForExit();
  1154. }
  1155. catch (Exception ex)
  1156. {
  1157. log.Error("InclusionsTraceability :" + ex.ToString());
  1158. }
  1159. }
  1160. private void rbClose_Click(object sender, EventArgs e)
  1161. {
  1162. m_RstWindow. RemoveSample();
  1163. //m_StandardLibrary.DataDeletion();
  1164. }
  1165. private void ribbonOrbMenuItem_purity_Click(object sender, EventArgs e)
  1166. {
  1167. string sou = m_conditionChoose.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  1168. if (sou.Contains("+"))
  1169. {
  1170. MessageBox.Show("This function does not support multiple samples!");
  1171. return;
  1172. }
  1173. try
  1174. {
  1175. _1_UI.GBCalculate.Purity purity = new _1_UI.GBCalculate.Purity(this);
  1176. purity.Show();
  1177. }
  1178. catch (Exception ex)
  1179. {
  1180. log.Error("purity:" + ex.ToString());
  1181. MessageBox.Show("purity启动失败!");
  1182. }
  1183. }
  1184. private void dpbTemplateEditing_Click(object sender, EventArgs e)
  1185. {
  1186. MemoryManagementClass.FlushMemory();
  1187. //系统菜单,输出
  1188. OTSReport_Export oe = new OTSReport_Export(this, false);
  1189. oe.ShowDialog();
  1190. oe.Dispose();
  1191. oe = null;
  1192. MemoryManagementClass.FlushMemory();
  1193. }
  1194. private void toolTip1_Popup(object sender, PopupEventArgs e)
  1195. {
  1196. }
  1197. private void DockWindowPanel_ActiveContentChanged(object sender, EventArgs e)
  1198. {
  1199. }
  1200. private void rbOpenprj_Click(object sender, EventArgs e)
  1201. {
  1202. OpenProFile();
  1203. }
  1204. private void frmReportApp_DragDrop(object sender, DragEventArgs e)
  1205. {
  1206. // 隐藏拖拽提示面板
  1207. HideDropHintPanel();
  1208. try
  1209. {
  1210. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  1211. {
  1212. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  1213. // 过滤出有效的文件
  1214. var validFiles = files.Where(f =>
  1215. Path.GetExtension(f)?.ToLower() == ".prj" ||
  1216. Path.GetExtension(f)?.ToLower() == ".rst").ToList();
  1217. if (!validFiles.Any())
  1218. {
  1219. MessageBox.Show("未找到有效的 .prj 或 .rst 文件", "提示",
  1220. MessageBoxButtons.OK, MessageBoxIcon.Information);
  1221. return;
  1222. }
  1223. this.Cursor = Cursors.WaitCursor;
  1224. try
  1225. {
  1226. ProcessDroppedFiles(validFiles);
  1227. }
  1228. finally
  1229. {
  1230. this.Cursor = Cursors.Default;
  1231. }
  1232. }
  1233. }
  1234. catch (Exception ex)
  1235. {
  1236. this.Cursor = Cursors.Default;
  1237. log.Error(ex, $"处理拖拽文件时发生错误: {ex.Message}");
  1238. MessageBox.Show($"处理文件时发生错误: {ex.Message}", "错误",
  1239. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1240. }
  1241. }
  1242. private void frmReportApp_DragEnter(object sender, DragEventArgs e)
  1243. {
  1244. try
  1245. {
  1246. // 检查拖放的数据是否包含文件
  1247. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  1248. {
  1249. // 获取拖放的文件
  1250. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  1251. // 检查是否有有效的.prj文件
  1252. bool hasValidFile = files.Any(f =>
  1253. !string.IsNullOrEmpty(Path.GetExtension(f)) &&
  1254. (Path.GetExtension(f).ToLower() == ".prj"|| Path.GetExtension(f).ToLower() == ".rst"));
  1255. if (hasValidFile)
  1256. {
  1257. // 显示拖拽提示面板
  1258. ShowDropHintPanel();
  1259. // 显示复制光标
  1260. e.Effect = DragDropEffects.Copy;
  1261. return;
  1262. }
  1263. }
  1264. }
  1265. catch (Exception ex)
  1266. {
  1267. log?.Warn($"DragEnter处理异常: {ex.Message}");
  1268. }
  1269. // 隐藏拖拽提示面板并设置无效文件类型
  1270. HideDropHintPanel();
  1271. e.Effect = DragDropEffects.None;
  1272. }
  1273. /// <summary>
  1274. /// 初始化拖拽提示面板
  1275. /// </summary>
  1276. private void InitializeDropHintPanel()
  1277. {
  1278. // 创建主面板
  1279. dropHintPanel = new Panel();
  1280. dropHintPanel.Name = "dropHintPanel";
  1281. dropHintPanel.BackColor = Color.FromArgb(200, Color.RoyalBlue);
  1282. dropHintPanel.Dock = DockStyle.Fill;
  1283. dropHintPanel.Visible = false;
  1284. dropHintPanel.BorderStyle = BorderStyle.None;
  1285. // 创建主提示文本
  1286. dropHintLabel = new Label();
  1287. dropHintLabel.Text = "拖拽 .prj 或 .rst文件到此处打开项目";
  1288. dropHintLabel.AutoSize = false;
  1289. dropHintLabel.TextAlign = ContentAlignment.MiddleCenter;
  1290. dropHintLabel.Font = new Font(this.Font.FontFamily, 18, FontStyle.Bold);
  1291. dropHintLabel.ForeColor = Color.White;
  1292. dropHintLabel.Dock = DockStyle.Fill;
  1293. dropHintLabel.BackColor = Color.Transparent;
  1294. // 创建辅助说明文本
  1295. dropSubLabel = new Label();
  1296. dropSubLabel.Text = "松开鼠标按键即可打开项目";
  1297. dropSubLabel.AutoSize = false;
  1298. dropSubLabel.TextAlign = ContentAlignment.MiddleCenter;
  1299. dropSubLabel.Font = new Font(this.Font.FontFamily, 12, FontStyle.Regular);
  1300. dropSubLabel.ForeColor = Color.LightGray;
  1301. dropSubLabel.Dock = DockStyle.Bottom;
  1302. dropSubLabel.Height = 30;
  1303. dropSubLabel.BackColor = Color.Transparent;
  1304. // 组装控件
  1305. dropHintPanel.Controls.Add(dropIconBox);
  1306. dropHintPanel.Controls.Add(dropHintLabel);
  1307. dropHintPanel.Controls.Add(dropSubLabel);
  1308. // 将面板添加到窗体中并置于顶层
  1309. this.Controls.Add(dropHintPanel);
  1310. dropHintPanel.BringToFront();
  1311. }
  1312. /// <summary>
  1313. /// 显示拖拽提示面板
  1314. /// </summary>
  1315. private void ShowDropHintPanel()
  1316. {
  1317. if (dropHintPanel == null) return;
  1318. dropHintPanel.Visible = true;
  1319. dropHintPanel.BringToFront();
  1320. }
  1321. /// <summary>
  1322. /// 隐藏拖拽提示面板
  1323. /// </summary>
  1324. private void HideDropHintPanel()
  1325. {
  1326. if (dropHintPanel == null) return;
  1327. dropHintPanel.Visible = false;
  1328. }
  1329. /// <summary>
  1330. /// 初始化拖拽功能
  1331. /// </summary>
  1332. private void InitializeDragDropFeatures()
  1333. {
  1334. this.AllowDrop = true;
  1335. InitializeDropHintPanel();
  1336. }
  1337. private void frmReportApp_DragOver(object sender, DragEventArgs e)
  1338. {
  1339. if (dropHintPanel != null && dropHintPanel.Visible)
  1340. {
  1341. e.Effect = DragDropEffects.Copy;
  1342. }
  1343. else
  1344. {
  1345. e.Effect = DragDropEffects.None;
  1346. }
  1347. }
  1348. private void frmReportApp_DragLeave(object sender, EventArgs e)
  1349. {
  1350. HideDropHintPanel();
  1351. }
  1352. private void ProcessDroppedFiles(List<string> files)
  1353. {
  1354. bool processed = false;
  1355. foreach (string filePath in files)
  1356. {
  1357. try
  1358. {
  1359. string extension = Path.GetExtension(filePath).ToLower();
  1360. if (extension == ".prj")
  1361. {
  1362. ProcessProjectFile(filePath);
  1363. processed = true;
  1364. break; // 只处理第一个项目文件
  1365. }
  1366. else if (extension == ".rst")
  1367. {
  1368. log.Info($"开始加载结果文件: {filePath}");
  1369. this.m_RstWindow.AddSampleResult(filePath);
  1370. this.m_StandardLibrary.DataRefresh();
  1371. processed = true;
  1372. }
  1373. }
  1374. catch (Exception ex)
  1375. {
  1376. log.Error(ex, $"处理文件 {filePath} 时发生错误: {ex.Message}");
  1377. MessageBox.Show($"处理文件 {filePath} 时发生错误: {ex.Message}", "错误",
  1378. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1379. }
  1380. }
  1381. if (!processed && files.Any())
  1382. {
  1383. MessageBox.Show("未能成功处理任何文件", "提示",
  1384. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1385. }
  1386. }
  1387. private void ProcessProjectFile(string projectFilePath)
  1388. {
  1389. try
  1390. {
  1391. string directoryPath = Path.GetDirectoryName(projectFilePath);
  1392. DirectoryInfo folder = new DirectoryInfo(directoryPath);
  1393. int loadedCount = 0;
  1394. foreach (System.IO.DirectoryInfo directory in folder.GetDirectories())
  1395. {
  1396. foreach (System.IO.FileInfo file in directory.GetFiles("*.rst"))
  1397. {
  1398. this.m_RstWindow.AddSampleResult(file.FullName);
  1399. loadedCount++;
  1400. }
  1401. }
  1402. if (loadedCount > 0)
  1403. {
  1404. this.m_StandardLibrary.DataRefresh();
  1405. log.Info($"从项目文件加载了 {loadedCount} 个结果文件");
  1406. }
  1407. else
  1408. {
  1409. log.Warn("项目文件夹中未找到 .rst 文件");
  1410. MessageBox.Show("项目文件夹中未找到 .rst 文件", "提示",
  1411. MessageBoxButtons.OK, MessageBoxIcon.Information);
  1412. }
  1413. }
  1414. catch (Exception ex)
  1415. {
  1416. throw new Exception($"处理项目文件时出错: {ex.Message}", ex);
  1417. }
  1418. }
  1419. }
  1420. }