AutomaticMeasurement.cs 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979
  1. using SmartCoalApplication.Core;
  2. using SmartCoalApplication.SystemLayer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using SmartCoalApplication.Base.AutoMeasure;
  13. using System.Xml;
  14. using OpenCvSharp;
  15. using SmartCoalApplication.Base.MeasureModel;
  16. using SmartCoalApplication.Base.CommTool;
  17. using System.IO;
  18. using Resources;
  19. using SmartCoalApplication.Annotation;
  20. using SmartCoalApplication.Base.SettingModel;
  21. using SmartCoalApplication.Core.DbOpreate.DbModel;
  22. using SmartCoalApplication.Resources;
  23. using SmartCoalApplication.AutomaticMeasurement.Model;
  24. using System.Text.RegularExpressions;
  25. namespace SmartCoalApplication.AutomaticMeasurement
  26. {
  27. internal partial class AutomaticMeasurement : Form
  28. {
  29. private MeasureInfoModel infoModel;//窗體共用,傳遞信息
  30. private int erjimuluCount = new int();//有检验项目的分类数目
  31. private List<Bitmap> bitmaps = new List<Bitmap>();//每次添加的图片
  32. private List<string> bitNames = new List<string>();//每次添加的图片的名称
  33. private List<string> filePathList = new List<string>();
  34. private Kongjian kongjians = new Kongjian();//自动显示的控件
  35. private int[] counts;//计数器,每行显示5张图
  36. public List<List<Bitmap>> pictures = new List<List<Bitmap>>();//所有的图片集合
  37. private List<List<string>> pictureNames = new List<List<string>>();//所有的图片名称集合
  38. private List<List<string>> picturePathNames = new List<List<string>>();//所有的图片名称集合
  39. private List<string> erjimulusName = new List<string>();//分类名称
  40. Dictionary<string, string> _listHoleType = new Dictionary<string, string>();
  41. Dictionary<string, bool> _listHoleTypePos = new Dictionary<string, bool>();
  42. private MeasureMaintenanceTypeList measureMaintenanceTypeList;
  43. private AppWorkspace appWorkspace;
  44. private Dictionary<string, List<Mat>> everyHoleImg = new Dictionary<string, List<Mat>>();
  45. private Dictionary<int, List<GraphicsList>> everyHoleImgGraphicsList = new Dictionary<int, List<GraphicsList>>();
  46. private Dictionary<int, List<bool>> everyHoleImgisConductive = new Dictionary<int, List<bool>>();
  47. private Dictionary<int, List<bool>> everyHoleImgisFanweibuchang = new Dictionary<int, List<bool>>();
  48. private Dictionary<int, List<bool>> everyHoleImgisErzhichuli = new Dictionary<int, List<bool>>();
  49. Dictionary<string, Dictionary<string ,double>> pidRuleDic = new Dictionary<string, Dictionary<string, double>>();
  50. /// <summary>
  51. /// 树状结构数据
  52. /// </summary>
  53. protected MeasureMaintenanceTreeData measureMaintenanceTreeData;
  54. /// <summary>
  55. /// 换算完的标尺信息,包含所有系统内得单位
  56. /// </summary>
  57. public Dictionary<int, double> rules = new Dictionary<int, double>();
  58. public AutomaticMeasurement(AppWorkspace appWorkspace)
  59. {
  60. var res = getResult("[[100-50] - [200 - 50 + (100 - 50 + (200 - 100) + [50])]] - 100");
  61. InitializeComponent();
  62. InitializeComponent2();
  63. this.Icon = PdnInfo.AppIcon;
  64. this.appWorkspace = appWorkspace;
  65. //初始化數據
  66. infoModel = new MeasureInfoModel();
  67. infoModel.stop = 0;
  68. CreatHoleType();
  69. #region [测试分类下拉选]
  70. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureMaintenanceTypeList.xml";
  71. if (!System.IO.File.Exists(filePath))
  72. {
  73. measureMaintenanceTypeList = new MeasureMaintenanceTypeList();
  74. measureMaintenanceTypeList.measureMaintenanceTypeList = new List<MeasureMaintenanceType>();
  75. }
  76. else
  77. {
  78. measureMaintenanceTypeList = XmlSerializeHelper.DESerializer<MeasureMaintenanceTypeList>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  79. }
  80. comboMingcheng.DataSource = measureMaintenanceTypeList.measureMaintenanceTypeList;
  81. this.comboMingcheng.SelectedIndexChanged -= new System.EventHandler(this.comboBox4_SelectedIndexChanged);
  82. comboMingcheng.DisplayMember = "measureMaintenanceName";
  83. this.comboMingcheng.SelectedIndexChanged += new System.EventHandler(this.comboBox4_SelectedIndexChanged);
  84. this.FormClosing += new FormClosingEventHandler(AutoFormClosed);
  85. #endregion
  86. #region [获取各项下拉选值]
  87. ReadXml2();
  88. #endregion
  89. this.comboBox4_SelectedIndexChanged(null, null);
  90. }
  91. /// <summary>
  92. /// 获取绝对值
  93. /// </summary>
  94. private double getResult(string formula)
  95. {
  96. formula = formula.Replace("[", "Math.abs(").Replace("]", ")");
  97. double res = Math.Abs(Convert.ToDouble(FormulaHelper.CaleByFormule(formula)));
  98. return res;
  99. }
  100. private void AutoFormClosed(object sender, FormClosingEventArgs e)
  101. {
  102. for (int i = 0; i < pictures.Count; i++)
  103. {
  104. for (int k = 0; k < pictures[i].Count; k++)
  105. {
  106. if (pictures[i][k] != null)
  107. {
  108. pictures[i][k].Dispose();
  109. }
  110. }
  111. }
  112. }
  113. /// <summary>
  114. ///
  115. /// </summary>
  116. private void InitializeComponent2()
  117. {
  118. this.Text = PdnResources.GetString("NewStartTestProcedure");
  119. this.groupBox2.Text = PdnResources.GetString("NewSelectTestProcedure");
  120. this.label1.Text = PdnResources.GetString("NewName");
  121. this.groupBox1.Text = PdnResources.GetString("NewOperation");
  122. this.buttonCancelMeasurement.Text = PdnResources.GetString("NewCancelMeasurement");
  123. this.buttonStartMeasuring.Text = PdnResources.GetString("NewStartMeasuring");
  124. this.label14.Text = PdnResources.GetString("NewDefaultRuler");
  125. this.label13.Text = PdnResources.GetString("NewRuler");
  126. this.groupBox3.Text = PdnResources.GetString("NewEssentialInformation");
  127. this.label11.Text = PdnResources.GetString("NewUnit") + ":";
  128. this.label10.Text = PdnResources.GetString("NewLayers") + ":";
  129. this.label7.Text = PdnResources.GetString("NewUseFactory") + ":";
  130. this.label6.Text = PdnResources.GetString("NewElectroplatingLine") + ":";
  131. this.label5.Text = PdnResources.GetString("NewMadeOf") + ":";
  132. this.label4.Text = PdnResources.GetString("NewBatchNumber") + ":";
  133. this.label3.Text = PdnResources.GetString("NewOrderNo") + ":";
  134. this.label2.Text = PdnResources.GetString("NewItemNo") + ":";
  135. this.label8.Text = PdnResources.GetString("NewLaboratory") + ":";
  136. this.label9.Text = PdnResources.GetString("NewFrequency") + ":";
  137. this.groupBox4.Text = PdnResources.GetString("NewcCassification");
  138. this.groupOutInfo.Text = PdnResources.GetString("NewOutputInformation");
  139. }
  140. /// <summary>
  141. /// 从硬盘选择多张图片
  142. /// </summary>
  143. private List<Bitmap> ChooseImagesFromImgDisk(List<string> imageNames, string id)
  144. {
  145. List<Bitmap> listBitmap = new List<Bitmap>();
  146. bitNames = new List<string>();
  147. filePathList = new List<string>();
  148. string pPath = null;
  149. foreach (string imgName in imageNames)
  150. {
  151. if (pPath == null)
  152. pPath = System.IO.Path.GetDirectoryName(imgName);
  153. string xmlPath = pPath + "\\" + Path.GetFileNameWithoutExtension(imgName) + ".xml";
  154. double ruleData = 1;
  155. ConfigModel configModel = Program.instance.configModel;
  156. //如果xml存在
  157. if (System.IO.File.Exists(xmlPath))
  158. {
  159. var configModel1 = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  160. ruleData = configModel1.rule.pixel_length == 0 ? 1 : Convert.ToDouble(configModel1.rule.physical_length / configModel1.rule.pixel_length);
  161. InitRulerInfo(configModel1.rule.ruler_units, ruleData);
  162. }
  163. else
  164. {
  165. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  166. if (measureMaintenanceTreeData != null)
  167. {
  168. MeasureMaintenanceTreeSpecificData data;
  169. this.appWorkspace.RecursionGetData(id, measureMaintenanceTreeData.MeasureMaintenanceTreeDataList, out data);
  170. if (data.ruleMessage != null)
  171. {
  172. ruleData = data.ruleMessage.pixelLength == 0 ? 1 : Convert.ToDouble(data.ruleMessage.physicalLength / Convert.ToDecimal(data.ruleMessage.pixelLength));
  173. InitRulerInfo(data.ruleMessage.rulerUnits, ruleData);
  174. }
  175. else
  176. {
  177. if (measureMaintenanceType.ruleMessage != null)
  178. {
  179. ruleData = measureMaintenanceType.ruleMessage.pixelLength == 0 ? 1 : Convert.ToDouble(measureMaintenanceType.ruleMessage.physicalLength / Convert.ToDecimal(measureMaintenanceType.ruleMessage.pixelLength));
  180. InitRulerInfo(measureMaintenanceType.ruleMessage.rulerUnits, ruleData);
  181. }
  182. else
  183. {
  184. List<mic_rulers> list = Program.instance.mic_rulersAll;
  185. var ruler = list.Where(m => m.id.Equals(configModel.RulerId)).FirstOrDefault();
  186. if (ruler != null)
  187. {
  188. ruleData = ruler.pixel_length == 0 ? 1 : Convert.ToDouble(ruler.physical_length / Convert.ToDecimal(ruler.pixel_length));
  189. InitRulerInfo(ruler.ruler_units, ruleData);
  190. }
  191. }
  192. }
  193. }
  194. else
  195. {
  196. if (measureMaintenanceType.ruleMessage != null)
  197. {
  198. ruleData = measureMaintenanceType.ruleMessage.pixelLength == 0 ? 1 : Convert.ToDouble(measureMaintenanceType.ruleMessage.physicalLength / Convert.ToDecimal(measureMaintenanceType.ruleMessage.pixelLength));
  199. InitRulerInfo(measureMaintenanceType.ruleMessage.rulerUnits, ruleData);
  200. }
  201. else
  202. {
  203. List<mic_rulers> list = Program.instance.mic_rulersAll;
  204. var ruler = list.Where(m => m.id.Equals(configModel.RulerId)).FirstOrDefault();
  205. if (ruler != null)
  206. {
  207. ruleData = ruler.pixel_length == 0 ? 1 : Convert.ToDouble(ruler.physical_length / Convert.ToDecimal(ruler.pixel_length));
  208. InitRulerInfo(ruler.ruler_units, ruleData);
  209. }
  210. }
  211. }
  212. }
  213. if (this.rules.ContainsKey(configModel.Unit))
  214. {
  215. this.rules.TryGetValue(configModel.Unit, out ruleData);
  216. }
  217. if (pidRuleDic.ContainsKey(id))
  218. {
  219. if (pidRuleDic[id].ContainsKey(Path.GetFileName(imgName)))
  220. {
  221. pidRuleDic[id][Path.GetFileName(imgName)] = ruleData;
  222. }
  223. else
  224. {
  225. pidRuleDic[id].Add(Path.GetFileName(imgName), ruleData);
  226. }
  227. }
  228. else
  229. {
  230. Dictionary<string, double> dataKeyValue = new Dictionary<string, double>();
  231. dataKeyValue.Add(Path.GetFileName(imgName), ruleData);
  232. pidRuleDic.Add(id, dataKeyValue);
  233. }
  234. Image image = Image.FromFile(imgName);
  235. listBitmap.Add(new Bitmap(image));
  236. bitNames.Add(System.IO.Path.GetFileName(imgName));
  237. filePathList.Add(System.IO.Path.GetDirectoryName(imgName));
  238. }
  239. return listBitmap;
  240. }
  241. /// <summary>
  242. /// 从硬盘选择多张图片
  243. /// </summary>
  244. private List<Bitmap> ChooseImagesFromHardDisk(string id)
  245. {
  246. var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
  247. openFileDialog.Multiselect = true;
  248. if (openFileDialog.ShowDialog() == DialogResult.OK)
  249. {
  250. string pPath = null;// System.IO.Path.GetDirectoryName(cmbInput.Text);
  251. string[] imageNames = openFileDialog.FileNames;
  252. List<Bitmap> listBitmap = new List<Bitmap>();
  253. bitNames = new List<string>();
  254. filePathList = new List<string>();
  255. foreach (string imgName in imageNames)
  256. {
  257. if (pPath == null)
  258. pPath = System.IO.Path.GetDirectoryName(imgName);
  259. string xmlPath = pPath + "\\" + Path.GetFileNameWithoutExtension(imgName) + ".xml";
  260. double ruleData = 1;
  261. ConfigModel configModel = Program.instance.configModel;
  262. //如果xml存在
  263. if (System.IO.File.Exists(xmlPath))
  264. {
  265. var configModel1 = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  266. ruleData = configModel1.rule.pixel_length == 0 ? 1 : Convert.ToDouble(configModel1.rule.physical_length / configModel1.rule.pixel_length);
  267. InitRulerInfo(configModel1.rule.ruler_units, ruleData);
  268. }
  269. else {
  270. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  271. if (measureMaintenanceTreeData != null)
  272. {
  273. MeasureMaintenanceTreeSpecificData data;
  274. this.appWorkspace.RecursionGetData(id, measureMaintenanceTreeData.MeasureMaintenanceTreeDataList, out data);
  275. if (data.ruleMessage != null)
  276. {
  277. ruleData = data.ruleMessage.pixelLength == 0 ? 1 : Convert.ToDouble(data.ruleMessage.physicalLength / Convert.ToDecimal(data.ruleMessage.pixelLength));
  278. InitRulerInfo(data.ruleMessage.rulerUnits, ruleData);
  279. }
  280. else
  281. {
  282. if (measureMaintenanceType.ruleMessage != null)
  283. {
  284. ruleData = measureMaintenanceType.ruleMessage.pixelLength == 0 ? 1 : Convert.ToDouble(measureMaintenanceType.ruleMessage.physicalLength / Convert.ToDecimal(measureMaintenanceType.ruleMessage.pixelLength));
  285. InitRulerInfo(measureMaintenanceType.ruleMessage.rulerUnits, ruleData);
  286. }
  287. else
  288. {
  289. List<mic_rulers> list = Program.instance.mic_rulersAll;
  290. var ruler = list.Where(m => m.id.Equals(configModel.RulerId)).FirstOrDefault();
  291. if (ruler != null)
  292. {
  293. ruleData = ruler.pixel_length == 0 ? 1 : Convert.ToDouble(ruler.physical_length / Convert.ToDecimal(ruler.pixel_length));
  294. InitRulerInfo(ruler.ruler_units, ruleData);
  295. }
  296. }
  297. }
  298. }
  299. else
  300. {
  301. if (measureMaintenanceType.ruleMessage != null)
  302. {
  303. ruleData = measureMaintenanceType.ruleMessage.pixelLength == 0 ? 1 : Convert.ToDouble(measureMaintenanceType.ruleMessage.physicalLength / Convert.ToDecimal(measureMaintenanceType.ruleMessage.pixelLength));
  304. InitRulerInfo(measureMaintenanceType.ruleMessage.rulerUnits, ruleData);
  305. }
  306. else
  307. {
  308. List<mic_rulers> list = Program.instance.mic_rulersAll;
  309. var ruler = list.Where(m => m.id.Equals(configModel.RulerId)).FirstOrDefault();
  310. if (ruler != null)
  311. {
  312. ruleData = ruler.pixel_length == 0 ? 1 : Convert.ToDouble(ruler.physical_length / Convert.ToDecimal(ruler.pixel_length));
  313. InitRulerInfo(ruler.ruler_units, ruleData);
  314. }
  315. }
  316. }
  317. }
  318. if (this.rules.ContainsKey(configModel.Unit)) {
  319. this.rules.TryGetValue(configModel.Unit, out ruleData);
  320. }
  321. if (pidRuleDic.ContainsKey(id))
  322. {
  323. if (pidRuleDic[id].ContainsKey(Path.GetFileName(imgName)))
  324. {
  325. pidRuleDic[id][Path.GetFileName(imgName)] = ruleData;
  326. }
  327. else {
  328. pidRuleDic[id].Add(Path.GetFileName(imgName), ruleData);
  329. }
  330. }
  331. else
  332. {
  333. Dictionary<string, double> dataKeyValue = new Dictionary<string, double>();
  334. dataKeyValue.Add(Path.GetFileName(imgName), ruleData);
  335. pidRuleDic.Add(id, dataKeyValue);
  336. }
  337. Image image = Image.FromFile(imgName);
  338. listBitmap.Add(new Bitmap(image));
  339. bitNames.Add(System.IO.Path.GetFileName(imgName));
  340. filePathList.Add(System.IO.Path.GetDirectoryName(imgName));
  341. }
  342. return listBitmap;
  343. }
  344. else
  345. {
  346. return null;
  347. }
  348. }
  349. /// <summary>
  350. /// 初始化标尺信息,图片对应的xml中读取
  351. /// 然后根据标尺的单位,换算出所有单位的数据
  352. /// </summary>
  353. public void InitRulerInfo(int units,double unitLength)
  354. {
  355. this.rules.Clear();
  356. switch (units)
  357. {
  358. case (int)1://英寸
  359. this.rules.Add(1, unitLength); //英寸
  360. this.rules.Add(7, 1000 * unitLength); //米尔
  361. this.rules.Add(2, 2.54 * unitLength); //厘米
  362. this.rules.Add(3, 25.4 * unitLength); //毫米
  363. this.rules.Add(4, 25400 * unitLength); //微米
  364. this.rules.Add(5, 25400000 * unitLength); //纳米
  365. break;
  366. case (int)7://米尔
  367. this.rules.Add(1, 0.001 * unitLength); //英寸
  368. this.rules.Add(7, unitLength); //米尔
  369. this.rules.Add(2, 0.00254 * unitLength); //厘米
  370. this.rules.Add(3, 0.0254 * unitLength); //毫米
  371. this.rules.Add(4, 25.4 * unitLength); //微米
  372. this.rules.Add(5, 25400 * unitLength); //纳米
  373. break;
  374. case (int)2://厘米
  375. this.rules.Add(1, 0.3937008 * unitLength); //英寸
  376. this.rules.Add(7, 393.7008 * unitLength); //米尔
  377. this.rules.Add(2, unitLength); //厘米
  378. this.rules.Add(3, 10 * unitLength); //毫米
  379. this.rules.Add(4, 10000 * unitLength); //微米
  380. this.rules.Add(5, 10000000 * unitLength); //纳米
  381. break;
  382. case (int)3://毫米
  383. this.rules.Add(1, 0.0393701 * unitLength); //英寸
  384. this.rules.Add(7, 39.3701 * unitLength); //米尔
  385. this.rules.Add(2, 0.1 * unitLength); //厘米
  386. this.rules.Add(3, unitLength); //毫米
  387. this.rules.Add(4, 1000 * unitLength); //微米
  388. this.rules.Add(5, 1000000 * unitLength); //纳米
  389. break;
  390. case (int)4://微米
  391. this.rules.Add(1, 0.00003937007874 * unitLength); //英寸
  392. this.rules.Add(7, 0.03937007874 * unitLength); //米尔
  393. this.rules.Add(2, 0.0001 * unitLength); //厘米
  394. this.rules.Add(3, 0.001 * unitLength); //毫米
  395. this.rules.Add(4, unitLength); //微米
  396. this.rules.Add(5, 1000 * unitLength); //纳米
  397. break;
  398. case (int)5://纳米
  399. this.rules.Add(1, 3.9370e-8 * unitLength); //英寸
  400. this.rules.Add(7, 3.9370e-5 * unitLength); //米尔
  401. this.rules.Add(2, 1e-7 * unitLength); //厘米
  402. this.rules.Add(3, 1e-6 * unitLength); //毫米
  403. this.rules.Add(4, 0.001 * unitLength); //微米
  404. this.rules.Add(5, unitLength); //纳米
  405. break;
  406. }
  407. }
  408. /// <summary>
  409. /// 點擊下拉列表時顯示(選擇規程名稱)
  410. /// 顯示輸出信息、基礎信息以及圖片分類信息
  411. /// </summary>
  412. private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
  413. {
  414. if (comboMingcheng.SelectedIndex == -1)
  415. {
  416. return;
  417. }
  418. #region [读取树状结构]
  419. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  420. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureMaintenanceType\\";
  421. var fileName = measureMaintenanceType.measureMaintenanceName;
  422. filePath = $"{filePath}{fileName}.xml";
  423. if (System.IO.File.Exists(filePath))
  424. {
  425. measureMaintenanceTreeData = XmlSerializeHelper.DESerializer<MeasureMaintenanceTreeData>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  426. }
  427. #endregion
  428. #region [获取标尺]
  429. if (measureMaintenanceType.ruleMessage != null)
  430. {
  431. //计算每像素物理长度
  432. double proportion = Math.Round((double)measureMaintenanceType.ruleMessage.physicalLength / measureMaintenanceType.ruleMessage.pixelLength, 4);
  433. string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), measureMaintenanceType.ruleMessage.rulerUnits)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  434. label14.Text = $"{measureMaintenanceType.ruleMessage.ruleName} {content}";
  435. }
  436. else {
  437. List<mic_rulers> list = Program.instance.mic_rulersAll;
  438. ConfigModel configModel = Program.instance.configModel;
  439. var ruler = list.Where(m => m.id.Equals(configModel.RulerId)).FirstOrDefault();
  440. if (ruler != null)
  441. {
  442. double proportion = ruler.pixel_length == 0 ? 1 : Math.Round((double)ruler.physical_length / ruler.pixel_length, 4);
  443. string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), ruler.ruler_units)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  444. label14.Text = $"{ruler.ruler_name} {content}";
  445. }
  446. else {
  447. label14.Text = PdnResources.GetString("NewBatchNumber") + ":1/1";
  448. }
  449. }
  450. #endregion
  451. #region [基础信息赋值]
  452. textLiaohao.Text = string.Empty;//料號
  453. comboBanci.SelectedIndex = -1;//班次
  454. comboShiyanshi.SelectedIndex = -1;//實驗室
  455. comboShiyongchangqu.SelectedIndex = -1;//使用廠區
  456. comboZhichengbie.SelectedIndex = -1;//製成別
  457. textDanhao.Text = string.Empty;//單號
  458. textPihao.Text = string.Empty;//批號
  459. comboCengbie.SelectedIndex = -1;//層別
  460. comboDianduxianbie.Text = string.Empty;//電鍍綫別
  461. textLiaohao.Text = measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue;//料號
  462. comboBanci.SelectedItem = measureMaintenanceType.measureMaintenanceBasicDataList[1].measureMaintenanceBasicDataValue;//班次
  463. comboShiyanshi.SelectedItem = measureMaintenanceType.measureMaintenanceBasicDataList[2].measureMaintenanceBasicDataValue;//實驗室
  464. comboShiyongchangqu.SelectedItem = measureMaintenanceType.measureMaintenanceBasicDataList[3].measureMaintenanceBasicDataValue;//使用廠區
  465. comboZhichengbie.SelectedItem = measureMaintenanceType.measureMaintenanceBasicDataList[4].measureMaintenanceBasicDataValue;//製成別
  466. textDanhao.Text = measureMaintenanceType.measureMaintenanceBasicDataList[5].measureMaintenanceBasicDataValue;//單號
  467. textPihao.Text = measureMaintenanceType.measureMaintenanceBasicDataList[6].measureMaintenanceBasicDataValue;//批號
  468. comboCengbie.SelectedItem = measureMaintenanceType.measureMaintenanceBasicDataList[7].measureMaintenanceBasicDataValue;//層別
  469. comboDianduxianbie.Text = measureMaintenanceType.measureMaintenanceBasicDataList[8].measureMaintenanceBasicDataValue;//電鍍綫別
  470. if (measureMaintenanceType.ruleMessage != null)
  471. {
  472. label12.Text = InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), measureMaintenanceType.ruleMessage.rulerUnits)))].ToString();//單位
  473. }
  474. else {
  475. List<mic_rulers> list = Program.instance.mic_rulersAll;
  476. ConfigModel configModel = Program.instance.configModel;
  477. var ruler = list.Where(m => m.id.Equals(configModel.RulerId)).FirstOrDefault();
  478. if (ruler != null)
  479. {
  480. label12.Text = InvariantData.unitsDictionary[configModel.Unit].ToString();//單位
  481. }
  482. }
  483. #endregion
  484. OutInfoShow();
  485. OperationControlInitialization();
  486. this.everyHoleImgGraphicsList.Clear();
  487. this.everyHoleImgisConductive.Clear();
  488. this.everyHoleImgisFanweibuchang.Clear();
  489. this.everyHoleImgisErzhichuli.Clear();
  490. }
  491. /// <summary>
  492. /// 輸出信息顯示
  493. /// </summary>
  494. private void OutInfoShow()
  495. {
  496. if (comboMingcheng.SelectedIndex == -1)
  497. {
  498. return;
  499. }
  500. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  501. panelOutInfo.Controls.Clear();
  502. int height = 38;
  503. int width = (groupOutInfo.Size.Width - 14) / 4;
  504. string[] titles = { PdnResources.GetString("NewHoleTypeName"), PdnResources.GetString("NewTestItemsName"), PdnResources.GetString("NewSpecificationName"), PdnResources.GetString("NewMeasuringPositionName") };
  505. string[] titleNames = { "kongxing", "jianyanxiangmu", "guige", "celiangweizhi" };
  506. List<Label> positions = new List<Label>();
  507. List<Label> specifications = new List<Label>();
  508. List<Label> testItems = new List<Label>();
  509. List<Label> holeTypes = new List<Label>();
  510. int i, k;
  511. for (i = 0; i < 4; i++)
  512. {
  513. Label title = new Label();
  514. title.AutoSize = false;
  515. title.TextAlign = ContentAlignment.MiddleCenter;
  516. title.BorderStyle = BorderStyle.FixedSingle;
  517. title.Location = new System.Drawing.Point(3 + (width - 1) * i, 1);
  518. title.Name = titleNames[i];
  519. title.Size = new System.Drawing.Size(width, height);
  520. title.TabIndex = 2;
  521. title.Text = titles[i];
  522. panelOutInfo.Controls.Add(title);
  523. }
  524. var list1 = measureMaintenanceType.MeasureMaintenanceTreeFourthDataList.GroupBy(m => m.HoleType);
  525. foreach (var item in list1)
  526. {
  527. int rowInt = 0;
  528. var list2 = item.GroupBy(m => m.TestItems);
  529. foreach (var item2 in list2)
  530. {
  531. k = 0;
  532. foreach (var item3 in item2)
  533. {
  534. #region [測量位置]
  535. Label position = new Label();
  536. position.AutoSize = false;
  537. position.TextAlign = ContentAlignment.MiddleCenter;
  538. position.BorderStyle = BorderStyle.FixedSingle;
  539. if (positions.Count == 0)
  540. position.Location = new System.Drawing.Point(3 + (width - 1) * 3, height);
  541. else
  542. position.Location = new System.Drawing.Point(3 + (width - 1) * 3, positions[positions.Count - 1].Location.Y + height - 1);
  543. position.Name = item3.FormulaParentId + "3";
  544. position.Size = new System.Drawing.Size(width, height);
  545. position.TabIndex = 2;
  546. position.Text = item3.FormulaName;
  547. panelOutInfo.Controls.Add(position);
  548. positions.Add(position);
  549. #endregion
  550. k++;
  551. rowInt++;
  552. }
  553. #region [規格]
  554. Label specification = new Label();
  555. specification.AutoSize = false;
  556. specification.TextAlign = ContentAlignment.MiddleCenter;
  557. specification.BorderStyle = BorderStyle.FixedSingle;
  558. if (specifications.Count == 0)
  559. specification.Location = new System.Drawing.Point(3 + (width - 1) * 2, height);
  560. else
  561. specification.Location = new System.Drawing.Point(3 + (width - 1) * 2, specifications[specifications.Count - 1].Location.Y + specifications[specifications.Count - 1].Size.Height - 1);
  562. specification.Name = item2.First().Specification + "2";
  563. specification.Size = new System.Drawing.Size(width, height * k - (k - 1));
  564. specification.TabIndex = 2;
  565. #region
  566. item2.First().Specification = item2.First().Specification.Replace("LQ", "<=");
  567. item2.First().Specification = item2.First().Specification.Replace("L", "<");
  568. #endregion
  569. specification.Text = item2.First().Specification;
  570. panelOutInfo.Controls.Add(specification);
  571. specifications.Add(specification);
  572. #endregion
  573. #region [檢驗項目]
  574. Label testItem = new Label();
  575. testItem.AutoSize = false;
  576. testItem.TextAlign = ContentAlignment.MiddleCenter;
  577. testItem.BorderStyle = BorderStyle.FixedSingle;
  578. if (testItems.Count == 0)
  579. testItem.Location = new System.Drawing.Point(3 + (width - 1) * 1, height);
  580. else
  581. testItem.Location = new System.Drawing.Point(3 + (width - 1) * 1, testItems[testItems.Count - 1].Location.Y + testItems[testItems.Count - 1].Size.Height - 1);
  582. testItem.Name = item2.Key + "1";
  583. testItem.Size = new System.Drawing.Size(width, height * k - (k - 1));
  584. testItem.TabIndex = 2;
  585. testItem.Text = item2.Key;
  586. panelOutInfo.Controls.Add(testItem);
  587. testItems.Add(testItem);
  588. #endregion
  589. }
  590. #region [孔型]
  591. Label holeType = new Label();
  592. holeType.AutoSize = false;
  593. holeType.TextAlign = ContentAlignment.MiddleCenter;
  594. holeType.BorderStyle = BorderStyle.FixedSingle;
  595. if (holeTypes.Count == 0)
  596. holeType.Location = new System.Drawing.Point(3, height);
  597. else
  598. holeType.Location = new System.Drawing.Point(3, holeTypes[holeTypes.Count - 1].Location.Y + holeTypes[holeTypes.Count - 1].Size.Height - 1);
  599. holeType.Name = item.Key + "0";
  600. holeType.Size = new System.Drawing.Size(width, height * rowInt - (rowInt - 1));
  601. holeType.TabIndex = 2;
  602. holeType.Text = item.Key;
  603. panelOutInfo.Controls.Add(holeType);
  604. holeTypes.Add(holeType);
  605. #endregion
  606. }
  607. }
  608. /// <summary>
  609. /// 操作界面控件初始化
  610. /// </summary>
  611. private void OperationControlInitialization()
  612. {
  613. if (comboMingcheng.SelectedIndex == -1)
  614. {
  615. return;
  616. }
  617. panel1.Controls.Clear();
  618. erjimulusName.Clear();
  619. everyHoleImg.Clear();
  620. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  621. for (int i = 0; i < pictures.Count; i++)
  622. {
  623. for (int k = 0; k < pictures[i].Count; k++)
  624. {
  625. if (pictures[i][k] != null)
  626. {
  627. pictures[i][k].Dispose();
  628. }
  629. }
  630. }
  631. pictures.Clear();
  632. pictureNames.Clear();
  633. picturePathNames.Clear();
  634. kongjians = new Kongjian();
  635. List<string> ruleList = new List<string>();
  636. List<string> holeTypeIDList = new List<string>();
  637. //尋找具有檢驗項目的二級目錄
  638. var list = measureMaintenanceType.MeasureMaintenanceTreeFourthDataList.GroupBy(m => m.HoleType);
  639. foreach (var item in list)
  640. {
  641. erjimulusName.Add(item.Key);
  642. holeTypeIDList.Add(item.FirstOrDefault().HoleTypeId);
  643. if (measureMaintenanceTreeData != null)
  644. {
  645. MeasureMaintenanceTreeSpecificData data;
  646. this.appWorkspace.RecursionGetData(item.FirstOrDefault().HoleTypeId, measureMaintenanceTreeData.MeasureMaintenanceTreeDataList, out data);
  647. string ruleName;
  648. if (data.ruleMessage == null)
  649. {
  650. ruleName = label14.Text;
  651. }
  652. else
  653. {
  654. //计算每像素物理长度
  655. double proportion = Math.Round((double)data.ruleMessage.physicalLength / data.ruleMessage.pixelLength, 4);
  656. string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), data.ruleMessage.rulerUnits)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  657. ruleName = $"{data.ruleMessage.ruleName} {content}";
  658. }
  659. ruleList.Add(ruleName);
  660. }
  661. else {
  662. ruleList.Add(label14.Text);
  663. }
  664. everyHoleImg.Add(item.FirstOrDefault().HoleTypeId,new List<Mat>() { });
  665. }
  666. erjimuluCount = erjimulusName.Count();
  667. //選擇的圖片計數,//圖片列表//删除按钮列表//加載圖片//圖片名
  668. counts = new int[erjimuluCount];
  669. for (int i = 0; i < erjimuluCount; i++)
  670. {
  671. counts[i] = 1;
  672. List<PictureBox> newPictureBox = new List<PictureBox>();
  673. kongjians.pictureBoxes.Add(newPictureBox);
  674. List<Button> newButton = new List<Button>();
  675. kongjians.shanchus.Add(newButton);
  676. List<Bitmap> bitmaps = new List<Bitmap>();
  677. pictures.Add(bitmaps);
  678. List<string> pictureName = new List<string>();
  679. List<string> picturePathName = new List<string>();
  680. pictureNames.Add(pictureName);
  681. picturePathNames.Add(picturePathName);
  682. }
  683. //新建label名稱
  684. List<string> labelNames = new List<string>();
  685. for (int i = 0; i < erjimulusName.Count; i++)
  686. {
  687. labelNames.Add("label" + erjimulusName[i]);
  688. }
  689. //新建操作信息與按鈕
  690. for (int i = 0; i < erjimulusName.Count; i++)
  691. {
  692. Label newFenleimingcheng = new Label();
  693. newFenleimingcheng.AutoSize = true;
  694. if (i == 0)
  695. {
  696. newFenleimingcheng.Location = new System.Drawing.Point(3, 10 + 100 * i);
  697. }
  698. else {
  699. newFenleimingcheng.Location = new System.Drawing.Point(3, 30 + 20 * (i - 1) + 100 * i);
  700. }
  701. newFenleimingcheng.Name = labelNames[i];
  702. newFenleimingcheng.Size = new System.Drawing.Size(98, 18);
  703. newFenleimingcheng.TabIndex = 2;
  704. newFenleimingcheng.Text = PdnResources.GetString("NewCategoryName") + ":" + erjimulusName[i];
  705. kongjians.fenleimingchengs.Add(newFenleimingcheng);
  706. Label newBiaochimingcheng = new Label();
  707. newBiaochimingcheng.AutoSize = true;
  708. if (i == 0)
  709. {
  710. newBiaochimingcheng.Location = new System.Drawing.Point(newFenleimingcheng.Width + 30, 10 + 100 * i);
  711. }
  712. else
  713. {
  714. newBiaochimingcheng.Location = new System.Drawing.Point(newFenleimingcheng.Width + 30, 30 + 20 * (i - 1) + 100 * i);
  715. }
  716. newBiaochimingcheng.Name = holeTypeIDList[i];
  717. newBiaochimingcheng.Size = new System.Drawing.Size(98, 18);
  718. newBiaochimingcheng.TabIndex = 2;
  719. newBiaochimingcheng.Text = PdnResources.GetString("NewRuler") + ruleList[i];
  720. kongjians.biaochimingchengs.Add(newBiaochimingcheng);
  721. Label newTupianweizhi = new Label();
  722. newTupianweizhi.AutoSize = true;
  723. if (i == 0)
  724. {
  725. newTupianweizhi.Location = new System.Drawing.Point(3, 30 + 100 * i);
  726. }
  727. else
  728. {
  729. newTupianweizhi.Location = new System.Drawing.Point(3, 50 + 20 * (i - 1) + 100 * i);
  730. }
  731. newTupianweizhi.Name = "tupianweizhi" + i.ToString();
  732. newTupianweizhi.Size = new System.Drawing.Size(98, 18);
  733. newTupianweizhi.TabIndex = 2;
  734. newTupianweizhi.Text = PdnResources.GetString("NewPictureLocation") + ":";
  735. kongjians.tupianweizhis.Add(newTupianweizhi);
  736. Button newWenjianxuanze = new Button();
  737. if (i == 0)
  738. {
  739. newWenjianxuanze.Location = new System.Drawing.Point(353, 10 + 100 * i);
  740. }
  741. else
  742. {
  743. newWenjianxuanze.Location = new System.Drawing.Point(353, 30 + 20 * (i - 1) + 100 * i);
  744. }
  745. newWenjianxuanze.Name = "wenjianxuanze" + i.ToString();
  746. newWenjianxuanze.Size = new System.Drawing.Size(73, 28);
  747. newWenjianxuanze.TabIndex = 0;
  748. newWenjianxuanze.Text = PdnResources.GetString("newWenjianxuanze");
  749. newWenjianxuanze.UseVisualStyleBackColor = true;
  750. newWenjianxuanze.Click += new System.EventHandler(this.buttonWenjianxuanze_Click);
  751. kongjians.wenjianxuanzes.Add(newWenjianxuanze);
  752. Button newHuizhifanwei = new Button();
  753. if (i == 0)
  754. {
  755. newHuizhifanwei.Location = new System.Drawing.Point(353, 40 + 100 * i);
  756. }
  757. else
  758. {
  759. newHuizhifanwei.Location = new System.Drawing.Point(353, 60 + 20 * (i - 1) + 100 * i);
  760. }
  761. newHuizhifanwei.Name = "buttonHuizhifanwei" + erjimulusName[i];
  762. newHuizhifanwei.Size = new System.Drawing.Size(73, 28);
  763. newHuizhifanwei.TabIndex = 0;
  764. newHuizhifanwei.Text = PdnResources.GetString("NewDrawRange") + "";
  765. newHuizhifanwei.UseVisualStyleBackColor = true;
  766. newHuizhifanwei.Click += new System.EventHandler(this.buttonHuizhitupian_Click);
  767. kongjians.huizhifanweis.Add(newHuizhifanwei);
  768. Button newQingkongquanbu = new Button();
  769. if (i == 0)
  770. {
  771. newQingkongquanbu.Location = new System.Drawing.Point(353, 70 + 100 * i);
  772. }
  773. else
  774. {
  775. newQingkongquanbu.Location = new System.Drawing.Point(353, 90 + 20 * (i - 1) + 100 * i);
  776. }
  777. newQingkongquanbu.Name = "buttonQingkongquanbu" + erjimulusName[i];
  778. newQingkongquanbu.Size = new System.Drawing.Size(73, 28);
  779. newQingkongquanbu.TabIndex = 0;
  780. newQingkongquanbu.Text = PdnResources.GetString("NewEmptyAll");
  781. newQingkongquanbu.UseVisualStyleBackColor = true;
  782. newQingkongquanbu.Click += new System.EventHandler(this.buttonQingkongquanbu_Click);
  783. kongjians.qingkongquanbus.Add(newQingkongquanbu);
  784. Button newTianjiatupian = new Button();
  785. if (i == 0)
  786. {
  787. newTianjiatupian.Location = new System.Drawing.Point(70, 30 + 100 * i);
  788. }
  789. else
  790. {
  791. newTianjiatupian.Location = new System.Drawing.Point(70, 50 + 20 * (i - 1) + 100 * i);
  792. }
  793. newTianjiatupian.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
  794. newTianjiatupian.Name = "buttonTianjiatupian" + i.ToString();
  795. newTianjiatupian.Size = new System.Drawing.Size(50, 70);
  796. newTianjiatupian.TabIndex = 0;
  797. newTianjiatupian.Text = "+";
  798. newTianjiatupian.UseVisualStyleBackColor = true;
  799. newTianjiatupian.Click += new System.EventHandler(this.buttonTianjiatupian_Click);
  800. kongjians.tianjiatupians.Add(newTianjiatupian);
  801. Label dividingLine = new Label();
  802. dividingLine.AutoSize = false;
  803. dividingLine.Location = new System.Drawing.Point(0, (newTianjiatupian.Location.Y + newTianjiatupian.Height + 10));
  804. dividingLine.Name = "dividingLine" + i.ToString();
  805. dividingLine.Size = new System.Drawing.Size(panel1.Width - 20, 2);
  806. dividingLine.TabIndex = 2;
  807. dividingLine.BorderStyle = BorderStyle.Fixed3D;
  808. kongjians.dividingLines.Add(dividingLine);
  809. panel1.Controls.Add(kongjians.fenleimingchengs[i]);
  810. panel1.Controls.Add(kongjians.biaochimingchengs[i]);
  811. panel1.Controls.Add(kongjians.tupianweizhis[i]);
  812. panel1.Controls.Add(kongjians.wenjianxuanzes[i]);
  813. panel1.Controls.Add(kongjians.tianjiatupians[i]);
  814. panel1.Controls.Add(kongjians.huizhifanweis[i]);
  815. panel1.Controls.Add(kongjians.qingkongquanbus[i]);
  816. panel1.Controls.Add(dividingLine);
  817. }
  818. GC.Collect();
  819. }
  820. /// <summary>
  821. /// 文件夹选择
  822. /// </summary>
  823. /// <param name="sender"></param>
  824. /// <param name="e"></param>
  825. private void buttonWenjianxuanze_Click(object sender, EventArgs e)
  826. {
  827. string path = string.Empty;
  828. Button button = (Button)sender;
  829. int rowOfFenlei = 0;
  830. for (int i = 0; i < kongjians.wenjianxuanzes.Count; i++)
  831. {
  832. if (kongjians.wenjianxuanzes[i].Name == button.Name)
  833. {
  834. rowOfFenlei = i;
  835. break;
  836. }
  837. }
  838. FolderBrowserDialog dialog = new FolderBrowserDialog();
  839. dialog.Description = "請選擇文件路徑";
  840. dialog.SelectedPath = path;
  841. if (dialog.ShowDialog() == DialogResult.OK)
  842. {
  843. string foldPath = dialog.SelectedPath;
  844. List<string> pathList = FileOperationHelper.GetAllImgList(foldPath);
  845. bitmaps = ChooseImagesFromImgDisk(pathList, kongjians.biaochimingchengs[rowOfFenlei].Name);
  846. if (bitmaps != null && bitmaps.Count > 0)
  847. {
  848. PictureShow(rowOfFenlei);
  849. }
  850. }
  851. }
  852. /// <summary>
  853. /// 點擊添加图片
  854. /// </summary>
  855. private void buttonTianjiatupian_Click(object sender, EventArgs e)
  856. {
  857. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  858. if (measureMaintenanceType == null)
  859. {
  860. MessageBox.Show(PdnResources.GetString("NoAvaliableRule"));
  861. return;
  862. }
  863. Button button = (Button)sender;
  864. int rowOfFenlei = 0;
  865. for (int i = 0; i < kongjians.tianjiatupians.Count; i++)
  866. {
  867. if (kongjians.tianjiatupians[i].Name == button.Name)
  868. {
  869. rowOfFenlei = i;
  870. break;
  871. }
  872. }
  873. bitmaps = ChooseImagesFromHardDisk(kongjians.biaochimingchengs[rowOfFenlei].Name);
  874. if (bitmaps != null && bitmaps.Count > 0)
  875. {
  876. PictureShow(rowOfFenlei);
  877. }
  878. }
  879. /// <summary>
  880. /// 點擊删除图片
  881. /// </summary>
  882. private void buttonShanchu_Click(object sender, EventArgs e)
  883. {
  884. Button button = (Button)sender;
  885. int rowsOfFenlei = 0;
  886. int position = 0;
  887. for (int i = 0; i < kongjians.shanchus.Count; i++)
  888. {
  889. for (int j = 0; j < kongjians.shanchus[i].Count; j++)
  890. {
  891. if (kongjians.shanchus[i][j].Name == button.Name)
  892. {
  893. rowsOfFenlei = i;
  894. position = j;
  895. }
  896. }
  897. }
  898. panel1.Controls.Remove(kongjians.shanchus[rowsOfFenlei][position]);
  899. panel1.Controls.Remove(kongjians.pictureBoxes[rowsOfFenlei][position]);
  900. kongjians.shanchus[rowsOfFenlei].RemoveAt(position);
  901. kongjians.pictureBoxes[rowsOfFenlei].RemoveAt(position);
  902. kongjians.ResetControlPosition2(rowsOfFenlei, position);
  903. string name = pictureNames[rowsOfFenlei][position];
  904. if (pictures[rowsOfFenlei][position] != null)
  905. {
  906. pictures[rowsOfFenlei][position].Dispose();
  907. }
  908. counts[rowsOfFenlei]--;
  909. pictureNames[rowsOfFenlei].RemoveAt(position);
  910. picturePathNames[rowsOfFenlei].RemoveAt(position);
  911. pictures[rowsOfFenlei].RemoveAt(position);
  912. if (everyHoleImgGraphicsList.ContainsKey(rowsOfFenlei))
  913. {
  914. if (position < everyHoleImgGraphicsList[rowsOfFenlei].Count) {
  915. everyHoleImgGraphicsList[rowsOfFenlei].RemoveAt(position);
  916. }
  917. }
  918. if (everyHoleImgisConductive.ContainsKey(rowsOfFenlei))
  919. {
  920. if (position < everyHoleImgisConductive[rowsOfFenlei].Count)
  921. {
  922. everyHoleImgisConductive[rowsOfFenlei].RemoveAt(position);
  923. }
  924. }
  925. if (everyHoleImgisFanweibuchang.ContainsKey(rowsOfFenlei))
  926. {
  927. if (position < everyHoleImgisFanweibuchang[rowsOfFenlei].Count)
  928. {
  929. everyHoleImgisFanweibuchang[rowsOfFenlei].RemoveAt(position);
  930. }
  931. }
  932. if (everyHoleImgisErzhichuli.ContainsKey(rowsOfFenlei))
  933. {
  934. if (position < everyHoleImgisErzhichuli[rowsOfFenlei].Count)
  935. {
  936. everyHoleImgisErzhichuli[rowsOfFenlei].RemoveAt(position);
  937. }
  938. }
  939. if (this.pidRuleDic.ContainsKey(kongjians.biaochimingchengs[rowsOfFenlei].Name))
  940. {
  941. if (this.pidRuleDic[kongjians.biaochimingchengs[rowsOfFenlei].Name].ContainsKey(name))
  942. {
  943. this.pidRuleDic[kongjians.biaochimingchengs[rowsOfFenlei].Name].Remove(name);
  944. };
  945. }
  946. GC.Collect();
  947. }
  948. /// <summary>
  949. /// 點擊清除圖片
  950. /// </summary>
  951. private void buttonQingkongquanbu_Click(object sender, EventArgs e)
  952. {
  953. Button button = (Button)sender;
  954. int rowOfFenlie = 0;
  955. for (int i = 0; i < kongjians.qingkongquanbus.Count; i++)
  956. {
  957. if (kongjians.qingkongquanbus[i].Name == button.Name)
  958. {
  959. rowOfFenlie = i; break;
  960. }
  961. }
  962. int cengshu = kongjians.pictureBoxes[rowOfFenlie].Count / 4;
  963. for (int i = kongjians.pictureBoxes[rowOfFenlie].Count - 1; i >= 0; i--)
  964. {
  965. panel1.Controls.Remove(kongjians.pictureBoxes[rowOfFenlie][i]);
  966. panel1.Controls.Remove(kongjians.shanchus[rowOfFenlie][i]);
  967. kongjians.shanchus[rowOfFenlie].RemoveAt(i);
  968. kongjians.pictureBoxes[rowOfFenlie].RemoveAt(i);
  969. }
  970. kongjians.tianjiatupians[rowOfFenlie].Location = new System.Drawing.Point(70, kongjians.tupianweizhis[rowOfFenlie].Location.Y);
  971. kongjians.dividingLines[rowOfFenlie].Location = new System.Drawing.Point(kongjians.dividingLines[rowOfFenlie].Location.X, kongjians.tianjiatupians[rowOfFenlie].Location.Y + kongjians.tianjiatupians[rowOfFenlie].Height + 20);
  972. counts[rowOfFenlie] = 1;
  973. for (int i = 0; i < pictures[rowOfFenlie].Count; i++) {
  974. if (pictures[rowOfFenlie][i] != null)
  975. {
  976. pictures[rowOfFenlie][i].Dispose();
  977. }
  978. }
  979. pictures[rowOfFenlie].Clear();
  980. pictureNames[rowOfFenlie].Clear();
  981. picturePathNames[rowOfFenlie].Clear();
  982. if (this.everyHoleImgGraphicsList.ContainsKey(rowOfFenlie))
  983. {
  984. this.everyHoleImgGraphicsList.Remove(rowOfFenlie);
  985. }
  986. if (everyHoleImgisConductive.ContainsKey(rowOfFenlie))
  987. {
  988. everyHoleImgisConductive.Remove(rowOfFenlie);
  989. }
  990. if (everyHoleImgisFanweibuchang.ContainsKey(rowOfFenlie))
  991. {
  992. everyHoleImgisFanweibuchang.Remove(rowOfFenlie);
  993. }
  994. if (everyHoleImgisErzhichuli.ContainsKey(rowOfFenlie))
  995. {
  996. everyHoleImgisErzhichuli.Remove(rowOfFenlie);
  997. }
  998. if (this.pidRuleDic.ContainsKey(kongjians.biaochimingchengs[rowOfFenlie].Name))
  999. {
  1000. this.pidRuleDic[kongjians.biaochimingchengs[rowOfFenlie].Name].Clear();
  1001. }
  1002. kongjians.ResetControlPosition3(rowOfFenlie, cengshu);
  1003. GC.Collect();
  1004. }
  1005. /// <summary>
  1006. /// 點擊繪製範圍
  1007. /// </summary>
  1008. private void buttonHuizhitupian_Click(object sender, EventArgs e)
  1009. {
  1010. Button button = (Button)sender;
  1011. int rowOfFenlie = 0;
  1012. for (int i = 0; i < kongjians.huizhifanweis.Count; i++)
  1013. {
  1014. if (button.Name == kongjians.huizhifanweis[i].Name)
  1015. {
  1016. rowOfFenlie = i;
  1017. break;
  1018. }
  1019. }
  1020. if (pictures[rowOfFenlie].Count == 0) {
  1021. MessageBox.Show(PdnResources.GetString("NewPleaseAddPicturesFirst"));
  1022. return;
  1023. }
  1024. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  1025. bool show = false;
  1026. bool showFanweibuchang = false;
  1027. bool showErzhichuli = false;
  1028. List<bool> list = new List<bool>();
  1029. if (measureMaintenanceType != null && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].FatherHoleTypeId == "9")
  1030. {
  1031. show = true;
  1032. if (!this.everyHoleImgisConductive.ContainsKey(rowOfFenlie))
  1033. {
  1034. for (int i = 0; i < pictures[rowOfFenlie].Count; i++)
  1035. {
  1036. if (measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].isConductiveCloth)
  1037. {
  1038. list.Add(true);
  1039. }
  1040. else
  1041. {
  1042. list.Add(false);
  1043. }
  1044. }
  1045. this.everyHoleImgisConductive.Add(rowOfFenlie, list);
  1046. }
  1047. }
  1048. else if (measureMaintenanceType != null && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].FatherHoleTypeId == "10"
  1049. && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].HoleTypeId == "100300")
  1050. {
  1051. showFanweibuchang = true;
  1052. if (!this.everyHoleImgisFanweibuchang.ContainsKey(rowOfFenlie))
  1053. {
  1054. for (int i = 0; i < pictures[rowOfFenlie].Count; i++)
  1055. {
  1056. if (measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].isFanweibuchang)
  1057. {
  1058. list.Add(true);
  1059. }
  1060. else
  1061. {
  1062. list.Add(false);
  1063. }
  1064. }
  1065. this.everyHoleImgisFanweibuchang.Add(rowOfFenlie, list);
  1066. }
  1067. }
  1068. else if (true && measureMaintenanceType != null && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].FatherHoleTypeId == "7"
  1069. && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].HoleTypeId == "100176")
  1070. {
  1071. showErzhichuli = true;
  1072. if (!this.everyHoleImgisErzhichuli.ContainsKey(rowOfFenlie))
  1073. {
  1074. for (int i = 0; i < pictures[rowOfFenlie].Count; i++)
  1075. {
  1076. if (measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[rowOfFenlie].isErzhichuli)
  1077. {
  1078. list.Add(true);
  1079. }
  1080. else
  1081. {
  1082. list.Add(false);
  1083. }
  1084. }
  1085. this.everyHoleImgisErzhichuli.Add(rowOfFenlie, list);
  1086. }
  1087. }
  1088. else {
  1089. for (int i = 0; i < pictures[rowOfFenlie].Count; i++)
  1090. {
  1091. list.Add(false);
  1092. }
  1093. if (this.everyHoleImgisConductive.ContainsKey(rowOfFenlie))
  1094. {
  1095. this.everyHoleImgisConductive[rowOfFenlie] = list;
  1096. }
  1097. else {
  1098. this.everyHoleImgisConductive.Add(rowOfFenlie, list);
  1099. }
  1100. if (this.everyHoleImgisFanweibuchang.ContainsKey(rowOfFenlie))
  1101. {
  1102. this.everyHoleImgisFanweibuchang[rowOfFenlie] = list;
  1103. }
  1104. else
  1105. {
  1106. this.everyHoleImgisFanweibuchang.Add(rowOfFenlie, list);
  1107. }
  1108. if (this.everyHoleImgisErzhichuli.ContainsKey(rowOfFenlie))
  1109. {
  1110. this.everyHoleImgisErzhichuli[rowOfFenlie] = list;
  1111. }
  1112. else
  1113. {
  1114. this.everyHoleImgisErzhichuli.Add(rowOfFenlie, list);
  1115. }
  1116. }
  1117. PlotTheMeasurementRange from2 = new PlotTheMeasurementRange(pictures[rowOfFenlie], pictureNames[rowOfFenlie],this.appWorkspace, this, rowOfFenlie,this.everyHoleImgGraphicsList,this.everyHoleImgisConductive, show
  1118. , this.everyHoleImgisFanweibuchang, showFanweibuchang, this.everyHoleImgisErzhichuli, showErzhichuli);
  1119. from2.StartPosition = FormStartPosition.CenterParent;
  1120. from2.ShowDialog();
  1121. }
  1122. /// <summary>
  1123. /// 添加圖片時顯示
  1124. /// </summary>
  1125. private void PictureShow(int rowOfFenlei)
  1126. {
  1127. int bitmapNumber = bitmaps.Count;
  1128. for (int i = 0; i < bitmapNumber; i++)
  1129. {
  1130. if (counts[rowOfFenlei] % 4 != 0)
  1131. {
  1132. Button newShanchu = new Button();
  1133. newShanchu.Location = new System.Drawing.Point(kongjians.tianjiatupians[rowOfFenlei].Location.X + 30, kongjians.tianjiatupians[rowOfFenlei].Location.Y + 50);
  1134. newShanchu.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
  1135. newShanchu.Name = "buttonShanchu" + bitNames[i] + rowOfFenlei.ToString();
  1136. newShanchu.Size = new System.Drawing.Size(20, 20);
  1137. newShanchu.TabIndex = 0;
  1138. newShanchu.Text = "×";
  1139. newShanchu.BackColor = Color.Transparent;
  1140. newShanchu.FlatStyle = FlatStyle.Flat;
  1141. //newShanchu.FlatAppearance.MouseOverBackColor = Color.Transparent;
  1142. //newShanchu.FlatAppearance.MouseDownBackColor = Color.Transparent;
  1143. newShanchu.FlatAppearance.BorderSize = 0;
  1144. newShanchu.ForeColor = Color.Red;
  1145. newShanchu.UseVisualStyleBackColor = true;
  1146. newShanchu.Click += new System.EventHandler(this.buttonShanchu_Click);
  1147. kongjians.shanchus[rowOfFenlei].Add(newShanchu);
  1148. panel1.Controls.Add(kongjians.shanchus[rowOfFenlei][kongjians.shanchus[rowOfFenlei].Count - 1]);
  1149. PictureBox newPicture = new PictureBox();
  1150. newPicture.Location = new System.Drawing.Point(kongjians.tianjiatupians[rowOfFenlei].Location.X, kongjians.tianjiatupians[rowOfFenlei].Location.Y);
  1151. newPicture.Name = bitNames[i];
  1152. newPicture.Size = new System.Drawing.Size(50, 70);
  1153. newPicture.TabIndex = 1;
  1154. newPicture.TabStop = false;
  1155. //panel1.Controls.Add(newPicture);
  1156. newPicture.Image = bitmaps[i];
  1157. newPicture.SizeMode = PictureBoxSizeMode.Zoom;
  1158. kongjians.pictureBoxes[rowOfFenlei].Add(newPicture);
  1159. panel1.Controls.Add(kongjians.pictureBoxes[rowOfFenlei][kongjians.pictureBoxes[rowOfFenlei].Count - 1]);
  1160. pictures[rowOfFenlei].Add(bitmaps[i]);
  1161. pictureNames[rowOfFenlei].Add(bitNames[i]);
  1162. picturePathNames[rowOfFenlei].Add(filePathList[i]);
  1163. kongjians.tianjiatupians[rowOfFenlei].Location = new System.Drawing.Point(kongjians.tianjiatupians[rowOfFenlei].Location.X + 70, kongjians.tianjiatupians[rowOfFenlei].Location.Y);
  1164. kongjians.dividingLines[rowOfFenlei].Location = new System.Drawing.Point(kongjians.dividingLines[rowOfFenlei].Location.X, kongjians.tianjiatupians[rowOfFenlei].Location.Y + kongjians.tianjiatupians[rowOfFenlei].Height + 20);
  1165. counts[rowOfFenlei]++;
  1166. }
  1167. else
  1168. {
  1169. Button newShanchu = new Button();
  1170. newShanchu.Location = new System.Drawing.Point(kongjians.tianjiatupians[rowOfFenlei].Location.X + 30, kongjians.tianjiatupians[rowOfFenlei].Location.Y + 50);
  1171. newShanchu.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
  1172. newShanchu.Name = "buttonShanchu" + bitNames[i] + rowOfFenlei.ToString();
  1173. newShanchu.Size = new System.Drawing.Size(20, 20);
  1174. newShanchu.TabIndex = 0;
  1175. newShanchu.Text = "×";
  1176. newShanchu.BackColor = Color.Transparent;
  1177. newShanchu.FlatStyle = FlatStyle.Flat;
  1178. //newShanchu.FlatAppearance.MouseOverBackColor = Color.Transparent;
  1179. //newShanchu.FlatAppearance.MouseDownBackColor = Color.Transparent;
  1180. newShanchu.FlatAppearance.BorderSize = 0;
  1181. newShanchu.ForeColor = Color.Red;
  1182. newShanchu.UseVisualStyleBackColor = true;
  1183. newShanchu.Click += new System.EventHandler(this.buttonShanchu_Click);
  1184. kongjians.shanchus[rowOfFenlei].Add(newShanchu);
  1185. panel1.Controls.Add(kongjians.shanchus[rowOfFenlei][kongjians.shanchus[rowOfFenlei].Count - 1]);
  1186. PictureBox newPicture = new PictureBox();
  1187. newPicture.Location = new System.Drawing.Point(kongjians.tianjiatupians[rowOfFenlei].Location.X, kongjians.tianjiatupians[rowOfFenlei].Location.Y);
  1188. newPicture.Name = bitNames[i];
  1189. newPicture.Size = new System.Drawing.Size(50, 70);
  1190. newPicture.TabIndex = 1;
  1191. newPicture.TabStop = false;
  1192. //panel1.Controls.Add(newPicture);
  1193. newPicture.Image = bitmaps[i];
  1194. newPicture.SizeMode = PictureBoxSizeMode.Zoom;
  1195. kongjians.pictureBoxes[rowOfFenlei].Add(newPicture);
  1196. panel1.Controls.Add(kongjians.pictureBoxes[rowOfFenlei][kongjians.pictureBoxes[rowOfFenlei].Count - 1]);
  1197. pictures[rowOfFenlei].Add(bitmaps[i]);
  1198. pictureNames[rowOfFenlei].Add(bitNames[i]);
  1199. picturePathNames[rowOfFenlei].Add(filePathList[i]);
  1200. kongjians.tianjiatupians[rowOfFenlei].Location = new System.Drawing.Point(kongjians.tianjiatupians[rowOfFenlei].Location.X - 70 * 3, kongjians.tianjiatupians[rowOfFenlei].Location.Y + 70);
  1201. kongjians.dividingLines[rowOfFenlei].Location = new System.Drawing.Point(kongjians.dividingLines[rowOfFenlei].Location.X, kongjians.tianjiatupians[rowOfFenlei].Location.Y + kongjians.tianjiatupians[rowOfFenlei].Height + 20);
  1202. kongjians.ResetControlPosition(rowOfFenlei);
  1203. counts[rowOfFenlei]++;
  1204. }
  1205. }
  1206. }
  1207. /// <summary>
  1208. /// 開始測量,顯示測量進度
  1209. /// </summary>
  1210. private void buttonStartMeasuring_Click(object sender, EventArgs e)
  1211. {
  1212. MeasureMaintenanceType measureMaintenanceType = (MeasureMaintenanceType)comboMingcheng.SelectedItem;
  1213. if (measureMaintenanceType == null || measureMaintenanceType.MeasureMaintenanceTreeFourthDataList == null || measureMaintenanceType.MeasureMaintenanceTreeFourthDataList.Count == 0)
  1214. {
  1215. MessageBox.Show(PdnResources.GetString("NewNoMeasurementClassification"));
  1216. return;
  1217. }
  1218. int[] pictureNumber = new int[erjimuluCount];//圖片數量
  1219. int[] yiceliangNumber = new int[erjimuluCount];//已測量圖片數量
  1220. int[] successNumber = new int[erjimuluCount];//已測量圖片數量
  1221. int[] failNumber = new int[erjimuluCount];//已測量圖片數量
  1222. if (infoModel.everyHoleImgName == null) {
  1223. infoModel.everyHoleImgName = new Dictionary<string, List<string>>();
  1224. }
  1225. if (infoModel.everyHoleImgGraphicsList == null)
  1226. {
  1227. infoModel.everyHoleImgGraphicsList = new Dictionary<int, List<GraphicsList>>();
  1228. }
  1229. if (infoModel.everyHoleImgisConductive == null)
  1230. {
  1231. infoModel.everyHoleImgisConductive = new Dictionary<int, List<bool>>();
  1232. }
  1233. if (infoModel.everyHoleImgisFanweibuchang == null)
  1234. {
  1235. infoModel.everyHoleImgisFanweibuchang = new Dictionary<int, List<bool>>();
  1236. }
  1237. if (infoModel.everyHoleImgisErzhichuli == null)
  1238. {
  1239. infoModel.everyHoleImgisErzhichuli = new Dictionary<int, List<bool>>();
  1240. }
  1241. for (int i = 0; i < erjimuluCount; i++)
  1242. {
  1243. pictureNumber[i] = pictures[i].Count;
  1244. yiceliangNumber[i] = 0;
  1245. }
  1246. int hasNoData = 0;
  1247. foreach (var item in pictures)
  1248. {
  1249. if (item.Count == 0)
  1250. {
  1251. hasNoData++;
  1252. }
  1253. }
  1254. //判斷第一個分類是否爲空
  1255. if (hasNoData == pictures.Count)
  1256. {
  1257. MessageBox.Show(PdnResources.GetString("NoClassificationImage"));
  1258. }
  1259. else
  1260. {
  1261. for (int i = 0; i < pictures.Count; i++)
  1262. {
  1263. everyHoleImg[(everyHoleImg.Keys.ToList())[i]].Clear();
  1264. if (infoModel.everyHoleImgName.ContainsKey((everyHoleImg.Keys.ToList())[i]))
  1265. {
  1266. infoModel.everyHoleImgName[(everyHoleImg.Keys.ToList())[i]].Clear(); ;
  1267. }
  1268. if (infoModel.everyHoleImgGraphicsList.ContainsKey(i))
  1269. {
  1270. infoModel.everyHoleImgGraphicsList[i].Clear(); ;
  1271. }
  1272. if (infoModel.everyHoleImgisConductive.ContainsKey(i))
  1273. {
  1274. infoModel.everyHoleImgisConductive[i].Clear(); ;
  1275. }
  1276. if (infoModel.everyHoleImgisFanweibuchang.ContainsKey(i))
  1277. {
  1278. infoModel.everyHoleImgisFanweibuchang[i].Clear(); ;
  1279. }
  1280. if (infoModel.everyHoleImgisErzhichuli.ContainsKey(i))
  1281. {
  1282. infoModel.everyHoleImgisErzhichuli[i].Clear(); ;
  1283. }
  1284. var list = new List<GraphicsList>();
  1285. var list1 = new List<bool>();
  1286. var listFanweibuchang = new List<bool>();
  1287. var listErzhichuli = new List<bool>();
  1288. for (int j = 0; j < pictures[i].Count; j++)
  1289. {
  1290. Mat image = OpenCvSharp.Extensions.BitmapConverter.ToMat(pictures[i][j]);
  1291. everyHoleImg[(everyHoleImg.Keys.ToList())[i]].Add(image);
  1292. if (infoModel.everyHoleImgName.ContainsKey((everyHoleImg.Keys.ToList())[i]))
  1293. {
  1294. infoModel.everyHoleImgName[(everyHoleImg.Keys.ToList())[i]].Add(pictureNames[i][j]);
  1295. }
  1296. else
  1297. {
  1298. infoModel.everyHoleImgName.Add((everyHoleImg.Keys.ToList())[i], new List<string>() { pictureNames[i][j] });
  1299. }
  1300. list.Add(new GraphicsList());
  1301. if (measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].FatherHoleTypeId == "9")
  1302. {
  1303. list1.Add(measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].isConductiveCloth);
  1304. }
  1305. else {
  1306. list1.Add(false);
  1307. }
  1308. if (measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].FatherHoleTypeId == "10"
  1309. && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].HoleTypeId == "100300")
  1310. {
  1311. listFanweibuchang.Add(measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].isFanweibuchang);
  1312. }
  1313. else
  1314. {
  1315. listFanweibuchang.Add(false);
  1316. }
  1317. if (true && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].FatherHoleTypeId == "7"
  1318. && measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].HoleTypeId == "100176")
  1319. {
  1320. listErzhichuli.Add(measureMaintenanceType.MeasureMaintenanceTreeFourthDataList[i].isErzhichuli);
  1321. }
  1322. else
  1323. {
  1324. listErzhichuli.Add(false);
  1325. }
  1326. }
  1327. if (everyHoleImgGraphicsList.ContainsKey(i))
  1328. {
  1329. List<GraphicsList> newGraphicsList = new List<GraphicsList>();
  1330. for (int k = 0; k < everyHoleImgGraphicsList[i].Count; k++)
  1331. {
  1332. GraphicsList graphicsList = new GraphicsList();
  1333. graphicsList.graphicsList = everyHoleImgGraphicsList[i][k].graphicsList;
  1334. newGraphicsList.Add(graphicsList);
  1335. }
  1336. if (infoModel.everyHoleImgGraphicsList.ContainsKey(i))
  1337. {
  1338. infoModel.everyHoleImgGraphicsList[i].AddRange(newGraphicsList);
  1339. }
  1340. else
  1341. {
  1342. infoModel.everyHoleImgGraphicsList.Add(i, newGraphicsList);
  1343. }
  1344. }
  1345. else
  1346. {
  1347. if (infoModel.everyHoleImgGraphicsList.ContainsKey(i))
  1348. {
  1349. infoModel.everyHoleImgGraphicsList[i].AddRange(list);
  1350. }
  1351. else
  1352. {
  1353. infoModel.everyHoleImgGraphicsList.Add(i,list);
  1354. }
  1355. }
  1356. if (everyHoleImgisConductive.ContainsKey(i))
  1357. {
  1358. if (infoModel.everyHoleImgisConductive.ContainsKey(i))
  1359. {
  1360. infoModel.everyHoleImgisConductive[i].AddRange(everyHoleImgisConductive[i]);
  1361. }
  1362. else
  1363. {
  1364. infoModel.everyHoleImgisConductive.Add(i, everyHoleImgisConductive[i]);
  1365. }
  1366. }
  1367. else
  1368. {
  1369. if (infoModel.everyHoleImgisConductive.ContainsKey(i))
  1370. {
  1371. infoModel.everyHoleImgisConductive[i].AddRange(list1);
  1372. }
  1373. else
  1374. {
  1375. infoModel.everyHoleImgisConductive.Add(i, list1);
  1376. }
  1377. }
  1378. if (everyHoleImgisFanweibuchang.ContainsKey(i))
  1379. {
  1380. if (infoModel.everyHoleImgisFanweibuchang.ContainsKey(i))
  1381. {
  1382. infoModel.everyHoleImgisFanweibuchang[i].AddRange(everyHoleImgisFanweibuchang[i]);
  1383. }
  1384. else
  1385. {
  1386. infoModel.everyHoleImgisFanweibuchang.Add(i, everyHoleImgisFanweibuchang[i]);
  1387. }
  1388. }
  1389. else
  1390. {
  1391. if (infoModel.everyHoleImgisFanweibuchang.ContainsKey(i))
  1392. {
  1393. infoModel.everyHoleImgisFanweibuchang[i].AddRange(listFanweibuchang);
  1394. }
  1395. else
  1396. {
  1397. infoModel.everyHoleImgisFanweibuchang.Add(i, listFanweibuchang);
  1398. }
  1399. }
  1400. if (everyHoleImgisErzhichuli.ContainsKey(i))
  1401. {
  1402. if (infoModel.everyHoleImgisErzhichuli.ContainsKey(i))
  1403. {
  1404. infoModel.everyHoleImgisErzhichuli[i].AddRange(everyHoleImgisErzhichuli[i]);
  1405. }
  1406. else
  1407. {
  1408. infoModel.everyHoleImgisErzhichuli.Add(i, everyHoleImgisErzhichuli[i]);
  1409. }
  1410. }
  1411. else
  1412. {
  1413. if (infoModel.everyHoleImgisErzhichuli.ContainsKey(i))
  1414. {
  1415. infoModel.everyHoleImgisErzhichuli[i].AddRange(listErzhichuli);
  1416. }
  1417. else
  1418. {
  1419. infoModel.everyHoleImgisErzhichuli.Add(i, listErzhichuli);
  1420. }
  1421. }
  1422. }
  1423. infoModel.pictureNumber = pictureNumber;
  1424. infoModel.yiceliangNumber = yiceliangNumber;
  1425. infoModel.failNumber = failNumber;
  1426. infoModel.successNumber = successNumber;
  1427. infoModel.text = erjimulusName;
  1428. infoModel.everyHoleImg = everyHoleImg;
  1429. measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue = textLiaohao.Text;//料號
  1430. measureMaintenanceType.measureMaintenanceBasicDataList[1].measureMaintenanceBasicDataValue = comboBanci.SelectedItem == null ? "" : comboBanci.SelectedItem.ToString();//班次
  1431. measureMaintenanceType.measureMaintenanceBasicDataList[2].measureMaintenanceBasicDataValue = comboShiyanshi.SelectedItem == null ? "" : comboShiyanshi.SelectedItem.ToString();//實驗室
  1432. measureMaintenanceType.measureMaintenanceBasicDataList[3].measureMaintenanceBasicDataValue = comboShiyongchangqu.SelectedItem == null ? "" : comboShiyongchangqu.SelectedItem.ToString();//使用廠區
  1433. measureMaintenanceType.measureMaintenanceBasicDataList[4].measureMaintenanceBasicDataValue = comboZhichengbie.SelectedItem == null ? "" : comboZhichengbie.SelectedItem.ToString();//製成別
  1434. measureMaintenanceType.measureMaintenanceBasicDataList[5].measureMaintenanceBasicDataValue = textDanhao.Text;//單號
  1435. measureMaintenanceType.measureMaintenanceBasicDataList[6].measureMaintenanceBasicDataValue = textPihao.Text;//批號
  1436. measureMaintenanceType.measureMaintenanceBasicDataList[7].measureMaintenanceBasicDataValue = comboCengbie.SelectedItem == null ? "" : comboCengbie.SelectedItem.ToString();//層別
  1437. measureMaintenanceType.measureMaintenanceBasicDataList[8].measureMaintenanceBasicDataValue = comboDianduxianbie.Text;//電鍍綫別
  1438. measureMaintenanceType.measureMaintenanceBasicDataList[9].measureMaintenanceBasicDataValue = label12.Text;//單位
  1439. string filePath = string.Empty;
  1440. foreach (var item in picturePathNames) {
  1441. if (item.Count == 0) {
  1442. continue;
  1443. }
  1444. filePath = item[0];
  1445. break;
  1446. }
  1447. if (measureMaintenanceTreeData == null)
  1448. {
  1449. string filePathA = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureMaintenanceType\\";
  1450. var fileName = comboMingcheng.Text;
  1451. filePathA = $"{filePathA}{fileName}.xml";
  1452. if (System.IO.File.Exists(filePathA))
  1453. {
  1454. measureMaintenanceTreeData = XmlSerializeHelper.DESerializer<MeasureMaintenanceTreeData>(FileOperationHelper.ReadStringFromFile(filePathA, FileMode.Open));
  1455. }
  1456. }
  1457. MeasureMaintenanceTreeSpecificData data;
  1458. this.appWorkspace.RecursionGetData("100000", measureMaintenanceTreeData.MeasureMaintenanceTreeDataList, out data);
  1459. if (_listHoleTypePos.ContainsKey("100000"))
  1460. {
  1461. _listHoleTypePos["100000"] = data.MeasureMaintenanceTreeSpecificIsPos;
  1462. }
  1463. else {
  1464. _listHoleTypePos.Add("100000", data.MeasureMaintenanceTreeSpecificIsPos);
  1465. }
  1466. this.appWorkspace.RecursionGetData("100013", measureMaintenanceTreeData.MeasureMaintenanceTreeDataList, out data);
  1467. if (_listHoleTypePos.ContainsKey("100013"))
  1468. {
  1469. _listHoleTypePos["100013"] = data.MeasureMaintenanceTreeSpecificIsPos;
  1470. }
  1471. else
  1472. {
  1473. _listHoleTypePos.Add("100013", data.MeasureMaintenanceTreeSpecificIsPos);
  1474. }
  1475. this.appWorkspace.RecursionGetData("100031", measureMaintenanceTreeData.MeasureMaintenanceTreeDataList, out data);
  1476. if (_listHoleTypePos.ContainsKey("100031"))
  1477. {
  1478. _listHoleTypePos["100031"] = data.MeasureMaintenanceTreeSpecificIsPos;
  1479. }
  1480. else
  1481. {
  1482. _listHoleTypePos.Add("100031", data.MeasureMaintenanceTreeSpecificIsPos);
  1483. }
  1484. BeingExecuted from3 = new BeingExecuted(infoModel,appWorkspace, _listHoleType, measureMaintenanceType, this.pidRuleDic, filePath, _listHoleTypePos);
  1485. from3.ShowDialog();
  1486. }
  1487. }
  1488. private void ReadXml2()
  1489. {
  1490. XmlDocument xDoc = new XmlDocument();
  1491. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicInformation.xml";
  1492. if (System.IO.File.Exists(filePath))
  1493. {
  1494. xDoc.Load(filePath);
  1495. }
  1496. else
  1497. {
  1498. XmlDeclaration declaration = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
  1499. xDoc.AppendChild(declaration);
  1500. //根结点
  1501. XmlElement genjiedian = xDoc.CreateElement("leixings");
  1502. xDoc.AppendChild(genjiedian);
  1503. //规程结点
  1504. for (int i = 0; i < 6; i++)
  1505. {
  1506. XmlElement leixing = xDoc.CreateElement("類型");
  1507. genjiedian.AppendChild(leixing);
  1508. }
  1509. xDoc.Save(filePath);
  1510. }
  1511. XmlNode rootNode = xDoc.SelectSingleNode("leixings");
  1512. XmlNodeList leixingList = rootNode.ChildNodes;
  1513. for (int i = 0; i < leixingList.Count; i++)
  1514. {
  1515. XmlNodeList leixingChild = leixingList[i].ChildNodes;
  1516. List<string> strList = new List<string>();
  1517. for (int j = 0; j < leixingChild.Count; j++)
  1518. {
  1519. string mingcheng = leixingChild[j].InnerText;
  1520. strList.Add(mingcheng);
  1521. }
  1522. switch (i)
  1523. {
  1524. case 0:
  1525. comboShiyongchangqu.DataSource = strList;
  1526. break;
  1527. case 1:
  1528. comboShiyanshi.DataSource = strList;
  1529. break;
  1530. case 2:
  1531. comboCengbie.DataSource = strList;
  1532. break;
  1533. case 3:
  1534. comboZhichengbie.DataSource = strList;
  1535. break;
  1536. case 4:
  1537. comboBanci.DataSource = strList;
  1538. break;
  1539. //case 5:
  1540. // comboDianduxianbie.DataSource = strList;
  1541. // break;
  1542. }
  1543. }
  1544. }
  1545. private void CreatHoleType()
  1546. {
  1547. _listHoleType.Add("100000", "Qianmangkong");
  1548. _listHoleType.Add("100142", "ShuangcengbanYou");
  1549. _listHoleType.Add("100134", "ShuangcengbanZuo");
  1550. _listHoleType.Add("100150", "ShuangcengbanQuan");
  1551. _listHoleType.Add("100103", "SancengbanYou");
  1552. _listHoleType.Add("100093", "SancengbanZuo");
  1553. _listHoleType.Add("100113", "SancengbanQuan");
  1554. _listHoleType.Add("100078", "SicengbanYou");
  1555. _listHoleType.Add("100066", "SicengbanZuo");
  1556. _listHoleType.Add("100090", "SicengbanKongjing");
  1557. _listHoleType.Add("100013", "DancengShenmangkong");
  1558. _listHoleType.Add("100031", "ShuangcengShenmangkong");
  1559. _listHoleType.Add("100167", "DancengShikeyinzi");
  1560. _listHoleType.Add("100171", "ShuangcengShikeyinzi");
  1561. _listHoleType.Add("100209", "Diegou");
  1562. _listHoleType.Add("100198", "GaoduchaZuo");
  1563. _listHoleType.Add("100201", "GaoduchaYou");
  1564. _listHoleType.Add("100204", "GaoduchaQuan");
  1565. _listHoleType.Add("100176", "FanghanMeikaikou");
  1566. _listHoleType.Add("100183", "FanghanYoukaikou");
  1567. _listHoleType.Add("100191", "FanghanShuangmiantong");
  1568. _listHoleType.Add("100300", "Xigao");
  1569. _listHoleType.Add("100305", "XigaoZ");
  1570. }
  1571. private void AutomaticMeasurement_Resize(object sender, EventArgs e)
  1572. {
  1573. panelOutInfo.Controls.Clear();
  1574. OutInfoShow();
  1575. }
  1576. private void AutomaticMeasurement_Load(object sender, EventArgs e)
  1577. {
  1578. //comboMingcheng.SelectedIndex = 14;// 23;// 24;// 19;// 24;// 19;// 17;// 16;// 15;// 14;// 23;// 16;// 15;// 14;// 0;// 23;// 24;// 0;// 16;// 15;// 14;// 19;// 17;// 18;// 19;// 15;// 14;// 19;// 11;// 21;// 11;// 14;// 21;// 8;// 14;// 21;// 8;// 14;// 11;// 10;//通孔双层板(槽孔双层板) 12;
  1579. }
  1580. /// <summary>
  1581. ///
  1582. /// </summary>
  1583. public void getList(Dictionary<int, GraphicsList> dataList,int index)
  1584. {
  1585. if (everyHoleImgGraphicsList.ContainsKey(index))
  1586. {
  1587. everyHoleImgGraphicsList[index].Clear();
  1588. for (int i = 0; i < dataList.Keys.Count; i++)
  1589. if (dataList.ContainsKey(i))
  1590. everyHoleImgGraphicsList[index].Add(dataList[i]);
  1591. else
  1592. everyHoleImgGraphicsList[index].Add(new GraphicsList());//避免空数据导致的后续bug: should never go here!
  1593. }
  1594. else {
  1595. List<GraphicsList> list = new List<GraphicsList>();
  1596. for (int i = 0; i < dataList.Keys.Count; i++)
  1597. if (dataList.ContainsKey(i))
  1598. list.Add(dataList[i]);
  1599. else
  1600. list.Add(new GraphicsList());//避免空数据导致的后续bug: should never go here!
  1601. everyHoleImgGraphicsList.Add(index, list);
  1602. }
  1603. }
  1604. public void getBoolList(Dictionary<int, bool> dataList, int index)
  1605. {
  1606. if (everyHoleImgisConductive.ContainsKey(index))
  1607. {
  1608. everyHoleImgisConductive[index].Clear();
  1609. for (int i = 0; i < dataList.Keys.Count; i++)
  1610. if (dataList.ContainsKey(i))
  1611. everyHoleImgisConductive[index].Add(dataList[i]);
  1612. else
  1613. everyHoleImgisConductive[index].Add(false);//避免空数据导致的后续bug: should never go here!
  1614. }
  1615. else
  1616. {
  1617. List<bool> list = new List<bool>();
  1618. for (int i = 0; i < dataList.Keys.Count; i++)
  1619. if (dataList.ContainsKey(i))
  1620. list.Add(dataList[i]);
  1621. else
  1622. list.Add(false);//避免空数据导致的后续bug: should never go here!
  1623. everyHoleImgisConductive.Add(index, list);
  1624. }
  1625. }
  1626. public void getIsFanweibuchangList(Dictionary<int, bool> dataList, int index)
  1627. {
  1628. if (everyHoleImgisFanweibuchang.ContainsKey(index))
  1629. {
  1630. everyHoleImgisFanweibuchang[index].Clear();
  1631. for (int i = 0; i < dataList.Keys.Count; i++)
  1632. if (dataList.ContainsKey(i))
  1633. everyHoleImgisFanweibuchang[index].Add(dataList[i]);
  1634. else
  1635. everyHoleImgisFanweibuchang[index].Add(false);//避免空数据导致的后续bug: should never go here!
  1636. }
  1637. else
  1638. {
  1639. List<bool> list = new List<bool>();
  1640. for (int i = 0; i < dataList.Keys.Count; i++)
  1641. if (dataList.ContainsKey(i))
  1642. list.Add(dataList[i]);
  1643. else
  1644. list.Add(false);//避免空数据导致的后续bug: should never go here!
  1645. everyHoleImgisFanweibuchang.Add(index, list);
  1646. }
  1647. }
  1648. public void getIsErzhichuliList(Dictionary<int, bool> dataList, int index)
  1649. {
  1650. if (everyHoleImgisErzhichuli.ContainsKey(index))
  1651. {
  1652. everyHoleImgisErzhichuli[index].Clear();
  1653. for (int i = 0; i < dataList.Keys.Count; i++)
  1654. if (dataList.ContainsKey(i))
  1655. everyHoleImgisErzhichuli[index].Add(dataList[i]);
  1656. else
  1657. everyHoleImgisErzhichuli[index].Add(false);//避免空数据导致的后续bug: should never go here!
  1658. }
  1659. else
  1660. {
  1661. List<bool> list = new List<bool>();
  1662. for (int i = 0; i < dataList.Keys.Count; i++)
  1663. if (dataList.ContainsKey(i))
  1664. list.Add(dataList[i]);
  1665. else
  1666. list.Add(false);//避免空数据导致的后续bug: should never go here!
  1667. everyHoleImgisErzhichuli.Add(index, list);
  1668. }
  1669. }
  1670. private void buttonCancelMeasurement_Click(object sender, EventArgs e)
  1671. {
  1672. this.Close();
  1673. }
  1674. private void textDanhao_KeyUp(object sender, KeyEventArgs e)
  1675. {
  1676. if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
  1677. {
  1678. if (!Program.instance.configModel.autoDownload)
  1679. {
  1680. return;
  1681. }
  1682. string singleNumber = this.textDanhao.Text;
  1683. string userName = Program.instance.configModel.UserName;
  1684. string passWord = Program.instance.configModel.PassWord;
  1685. string equId = Program.instance.configModel.EquId;
  1686. string groupId = Program.instance.configModel.GroupId;
  1687. string funId = Program.instance.configModel.FunId4;
  1688. GetDataModel getDataModel = new GetDataModel();
  1689. try
  1690. {
  1691. var result = webServiceDll.ws.getDataFromSer(userName, passWord, equId, groupId, funId, singleNumber, System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  1692. if (result.Tables.Count > 0)
  1693. {
  1694. if (result.Tables[0].Rows.Count > 0)
  1695. {
  1696. getDataModel.dianDu = result.Tables[0].Rows[0]["v_opendep"].ToString();
  1697. getDataModel.liaoHao = result.Tables[0].Rows[0]["v_material"].ToString();
  1698. getDataModel.piHao = result.Tables[0].Rows[0]["v_product_num"].ToString();
  1699. }
  1700. }
  1701. }
  1702. catch (Exception ex)
  1703. {
  1704. writeLog(ex.Message, "下拉接口错误");
  1705. }
  1706. textLiaohao.Text = getDataModel.liaoHao;
  1707. textPihao.Text = getDataModel.piHao;
  1708. comboDianduxianbie.Text = getDataModel.dianDu;
  1709. }
  1710. }
  1711. private void writeLog(string error, string typeName = "")
  1712. {
  1713. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\ErrorLog";
  1714. if (!Directory.Exists(filePath))
  1715. {
  1716. Directory.CreateDirectory(filePath);
  1717. }
  1718. using (StreamWriter sw = new StreamWriter(filePath + "\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + typeName + "log.txt"))
  1719. {
  1720. sw.WriteLine(error);
  1721. }
  1722. }
  1723. }
  1724. }