| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915 | using Microsoft.Office.Core;using OpenCvSharp;using Resources;using SmartCoalApplication.Annotation;using SmartCoalApplication.Annotation.Enum;using SmartCoalApplication.Annotation.Measure;using SmartCoalApplication.AutomaticMeasurement.Model;using SmartCoalApplication.Base;using SmartCoalApplication.Base.AutoMeasure;using SmartCoalApplication.Base.CommTool;using SmartCoalApplication.Base.FunctionModel;using SmartCoalApplication.Base.MeasureModel;using SmartCoalApplication.Core;using SmartCoalApplication.Core.CustomControl;using SmartCoalApplication.Core.DbOpreate.DbModel;using SmartCoalApplication.PluginAssemblys;using SmartCoalApplication.Resources;using SPCwebServiceDll;using System;using System.Collections.Generic;using System.Data;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.Dynamic;using System.IO;using System.Linq;using System.Reflection;using System.Text.RegularExpressions;using System.Windows.Forms;using static SmartCoalApplication.AutomaticMeasurement.Model.SpcApiSchemesModel;using Excel = Microsoft.Office.Interop.Excel;namespace SmartCoalApplication.AutomaticMeasurement{    public partial class ResultsView : PdnBaseForm    {        /// <summary>        /// 分析结果图集合        /// </summary>        private List<MeasureInfoResultModel> resultMatList = new List<MeasureInfoResultModel>();        /// <summary>        /// 分析结果图集合        /// </summary>        private List<MeasureInfoResultModel> realResultMatList = new List<MeasureInfoResultModel>();        private MeasureInfoModel infoModel = new MeasureInfoModel();        /// <summary>        /// 图像面板        /// </summary>        private DocumentWorkspaceWindow documentWorkspace;        private Bitmap bitmap;        private AppWorkspace appWorkspace;        private CommonControlButtons commonControlButtons;        private int selectedNum = 0;        private MeasureMaintenanceType measureMaintenanceType;        private MeasureMaintenanceTreeData measureMaintenanceTypeList;        private Dictionary<string, Dictionary<string, double>> pidRuleDic;        private Dictionary<string, List<string>> LineShowDic = new Dictionary<string, List<string>>();        private int successNum = 0;        private int failNum = 0;        private string filePath;        private Dictionary<int, GraphicsList> graphicsListDic = new Dictionary<int, GraphicsList>();        //像素跟踪窗口        private PixelTrackingDialog pixelTrackingDialog;        private bool pixelTrackingEnabled = false;        /// <summary>        /// hint 提示信息        /// </summary>        private ToolTip toolTip;        /// <summary>        /// SPC接口 字段配置方案        /// </summary>        private SpcApiSchemesModel spcApiSchemesModel = new SpcApiSchemesModel();        /// <summary>        /// 公式符号        /// </summary>        private string[] symbolArray = new string[] { "+", "-", "*", "/" };        private Dictionary<string, string> _listHoleType;        private NameRuleListDetails thisNameRuleListDetails;        private bool isSPCItemNull = false;        private List<MeasureInfoResultModel> hasDelResultMatList = new List<MeasureInfoResultModel>();        /// <summary>        /// 辅助线的横线和竖线        /// </summary>        private GraphicsPath path, path1;        internal ResultsView(MeasureInfoModel infoModel, List<MeasureInfoResultModel> measureInfoResultModels, AppWorkspace appWorkspace, BeingExecuted beingExecuted, Dictionary<string, string> _listHoleType)        {            this.resultMatList.AddRange(measureInfoResultModels);            this.realResultMatList.AddRange(measureInfoResultModels);            this.infoModel = infoModel;            InitializeComponent();            InitializeComponent2();            this._listHoleType = _listHoleType;            this.FormClosing += new FormClosingEventHandler(ResultsViewClosing);            this.comboStatus.Items.AddRange(new object[] {            PdnResources.GetString("NewWhole"),            PdnResources.GetString("NewNormal"),            PdnResources.GetString("NewAbnormal")});            InitializeCombo();            this.Icon = PdnInfo.AppIcon;            this.filePath = beingExecuted.filePath;            this.measureMaintenanceType = beingExecuted.measureMaintenanceType;            this.pidRuleDic = beingExecuted.pidRuleDic;            #region [组织应该展示的线 去除不应该展示的线]            foreach (var item in this.measureMaintenanceType.MeasureMaintenanceTreeFourthDataList)            {                if (this.LineShowDic.ContainsKey(item.HoleTypeId))                {                    foreach (var item2 in item.FormulaExpressionLineID)                    {                        if (!this.LineShowDic[item.HoleTypeId].Contains(item2))                        {                            this.LineShowDic[item.HoleTypeId].Add(item2);                        }                    }                }                else                {                    List<string> list = new List<string>();                    foreach (var item2 in item.FormulaExpressionLineID)                    {                        if (!list.Contains(item2))                        {                            list.Add(item2);                        }                    }                    this.LineShowDic.Add(item.HoleTypeId, list);                }            }            foreach (var item in resultMatList)            {                List<DataInfor> removeList = new List<DataInfor>();                if (this.LineShowDic.ContainsKey(item.parentId))                {                    foreach (var item2 in item.dataInforList)                    {                        if (!this.LineShowDic[item.parentId].Contains(item2.ID))                        {                            removeList.Add(item2);                        }                    }                    foreach (var item2 in removeList)                    {                        item.dataInforList.Remove(item2);                    }                }            }            #endregion [组织应该展示的线 去除不应该展示的线]            measureInfoResultModels.Clear();            beingExecuted.Close();            beingExecuted.Dispose();            infoModel = null;            GC.Collect();            this.appWorkspace = appWorkspace;            #region [搜索项下拉选]            string filePath;            if (Program.instance.configModel.Language == 1)            {                filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicTreeDataSimple.xml";            }            else            {                filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicTreeDataTraditional.xml";            }            if (System.IO.File.Exists(filePath))            {                MeasureMaintenanceTreeSpecificData measureMaintenanceTreeSpecificData = new MeasureMaintenanceTreeSpecificData();                measureMaintenanceTreeSpecificData.MeasureMaintenanceTreeSpecificDataId = "0";                measureMaintenanceTreeSpecificData.MeasureMaintenanceTreeSpecificName = "全部";                List<MeasureMaintenanceTreeSpecificData> measureMaintenanceTypes = new List<MeasureMaintenanceTreeSpecificData>() { measureMaintenanceTreeSpecificData };                measureMaintenanceTypeList = XmlSerializeHelper.DESerializer<MeasureMaintenanceTreeData>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));                var selectedList = resultMatList.GroupBy(m => m.parentId);                foreach (var item in selectedList)                {                    MeasureMaintenanceTreeSpecificData sonData;                    this.appWorkspace.RecursionGetData(item.Key, measureMaintenanceTypeList.MeasureMaintenanceTreeDataList, out sonData);                    if (sonData != null)                    {                        measureMaintenanceTypes.Add(sonData);                    }                }                this.comboClassification.SelectedIndexChanged -= new System.EventHandler(this.comboClassification_SelectedIndexChanged);                comboClassification.DataSource = measureMaintenanceTypes;                comboClassification.DisplayMember = "MeasureMaintenanceTreeSpecificName";                this.comboClassification.SelectedIndexChanged += new System.EventHandler(this.comboClassification_SelectedIndexChanged);            }            #endregion [搜索项下拉选]            #region [图片集合初始化]            InitPicList();            #endregion [图片集合初始化]            #region [图像面板相关]            //            //初始化图像控件            //            this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace, 1);            this.documentWorkspace.Cursor = Cursors.Default;            this.documentWorkspace.Dock = DockStyle.Fill;            //this.documentWorkspace.HookMouseEvents();            this.documentWorkspace.Visible = true;            //this.documentWorkspace.panel.Click += new EventHandler(this.documentWorkspace_panel_Click);            //this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.documentWorkspace_panel_MouseDown);            //this.documentWorkspace.panel.Paint += new PaintEventHandler(this.panelPaint);            this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.documentWorkspace_panel_MouseMove);            this.documentWorkspace.panel.MouseWheel += new MouseEventHandler(this.documentWorkspace_panel_MouseWheel);            this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.documentWorkspace_panel_MouseUp);            this.groupBox4.Controls.Add(this.documentWorkspace);            PdnBaseForm.RegisterFormHotKey(Keys.Delete, OnDeleteHotKeyPressed);            #endregion [图像面板相关]            this.commonControlButtons = new CommonControlButtons(this.documentWorkspace.Width - 25);            this.commonControlButtons.Dock = DockStyle.Top;            this.commonControlButtons.Height = 30;            this.commonControlButtons.HideZoomToWindowAndActualSize();            this.commonControlButtons.ShowRight();            this.groupBox4.Controls.Add(commonControlButtons);            InitCommonButtonEvent();            label3.Visible = false;            label4.Visible = false;            label5.Visible = false;            this.Resize += new EventHandler(DialogResize);            this.Shown += new EventHandler(shownMethod);            this.toolTip = new ToolTip();            var oldNameRuleListDetails = Program.instance.fileNameRule.NameRuleList.Where(m => m.ID == this.measureMaintenanceType.NameRuleID).FirstOrDefault();            this.yuLan(oldNameRuleListDetails);        }        public void yuLan(NameRuleListDetails nameRuleListDetails)         {            if (nameRuleListDetails == null)             {                this.textBox5.Text = DateTime.Now.ToString("yyyyMMddhhmmss") + "切片报告.xls";                return;            }            string ruleName = string.Empty;            string ruleGain = string.Empty;            if (this.measureMaintenanceType.ruleMessage != null)            {                ruleName = this.measureMaintenanceType.ruleMessage.ruleName;                ruleGain = this.measureMaintenanceType.ruleMessage.ruleGain.ToString();            }            else            {                List<mic_rulers> list = Program.instance.mic_rulersAll;                var ruler = list.Where(m => m.id.Equals(Program.instance.configModel.RulerId)).FirstOrDefault();                if (ruler != null)                {                    ruleName = ruler.ruler_name;                    ruleGain = ruler.gain_multiple.ToString();                }            }            NamingRuleHelper namingRuleHelper = new NamingRuleHelper();            this.textBox5.Text = namingRuleHelper.GetNameFromXml(nameRuleListDetails, ruleName, ruleGain, this.measureMaintenanceType, "") + ".xls";        }        private void ResultsViewClosing(object sender, FormClosingEventArgs e)        {            this.realResultMatList.Clear();            this.resultMatList.Clear();            this.hasDelResultMatList.Clear();            GC.Collect();        }        private void InitializeComponent2()        {            this.Text = PdnResources.GetString("NewResultsView");            this.groupBox1.Text = PdnResources.GetString("NewOperation");            this.checkBox2.Text = PdnResources.GetString("NewDisplayDrawingRange");            this.checkBox1.Text = PdnResources.GetString("NewOpenReport");            this.checkBox3.Text = PdnResources.GetString("ResultView.checkBox3"); // 开启像素追踪            this.button1.Text = PdnResources.GetString("ResultView.button1"); // 再次分析            this.button2.Text = PdnResources.GetString("ResultView.button2"); // 绘制范围            this.button3.Text = PdnResources.GetString("ResultView.button3"); // 全选            this.button4.Text = PdnResources.GetString("ResultView.button4"); // 全不选            this.button5.Text = PdnResources.GetString("ResultView.button5"); // 反选            this.button6.Text = PdnResources.GetString("ResultView.button6"); // 命名规则            this.buttonGenerateReport.Text = PdnResources.GetString("NewGenerateReport"); // 生成报告            this.label2.Text = PdnResources.GetString("NewStatus") + ":";            this.label1.Text = PdnResources.GetString("NewClassification") + ":";            this.groupBox2.Text = PdnResources.GetString("Newlist");            this.groupBox3.Text = PdnResources.GetString("NewAddSketchLine");            this.groupBox4.Text = PdnResources.GetString("NewPicture");            this.checkBox4.Text = PdnResources.GetString("ResultView.checkBox4");            this.button7.Text = PdnResources.GetString("NewSelectTemplate");        }        private void documentWorkspace_panel_MouseWheel(object sender, MouseEventArgs e)        {        }        private void shownMethod(object sender, EventArgs e)        {            #region [默认选中]            int choose = 0;            foreach (var item in this.resultMatList)            {                if (item.dataInforList.Where(m => m.value == 0).ToList().Count() > 0)                {                    choose = this.resultMatList.IndexOf(item);                    break;                }            }            if (this.listView1.Items.Count > 0)            {                this.listView1.Focus();                //滚动到指定的行位置                this.listView1.EnsureVisible(choose);                this.listView1.Items[choose].Focused = true;                this.listView1.Items[choose].Selected = true;                if (choose == 0)                {                    listView1_SelectedIndexChanged(null, null);                }            }            #endregion [默认选中]        }        private void DialogResize(object sender, EventArgs e)        {            this.commonControlButtons.reset(this.documentWorkspace.Width - 25);        }        private bool OnDeleteHotKeyPressed(Keys keys)        {            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return false;            }            if (this.listView1.SelectedItems.Count > 1) {                var index = this.listView1.SelectedItems[0].Index;                this.listView1.Items[index].Focused = true;            }            if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)            {                string id = this.listView1.FocusedItem.Tag.ToString();                var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();                int index = 0;                if (result != null)                 {                    index = this.resultMatList.IndexOf(result);                }                if (this.documentWorkspace.GraphicsList != null && this.documentWorkspace.GraphicsList.Count > 0)                {                    var list = this.resultMatList[index].dataInforList.Where(m => m.deleteFlag == 2).ToList();                    for (int i = this.documentWorkspace.GraphicsList.Count - 1; i >= 0; i--)                    {                        if (this.documentWorkspace.GraphicsList[i].objectType != DrawClass.Measure)                        {                            continue;                        }                        if (this.documentWorkspace.GraphicsList[i].Selected == true)                        {                            var data = list.Where(m => m.aliasName == ((MeasureDrawObject)this.documentWorkspace.GraphicsList[i]).aliasName).FirstOrDefault();                            if (data != null)                            {                                int dataIndex = list.IndexOf(data);                                list[dataIndex].value = 0;                                list[dataIndex].deleteFlag = 1;                                list[dataIndex].point1 = new System.Drawing.Point(0, 0);                                list[dataIndex].point2 = new System.Drawing.Point(0, 0);                                this.documentWorkspace.GraphicsList.RemoveObj(this.documentWorkspace.GraphicsList[i]);                            }                        }                    }                    InitButtonList();                }                this.successNum = this.resultMatList[index].dataInforList.Where(m => m.value != 0).Count();                this.failNum = this.resultMatList[index].dataInforList.Where(m => m.value == 0).Count();                label4.Text = $"已绘制{this.successNum}条";                label5.Text = $"剩余{this.failNum}条";                #region [重置列表]                //this.imageList1.Images.Clear();                //this.listView1.Items.Clear();                //InitPicList();                //this.listView1.Focus();                ////滚动到指定的行位置                //this.listView1.EnsureVisible(index);                //this.listView1.Items[index].Focused = true;                //this.listView1.Items[index].Selected = true;                this.listView1.Items[index].BackColor = this.resultMatList[index].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                this.listView1.Refresh();                #endregion [重置列表]                this.documentWorkspace.Refresh();            }            return true;        }        #region 公共按钮        private void InitCommonButtonEvent()        {            this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);            this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);            this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);            this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);            this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);            this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);            this.commonControlButtons.zoomInFirst.Click += new EventHandler(zoomInFirst_Click);            this.commonControlButtons.zoomInLast.Click += new EventHandler(zoomInLast_Click);            this.commonControlButtons.zoomInNext.Click += new EventHandler(zoomInNext_Click);            this.commonControlButtons.zoomInZuihou.Click += new EventHandler(zoomInZuihou_Click);        }        private void zoomInFirst_Click(object sender, EventArgs e)        {            if (listView1.Items.Count > 0)            {                listView1.Focus();                listView1.SelectedItems.Clear();                //滚动到指定的行位置                this.listView1.EnsureVisible(0);                this.listView1.Items[0].Focused = true;                this.listView1.Items[0].Selected = true;            }        }        private void zoomInLast_Click(object sender, EventArgs e)        {            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return;            }            if (this.listView1.SelectedItems.Count > 1)            {                var index = this.listView1.SelectedItems[0].Index;                this.listView1.SelectedItems.Clear();                this.listView1.Items[index].Focused = true;                this.listView1.Items[index].Selected = true;            }            if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)            {                int index = this.listView1.FocusedItem.Index;                if (index != 0)                {                    listView1.Focus();                    listView1.SelectedItems.Clear();                    //滚动到指定的行位置                    this.listView1.EnsureVisible(index - 1);                    this.listView1.Items[index - 1].Focused = true;                    this.listView1.Items[index - 1].Selected = true;                }            }        }        private void zoomInNext_Click(object sender, EventArgs e)        {            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return;            }            if (this.listView1.SelectedItems.Count > 1)            {                var index = this.listView1.SelectedItems[this.listView1.SelectedItems.Count - 1].Index;                this.listView1.SelectedItems.Clear();                this.listView1.Items[index].Focused = true;                this.listView1.Items[index].Selected = true;            }            if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)            {                if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)                {                    int index = this.listView1.FocusedItem.Index;                    if (index != this.listView1.Items.Count - 1)                    {                        listView1.Focus();                        listView1.SelectedItems.Clear();                        //滚动到指定的行位置                        this.listView1.EnsureVisible(index + 1);                        this.listView1.Items[index + 1].Focused = true;                        this.listView1.Items[index + 1].Selected = true;                    }                }            }        }        private void zoomInZuihou_Click(object sender, EventArgs e)        {            if (listView1.Items.Count > 0)            {                listView1.Focus();                listView1.SelectedItems.Clear();                //滚动到指定的行位置                this.listView1.EnsureVisible(this.listView1.Items.Count - 1);                this.listView1.Items[this.listView1.Items.Count - 1].Focused = true;                this.listView1.Items[this.listView1.Items.Count - 1].Selected = true;            }        }        private void zoomInButton_Click(object sender, EventArgs e)        {            if (this.bitmap != null)                this.documentWorkspace.ZoomIn();        }        private void zoomOutButton_Click(object sender, EventArgs e)        {            if (this.bitmap != null)                this.documentWorkspace.ZoomOut();        }        private void zoomToWindowButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;        }        private void actualSizeButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;            this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;        }        private void pointerButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;        }        private void mobileModeButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;        }        #endregion 公共按钮        //下拉列表初始化        private void InitializeCombo()        {            this.comboStatus.SelectedIndexChanged -= new System.EventHandler(this.comboStatus_SelectedIndexChanged);            comboStatus.SelectedIndex = 0;            this.comboStatus.SelectedIndexChanged += new System.EventHandler(this.comboStatus_SelectedIndexChanged);        }        public void InitPicList()        {            //初始化图片列表            for (int i = 0; i < this.resultMatList.Count; i++)            {                Mat mat = new Mat();                Cv2.CvtColor(this.resultMatList[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                this.listView1.Items.Add("", i);                this.listView1.Items[i].ImageIndex = i;                this.listView1.Items[i].Tag = this.resultMatList[i].ID;                this.listView1.Items[i].Text = this.resultMatList[i].fileName;                this.listView1.Items[i].BackColor = this.resultMatList[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                mat.Dispose();            }        }        /// <summary>        /// 创建缩略图        /// </summary>        public Bitmap CreateThumbnail(Mat mat)        {            Bitmap origin = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);            Bitmap bitmap;            if (origin.Width > origin.Height)            {                bitmap = MakeThumbnail(origin, 90, 90, "W");            }            else if (origin.Height > origin.Width)            {                bitmap = MakeThumbnail(origin, 90, 90, "H");            }            else            {                bitmap = MakeThumbnail(origin, 90, 90, "W");            }            return bitmap;        }        ///<summary>        /// 生成缩略图        /// </summary>        /// <param name="originalImage">源图片</param>        /// <param name="width">缩略图宽度</param>        /// <param name="height">缩略图高度</param>        /// <param name="mode">生成缩略图的方式</param>        public static Bitmap MakeThumbnail(Image originalImage, int width, int height, string mode)        {            int towidth = width;            int toheight = height;            int x = 0;            int y = 0;            int ow = originalImage.Width;            int oh = originalImage.Height;            switch (mode)            {                case "HW"://指定高宽缩放(可能变形)                    break;                case "W"://指定宽,高按比例                    toheight = originalImage.Height * width / originalImage.Width;                    break;                case "H"://指定高,宽按比例                    towidth = originalImage.Width * height / originalImage.Height;                    break;                case "Cut"://指定高宽裁减(不变形)                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)                    {                        oh = originalImage.Height;                        ow = originalImage.Height * towidth / toheight;                        y = 0;                        x = (originalImage.Width - ow) / 2;                    }                    else                    {                        ow = originalImage.Width;                        oh = originalImage.Width * height / towidth;                        x = 0;                        y = (originalImage.Height - oh) / 2;                    }                    break;                default:                    break;            }            //新建一个bmp图片            Bitmap bitmap = new System.Drawing.Bitmap(towidth, toheight);            //新建一个画板            Graphics g = System.Drawing.Graphics.FromImage(bitmap);            //设置高质量插值法            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;            //设置高质量,低速度呈现平滑程度            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;            //清空画布并以透明背景色填充            g.Clear(Color.Transparent);            //在指定位置并且按指定大小绘制原图片的指定部分            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),             new Rectangle(x, y, ow, oh),             GraphicsUnit.Pixel);            return bitmap;        }        /// <summary>        /// 改变图片选择        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void listView1_SelectedIndexChanged(object sender, EventArgs e)        {            if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)            {                string id = this.listView1.FocusedItem.Tag.ToString();                var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();                int index = 0;                if (result != null)                 {                    index = this.resultMatList.IndexOf(result);                }                label3.Visible = true;                label4.Visible = true;                label5.Visible = true;                Mat mat = new Mat();                Cv2.CvtColor(this.resultMatList[index].resultMat, mat, ColorConversionCodes.BGRA2BGR);                if (pixelTrackingDialog != null)                {                    pixelTrackingDialog.Mat = mat;                }                this.bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);                Document document = Document.FromMat(mat);                this.documentWorkspace.Document = document;                this.documentWorkspace.Visible = true;                label3.Text = $"共{this.resultMatList[index].allLineNum}条输出线";                this.successNum = this.resultMatList[index].dataInforList.Where(m => m.value != 0).Count();                this.failNum = this.resultMatList[index].dataInforList.Where(m => m.value == 0).Count();                label4.Text = $"已绘制{this.successNum}条";                label5.Text = $"剩余{this.failNum}条";                InitButtonList();                #region [往面板上绘制测量线]                this.documentWorkspace.GraphicsList.Clear();                DrawLine(index);                if (checkBox2.Checked)                {                    if (this.resultMatList[index].GraphicsListList.Count > 0)                    {                        this.resultMatList[index].GraphicsListList[0].canMove = false;                        GraphicsList graphicsList = new GraphicsList();                        graphicsList.Add(this.resultMatList[index].GraphicsListList[0].Clone(this.documentWorkspace));                        graphicsList[0].Selected = false;                        this.documentWorkspace.GraphicsList.Add(graphicsList[0]);                    }                    this.documentWorkspace.Refresh();                }                #endregion [往面板上绘制测量线]            }            else            {                label3.Visible = false;                label4.Visible = false;                label5.Visible = false;            }        }        private void DrawLine(int index)        {            var list = this.resultMatList[index].dataInforList;            this.documentWorkspace.GraphicsList.Clear();            List<DrawObject> lines = new List<DrawObject>();            foreach (var item in list)            {                if (item.value == 0)                {                    continue;                }                double unit = 1;                if (this.pidRuleDic.ContainsKey(this.resultMatList[index].parentId))                {                    if (this.pidRuleDic[this.resultMatList[index].parentId].ContainsKey(this.resultMatList[index].fileName))                    {                        unit = this.pidRuleDic[this.resultMatList[index].parentId][this.resultMatList[index].fileName];                    }                }                this.appWorkspace.setUnitNum(unit);                var point1 = item.point1;                var point2 = item.point2;                switch (item.drawType)                {                    case "MeasureLine":                        MeasureLine line = new MeasureLine(this.documentWorkspace, point1, point2, item.aliasName, unit);                        line.moved = true;                        line.ISurfaceBox = this.documentWorkspace;                        lines.Add(line);                        break;                    case "MeasureVLine":                        MeasureVLine vline = new MeasureVLine(this.documentWorkspace, point1, point2, item.aliasName, unit);                        vline.moved = true;                        vline.ISurfaceBox = this.documentWorkspace;                        lines.Add(vline);                        break;                    case "MeasureHLine":                        MeasureHLine hline = new MeasureHLine(this.documentWorkspace, point1, point2,  item.aliasName, unit);                        hline.moved = true;                        hline.ISurfaceBox = this.documentWorkspace;                        lines.Add(hline);                        break;                }            }            this.documentWorkspace.GraphicsList.AddRange(lines);            this.documentWorkspace.GraphicsList.UnselectAll();            this.documentWorkspace.Refresh();        }        /// <summary>        /// 生成失败线的按钮        /// </summary>        private void InitButtonList()        {            this.panel2.Controls.Clear();            string id = this.listView1.FocusedItem.Tag.ToString();                        var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();            int dataIndex = 0;            if (result != null)            {                dataIndex = this.resultMatList.IndexOf(result);            }            var list = this.resultMatList[dataIndex].dataInforList.Where(m => m.value.Equals(0)).ToList();            //var list = this.resultMatList[dataIndex].dataInforList;            int index = 0;            foreach (var item in list)                //for (int i = list.Count - 1; i >= 0; i--)            {                if (item.value.Equals(0))                {                    //int index = list.IndexOf(item);                                        Button button = new Button();                    if (index == 0)                    {                        button.Location = new System.Drawing.Point(17, 35);                    }                    else                    {                        button.Location = new System.Drawing.Point(17, 35 + 23 * index + 10 * index);                    }                    button.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);                    button.Name = item.drawType + (index + 1).ToString();                    button.Size = new System.Drawing.Size(75, 23);                    button.TabIndex = 0;                    button.Tag = item.aliasName;                    if (this.resultMatList[dataIndex].parentId.Equals("100209"))                    {                        button.Text = "曡構";                    }                    else                    {                        button.Text = item.name;                    }                    button.UseVisualStyleBackColor = true;                    button.Click += new System.EventHandler(this.buttonShanchu_Click);                    panel2.Controls.Add(button);                    index++;                }                //var item = list[i];                            }        }        private bool checkIsNum(string num)        {            try            {                int strNum = Convert.ToInt32(num);                return true;            }            catch (Exception)            {                return false;            }        }        private void buttonShanchu_Click(object sender, EventArgs e)        {            Button button = (Button)sender;            this.selectedNum = Convert.ToInt32(button.Name.Substring(button.Name.Length - 1, 1));            var drawTypeName = button.Name.Substring(0, button.Name.Length - 1);            if(checkIsNum(drawTypeName.Substring(drawTypeName.Length - 1, 1)))            {                drawTypeName = drawTypeName.Substring(0, drawTypeName.Length - 1);                this.selectedNum = Convert.ToInt32(button.Name.Substring(button.Name.Length - 2, 2));            }            //this.pixelTrackingEnabled = false;            this.appWorkspace.setAliasName(button.Tag.ToString());            switch (drawTypeName)            {                case "MeasureLine":                    this.documentWorkspace.activeTool = DrawToolType.MeasureLine;                    break;                case "MeasureVLine":                    this.documentWorkspace.activeTool = DrawToolType.MeasureVLine;                    break;                case "MeasureHLine":                    this.documentWorkspace.activeTool = DrawToolType.MeasureHLine;                    break;            }        }        private void documentWorkspace_panel_MouseUp(object sender, MouseEventArgs e)        {            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return;            }            if (this.listView1.SelectedItems.Count > 1)            {                var index = this.listView1.SelectedItems[0].Index;                this.listView1.Items[index].Focused = true;            }            if (this.selectedNum == 0)            {                string id = this.listView1.FocusedItem.Tag.ToString();                var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();                int index = 0;                if (result != null)                {                    index = this.resultMatList.IndexOf(result);                }                if (this.documentWorkspace.GraphicsList != null && this.documentWorkspace.GraphicsList.Count > 0)                {                    var list = this.resultMatList[index].dataInforList.Where(m => m.deleteFlag == 2).ToList();                    for (int i = this.documentWorkspace.GraphicsList.Count - 1; i >= 0; i--)                    {                        if (this.documentWorkspace.GraphicsList[i].objectType != DrawClass.Measure)                        {                            continue;                        }                        var data = list.Where(m => m.aliasName == ((MeasureDrawObject)this.documentWorkspace.GraphicsList[i]).aliasName).FirstOrDefault();                        if (data != null)                        {                            MeasureDrawObject measureDrawObject = (MeasureDrawObject)this.documentWorkspace.GraphicsList[i];                            int dataIndex = list.IndexOf(data);                            list[dataIndex].value = measureDrawObject.length;                            list[dataIndex].point1 = new System.Drawing.Point(Convert.ToInt32(measureDrawObject.startPoint.X), Convert.ToInt32(measureDrawObject.startPoint.Y));                            list[dataIndex].point2 = new System.Drawing.Point(Convert.ToInt32(measureDrawObject.endPoint.X), Convert.ToInt32(measureDrawObject.endPoint.Y));                        }                    }                }            }            else            {                string id = this.listView1.FocusedItem.Tag.ToString();                var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();                int dataIndex = 0;                if (result != null)                {                    dataIndex = this.resultMatList.IndexOf(result);                }                var list = this.resultMatList[dataIndex].dataInforList.Where(m => m.value.Equals(0)).ToList();                //var list = this.resultMatList[dataIndex].dataInforList;                if (this.documentWorkspace.GraphicsList.Count == 0)                 {                    return;                }                if(list == null || list.Count == 0)                {                    return;                }                var gra = (DrawObject)this.documentWorkspace.GraphicsList[0];                                DataInfor data = new DataInfor();                data.name = list[this.selectedNum - 1].name;                data.aliasName = list[this.selectedNum - 1].aliasName;                data.point1 = new System.Drawing.Point((int)gra.startPoint.X, (int)gra.startPoint.Y);                data.point2 = new System.Drawing.Point((int)gra.endPoint.X, (int)gra.endPoint.Y);                data.value = gra.length;                data.drawType = list[this.selectedNum - 1].drawType;                data.ID = list[this.selectedNum - 1].ID;                               int index = this.resultMatList[dataIndex].dataInforList.IndexOf(list[this.selectedNum - 1]);                this.resultMatList[dataIndex].dataInforList.RemoveAt(index);                this.resultMatList[dataIndex].dataInforList.Insert(index, data);                if (data.value != 0)                {                    this.selectedNum = 0;                }                this.successNum = this.resultMatList[dataIndex].dataInforList.Where(m => m.value != 0).Count();                this.failNum = this.resultMatList[dataIndex].dataInforList.Where(m => m.value == 0).Count();                label4.Text = $"已绘制{this.successNum}条";                label5.Text = $"剩余{this.failNum}条";                InitButtonList();                //this.imageList1.Images.Clear();                //this.listView1.Items.Clear();                //InitPicList();                //this.listView1.Focus();                ////滚动到指定的行位置                //this.listView1.EnsureVisible(dataIndex);                //this.listView1.Items[dataIndex].Focused = true;                //this.listView1.Items[dataIndex].Selected = true;                this.listView1.Items[dataIndex].BackColor = this.resultMatList[dataIndex].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                this.listView1.Refresh();            }        }        /// <summary>        /// 不可点击空白区域        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void listView1_MouseUp(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)            {                if (listView1.SelectedItems.Count > 0)                {                }                else if (listView1.SelectedItems.Count <= 0)//点击空白区                {                    if (this.listView1.FocusedItem != null)                    {                        ListViewItem item = this.listView1.GetItemAt(e.X, e.Y);                        if (item == null)                        {                            this.listView1.FocusedItem.Selected = true;                        }                    }                }            }        }        /// <summary>        /// 分类选择        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        // TODO:筛选bug        private void comboClassification_SelectedIndexChanged(object sender, EventArgs e)        {            MeasureMaintenanceTreeSpecificData data = (MeasureMaintenanceTreeSpecificData)comboClassification.SelectedItem;            this.listView1.Items.Clear();            this.imageList1.Images.Clear();            this.documentWorkspace.Visible = false;            int index = comboStatus.SelectedIndex;            this.resultMatList.Clear();            if (data.MeasureMaintenanceTreeSpecificDataId.Equals("0"))            {                switch (index)                {                    case 0:                        this.resultMatList.AddRange(this.realResultMatList);                        InitPicList();                        break;                    case 1:                        List<MeasureInfoResultModel> list = this.realResultMatList.Where(m => m.dataInforList.Where(n => n.value == 0).Count() == 0).ToList();                        //初始化图片列表                        for (int i = 0; i < list.Count; i++)                        {                            MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                            measureInfoResultModel.ID = list[i].ID;                            measureInfoResultModel.allLineNum = list[i].allLineNum;                            measureInfoResultModel.dataInforList = list[i].dataInforList;                            measureInfoResultModel.failNum = list[i].failNum;                            measureInfoResultModel.fileName = list[i].fileName;                            measureInfoResultModel.GraphicsListList = list[i].GraphicsListList;                            measureInfoResultModel.imgStatus = list[i].imgStatus;                            measureInfoResultModel.isConductive = list[i].isConductive;                            measureInfoResultModel.isFanweibuchang = list[i].isFanweibuchang;                            measureInfoResultModel.isErzhichuli = list[i].isErzhichuli;                            measureInfoResultModel.OriginalImage = list[i].OriginalImage;                            measureInfoResultModel.parentId = list[i].parentId;                            measureInfoResultModel.resultMat = list[i].resultMat;                            measureInfoResultModel.successNum = list[i].successNum;                            this.resultMatList.Add(measureInfoResultModel);                            Mat mat = new Mat();                            Cv2.CvtColor(list[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                            this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                            this.listView1.Items.Add("", i);                            this.listView1.Items[i].Tag = list[i].ID;                            this.listView1.Items[i].ImageIndex = i;                            this.listView1.Items[i].Text = list[i].fileName;                            this.listView1.Items[i].BackColor = list[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                        }                        break;                    case 2:                        List<MeasureInfoResultModel> list1 = this.realResultMatList.Where(m => m.dataInforList.Where(n => n.value == 0).Count() != 0).ToList(); ;                        //初始化图片列表                        for (int i = 0; i < list1.Count; i++)                        {                            MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                            measureInfoResultModel.ID = list1[i].ID;                            measureInfoResultModel.allLineNum = list1[i].allLineNum;                            measureInfoResultModel.dataInforList = list1[i].dataInforList;                            measureInfoResultModel.failNum = list1[i].failNum;                            measureInfoResultModel.fileName = list1[i].fileName;                            measureInfoResultModel.GraphicsListList = list1[i].GraphicsListList;                            measureInfoResultModel.imgStatus = list1[i].imgStatus;                            measureInfoResultModel.isConductive = list1[i].isConductive;                            measureInfoResultModel.isFanweibuchang = list1[i].isFanweibuchang;                            measureInfoResultModel.isErzhichuli = list1[i].isErzhichuli;                            measureInfoResultModel.OriginalImage = list1[i].OriginalImage;                            measureInfoResultModel.parentId = list1[i].parentId;                            measureInfoResultModel.resultMat = list1[i].resultMat;                            measureInfoResultModel.successNum = list1[i].successNum;                            this.resultMatList.Add(measureInfoResultModel);                            Mat mat = new Mat();                            Cv2.CvtColor(list1[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                            this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                            this.listView1.Items.Add("", i);                            this.listView1.Items[i].Tag = list1[i].ID;                            this.listView1.Items[i].ImageIndex = i;                            this.listView1.Items[i].Text = list1[i].fileName;                            this.listView1.Items[i].BackColor = list1[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                        }                        break;                }            }            else            {                switch (index)                {                    case 0:                        List<MeasureInfoResultModel> list2 = this.realResultMatList.Where(m => m.parentId.Equals(data.MeasureMaintenanceTreeSpecificDataId)).ToList(); ;                        //初始化图片列表                        for (int i = 0; i < list2.Count; i++)                        {                            MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                            measureInfoResultModel.ID = list2[i].ID;                            measureInfoResultModel.allLineNum = list2[i].allLineNum;                            measureInfoResultModel.dataInforList = list2[i].dataInforList;                            measureInfoResultModel.failNum = list2[i].failNum;                            measureInfoResultModel.fileName = list2[i].fileName;                            measureInfoResultModel.GraphicsListList = list2[i].GraphicsListList;                            measureInfoResultModel.imgStatus = list2[i].imgStatus;                            measureInfoResultModel.isConductive = list2[i].isConductive;                            measureInfoResultModel.isFanweibuchang = list2[i].isFanweibuchang;                            measureInfoResultModel.isErzhichuli = list2[i].isErzhichuli;                            measureInfoResultModel.OriginalImage = list2[i].OriginalImage;                            measureInfoResultModel.parentId = list2[i].parentId;                            measureInfoResultModel.resultMat = list2[i].resultMat;                            measureInfoResultModel.successNum = list2[i].successNum;                            this.resultMatList.Add(measureInfoResultModel);                            Mat mat = new Mat();                            Cv2.CvtColor(list2[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                            this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                            this.listView1.Items.Add("", i);                            this.listView1.Items[i].Tag = list2[i].ID;                            this.listView1.Items[i].ImageIndex = i;                            this.listView1.Items[i].Text = list2[i].fileName;                            this.listView1.Items[i].BackColor = list2[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                        }                        break;                    case 1:                        List<MeasureInfoResultModel> list = this.realResultMatList.Where(m => m.parentId.Equals(data.MeasureMaintenanceTreeSpecificDataId) && m.dataInforList.Where(n => n.value == 0).Count() == 0).ToList(); ;                        //初始化图片列表                        for (int i = 0; i < list.Count; i++)                        {                            MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                            measureInfoResultModel.ID = list[i].ID;                            measureInfoResultModel.allLineNum = list[i].allLineNum;                            measureInfoResultModel.dataInforList = list[i].dataInforList;                            measureInfoResultModel.failNum = list[i].failNum;                            measureInfoResultModel.fileName = list[i].fileName;                            measureInfoResultModel.GraphicsListList = list[i].GraphicsListList;                            measureInfoResultModel.imgStatus = list[i].imgStatus;                            measureInfoResultModel.isConductive = list[i].isConductive;                            measureInfoResultModel.isFanweibuchang = list[i].isFanweibuchang;                            measureInfoResultModel.isErzhichuli = list[i].isErzhichuli;                            measureInfoResultModel.OriginalImage = list[i].OriginalImage;                            measureInfoResultModel.parentId = list[i].parentId;                            measureInfoResultModel.resultMat = list[i].resultMat;                            measureInfoResultModel.successNum = list[i].successNum;                            this.resultMatList.Add(measureInfoResultModel);                            Mat mat = new Mat();                            Cv2.CvtColor(list[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                            this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                            this.listView1.Items.Add("", i);                            this.listView1.Items[i].Tag = list[i].ID;                            this.listView1.Items[i].ImageIndex = i;                            this.listView1.Items[i].Text = list[i].fileName;                            this.listView1.Items[i].BackColor = list[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                        }                        break;                    case 2:                        List<MeasureInfoResultModel> list1 = this.realResultMatList.Where(m => m.parentId.Equals(data.MeasureMaintenanceTreeSpecificDataId) && m.dataInforList.Where(n => n.value == 0).Count() != 0).ToList();                        //初始化图片列表                        for (int i = 0; i < list1.Count; i++)                        {                            MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                            measureInfoResultModel.ID = list1[i].ID;                            measureInfoResultModel.allLineNum = list1[i].allLineNum;                            measureInfoResultModel.dataInforList = list1[i].dataInforList;                            measureInfoResultModel.failNum = list1[i].failNum;                            measureInfoResultModel.fileName = list1[i].fileName;                            measureInfoResultModel.GraphicsListList = list1[i].GraphicsListList;                            measureInfoResultModel.imgStatus = list1[i].imgStatus;                            measureInfoResultModel.isConductive = list1[i].isConductive;                            measureInfoResultModel.isFanweibuchang = list1[i].isFanweibuchang;                            measureInfoResultModel.isErzhichuli = list1[i].isErzhichuli;                            measureInfoResultModel.OriginalImage = list1[i].OriginalImage;                            measureInfoResultModel.parentId = list1[i].parentId;                            measureInfoResultModel.resultMat = list1[i].resultMat;                            measureInfoResultModel.successNum = list1[i].successNum;                            this.resultMatList.Add(measureInfoResultModel);                            Mat mat = new Mat();                            Cv2.CvtColor(list1[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                            this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                            this.listView1.Items.Add("", i);                            this.listView1.Items[i].Tag = list1[i].ID;                            this.listView1.Items[i].ImageIndex = i;                            this.listView1.Items[i].Text = list1[i].fileName;                            this.listView1.Items[i].BackColor = list1[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                        }                        break;                }            }            this.bitmap = null;        }        /// <summary>        /// 状态选择        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void comboStatus_SelectedIndexChanged(object sender, EventArgs e)        {            int index = comboStatus.SelectedIndex;            this.listView1.Items.Clear();            this.imageList1.Images.Clear();            this.documentWorkspace.Visible = false;            this.resultMatList.Clear();            MeasureMaintenanceTreeSpecificData data = (MeasureMaintenanceTreeSpecificData)comboClassification.SelectedItem;            switch (index)            {                case 0:                    List<MeasureInfoResultModel> list2;                    if (data.MeasureMaintenanceTreeSpecificDataId.Equals("0"))                    {                        list2 = this.realResultMatList;                    }                    else                    {                        list2 = this.realResultMatList.Where(m => m.parentId.Equals(data.MeasureMaintenanceTreeSpecificDataId)).ToList();                    }                    //初始化图片列表                    for (int i = 0; i < list2.Count; i++)                    {                        MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                        measureInfoResultModel.ID = list2[i].ID;                        measureInfoResultModel.allLineNum = list2[i].allLineNum;                        measureInfoResultModel.dataInforList = list2[i].dataInforList;                        measureInfoResultModel.failNum = list2[i].failNum;                        measureInfoResultModel.fileName = list2[i].fileName;                        measureInfoResultModel.GraphicsListList = list2[i].GraphicsListList;                        measureInfoResultModel.imgStatus = list2[i].imgStatus;                        measureInfoResultModel.isConductive = list2[i].isConductive;                        measureInfoResultModel.isFanweibuchang = list2[i].isFanweibuchang;                        measureInfoResultModel.isErzhichuli = list2[i].isErzhichuli;                        measureInfoResultModel.OriginalImage = list2[i].OriginalImage;                        measureInfoResultModel.parentId = list2[i].parentId;                        measureInfoResultModel.resultMat = list2[i].resultMat;                        measureInfoResultModel.successNum = list2[i].successNum;                        this.resultMatList.Add(measureInfoResultModel);                        Mat mat = new Mat();                        Cv2.CvtColor(list2[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                        this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                        this.listView1.Items.Add("", i);                        this.listView1.Items[i].Tag = list2[i].ID;                        this.listView1.Items[i].ImageIndex = i;                        this.listView1.Items[i].Text = list2[i].fileName;                        this.listView1.Items[i].BackColor = list2[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                    }                    break;                case 1:                    List<MeasureInfoResultModel> list;                    if (data.MeasureMaintenanceTreeSpecificDataId.Equals("0"))                    {                        list = this.realResultMatList.Where(m => m.dataInforList.Where(n => n.value == 0).Count() == 0).ToList();                    }                    else                    {                        list = this.realResultMatList.Where(m => m.parentId.Equals(data.MeasureMaintenanceTreeSpecificDataId) && m.dataInforList.Where(n => n.value == 0).Count() == 0).ToList();                    }                    //初始化图片列表                    for (int i = 0; i < list.Count; i++)                    {                        MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                        measureInfoResultModel.ID = list[i].ID;                        measureInfoResultModel.allLineNum = list[i].allLineNum;                        measureInfoResultModel.dataInforList = list[i].dataInforList;                        measureInfoResultModel.failNum = list[i].failNum;                        measureInfoResultModel.fileName = list[i].fileName;                        measureInfoResultModel.GraphicsListList = list[i].GraphicsListList;                        measureInfoResultModel.imgStatus = list[i].imgStatus;                        measureInfoResultModel.isConductive = list[i].isConductive;                        measureInfoResultModel.isFanweibuchang = list[i].isFanweibuchang;                        measureInfoResultModel.isErzhichuli = list[i].isErzhichuli;                        measureInfoResultModel.OriginalImage = list[i].OriginalImage;                        measureInfoResultModel.parentId = list[i].parentId;                        measureInfoResultModel.resultMat = list[i].resultMat;                        measureInfoResultModel.successNum = list[i].successNum;                        this.resultMatList.Add(measureInfoResultModel);                        Mat mat = new Mat();                        Cv2.CvtColor(list[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                        this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                        this.listView1.Items.Add("", i);                        this.listView1.Items[i].Tag = list[i].ID;                        this.listView1.Items[i].ImageIndex = i;                        this.listView1.Items[i].Text = list[i].fileName;                        this.listView1.Items[i].BackColor = list[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                    }                    break;                case 2:                    List<MeasureInfoResultModel> list1;                    if (data.MeasureMaintenanceTreeSpecificDataId.Equals("0"))                    {                        list1 = this.realResultMatList.Where(m => m.dataInforList.Where(n => n.value == 0).Count() != 0).ToList();                    }                    else                    {                        list1 = this.realResultMatList.Where(m => m.parentId.Equals(data.MeasureMaintenanceTreeSpecificDataId) && m.dataInforList.Where(n => n.value == 0).Count() != 0).ToList();                    }                    //初始化图片列表                    for (int i = 0; i < list1.Count; i++)                    {                        MeasureInfoResultModel measureInfoResultModel = new MeasureInfoResultModel();                        measureInfoResultModel.ID = list1[i].ID;                        measureInfoResultModel.allLineNum = list1[i].allLineNum;                        measureInfoResultModel.dataInforList = list1[i].dataInforList;                        measureInfoResultModel.failNum = list1[i].failNum;                        measureInfoResultModel.fileName = list1[i].fileName;                        measureInfoResultModel.GraphicsListList = list1[i].GraphicsListList;                        measureInfoResultModel.imgStatus = list1[i].imgStatus;                        measureInfoResultModel.isConductive = list1[i].isConductive;                        measureInfoResultModel.isFanweibuchang = list1[i].isFanweibuchang;                        measureInfoResultModel.isErzhichuli = list1[i].isErzhichuli;                        measureInfoResultModel.OriginalImage = list1[i].OriginalImage;                        measureInfoResultModel.parentId = list1[i].parentId;                        measureInfoResultModel.resultMat = list1[i].resultMat;                        measureInfoResultModel.successNum = list1[i].successNum;                        this.resultMatList.Add(measureInfoResultModel);                        Mat mat = new Mat();                        Cv2.CvtColor(list1[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                        this.imageList1.Images.Add("img" + i, CreateThumbnail(mat));                        this.listView1.Items.Add("", i);                        this.listView1.Items[i].Tag = list1[i].ID;                        this.listView1.Items[i].ImageIndex = i;                        this.listView1.Items[i].Text = list1[i].fileName;                        this.listView1.Items[i].BackColor = list1[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                    }                    break;            }            this.bitmap = null;        }        /// <summary>        /// 生成报告        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void buttonGenerateReport_Click(object sender, EventArgs e)        {            if (listView1.Items.Count == 0)            {                MessageBox.Show(PdnResources.GetString("NewNoDataGenerateReport") + "!");                return;            }            if (string.IsNullOrEmpty(measureMaintenanceType.templateFilePath) || !System.IO.File.Exists(measureMaintenanceType.templateFilePath))            {                MessageBox.Show(PdnResources.GetString("NoTemplateSelected"));                OpenFileDialog dialog = new OpenFileDialog();                dialog.Filter = "Excel文件|*.xls;*.xlsx";                dialog.Title = "选择模板";                dialog.Multiselect = false; //该值确定是否可以选择多个文件                if (dialog.ShowDialog() != DialogResult.OK)                {                    return;                }                string file = dialog.FileName;                measureMaintenanceType.templateFilePath = file;            }            #region [上传数据库组织数据]            bool needUploadData = false;            bool needSPCUploadData = false;            //配置文档中关于接口的相关配置项            string userName = Program.instance.configModel.UserName;            string passWord = Program.instance.configModel.PassWord;            string equId = Program.instance.configModel.EquId;            string groupId = Program.instance.configModel.GroupId;            string funId = Program.instance.configModel.FunId;            string funId2 = Program.instance.configModel.FunId2;            string funId3 = Program.instance.configModel.FunId3;            string createdate = DateTime.Now.ToString("yyyy-MM-dd");            string mainID = Guid.NewGuid().ToString();            string paraname = "ID|Name| RulerName| RulerPixelLength| RulerPhysicalLength| PartNo| UseFactory|OrderNum|Laboratory|BatchNumber|Shift|ProcessType|Level1| ElectroplatingLine|Unit|Remark ";            string rulerName = this.measureMaintenanceType.ruleMessage == null ? string.Empty : this.measureMaintenanceType.ruleMessage.ruleName;            decimal rulerPhysicalLength = this.measureMaintenanceType.ruleMessage == null ? 0 : this.measureMaintenanceType.ruleMessage.physicalLength;            float rulerPixelLength = this.measureMaintenanceType.ruleMessage == null ? 0 : this.measureMaintenanceType.ruleMessage.pixelLength;            if (string.IsNullOrEmpty(this.measureMaintenanceType.measureMaintenanceContent))            {                this.measureMaintenanceType.measureMaintenanceContent = "默認備註";            }            //实验室需要的数据字段,一个主表两个子表。有递进关系            string paravalue = $"{mainID}|{this.measureMaintenanceType.measureMaintenanceName}|{rulerName}|{rulerPixelLength}|{rulerPhysicalLength}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[3].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[5].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[2].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[6].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[1].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[4].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[7].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[8].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceBasicDataList[9].measureMaintenanceBasicDataValue}|{this.measureMaintenanceType.measureMaintenanceContent}";            string paraname2 = "ID|MainId|HoleType|TestItem|SpecificationCondition|scnum|scrangegreatenum|Judgment ";            string paraname3 = "ID|Name|Value|FilePath|DataId|MainId ";            #endregion [上传数据库组织数据]            //SPC上传            switch (Program.instance.configModel.autoSPCUpload)            {                case 1:                    needSPCUploadData = true;                    if (string.IsNullOrEmpty(this.measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue))                    {                        ResultViewItemNo resultViewItemNo = new ResultViewItemNo(this);                        resultViewItemNo.StartPosition = FormStartPosition.CenterParent;                        resultViewItemNo.ShowDialog();                        return;                    }                    break;                case 2:                    needSPCUploadData = false;                    break;                case 3:                    if (!this.isSPCItemNull)                    {                        DialogResult result = MessageBox.Show(PdnResources.GetString("UpdateSpc"), PdnResources.GetString("NewTips"), MessageBoxButtons.OKCancel);                        if (result == DialogResult.OK)                        {                            needSPCUploadData = true;                            if (string.IsNullOrEmpty(this.measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue))                            {                                ResultViewItemNo resultViewItemNo = new ResultViewItemNo(this);                                resultViewItemNo.StartPosition = FormStartPosition.CenterParent;                                resultViewItemNo.ShowDialog();                                return;                            }                        }                    }                    break;            }            //实验室上传            switch (Program.instance.configModel.autoUpload)            {                case 1:                    needUploadData = true;                    try                    {                        var resultData = webServiceDll.ws.sendDataToSerGrp(userName, passWord, equId, groupId, funId, paraname, paravalue, createdate);                        writeLog(resultData, "0003上传回参");                    }                    catch (Exception ex)                    {                        writeLog(ex.Message);                    }                    break;                case 2:                    needUploadData = false;                    break;                case 3:                    DialogResult result = MessageBox.Show(PdnResources.GetString("NewUploadDatabase") + "?", PdnResources.GetString("NewTips"), MessageBoxButtons.OKCancel);                    if (result == DialogResult.OK)                    {                        needUploadData = true;                        try                        {                            var resultData = webServiceDll.ws.sendDataToSerGrp(userName, passWord, equId, groupId, funId, paraname, paravalue, createdate);                            writeLog(resultData, "0003上传回参");                        }                        catch (Exception ex)                        {                            writeLog(ex.Message);                        }                    }                    break;            }            string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "切片报告.xls";            #region [命名规则]            string ruleName = string.Empty;            string ruleGain = string.Empty;            if (this.measureMaintenanceType.ruleMessage != null)            {                ruleName = this.measureMaintenanceType.ruleMessage.ruleName;                ruleGain = this.measureMaintenanceType.ruleMessage.ruleGain.ToString();            }            else            {                List<mic_rulers> list = Program.instance.mic_rulersAll;                var ruler = list.Where(m => m.id.Equals(Program.instance.configModel.RulerId)).FirstOrDefault();                if (ruler != null)                {                    ruleName = ruler.ruler_name;                    ruleGain = ruler.gain_multiple.ToString();                }            }            NamingRuleHelper namingRuleHelper = new NamingRuleHelper();            if (this.thisNameRuleListDetails == null)            {                if (!string.IsNullOrEmpty(this.measureMaintenanceType.NameRuleID))                {                    NameRuleListDetails nameRuleListDetails = Program.instance.fileNameRule.NameRuleList.Where(m => m.ID == this.measureMaintenanceType.NameRuleID).FirstOrDefault();                    if (nameRuleListDetails != null)                    {                        fileName = namingRuleHelper.GetNameFromXml(nameRuleListDetails, ruleName, ruleGain, this.measureMaintenanceType, this.filePath) + ".xls";                        if (nameRuleListDetails.isContinue)                        {                            nameRuleListDetails.NowNumber += 1;                        }                        string stageModelXml = XmlSerializeHelper.XmlSerialize<FileNameRule>(Program.instance.fileNameRule);                        FileOperationHelper.WriteStringToFile(stageModelXml, Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\FileNameRule.xml", FileMode.Create);                    }                }            }            else            {                fileName = namingRuleHelper.GetNameFromXml(this.thisNameRuleListDetails, ruleName, ruleGain, this.measureMaintenanceType, this.filePath) + ".xls";                if (this.thisNameRuleListDetails.isContinue)                {                    this.thisNameRuleListDetails.NowNumber += 1;                }            }            if (string.IsNullOrEmpty(fileName) || fileName.Equals(".xls"))            {                fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "切片报告.xls";            }            #endregion            string path = this.filePath + "\\" + fileName;            string temp = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\TempFile";            if (!System.IO.Directory.Exists(temp))            {                System.IO.Directory.CreateDirectory(temp);            }            string tempFilePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\TempFile\\" + fileName;            //List<MeasureInfoResultModel> thisResultMatList = new List<MeasureInfoResultModel>();            //for (int i = 0; i < this.listView1.SelectedItems.Count; i++)            //{            //    int index = this.listView1.SelectedItems[i].Index;            //    thisResultMatList.Add(this.resultMatList[index]);            //}            ProgressThreadProcClass procClass = new ProgressThreadProcClass();            int itemCount = 100;            ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();            System.Threading.ThreadStart copyThreadProc =                delegate ()                {                    #region [对公式进行赋值]                    MeasureInfoExportModel measureInfoExportModel = OrganizeResultData(this.resultMatList);                    #endregion [对公式进行赋值]                    #region [组织数据 开整!]                    Excel.Application excelApp = new Excel.Application();                    Excel.Workbook workBook = excelApp.Workbooks.Open(this.measureMaintenanceType.templateFilePath);                    try                    {                        Excel.Names wbNames = workBook.Names;                        int columnValue = 0;                        int rowValue = 0;                        int dataColumnValue = 0;                        int dataCowValue = 0;                        //根据单元格名称放值                        foreach (var item in this.measureMaintenanceType.measureMaintenanceBasicDataList)                        {                            int index = this.measureMaintenanceType.measureMaintenanceBasicDataList.IndexOf(item);                            foreach (Excel.Name n in wbNames)                            {                                if (n.Name.Equals(item.measureMaintenanceBasicDataPosition))                                {                                    n.RefersToRange.Value = item.measureMaintenanceBasicDataValue;                                    if (item.measureMaintenanceBasicDataIndex == 10)                                    {                                        n.RefersToRange.Value = $"{DateTime.Now.Year}年{DateTime.Now.Month}月{DateTime.Now.Day}日";                                    }                                }                                if (n.Name.Equals("Value1"))                                {                                    dataColumnValue = n.RefersToRange.Column;                                    dataCowValue = n.RefersToRange.Row + 1;                                }                                if (n.Name.Equals("Judgment"))                                {                                    columnValue = n.RefersToRange.Column;                                    rowValue = n.RefersToRange.Row;                                }                            }                        }                        DataTable dataTable = new DataTable();                        var workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];                        Excel.Range range = workSheet.Range["Judgment"];                        if (this.measureMaintenanceType.outputPicturesNum > 5)                        {                            double width = Convert.ToDouble(((Excel.Range)workSheet.Columns[columnValue - 1]).ColumnWidth);                            for (int i = 6; i <= this.measureMaintenanceType.outputPicturesNum; i++)                            {                                #region [添加列]                                range.EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, Excel.XlInsertFormatOrigin.xlFormatFromRightOrBelow);                                workSheet.Cells[rowValue, columnValue] = i.ToString();                                workBook.Names.Add($"Value{i}", workSheet.Cells[rowValue, columnValue], true);                                ((Excel.Range)workSheet.Columns[columnValue]).ColumnWidth = width;                                //合并单元格                                Excel.Range range1 = workSheet.Range[workSheet.Cells[rowValue, columnValue], workSheet.Cells[rowValue + 1, columnValue]];                                range1.Merge(0);                                columnValue++;                                #endregion [添加列]                            }                        }                        #region [分组铺数据]                        var HoleTypeList = measureInfoExportModel.measureInfoExportDataModelList;                        int realDataRowValue = dataCowValue;                        int secondRowValue = dataCowValue + 1;                        int firstRowValue = dataCowValue + 1;                        Excel.Range range2 = workSheet.Range["Standard"];                        int dataIndex = 1;                        Dictionary<string, List<dynamic>> spcDataList = new Dictionary<string, List<dynamic>>();                        foreach (var item in HoleTypeList)                        {                            this.Invoke(new Action(() =>                            {                                progressEvents.SetStringProgress(PdnResources.GetString("Dealing") + dataIndex + PdnResources.GetString("GeCeLiangFenLiangZhong"));                            }));                            List<dynamic> dynamicList = new List<dynamic>();                            int rowIndex = -1;                            foreach (var item2 in item.itemTypeList)                            {                                string dataId = Guid.NewGuid().ToString();                                int index = -1;                                foreach (var item3 in item2.LineDataList)                                {                                    int realDataColumnValue = dataColumnValue;                                    //添加1行                                    range2.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown, Excel.XlInsertFormatOrigin.xlFormatFromRightOrBelow);                                    #region [量测位置]                                    workSheet.Cells[realDataRowValue + 1, dataColumnValue - 1] = item3.name;                                    workSheet.Cells[realDataRowValue + 1, dataColumnValue - 1].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                    workSheet.Cells[realDataRowValue + 1, dataColumnValue - 1].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                    Excel.Range range3 = workSheet.Range[workSheet.Cells[realDataRowValue + 1, dataColumnValue - 1], workSheet.Cells[realDataRowValue + 1, dataColumnValue - 1]];                                    range3.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                    #endregion [量测位置]                                    #region [数据]                                    string douData = "0";                                    //如果是最大值 最小值 平均值 则只取一个值                                    if (item3.isMaxOrMin)                                    {                                        switch (item3.typeCase)                                        {                                            case 1:                                                douData = Math.Round(item3.value.Max(), Program.instance.decimalPlaces).ToString();                                                break;                                            case 2:                                                douData = Math.Round(item3.value.Min(), Program.instance.decimalPlaces).ToString();                                                break;                                            case 3:                                                douData = Math.Round(item3.value.Average(), Program.instance.decimalPlaces).ToString();                                                break;                                        }                                        workSheet.Cells[realDataRowValue + 1, realDataColumnValue] = douData;                                        dynamic dy = new ExpandoObject();                                        dy.name = item3.name;                                        dy.dataId = dataId;                                        dy.dataType = 1;                                        dy.testItems = item2.TestItems;                                        dy.value = workSheet.Cells[realDataRowValue + 1, realDataColumnValue];                                        dynamicList.Add(dy);                                        if (spcDataList.ContainsKey(item2.TestItems))                                        {                                            spcDataList[item2.TestItems].Add(dy);                                        }                                        else                                        {                                            spcDataList.Add(item2.TestItems, new List<dynamic>() { dy });                                        }                                        workSheet.Cells[realDataRowValue + 1, realDataColumnValue].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                        workSheet.Cells[realDataRowValue + 1, realDataColumnValue].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                        //合并单元格                                        Excel.Range range15 = workSheet.Range[workSheet.Cells[realDataRowValue + 1, realDataColumnValue], workSheet.Cells[realDataRowValue + 1, realDataColumnValue + (this.measureMaintenanceType.outputPicturesNum - 1)]];                                        double doubleData = Convert.ToDouble(douData);                                        if (!outOk(doubleData, item2.Specification))                                        {                                            range15.Cells.Interior.Color = Color.FromArgb(0, 0, 255).ToArgb();                                        }                                        range15.Merge(0);                                        range15.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                        realDataRowValue++;                                    }                                    else                                    {                                        foreach (var item4 in item3.value)                                        {                                            workSheet.Cells[realDataRowValue + 1, realDataColumnValue] = item4;                                            workSheet.Cells[realDataRowValue + 1, realDataColumnValue].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                            workSheet.Cells[realDataRowValue + 1, realDataColumnValue].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                            Excel.Range range1 = workSheet.Range[workSheet.Cells[realDataRowValue + 1, realDataColumnValue], workSheet.Cells[realDataRowValue + 1, realDataColumnValue]];                                            dynamic dy = new ExpandoObject();                                            dy.name = item3.name;                                            dy.dataId = dataId;                                            dy.testItems = item2.TestItems;                                            dy.dataType = 2;                                            dy.value = item4;                                            dy.imgIndex = item3.value.IndexOf(item4);                                            dynamicList.Add(dy);                                            if (spcDataList.ContainsKey(item2.TestItems))                                            {                                                spcDataList[item2.TestItems].Add(dy);                                            }                                            else                                            {                                                spcDataList.Add(item2.TestItems, new List<dynamic>() { dy });                                            }                                            if (item3.NgValue.Contains(item4))                                            {                                                if (double.IsInfinity(item4) || double.IsNaN(item4))                                                {                                                    workSheet.Cells[realDataRowValue + 1, realDataColumnValue] = "error";                                                    workSheet.Cells[realDataRowValue + 1, realDataColumnValue].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                                    workSheet.Cells[realDataRowValue + 1, realDataColumnValue].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                                    range1 = workSheet.Range[workSheet.Cells[realDataRowValue + 1, realDataColumnValue], workSheet.Cells[realDataRowValue + 1, realDataColumnValue]];                                                }                                                range1.Cells.Interior.Color = Color.FromArgb(0, 0, 255).ToArgb();                                            }                                            range1.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                            realDataColumnValue++;                                        }                                        realDataRowValue++;                                    }                                    #endregion [数据]                                    index++;                                    rowIndex++;                                }                                #region [规格]                                var spec = item2.Specification;                                string data = string.Empty;                                string SpecificationCondition = "Unconditional";                                decimal SpecificationCOnditionNum = 0;                                decimal SpecificationCOnditionRangeGreateNum = 0;                                List<string> list = new List<string>();                                if (!string.IsNullOrEmpty(spec) && !spec.Contains("-"))                                {                                    list = spec.Split('X').ToList();                                    if (list.Count == 2)                                    {                                        list[0] = list[0].Replace("<=", "LQ").Replace("<", "L");                                        list[1] = list[1].Replace("<=", "LQ").Replace("<", "L");                                        if (string.IsNullOrEmpty(list[0]) && string.IsNullOrEmpty(list[1]))                                        {                                        }                                        else if (string.IsNullOrEmpty(list[0]))                                        {                                            if (list[1].Contains("LQ"))                                            {                                                data = $"{list[1].Replace("LQ", "<=")}";                                                SpecificationCondition = "LessEqual";                                                SpecificationCOnditionNum = Convert.ToDecimal(list[1].Replace("LQ", ""));                                            }                                            else                                            {                                                data = $"{list[1].Replace("L", "<")}";                                                SpecificationCondition = "Less";                                                SpecificationCOnditionNum = Convert.ToDecimal(list[1].Replace("L", ""));                                            }                                        }                                        else if (string.IsNullOrEmpty(list[1]))                                        {                                            if (list[0].Contains("LQ"))                                            {                                                data = $"{list[0].Replace("LQ", "<=")}";                                                SpecificationCondition = "GreaterEqual";                                                SpecificationCOnditionNum = Convert.ToDecimal(list[0].Replace("LQ", ""));                                            }                                            else                                            {                                                data = $"{list[0].Replace("L", "<")}";                                                SpecificationCondition = "Greater";                                                SpecificationCOnditionNum = Convert.ToDecimal(list[0].Replace("L", ""));                                            }                                        }                                        else                                        {                                            data = $"{spec.Replace("<=", "").Replace("<", "").Replace("X", "~")}";                                            SpecificationCondition = "Range";                                            SpecificationCOnditionNum = Convert.ToDecimal(list[0].Replace("LQ", "").Replace("L", ""));                                            SpecificationCOnditionRangeGreateNum = Convert.ToDecimal(list[1].Replace("LQ", "").Replace("L", ""));                                        }                                    }                                }                                workSheet.Cells[secondRowValue, dataColumnValue - 2] = data;                                workSheet.Cells[secondRowValue, dataColumnValue - 2].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                workSheet.Cells[secondRowValue, dataColumnValue - 2].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                //合并单元格                                Excel.Range range5 = workSheet.Range[workSheet.Cells[secondRowValue, dataColumnValue - 2], workSheet.Cells[secondRowValue + index, dataColumnValue - 2]];                                range5.Merge(0);                                range5.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                #endregion [规格]                                #region [检测项目]                                workSheet.Cells[secondRowValue, dataColumnValue - 3] = item2.TestItems;                                workSheet.Cells[secondRowValue, dataColumnValue - 3].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                workSheet.Cells[secondRowValue, dataColumnValue - 3].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                //合并单元格                                Excel.Range range4 = workSheet.Range[workSheet.Cells[secondRowValue, dataColumnValue - 3], workSheet.Cells[secondRowValue + index, dataColumnValue - 3]];                                range4.Merge(0);                                range4.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                #endregion [检测项目]                                #region [判断]                                string resultData;                                string Judgment = "N/A";                                if (!string.IsNullOrEmpty(spec) && !spec.Equals("-") && item.matList.Count != 0)                                {                                    resultData = "V";                                    if (!item2.isOk)                                    {                                        workSheet.Cells[secondRowValue, columnValue + 1] = resultData;                                        workSheet.Cells[secondRowValue, columnValue + 1].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                        workSheet.Cells[secondRowValue, columnValue + 1].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                        Judgment = "NG";                                    }                                    else                                    {                                        workSheet.Cells[secondRowValue, columnValue] = resultData;                                        workSheet.Cells[secondRowValue, columnValue].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                        workSheet.Cells[secondRowValue, columnValue].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                        Judgment = "OK";                                    }                                    //合并单元格                                    Excel.Range range8 = workSheet.Range[workSheet.Cells[secondRowValue, columnValue], workSheet.Cells[secondRowValue + index, columnValue]];                                    range8.Merge(0);                                    range8.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                    //合并单元格                                    Excel.Range range9 = workSheet.Range[workSheet.Cells[secondRowValue, columnValue + 1], workSheet.Cells[secondRowValue + index, columnValue + 1]];                                    range9.Merge(0);                                    range9.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                }                                else                                {                                    resultData = "N/A";                                    workSheet.Cells[secondRowValue, columnValue] = resultData;                                    workSheet.Cells[secondRowValue, columnValue].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                                    workSheet.Cells[secondRowValue, columnValue].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                                    //合并单元格                                    Excel.Range range7 = workSheet.Range[workSheet.Cells[secondRowValue, columnValue], workSheet.Cells[secondRowValue + index, columnValue + 1]];                                    range7.Merge(0);                                    range7.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                                }                                #endregion [判断]                                #region [上传数据库]                                if (needUploadData)                                {                                    string paravalue2 = string.Empty;                                    paravalue2 = $"{dataId}|{mainID}|{item.HoleType}|{item2.TestItems}|{SpecificationCondition}|{SpecificationCOnditionNum}|{SpecificationCOnditionRangeGreateNum}|{Judgment}";                                    try                                    {                                        var result1 = webServiceDll.ws.sendDataToSerGrp(userName, passWord, equId, groupId, funId2, paraname2, paravalue2, createdate);                                        writeLog(result1, "0004上传回参");                                    }                                    catch (Exception ex)                                    {                                        writeLog(ex.Message);                                    }                                }                                #endregion [上传数据库]                                secondRowValue += (index + 1);                            }                            #region [孔型]                            workSheet.Cells[firstRowValue, dataColumnValue - 4] = item.HoleType;                            workSheet.Cells[firstRowValue, dataColumnValue - 4].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;                            workSheet.Cells[firstRowValue, dataColumnValue - 4].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;                            //合并单元格                            Excel.Range range6 = workSheet.Range[workSheet.Cells[firstRowValue, dataColumnValue - 4], workSheet.Cells[firstRowValue + rowIndex, dataColumnValue - 4]];                            range6.Merge(0);                            range6.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                            #endregion [孔型]                            #region [图片]                            List<string> pathList = new List<string>();                            //合并单元格                            Excel.Range range10 = workSheet.Range["Dan"];                            int lastCol = range10.Column;                            Excel.Range range11 = workSheet.Range[workSheet.Cells[firstRowValue, columnValue + 2], workSheet.Cells[firstRowValue + rowIndex, lastCol + 1]];                            range11.Merge(0);                            range11.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());                            float PicLeft, PicTop, PicWidth, PicHeight;                            int haltWidth = Convert.ToInt32(range11.Width / ((item.matList.Count) == 0 ? 1 : item.matList.Count));                            int Index = 0;                            foreach (var mat in item.matList)                            {                                this.Invoke(new Action(() =>                                {                                    progressEvents.SetStringProgress((PdnResources.GetString("Dealing") + dataIndex + PdnResources.GetString("GeCeLiangFenLiangZhong") + ",第" + (Index + 1) + "/" + item.matList.Count + PdnResources.GetString("Image")));                                }));                                string ImgPath = SaveAllImage(mat, item.GraphicsListList[Index]);                                pathList.Add(ImgPath);                                PicWidth = (float)(5.2d / 0.035d);                                PicTop = Convert.ToSingle(range11.Top);                                PicLeft = Convert.ToSingle(range11.Left + PicWidth * Index + 10);                                PicHeight = (float)(3.6d / 0.035d);                                //workSheet.Shapes.AddPicture2(ImgPath, MsoTriState.msoFalse, MsoTriState.msoTrue, PicLeft, PicTop, PicWidth, PicHeight, MsoPictureCompress.msoPictureCompressFalse);                                workSheet.Shapes.AddPicture(ImgPath, MsoTriState.msoFalse, MsoTriState.msoTrue, PicLeft, PicTop, PicWidth, PicHeight);                                Index++;                            }                            firstRowValue += (rowIndex + 1);                            #endregion [图片]                            #region [上传数据库]                            if (needUploadData)                            {                                try                                {                                    #region [上传FTP]                                    string ftpStr = DateTime.Now.ToString("yyyyMMdd");                                    try                                    {                                        FTPWebsiteHelper fTPWebsiteHelper = new FTPWebsiteHelper();                                        fTPWebsiteHelper.ftpPath = Program.instance.configModel.FTPURL;                                        fTPWebsiteHelper.ftpUserID = Program.instance.configModel.FTPUserName;                                        fTPWebsiteHelper.ftpPassword = Program.instance.configModel.FTPPassword;                                        //fTPWebsiteHelper.ftpPath = "ftp://127.0.0.1";                                        //fTPWebsiteHelper.ftpUserID = "admin";                                        //fTPWebsiteHelper.ftpPassword = "123456";                                        foreach (var file in pathList)                                        {                                            fTPWebsiteHelper.UpLoadFile(file);                                        }                                        ftpStr = fTPWebsiteHelper.ftpStr;                                    }                                    catch (Exception ex)                                    {                                        writeLog(ex.Message, "FTP错误");                                    }                                    #endregion [上传FTP]                                    foreach (dynamic dy in dynamicList)                                    {                                        string dataFilePath = string.Empty;                                        if (dy.dataType == 1)                                        {                                            //foreach (var file in pathList)                                            //{                                            //    FileInfo fileInf = new FileInfo(file);                                            //    dataFilePath += $"{Program.instance.configModel.FTPFilePath + "/" + fileInf.Name},";                                            //}                                        }                                        else                                        {                                            FileInfo fileInf = new FileInfo(pathList[dy.imgIndex]);                                            dataFilePath = $"{Program.instance.configModel.FTPFilePath + "/" + ftpStr + "/" + fileInf.Name}";                                        }                                        string paravalue3 = $"{Guid.NewGuid().ToString()}| {dy.name}|{dy.value}|{dataFilePath}|{dy.dataId}|{mainID}";                                        var result2 = webServiceDll.ws.sendDataToSerGrp(userName, passWord, equId, groupId, funId3, paraname3, paravalue3, createdate);                                        //writeLog(result2, "0004上传回参");                                    }                                }                                catch (Exception ex)                                {                                    writeLog(ex.Message);                                }                            }                            #endregion [上传数据库]                            dataIndex++;                        }                        #endregion [分组铺数据]                        //SPC上传                        #region [上传数据库]                         if (needSPCUploadData)                        {                            Scheme schemeModel = getSpcApiSetting();                            if (schemeModel != null)                            {                                try                                {                                    //通过“料号获取SPC管制清单”                                    var rs = ws.getctrlitem(this.measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue /*料号*/);                                                                        string daStr = DateTime.Now.ToString("yyyy-MM-dd HH:ss");                                    if (rs.msg.Contains("OK"))                                    {                                        int spcDataIndex = 0;                                        foreach (var spcData in rs.ds.Tables[0].Rows)                                        {                                            string dateStr = string.Empty;//时间                                            string dataStr = string.Empty;//数据                                            var filegroup = rs.ds.Tables[0].Rows[spcDataIndex]["filegroup"].ToString();//SPC群組                                            var filename = rs.ds.Tables[0].Rows[spcDataIndex]["filename"].ToString();//SPC檔案                                            var ctrlitem = rs.ds.Tables[0].Rows[spcDataIndex]["ctrlitem"].ToString();//管制项目                                            var spsize = rs.ds.Tables[0].Rows[spcDataIndex]["spsize"].ToString();//切片数量                                                                                                                 //系统中“电镀线别”为空直接退出                                            if (string.IsNullOrEmpty(this.measureMaintenanceType.measureMaintenanceBasicDataList[8].measureMaintenanceBasicDataValue))                                            {                                                break;                                            }                                            //SPC檔案中不包括“电镀线别”                                            if (!filename.Contains(this.measureMaintenanceType.measureMaintenanceBasicDataList[8].measureMaintenanceBasicDataValue /*电镀线别*/))                                            {                                                spcDataIndex++;                                                continue;                                            }                                            spcDataIndex++;                                            int count = Convert.ToInt32(spsize);                                            int needCount = 0;//需要的检测项目数量                                            var dataList = spcDataList.Values.ToList();//当前检测项目及测量数据信息                                            foreach (var item in dataList)                                            {                                                foreach (dynamic dy in item)//从SPC檔案筛选出当前使用的检测项目及测量数据(SPC檔案包含全部检测项目,需要挑选中使用的)                                                {                                                    if (!filename.Contains(dy.testItems))                                                    {                                                        continue;                                                    }                                                    if (needCount >= count)                                                    {                                                        break;                                                    }                                                    dateStr += $"{daStr}|";//系统当前时间                                                    dataStr += $"{dy.value}|";//测量值                                                    needCount++;                                                }                                            }                                            //如果筛选出来的检测项目数量小于切片数量.余下的切片对应的数据设置为0。                                            if (needCount < count)                                            {                                                for (int i = 1; i <= (count - needCount); i++)                                                {                                                    dateStr += $"{daStr}|";                                                    dataStr += $"{0}|";                                                }                                            }                                            dateStr = dateStr.Remove(dateStr.Length - 1, 1);                                            dataStr = dataStr.Remove(dataStr.Length - 1, 1);                                            writeLog(count.ToString() + "和" + dateStr + "和" + dataStr, "SPC上传接口参数展示");                                            var interfacePassWord = Program.instance.configModel.interfacePassWord;                                            //根据配置文件组织数据                                            int t = 0;                                            List<string> paraList = new List<string>();                                            foreach (Item item in schemeModel.items)                                            {                                                try                                                {                                                    t = int.Parse(item.filedNum.Trim());                                                    paraList.Add(measureMaintenanceType.measureMaintenanceBasicDataList[t - 1].measureMaintenanceBasicDataValue);                                                }                                                catch (Exception)                                                {                                                    paraList.Add("");                                                    continue;                                                }                                            }                                            //var result = ws.spcapi(interfacePassWord, "filegroup", "filename", "ctrlitem", "dateStr", "dataStr", "count", paraList[0], paraList[1], paraList[2], paraList[3], paraList[4], paraList[5], paraList[6], paraList[7], paraList[8], paraList[9], paraList[10], paraList[11], paraList[12], paraList[13], paraList[14], paraList[15], paraList[16], paraList[17], paraList[18], paraList[19]);                                            var result = ws.spcapi(interfacePassWord, filegroup.ToString(), filename.ToString(), ctrlitem.ToString(), dateStr, dataStr, count.ToString(), paraList[0], paraList[1], paraList[2], paraList[3], paraList[4], paraList[5], paraList[6], paraList[7], paraList[8], paraList[9], paraList[10], paraList[11], paraList[12], paraList[13], paraList[14], paraList[15], paraList[16], paraList[17], paraList[18], paraList[19]);                                            //if (result.Contains("NG"))                                            //{                                            //    writeLog( result, "SPC上传接口错误");                                            //}                                            writeLog(result, "SPC上传接口调用结果反馈");                                        }                                    }                                    else                                    {                                        writeLog(rs.msg, "SPC-料号获取SPC管制清单方法错误");                                    }                                }                                catch (Exception ex)                                {                                    writeLog(ex.Message, "SPC下拉接口错误");                                }                            }                            else                            {                                writeLog("请检测配置文档", "SPC配置返回空");                            }                        }                        #endregion                        object nothing = Type.Missing;                        workBook.SaveAs(tempFilePath, nothing, nothing, nothing, nothing, nothing,                              Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);                    }                    catch (Exception ex)                    {                        writeLog(ex.Message);                    }                    finally                    {                        if (excelApp != null)                        {                            if (excelApp != null && workBook != null)                                workBook.Close(false);                            excelApp.Quit();                            OfficeFileHandleHelper.Kill(excelApp);                        }                        progressEvents.EndOperation(OperationResult.Finished);                    }                    #endregion [组织数据 开整!]                };            procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null);            string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\TempImg";            #region [复制文件到另一个文件夹]            try            {                FileOperationHelper.CopyFile(tempFilePath, this.filePath, "", true);                Directory.Delete(temp, true);            }            catch (Exception ex)            {            }            #endregion [复制文件到另一个文件夹]            try            {                if (Directory.Exists(filePath))                {                    Directory.Delete(filePath, true);                }            }            catch (Exception ex)            {            }            if (checkBox1.Checked)            {                if (!OfficeFileHandleHelper.OpenOfficeFile(path))                    MessageBox.Show(PdnResources.GetString("Menu.Fileopenfailed.Text"));            }            this.isSPCItemNull = false;            MessageBox.Show(PdnResources.GetString("NewExportSucceeded"));        }        /// <summary>        /// 读取SPCApi配置方案        /// </summary>        private Scheme getSpcApiSetting()        {            string filePath;            filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\SpcApiSchemes.xml";            if (System.IO.File.Exists(filePath))            {                spcApiSchemesModel = XmlSerializeHelper.DESerializer<SpcApiSchemesModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));                if (spcApiSchemesModel.schemes.Count > 0)                {                    Scheme schemeModel = new Scheme();                    int cnt = 0;                    foreach (Scheme scheme in spcApiSchemesModel.schemes)                    {                        if (scheme.isUse)                        {                            cnt = cnt + 1;                            schemeModel = scheme;                        }                    }                    if (cnt == 1)                    {                        if ( schemeModel.items.Count == 20)                        {                             return schemeModel;                         }                        else                        {                            writeLog("栏位总数必须为20!", "SPC上传接口错误");                            return null;                        }                    }                    else                    {                        writeLog("接口数据项配置错误,无启用方案或启用方案不唯一!", "SPC上传接口错误");                        return null;                    }                }                else                {                    writeLog("接口数据项配置错误,未找到可用配置!", "SPC上传接口错误");                    return null;                }            }            else            {                writeLog("配置文件不存在!","SPC上传接口错误");                return null;            }        }        /// <summary>        /// 组织最终导出数据        /// </summary>        private MeasureInfoExportModel OrganizeResultData(List<MeasureInfoResultModel> thisResultMatList)        {            MeasureInfoExportModel measureInfoExportModel = new MeasureInfoExportModel();            var HoleTypeList = this.measureMaintenanceType.MeasureMaintenanceTreeFourthDataList.GroupBy(m => m.HoleType);            #region [先整理下整体的数据]            #region [特殊处理下叠构]            var resList = thisResultMatList.Where(m => m.parentId.Equals("100209")).ToList();            if (resList.Count > 0)            {                foreach (var item in resList)                {                    List<string> nameList = item.dataInforList.Select(m => m.name).ToList();                    var ls = item.dataInforList.OrderBy(m => m.point1.Y).ToList();                    for (int i = 0; i < ls.Count(); i++)                    {                        ls[i].name = nameList[i];                    }                }                thisResultMatList.RemoveAll(m => m.parentId.Equals("100209"));                thisResultMatList.AddRange(resList);            }            #endregion [特殊处理下叠构]            var dataList = HoleTypeList.ToList();            for (int i = dataList.Count - 1; i >= 0; i--)            {                var data = dataList[i];                var resultDataList = thisResultMatList.Where(m => m.parentId.Equals(data.First().HoleTypeId)).ToList();                var a = Math.Ceiling(Convert.ToDouble(resultDataList.Count()) / Convert.ToDouble(this.measureMaintenanceType.outputPicturesNum));                if (a > 0)                {                    for (int j = 1; j <= a; j++)                    {                        dataList.Insert(i + j, data);                    }                    dataList.RemoveAt(i);                }            }            #endregion [先整理下整体的数据]            string name = string.Empty;            int startNum = 0;            foreach (var item in dataList)            {                MeasureInfoExportDataModel measureInfoExportDataModel = new MeasureInfoExportDataModel();                measureInfoExportDataModel.HoleType = item.Key;                measureInfoExportDataModel.HoleTypeId = item.FirstOrDefault().HoleTypeId;                var resultDataList = thisResultMatList.Where(m => m.parentId.Equals(measureInfoExportDataModel.HoleTypeId)).ToList();                if (name.Equals(item.Key))                {                    startNum++;                }                else                {                    name = item.Key;                    startNum = 0;                }                resultDataList = resultDataList.Skip(this.measureMaintenanceType.outputPicturesNum * startNum).Take(this.measureMaintenanceType.outputPicturesNum).ToList();                //添加图片及名称                foreach (var result in resultDataList)                {                    var list = result.dataInforList;                    List<DrawObject> lines = new List<DrawObject>();                    GraphicsList graphicsList = new GraphicsList();                    if (result.GraphicsListList != null)                    {                        for (int i = 0; i < result.GraphicsListList.Count; i++)                        {                            graphicsList.Add(result.GraphicsListList[i]);                        }                    }                    if (checkBox2.Checked)                    {                        if (graphicsList.Count > 0)                        {                            graphicsList[0].Selected = false;                            lines.Add(graphicsList[0]);                        }                        graphicsList = new GraphicsList();                    }                    else {                        graphicsList = new GraphicsList();                    }                    //if (result.GraphicsListList != null)                    //{                    //    if (checkBox2.Checked)                    //    {                    //        if (result.GraphicsListList.Count > 0)                    //        {                    //            lines.Add(result.GraphicsListList[0]);                    //        }                    //    }                    //    result.GraphicsListList = new GraphicsList();                    //}                    //else                    //{                    //    result.GraphicsListList = new GraphicsList();                    //}                    var documentWorkspace1 = new DocumentWorkspaceWindow(this.appWorkspace);                    Document document = Document.FromMat(result.resultMat);                    documentWorkspace1.Document = document;                    double unit = 1;                    if (this.pidRuleDic.ContainsKey(result.parentId))                    {                        if (this.pidRuleDic[result.parentId].ContainsKey(result.fileName))                        {                            unit = this.pidRuleDic[result.parentId][result.fileName];                        }                    }                    foreach (var draw in list)                    {                        if (draw.value == 0)                        {                            continue;                        }                        switch (draw.drawType)                        {                            case "MeasureLine":                                MeasureLine line = new MeasureLine(documentWorkspace1, draw.point1, draw.point2, draw.aliasName, unit);                                line.moved = true;                                line.ISurfaceBox = documentWorkspace1;                                lines.Add(line);                                break;                            case "MeasureVLine":                                MeasureVLine vline = new MeasureVLine(documentWorkspace1, draw.point1, draw.point2, draw.aliasName, unit);                                vline.moved = true;                                vline.ISurfaceBox = documentWorkspace1;                                lines.Add(vline);                                break;                            case "MeasureHLine":                                MeasureHLine hline = new MeasureHLine(documentWorkspace1, draw.point1, draw.point2, draw.aliasName, unit);                                hline.moved = true;                                hline.ISurfaceBox = documentWorkspace1;                                lines.Add(hline);                                break;                        }                    }                    graphicsList.AddRange(lines);                    measureInfoExportDataModel.matList.Add(result.resultMat);                    measureInfoExportDataModel.fileNameList.Add(result.fileName);                    measureInfoExportDataModel.GraphicsListList.Add(graphicsList);                }                var itemTypeList = item.GroupBy(m => m.TestItems);                foreach (var item2 in itemTypeList)                {                    ItemType itemType = new ItemType();                    itemType.TestItems = item2.Key;                    itemType.Specification = item2.FirstOrDefault().Specification;                    itemType.isOk = true;                    foreach (var item3 in item2)                    {                        LineData lineData = new LineData();                        lineData.name = item3.FormulaName;                        lineData.isOk = true;                        lineData.isMaxOrMin = (item3.FormulaExpression.Contains("最大值") || item3.FormulaExpression.Contains("最小值") || item3.FormulaExpression.Contains("平均值"));                        if (item3.FormulaExpression.Contains("最大值"))                        {                            lineData.typeCase = 1;                        }                        else if (item3.FormulaExpression.Contains("最小值"))                        {                            lineData.typeCase = 2;                        }                        else if (item3.FormulaExpression.Contains("平均值"))                        {                            lineData.typeCase = 3;                        }                        //计算结果                        foreach (var data in resultDataList)                        {                            double result;                            double unit = 1;                            if (this.pidRuleDic.ContainsKey(data.parentId))                            {                                if (this.pidRuleDic[data.parentId].ContainsKey(data.fileName))                                {                                    unit = this.pidRuleDic[data.parentId][data.fileName];                                }                            }                            outPutResult(data.dataInforList, lineData.isMaxOrMin, item3.FormulaExpression, unit, lineData.typeCase, out result);                            result = Math.Round(result, Program.instance.decimalPlaces);                            lineData.value.Add(result);                            if (double.IsInfinity(result) || double.IsNaN(result))                            {                                lineData.NgValue.Add(result);                                lineData.isOk = false;                                itemType.isOk = false;                            }                            else {                                if (!outOk(result, item3.Specification))                                {                                    lineData.NgValue.Add(result);                                    lineData.isOk = false;                                    itemType.isOk = false;                                }                            }                        }                        itemType.LineDataList.Add(lineData);                    }                    measureInfoExportDataModel.itemTypeList.Add(itemType);                }                measureInfoExportModel.measureInfoExportDataModelList.Add(measureInfoExportDataModel);            }            return measureInfoExportModel;        }        /// <summary>        /// 返回公式所得值        /// </summary>        /// <param name="dataInforList"></param>        /// <param name="formula"></param>        /// <param name="result"></param>        /// <returns></returns>        private double outPutResult(List<DataInfor> dataInforList, bool isMaxOrMin, string formula, double unit, int typeCase, out double result)        {            if (isMaxOrMin)            {                var str = formula.Split('\\').ToList();                str.RemoveAt(str.Count - 1);                List<double> resultList = new List<double>();                foreach (var everyStr in str)                {                    var data = dataInforList.Where(m => m.aliasName.Equals(everyStr)).FirstOrDefault();                    if (data != null)                    {                        resultList.Add(data.value * unit);                    }                    else                    {                        resultList.Add(0);                    }                }                switch (typeCase)                {                    case 1:                        result = resultList.Max();                        break;                    case 2:                        result = resultList.Min();                        break;                    case 3:                        result = resultList.Average();                        break;                    default:                        result = 0;                        break;                }            }            else            {                                foreach (var item in dataInforList)                {                    if (formula.Contains(item.aliasName))                    {                        formula = formula.Replace(item.aliasName, (item.value * unit).ToString());                    }                }                if (formula.Contains("["))                {                    result = getResult(formula);                }                else {                     result = Convert.ToDouble(FormulaHelper.CaleByFormule(formula));                }            }            return result;        }        /// <summary>        /// 获取绝对值        /// </summary>        private double getResult(string formula)        {            formula = formula.Replace("[", "Math.abs(").Replace("]", ")");            double res = Math.Abs(Convert.ToDouble(FormulaHelper.CaleByFormule(formula)));            return res;        }        /// <summary>        /// 计算单个绝对值        /// 传出绝对值结尾的下一个字符的位置pos        /// 并返回绝对值计算结果        /// </summary>        /// <param name="formula"></param>        /// <returns></returns>        private string calcuAbsVal(string formula, out int pos)        {                    string result = "";            bool inBra = false;            int braCount = 0;            pos = 0;            int i = 1;            while(i < formula.Length)            {                if(formula[i] == '[')                {                    return calcuAbsVal(formula.Substring(i), out i);                }                else if (formula[i] == ']')                 {                    // 记录该绝对值结束的位置                    pos = i + 1;                    string temp = FormulaHelper.CaleByFormule(formula.Substring(1, i));                    if(Convert.ToDouble(temp) < 0)                    {                        temp = temp.Replace("-", "");                    }                    return temp;                }            }            return FormulaHelper.CaleByFormule(result);        }        /// <summary>        /// 返回是否合格        /// </summary>        /// <returns></returns>        private bool outOk(double result, string specification)        {            specification = specification.Replace("<=", "LQ").Replace("<", "L");            List<string> list;            if (!string.IsNullOrEmpty(specification))            {                if (specification.Contains('-'))                 {                    return true;                }                list = specification.Split('X').ToList();                if (list.Count == 2)                {                    if (string.IsNullOrEmpty(list[0]))                    {                        if (list[1].Contains("LQ"))                        {                            return result <= Convert.ToDouble(list[1].Replace("LQ", ""));                        }                        else {                            return result < Convert.ToDouble(list[1].Replace("L", ""));                        }                    }                    else if (string.IsNullOrEmpty(list[1]))                    {                        if (list[0].Contains("LQ"))                        {                            return result >= Convert.ToDouble(list[0].Replace("LQ", ""));                        }                        else                        {                            return result > Convert.ToDouble(list[0].Replace("L", ""));                        }                    }                    else                    {                        bool right = true;                        bool left = true;                        if (list[1].Contains("LQ"))                        {                            right = result <= Convert.ToDouble(list[1].Replace("LQ", ""));                        }                        else                        {                            right = result < Convert.ToDouble(list[1].Replace("L", ""));                        }                        if (list[0].Contains("LQ"))                        {                            left = result >= Convert.ToDouble(list[0].Replace("LQ", ""));                        }                        else                        {                            left = result > Convert.ToDouble(list[0].Replace("L", ""));                        }                        return right && left;                    }                }                else                {                    return true;                }            }            return true;        }        /// <summary>        /// 保存图片到本地        /// </summary>        /// <param name="bitList"></param>        private string SaveAllImage(Mat mat, GraphicsList graphicsList)        {            string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\TempImg\\";            if (!Directory.Exists(filePath))            {                Directory.CreateDirectory(filePath);            }            Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);            Graphics graphics = Graphics.FromImage(bitmap);            if (graphicsList != null && graphicsList.Count > 0)            {                graphicsList.DrawPicture(graphics);            }            string fileName = filePath + Guid.NewGuid().ToString() + ".jpg";            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);            EncoderParameters parms = new EncoderParameters(1);            EncoderParameter parm;            if (Program.instance.isCompression)            {                parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 50L);            }            else            {                parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L);            }            parms.Param[0] = parm;            bitmap.Save(fileName, icf, parms);            return fileName;        }        /// <summary>        /// 显示绘制范围        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void checkBox2_CheckedChanged(object sender, EventArgs e)        {            this.documentWorkspace.GraphicsList.DeleteAllView();            if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)            {                if (checkBox2.Checked)                {                    string id = this.listView1.FocusedItem.Tag.ToString();                    var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();                    int dataIndex = 0;                    if (result != null)                    {                        dataIndex = this.resultMatList.IndexOf(result);                    }                    if (this.resultMatList[dataIndex].GraphicsListList.Count > 0)                    {                        this.resultMatList[dataIndex].GraphicsListList[0].canMove = false;                        GraphicsList graphicsList = new GraphicsList();                        graphicsList.Add(this.resultMatList[dataIndex].GraphicsListList[0].Clone(this.documentWorkspace));                        graphicsList[0].Selected = false;                        this.documentWorkspace.GraphicsList.Add(graphicsList[0]);                    }                }                else                {                    this.documentWorkspace.GraphicsList.DeleteAllView();                }                this.documentWorkspace.Refresh();            }        }        private void writeLog(string error, string typeName = "")        {            string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\ErrorLog";            if (!Directory.Exists(filePath))            {                Directory.CreateDirectory(filePath);            }            using (StreamWriter sw = new StreamWriter(filePath + "\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + typeName + "log.txt"))            {                sw.WriteLine(error);            }        }        /// <summary>        /// 开启像素跟踪        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void checkBox3_CheckedChanged(object sender, EventArgs e)        {            if (checkBox3.Checked)            {                pixelTrackingDialog = (PixelTrackingDialog)Application.OpenForms["PixelTrackingDialog"];//尝试获取已经弹出的窗口对象                if (pixelTrackingDialog == null)                {                    pixelTrackingDialog = new PixelTrackingDialog(this.appWorkspace);                }                this.pixelTrackingEnabled = true;                this.pixelTrackingDialog.TransferEvent += checkBox3Change;                FloatingFormMethod.ShowResultFloatForm(this, pixelTrackingDialog, this.appWorkspace);            }            else            {                pixelTrackingDialog = (PixelTrackingDialog)Application.OpenForms["PixelTrackingDialog"];//尝试获取已经弹出的窗口对象                this.pixelTrackingEnabled = false;                if (pixelTrackingDialog != null)                {                    pixelTrackingDialog.Close();                }            }        }        private void checkBox3Change()        {            this.checkBox3.Checked = false;        }        /// <summary>        /// 像素跟踪        /// 需要增加标记,在进行比如图像旋转等直接在当前        /// 面板进行图像大小变化操作的,需要停止像素跟踪,        /// 处理完成之后在恢复,否则可能会导致读取内存异常        /// </summary>        /// <param name="location"></param>        public void SetImageAndData(System.Drawing.Point location, DocumentView doc)        {            if (this.pixelTrackingDialog != null)            {                this.pixelTrackingDialog.SetImageAndData(location, doc);            }        }        private DateTime _time;        private void documentWorkspace_panel_MouseMove(object sender, MouseEventArgs e)        {            if (this.pixelTrackingEnabled && this.pixelTrackingDialog != null)            {                if ((DateTime.Now - _time).TotalMilliseconds > 20)                {                    this.SetImageAndData(this.documentWorkspace.CalcPixelPoint(e.Location), this.documentWorkspace);                    _time = DateTime.Now;                }            }            int count = this.documentWorkspace.GraphicsList.SelectionCount;            if (count == 1)             {                DrawObject drawObject = this.documentWorkspace.GraphicsList.Selection.ToList()[0];                if (drawObject.objectType == DrawClass.Measure) {                    MeasureDrawObject measureDrawObject = (MeasureDrawObject)drawObject;                    RectangleF rectangle = measureDrawObject.GetBoundingBox();                    Rectangle newRectangle;                    switch (measureDrawObject.drawToolType) {                        case DrawToolType.MeasureLine:                            newRectangle = new Rectangle((int)(rectangle.X - 20), (int)(rectangle.Y - 20), (int)(rectangle.Width + 20), (int)(rectangle.Height + 20));                            break;                        case DrawToolType.MeasureHLine:                            newRectangle = new Rectangle((int)(rectangle.X - 20), (int)(rectangle.Y - 20), (int)(rectangle.Width + 20), 40);                            break;                        case DrawToolType.MeasureVLine:                            newRectangle = new Rectangle((int)(rectangle.X - 20), (int)(rectangle.Y - 20), 40, (int)(rectangle.Height + 20));                            break;                        default:                            newRectangle = new Rectangle((int)(rectangle.X - 20), (int)(rectangle.Y - 20), 40, (int)(rectangle.Height + 20));                            break;                    }                    if (newRectangle.Contains(this.documentWorkspace.CalcPixelPoint(e.Location)))                    {                        string name = this.appWorkspace.getRealName(this.measureMaintenanceTypeList.MeasureMaintenanceTreeDataList, measureDrawObject.aliasName);                        this.toolTip.Show(name, this.documentWorkspace, new System.Drawing.Point(e.Location.X + 10, e.Location.Y + 10));                    }                    else                    {                        this.toolTip.Hide(this.documentWorkspace);                    }                }            }        }        /// <summary>        /// 绘制范围        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button2_Click(object sender, EventArgs e)        {            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return;            }            List<Bitmap> bitmaps = new List<Bitmap>();            List<string> nameList = new List<string>();            Dictionary<int, GraphicsList> imgGraphicsList = new Dictionary<int, GraphicsList>();            Dictionary<int, bool> ImgisConductive = new Dictionary<int, bool>();            Dictionary<int, bool> ImgisFanweibuchang = new Dictionary<int, bool>();            Dictionary<int, bool> ImgisErzhichuli = new Dictionary<int, bool>();            Dictionary<int, bool> needShowDaoDianbu = new Dictionary<int, bool>();            Dictionary<int, bool> needShowFanweibuchang = new Dictionary<int, bool>();            Dictionary<int, bool> needShowErzhichuli = new Dictionary<int, bool>();            Dictionary<int, int> correspondNum = new Dictionary<int, int>();            for (int i = 0; i < this.listView1.SelectedItems.Count; i++)             {                var index = this.listView1.SelectedItems[i].Index;                Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.resultMatList[index].resultMat);                bitmaps.Add(bitmap);                nameList.Add(this.listView1.SelectedItems[i].Text);                bool show;                bool showFanweibuchang;                bool showErzhichuli;                string id = this.resultMatList[index].parentId;                MeasureMaintenanceTreeSpecificData data;                this.appWorkspace.RecursionGetData(id, this.measureMaintenanceTypeList.MeasureMaintenanceTreeDataList, out data);                if (data.MeasureMaintenanceTreeSpecificDataParentId == "9")                {                    show = true;                }                else                {                    show = false;                }                if (data.MeasureMaintenanceTreeSpecificDataParentId == "10"                    && data.MeasureMaintenanceTreeSpecificDataId == "100300")                {                    showFanweibuchang = true;                }                else                {                    showFanweibuchang = false;                }                if (true && data.MeasureMaintenanceTreeSpecificDataParentId == "7"                    && data.MeasureMaintenanceTreeSpecificDataId == "100176")                {                    showErzhichuli = true;                }                else                {                    showErzhichuli = false;                }                GraphicsList graphicsList = new GraphicsList();                for (int j = 0; j < this.resultMatList[index].GraphicsListList.Count; j++)                 {                    if (this.resultMatList[index].GraphicsListList[j].drawToolType == DrawToolType.ViewRectangle)                     {                        graphicsList.Add(this.resultMatList[index].GraphicsListList[j]);                    }                }                needShowDaoDianbu.Add(index, show);                needShowFanweibuchang.Add(index, showFanweibuchang);                needShowErzhichuli.Add(index, showErzhichuli);                imgGraphicsList.Add(index, graphicsList);                ImgisConductive.Add(index, this.resultMatList[index].isConductive);                ImgisFanweibuchang.Add(index, this.resultMatList[index].isFanweibuchang);                ImgisErzhichuli.Add(index, this.resultMatList[index].isErzhichuli);                correspondNum.Add(i, index);            }            ResultsViewRange from2 = new ResultsViewRange(bitmaps, nameList, this, this.appWorkspace, imgGraphicsList, ImgisConductive, needShowDaoDianbu, ImgisFanweibuchang, needShowFanweibuchang, ImgisErzhichuli, needShowErzhichuli, correspondNum);            from2.StartPosition = FormStartPosition.CenterParent;            from2.ShowDialog();        }        public void getList(Dictionary<int, GraphicsList> dataList)        {            foreach (var item in dataList)            {                this.resultMatList[item.Key].GraphicsListList = item.Value;                var result = this.realResultMatList.Where(m => m.ID == this.resultMatList[item.Key].ID).FirstOrDefault();                if (result != null)                 {                    result.GraphicsListList = item.Value;                }            }        }        public void getBoolList(Dictionary<int, bool> dataList)        {            foreach (var item in dataList)            {                this.resultMatList[item.Key].isConductive = item.Value;                var result = this.realResultMatList.Where(m => m.ID == this.resultMatList[item.Key].ID).FirstOrDefault();                if (result != null)                {                    result.isConductive = item.Value;                }            }        }        public void getErzhichuliList(Dictionary<int, bool> dataList)        {            foreach (var item in dataList)            {                this.resultMatList[item.Key].isErzhichuli = item.Value;                var result = this.realResultMatList.Where(m => m.ID == this.resultMatList[item.Key].ID).FirstOrDefault();                if (result != null)                {                    result.isErzhichuli = item.Value;                }            }        }        public void getFanweibuchangList(Dictionary<int, bool> dataList)        {            foreach (var item in dataList)            {                this.resultMatList[item.Key].isFanweibuchang = item.Value;                var result = this.realResultMatList.Where(m => m.ID == this.resultMatList[item.Key].ID).FirstOrDefault();                if (result != null)                {                    result.isFanweibuchang = item.Value;                }            }        }        public void getMatList(Dictionary<int, Bitmap> bitmapData)        {            foreach (var item in bitmapData)            {                this.resultMatList[item.Key].resultMat = OpenCvSharp.Extensions.BitmapConverter.ToMat(item.Value);                this.imageList1.Images[item.Key] = CreateThumbnail(this.resultMatList[item.Key].resultMat);                for (int i = 0; i < this.resultMatList[item.Key].dataInforList.Count; i++)                 {                    this.resultMatList[item.Key].dataInforList[i].point1 = new System.Drawing.Point(0, 0);                    this.resultMatList[item.Key].dataInforList[i].point2 = new System.Drawing.Point(0, 0);                    this.resultMatList[item.Key].dataInforList[i].value = 0;                }                this.listView1.Refresh();            }            this.listView1_SelectedIndexChanged(null, null);        }        /// <summary>        /// 再次分析        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        // TODO:bug        private void button1_Click(object sender, EventArgs e)        {            this.documentWorkspace.activeTool = DrawToolType.Pointer;            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return;            }            List<int> indexList = new List<int>();            for (int i = 0; i < this.listView1.SelectedItems.Count; i++)            {                int index = this.listView1.SelectedItems[i].Index;                indexList.Add(index);            }            ProgressThreadProcClass procClass = new ProgressThreadProcClass();            int itemCount = 100;            ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();            System.Threading.ThreadStart copyThreadProc =                delegate ()                {                    for (int i = 0; i < indexList.Count; i++)                    {                        var resultMat = this.resultMatList[indexList[i]];                        string className = InvariantData.path_auto + $".{this._listHoleType[resultMat.parentId]}";                        GraphicsList graphicsList = resultMat.GraphicsListList;                        bool isErzhichuli = resultMat.isErzhichuli;                        bool isFanweibuchang = resultMat.isFanweibuchang;                        bool isConductive = resultMat.isConductive;                        bool position = resultMat.isPosition;                        var currentParam = (AutoMeasureAnalysis)Assembly.Load(InvariantData.auto_Data).CreateInstance(className);                        Mat thisMat = resultMat.resultMat.Clone();                        currentParam.setErzhichuli(isErzhichuli);                        currentParam.setFanweibuchang(isFanweibuchang);                        currentParam.setBool(isConductive);                        currentParam.setIsNewSuanfa(position);                        try                        {                            GraphicsList newGraphicsList = new GraphicsList();                            for (int j = 0; j < resultMat.GraphicsListList.Count; j++)                            {                                if (resultMat.GraphicsListList[j].drawToolType == DrawToolType.ViewRectangle)                                {                                    newGraphicsList.Add(resultMat.GraphicsListList[j]);                                }                            }                            if (newGraphicsList.Count == 0)                            {                                currentParam.Compute(thisMat, false, 0, 0);                            }                            else                            {                                int X = (int)newGraphicsList[0].Rectangle.X;                                int Y = (int)newGraphicsList[0].Rectangle.Y;                                int reWidth = (int)newGraphicsList[0].Rectangle.Width;                                int reHeight = (int)newGraphicsList[0].Rectangle.Height;                                Bitmap newBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(thisMat);                                if (newGraphicsList[0].Rectangle.Contains(new RectangleF(0, 0, newBitmap.Width, newBitmap.Height)))                                {                                    X = 0;                                    Y = 0;                                    reWidth = newBitmap.Width;                                    reHeight = newBitmap.Height;                                }                                else                                {                                    if (newGraphicsList[0].Rectangle.IntersectsWith(new RectangleF(0, 0, newBitmap.Width, newBitmap.Height)))                                    {                                        RectangleF rectangleF = new RectangleF(newGraphicsList[0].Rectangle.X, newGraphicsList[0].Rectangle.Y,newGraphicsList[0].Rectangle.Width, newGraphicsList[0].Rectangle.Height);                                        rectangleF.Intersect(new RectangleF(0, 0, newBitmap.Width, newBitmap.Height));                                        X = (int)rectangleF.X;                                        Y = (int)rectangleF.Y;                                        reWidth = (int)rectangleF.Width;                                        reHeight = (int)rectangleF.Height;                                    }                                }                                Mat mat = new Mat(thisMat, new Rect(X, Y, reWidth, reHeight));                                currentParam.Compute(mat, true, X, Y);                            }                        }                        catch (Exception ex)                        {                        }                        resultMat.resultMat = thisMat;                        resultMat.allLineNum = currentParam.number;                        resultMat.successNum = currentParam.success;                        resultMat.failNum = currentParam.wrongNumber;                        resultMat.dataInforList.Clear();                        List<DataInfor> listdata = new List<DataInfor>();                        foreach (var dataInfo in currentParam.dataInfors)                        {                            DataInfor dataInfor = new DataInfor();                            dataInfor.drawType = dataInfo.drawType;                            dataInfor.value = dataInfo.value;                            dataInfor.point1 = dataInfo.point1;                            dataInfor.point2 = dataInfo.point2;                            dataInfor.name = dataInfo.name;                            dataInfor.aliasName = dataInfo.aliasName;                            dataInfor.ID = dataInfo.ID;                            dataInfor.deleteFlag = dataInfo.deleteFlag;                            listdata.Add(dataInfor);                        }                        resultMat.dataInforList.AddRange(listdata);                    }                    progressEvents.EndOperation(OperationResult.Finished);                };            procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null);            for (int i = 0; i < this.listView1.SelectedItems.Count; i++)            {                var index = this.listView1.SelectedItems[i].Index;                this.listView1.SelectedItems[i].BackColor = this.resultMatList[index].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                if (i == 0)                 {                    this.listView1.Items[index].Focused = true;                }            }                        this.listView1.Refresh();            #region [组织应该展示的线 去除不应该展示的线]            foreach (var item in resultMatList)            {                List<DataInfor> removeList = new List<DataInfor>();                if (this.LineShowDic.ContainsKey(item.parentId))                {                    foreach (var item2 in item.dataInforList)                    {                        if (!this.LineShowDic[item.parentId].Contains(item2.ID))                        {                            removeList.Add(item2);                        }                    }                    foreach (var item2 in removeList)                    {                        item.dataInforList.Remove(item2);                    }                }            }            #endregion [组织应该展示的线 去除不应该展示的线]            listView1_SelectedIndexChanged(null, null);        }        /// <summary>        /// 全选        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button3_Click(object sender, EventArgs e)        {            for (int i = 0; i < this.listView1.Items.Count; i++)            {                this.listView1.Items[i].Selected = true;                if (i == 0)                {                    this.listView1.Items[i].Focused = true;                }            }        }        /// <summary>        /// 全不选        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button4_Click(object sender, EventArgs e)        {            for (int i = 0; i < this.listView1.Items.Count; i++)            {                this.listView1.Items[i].Selected = false;                if (i == 0)                {                    this.listView1.Items[i].Selected = true;                    this.listView1.Items[i].Focused = true;                }            }        }        /// <summary>        /// 反选        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button5_Click(object sender, EventArgs e)        {            for (int i = 0; i < this.listView1.Items.Count; i++)            {                this.listView1.Items[i].Selected = !this.listView1.Items[i].Selected;            }            if (this.listView1.SelectedItems.Count > 0)             {                this.listView1.SelectedItems[0].Focused = true;                this.listView1_SelectedIndexChanged(null, null);            }        }        /// <summary>        /// 命名规则        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button6_Click(object sender, EventArgs e)        {            //NameRuleListDetails nameRuleListDetails = new NameRuleListDetails();            //if (this.thisNameRuleListDetails == null)            //{            //    if (!string.IsNullOrEmpty(this.measureMaintenanceType.NameRuleID))            //    {            //        var oldNameRuleListDetails = Program.instance.fileNameRule.NameRuleList.Where(m => m.ID == this.measureMaintenanceType.NameRuleID).FirstOrDefault();            //        if (oldNameRuleListDetails != null)            //        {            //            nameRuleListDetails.ContinueNumber = oldNameRuleListDetails.ContinueNumber;            //            nameRuleListDetails.DigitNum = oldNameRuleListDetails.DigitNum;            //            nameRuleListDetails.ID = oldNameRuleListDetails.ID;            //            nameRuleListDetails.isContinue = oldNameRuleListDetails.isContinue;            //            nameRuleListDetails.Name = oldNameRuleListDetails.Name;            //            nameRuleListDetails.NameFormat = oldNameRuleListDetails.NameFormat;            //            nameRuleListDetails.NowNumber = oldNameRuleListDetails.NowNumber;            //            nameRuleListDetails.Text = oldNameRuleListDetails.Text;            //            nameRuleListDetails.ZTextOne = oldNameRuleListDetails.ZTextOne;            //            nameRuleListDetails.ZTextTwo = oldNameRuleListDetails.ZTextTwo;            //        }            //    }            //}            //else {            //    nameRuleListDetails = this.thisNameRuleListDetails;            //}            using (ResultViewNameRule2 af = new ResultViewNameRule2(this,this.measureMaintenanceType))            {                af.StartPosition = FormStartPosition.CenterScreen;                af.ShowDialog();            }        }        public void NameRuleCallBack(NameRuleListDetails nameRuleListDetails)         {            if(nameRuleListDetails != null)                this.measureMaintenanceType.NameRuleID = nameRuleListDetails.ID;            if (nameRuleListDetails != null)                this.thisNameRuleListDetails = nameRuleListDetails;            this.yuLan(nameRuleListDetails);        }        public void itemNumCallBack(string itemNum)         {            this.measureMaintenanceType.measureMaintenanceBasicDataList[0].measureMaintenanceBasicDataValue = itemNum;            this.isSPCItemNull = true;            buttonGenerateReport_Click(null, null);        }        /// <summary>        /// 选择模板        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button7_Click(object sender, EventArgs e)        {            OpenFileDialog dialog = new OpenFileDialog();            dialog.Filter = "Excel文件|*.xls;*.xlsx";            dialog.Title = "选择模板";            dialog.Multiselect = false; //该值确定是否可以选择多个文件            if (dialog.ShowDialog() != DialogResult.OK)            {                return;            }            string file = dialog.FileName;            measureMaintenanceType.templateFilePath = file;            MessageBox.Show("模板更换成功!");        }        /// <summary>        /// 图片删除        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button8_Click(object sender, EventArgs e)        {            if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)            {                return;            }            this.listView1.SelectedIndexChanged -= listView1_SelectedIndexChanged;            for (int i = this.listView1.SelectedItems.Count - 1; i >= 0; i--)            {                string id = this.listView1.SelectedItems[i].Tag.ToString();                var result = this.resultMatList.Where(m => m.ID == id).FirstOrDefault();                if (result != null)                 {                    this.hasDelResultMatList.Add(result);                    this.resultMatList.Remove(result);                    var realresult = this.realResultMatList.Where(m => m.ID == id).FirstOrDefault();                    if (realresult != null)                     {                         this.realResultMatList.Remove(realresult);                    }                }                this.listView1.Items.Remove(this.listView1.SelectedItems[i]);            }            this.listView1.SelectedIndexChanged += listView1_SelectedIndexChanged;            if (this.listView1.Items.Count > 0)            {                this.listView1.Items[0].Focused = true;                this.listView1.Items[0].Selected = true;                this.listView1_SelectedIndexChanged(null, null);            }            else             {                this.documentWorkspace.Visible = false;                if (panel2.Controls != null)                {                    foreach (Control c in panel2.Controls)                    {                        c.Visible = false;                    }                }            }            this.listView1.Refresh();        }        /// <summary>        /// 图片恢复        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button9_Click(object sender, EventArgs e)        {            int count = this.listView1.Items.Count;            this.hasDelResultMatList.Reverse();            for (int i = 0; i < this.hasDelResultMatList.Count; i++)            {                Mat mat = new Mat();                Cv2.CvtColor(this.hasDelResultMatList[i].resultMat, mat, ColorConversionCodes.BGRA2BGR);                this.imageList1.Images.Add("img" + count, CreateThumbnail(mat));                this.listView1.Items.Add("", count);                this.listView1.Items[count].ImageIndex = count;                this.listView1.Items[count].Tag = this.hasDelResultMatList[i].ID;                this.listView1.Items[count].Text = this.hasDelResultMatList[i].fileName;                this.listView1.Items[count].BackColor = this.hasDelResultMatList[i].dataInforList.Where(m => m.value == 0).FirstOrDefault() == null ? Color.White : Color.Red;                count++;                mat.Dispose();                this.resultMatList.Add(this.hasDelResultMatList[i]);                this.realResultMatList.Add(this.hasDelResultMatList[i]);            }            comboClassification_SelectedIndexChanged(sender, e);            comboStatus_SelectedIndexChanged(sender, e);            this.listView1.Refresh();            this.hasDelResultMatList.Clear();        }        /// <summary>        /// 勾选辅助线        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void checkBox4_CheckedChanged(object sender, EventArgs e)        {            this.documentWorkspace.auxiliaryLineEnabled = !this.documentWorkspace.auxiliaryLineEnabled;            if (this.documentWorkspace.auxiliaryLineEnabled)             {                this.documentWorkspace.girdLineColour = Program.instance.configModel.girdLineColour;                this.documentWorkspace.girdLineStyle = Program.instance.configModel.girdLineStyle;                this.documentWorkspace.girdLineWidth = Program.instance.configModel.girdLineWidth;            }            this.documentWorkspace.Refresh();        }        public string getMeasureMaintenanceTypeID()        {            return this.measureMaintenanceType.NameRuleID;        }        /// <summary>        /// 结果预览        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button10_Click(object sender, EventArgs e)        {                        string titleName = measureMaintenanceType.measureMaintenanceName;            #region [组织预览数据]            MeasureInfoExportModel measureInfoExportModel = OrganizePreviewResultData(this.resultMatList);            #endregion            ResultViewPreview resultViewPreview = new ResultViewPreview(this,titleName, this.measureMaintenanceType.outputPicturesNum, measureInfoExportModel);            resultViewPreview.StartPosition = FormStartPosition.CenterParent;            resultViewPreview.ShowDialog();        }        /// <summary>        /// 组织预览数据        /// </summary>        private MeasureInfoExportModel OrganizePreviewResultData(List<MeasureInfoResultModel> thisResultMatList)        {            MeasureInfoExportModel measureInfoExportModel = new MeasureInfoExportModel();            var HoleTypeList = this.measureMaintenanceType.MeasureMaintenanceTreeFourthDataList.GroupBy(m => m.HoleType);            #region [先整理下整体的数据]            #region [特殊处理下叠构]            var resList = thisResultMatList.Where(m => m.parentId.Equals("100209")).ToList();            if (resList.Count > 0)            {                foreach (var item in resList)                {                    List<string> nameList = item.dataInforList.Select(m => m.name).ToList();                    var ls = item.dataInforList.OrderBy(m => m.point1.Y).ToList();                    for (int i = 0; i < ls.Count(); i++)                    {                        ls[i].name = nameList[i];                    }                }                thisResultMatList.RemoveAll(m => m.parentId.Equals("100209"));                thisResultMatList.AddRange(resList);            }            #endregion [特殊处理下叠构]            var dataList = HoleTypeList.ToList();            for (int i = dataList.Count - 1; i >= 0; i--)            {                var data = dataList[i];                var resultDataList = thisResultMatList.Where(m => m.parentId.Equals(data.First().HoleTypeId)).ToList();                var a = Math.Ceiling(Convert.ToDouble(resultDataList.Count()) / Convert.ToDouble(this.measureMaintenanceType.outputPicturesNum));                if (a > 0)                {                    for (int j = 1; j <= a; j++)                    {                        dataList.Insert(i + j, data);                    }                    dataList.RemoveAt(i);                }            }            #endregion [先整理下整体的数据]            string name = string.Empty;            int startNum = 0;            foreach (var item in dataList)            {                MeasureInfoExportDataModel measureInfoExportDataModel = new MeasureInfoExportDataModel();                measureInfoExportDataModel.HoleType = item.Key;                measureInfoExportDataModel.HoleTypeId = item.FirstOrDefault().HoleTypeId;                var resultDataList = thisResultMatList.Where(m => m.parentId.Equals(measureInfoExportDataModel.HoleTypeId)).ToList();                if (name.Equals(item.Key))                {                    startNum++;                }                else                {                    name = item.Key;                    startNum = 0;                }                resultDataList = resultDataList.Skip(this.measureMaintenanceType.outputPicturesNum * startNum).Take(this.measureMaintenanceType.outputPicturesNum).ToList();                var itemTypeList = item.GroupBy(m => m.TestItems);                foreach (var item2 in itemTypeList)                {                    ItemType itemType = new ItemType();                    itemType.TestItems = item2.Key;                    itemType.Specification = item2.FirstOrDefault().Specification;                    itemType.isOk = true;                    foreach (var item3 in item2)                    {                        LineData lineData = new LineData();                        lineData.name = item3.FormulaName;                        lineData.isOk = true;                        lineData.isMaxOrMin = (item3.FormulaExpression.Contains("最大值") || item3.FormulaExpression.Contains("最小值") || item3.FormulaExpression.Contains("平均值"));                        if (item3.FormulaExpression.Contains("最大值"))                        {                            lineData.typeCase = 1;                        }                        else if (item3.FormulaExpression.Contains("最小值"))                        {                            lineData.typeCase = 2;                        }                        else if (item3.FormulaExpression.Contains("平均值"))                        {                            lineData.typeCase = 3;                        }                        //计算结果                        foreach (var data in resultDataList)                        {                            double result;                            double unit = 1;                            if (this.pidRuleDic.ContainsKey(data.parentId))                            {                                if (this.pidRuleDic[data.parentId].ContainsKey(data.fileName))                                {                                    unit = this.pidRuleDic[data.parentId][data.fileName];                                }                            }                            outPutResult(data.dataInforList, lineData.isMaxOrMin, item3.FormulaExpression, unit, lineData.typeCase, out result);                            result = Math.Round(result, Program.instance.decimalPlaces);                            lineData.value.Add(result);                            lineData.matIndex.Add(this.resultMatList.IndexOf(data));                            if (double.IsInfinity(result) || double.IsNaN(result))                            {                                lineData.NgValue.Add(result);                                lineData.isOk = false;                                itemType.isOk = false;                            }                            else                            {                                if (!outOk(result, item3.Specification))                                {                                    lineData.NgValue.Add(result);                                    lineData.isOk = false;                                    itemType.isOk = false;                                }                            }                        }                        itemType.LineDataList.Add(lineData);                    }                    measureInfoExportDataModel.itemTypeList.Add(itemType);                }                measureInfoExportModel.measureInfoExportDataModelList.Add(measureInfoExportDataModel);            }            return measureInfoExportModel;        }        public void returnMatView(int index)         {            for (int i = 0; i < this.listView1.Items.Count; i++)            {                this.listView1.Items[i].Selected = false;            }            this.listView1.Focus();            //滚动到指定的行位置            this.listView1.EnsureVisible(index);            this.listView1.Items[index].Focused = true;            this.listView1.Items[index].Selected = true;        }    }}
 |