| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 | using Resources;using SmartCoalApplication.Core;using SmartCoalApplication.Resources;using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Text.RegularExpressions;using System.Windows.Forms;namespace SmartCoalApplication.AutomaticMeasurement{    public partial class ResultViewPreview : PdnBaseForm    {        private ResultsView resultsView;        public const int WM_NCLBUTTONDBLCLK = 0xA3;        private const int WM_NCLBUTTONDOWN = 0x00A1;        private const int HTCAPTION = 2;        private MeasureInfoExportModel measureInfoExportModel;        private int rowLine = 5;        protected override void WndProc(ref Message m)        {            if (m.Msg == WM_NCLBUTTONDOWN && m.WParam.ToInt32() == HTCAPTION)                return;            if (m.Msg == WM_NCLBUTTONDBLCLK)                return;            base.WndProc(ref m);        }        public ResultViewPreview(ResultsView resultsView, string titleName, int rowLines, MeasureInfoExportModel measureInfoExportModel)        {            InitializeComponent();            this.resultsView = resultsView;            this.Text = $"切片检验报告-{titleName}";            this.Icon = PdnInfo.AppIcon;            this.measureInfoExportModel = measureInfoExportModel;            if (rowLines > 5)            {                this.rowLine = rowLines;            }            #region[左边相同的部分]            // 表头            int height = 38;            int width = (this.Size.Width + 280) / 10;            int dataWidth = (this.Size.Width - width * 5) / 5 + 5;            string[] titles = { PdnResources.GetString("NewHoleTypeName"), PdnResources.GetString("NewTestItemsName"), PdnResources.GetString("NewSpecificationName"), PdnResources.GetString("NewMeasuringPositionName") };            string[] titleNames = { "kongxing", "jianyanxiangmu", "guige", "celiangweizhi" };            List<Label> positions = new List<Label>();            List<Label> specifications = new List<Label>();            List<Label> testItems = new List<Label>();            List<Label> holeTypes = new List<Label>();            List<Label> datas = new List<Label>();            List<Label> judges = new List<Label>();            List<Label> judgeFalses = new List<Label>();            List<bool> judgeList = new List<bool>();            int groupsNum = this.measureInfoExportModel.measureInfoExportDataModelList.Count / this.rowLine; // 共输出几组数据            int i, k, judgeSame;            for (i = 0; i < 4; i++)            {                Label title = new Label();                title.AutoSize = false;                title.TextAlign = ContentAlignment.MiddleCenter;                title.BorderStyle = BorderStyle.FixedSingle;                title.Location = new System.Drawing.Point(3 + (width - 1) * i, 3);                title.Name = titleNames[i];                title.Size = new System.Drawing.Size(width, height);                title.TabIndex = 2;                title.Text = titles[i];                panelResultViewPreview.Controls.Add(title);            }            // 表头            for (int c = 0; c < rowLine; c++)            {                Label num = new Label();                num.AutoSize = false;                num.TextAlign = ContentAlignment.MiddleCenter;                num.BorderStyle = BorderStyle.FixedSingle;                if (testItems.Count == 0)                    num.Location = new System.Drawing.Point((width - 1) * 4, 3);                else                    num.Location = new System.Drawing.Point((width - 1) * 4 + c * dataWidth, 3);                num.Name = c.ToString();                num.Size = new System.Drawing.Size(dataWidth + 1, height);                num.TabIndex = 2;                num.Text = (c + 1).ToString();                panelResultViewPreview.Controls.Add(num);                testItems.Add(num);            }            #region[右边判断]            // 判断栏表头            for (int c = 0; c < 3; c++)            {                Label judge = new Label();                judge.AutoSize = false;                judge.TextAlign = ContentAlignment.MiddleCenter;                judge.BorderStyle = BorderStyle.FixedSingle;                switch (c)                {                    // 判断                    case 0:                        judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, 3);                        judge.Size = new System.Drawing.Size(dataWidth + 1, height / 2);                        judge.Text = PdnResources.GetString("judge");                        break;                    // OK                    case 1:                        judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, height / 2 - 1);                        judge.Size = new System.Drawing.Size(dataWidth / 2 + 4, height / 2 + 4);                        judge.Text = "OK";                        break;                    // NG                    case 2:                        judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width + dataWidth / 2, height / 2 - 1);                        judge.Size = new System.Drawing.Size(dataWidth / 2 + 2, height / 2 + 4);                        judge.Text = "NG";                        break;                    default: break;                }                //data.Name = item2.Key + "1";                judge.TabIndex = 2;                if (c == 0)                {                    judge.Text = PdnResources.GetString("judge");                }                panelResultViewPreview.Controls.Add(judge);                judges.Add(judge);            }            #endregion            var list1 = this.measureInfoExportModel.measureInfoExportDataModelList;            int s = 0;            int index = 0;                        List<int> same = new List<int>();            int n = 0;            foreach (var item in list1)            {                int rowInt = 0;                foreach (var item2 in item.itemTypeList)                {                    k = 0;                    int p = -1;                    foreach (var item3 in item2.LineDataList)                    {                        #region [測量位置]                        Label position = new Label();                        position.AutoSize = false;                        position.TextAlign = ContentAlignment.MiddleCenter;                        position.BorderStyle = BorderStyle.FixedSingle;                        if (positions.Count == 0)                            position.Location = new System.Drawing.Point(3 + (width - 1) * 3, height);                        else                            position.Location = new System.Drawing.Point(3 + (width - 1) * 3, positions[positions.Count - 1].Location.Y + height);                        position.Name = item3.name;                        position.Size = new System.Drawing.Size(width, height + 1);                        position.TabIndex = 2;                        position.Text = item3.name;                        panelResultViewPreview.Controls.Add(position);                        positions.Add(position);                        #endregion [測量位置]                        #region [填充数据]                        if (!item3.isMaxOrMin)                        {                            int colCount = 0;                            foreach (var item4 in item3.value)                            {                                Label data = new Label();                                data.AutoSize = false;                                data.TextAlign = ContentAlignment.MiddleCenter;                                data.BorderStyle = BorderStyle.FixedSingle;                                if (datas.Count == 0)                                {                                    data.Location = new System.Drawing.Point((width - 1) * 4, position.Location.Y);                                }                                else                                {                                    data.Location = new System.Drawing.Point((width - 1) * 4 + colCount * dataWidth, position.Location.Y);                                }                                //data.Name = item2.Key + "1";                                data.Size = new System.Drawing.Size(dataWidth + 1, height + 1);                                data.TabIndex = 2;                                data.Text = item4.ToString();                                if (item3.NgValue.Contains(item4))                                {                                    data.ForeColor = Color.Red;                                }                                data.DoubleClick += ReturnView;                                if (!item3.isMaxOrMin)                                {                                    data.Tag = item3.matIndex[colCount];                                }                                panelResultViewPreview.Controls.Add(data);                                datas.Add(data);                                colCount++;                            }                            if (item3.value.Count < this.rowLine)                            {                                for (int o = colCount; o < this.rowLine && o >= colCount; o++)                                {                                    Label data = new Label();                                    data.AutoSize = false;                                    data.TextAlign = ContentAlignment.MiddleCenter;                                    data.BorderStyle = BorderStyle.FixedSingle;                                    if (datas.Count == 0)                                    {                                        data.Location = new System.Drawing.Point((width - 1) * 4, position.Location.Y);                                    }                                    else                                    {                                        data.Location = new System.Drawing.Point((width - 1) * 4 + o * dataWidth, position.Location.Y);                                    }                                    //data.Name = item2.Key + "1";                                    data.Size = new System.Drawing.Size(dataWidth + 1, height + 1);                                    data.TabIndex = 2;                                    data.Text = "-";                                    panelResultViewPreview.Controls.Add(data);                                    datas.Add(data);                                }                            }                        }                        else                        {                            Label data = new Label();                            data.AutoSize = false;                            data.TextAlign = ContentAlignment.MiddleCenter;                            data.BorderStyle = BorderStyle.FixedSingle;                            data.Location = new System.Drawing.Point((width - 1) * 4, position.Location.Y);                            //data.Name = item2.Key + "1";                            data.Size = new System.Drawing.Size((dataWidth) * this.rowLine + 1, height + 1);                            data.TabIndex = 2;                            if (item3.NgValue.Contains(Math.Round(item3.value.Max())))                            {                                data.ForeColor = Color.Red;                            }                            if(item3.value != null && item3.value.Count != 0)                            {                                switch (item3.typeCase)                                {                                    case 1:                                        data.Text = Math.Round(item3.value.Max(), Program.instance.decimalPlaces).ToString();                                        break;                                    case 2:                                        data.Text = Math.Round(item3.value.Min(), Program.instance.decimalPlaces).ToString();                                        break;                                    case 3:                                        data.Text = Math.Round(item3.value.Average(), Program.instance.decimalPlaces).ToString();                                        break;                                    default:                                        data.Text = "0";                                        break;                                }                            }                            else                            {                                data.Text = "-";                            }                            panelResultViewPreview.Controls.Add(data);                            datas.Add(data);                        }                        #endregion                        k++;                        rowInt++;                        n++;                                            }                    #region [規格]                    Label specification = new Label();                    specification.AutoSize = false;                    specification.TextAlign = ContentAlignment.MiddleCenter;                    specification.BorderStyle = BorderStyle.FixedSingle;                    if (specifications.Count == 0)                        specification.Location = new System.Drawing.Point(3 + (width - 1) * 2, positions[positions.Count - k].Location.Y);                    else                        specification.Location = new System.Drawing.Point(3 + (width - 1) * 2, positions[positions.Count - k].Location.Y);                    specification.Name = item2.Specification;                    specification.Size = new System.Drawing.Size(width, height * k + 1);                    specification.TabIndex = 2;                    item2.Specification = item2.Specification.Replace("LQ", "<=");                    item2.Specification = item2.Specification.Replace("L", "<");                    // 替換為與excel相同的字符                    string pattern = @"<=?X<=?";                    item2.Specification = Regex.Replace(item2.Specification, pattern, "~");                    item2.Specification = item2.Specification.Replace("X", "");                    specification.Text = item2.Specification;                    panelResultViewPreview.Controls.Add(specification);                    specifications.Add(specification);                    bool haveData = true;                    foreach (var item3 in item2.LineDataList)                    {                        if(item3.value.Count == 0)                        {                            haveData = false;                        }                    }                    if (!string.IsNullOrEmpty(item2.Specification) && !item2.Specification.Equals("-") && haveData)                    {                        Label judge = new Label();                        judge.AutoSize = false;                        judge.TextAlign = ContentAlignment.MiddleCenter;                        judge.BorderStyle = BorderStyle.FixedSingle;                        if (judges.Count == 0)                        {                            judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, specification.Location.Y);                            judge.Size = new System.Drawing.Size(dataWidth / 2 + 4, specification.Height);                        }                        else                        {                            judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, specification.Location.Y);                            judge.Size = new System.Drawing.Size(dataWidth / 2 + 4, specification.Height);                        }                        judge.TabIndex = 2;                        if (item2.isOk)                        {                            judge.Text = "V";                        }                        panelResultViewPreview.Controls.Add(judge);                        judges.Add(judge);                        Label judgeFalse = new Label();                        judgeFalse.AutoSize = false;                        judgeFalse.TextAlign = ContentAlignment.MiddleCenter;                        judgeFalse.BorderStyle = BorderStyle.FixedSingle;                        if (judgeFalses.Count == 0)                        {                            judgeFalse.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width + dataWidth / 2 - 1, specification.Location.Y);                            judgeFalse.Size = new System.Drawing.Size(dataWidth / 2 + 3, specification.Height);                        }                        else                        {                            judgeFalse.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width + dataWidth / 2 - 1, specification.Location.Y);                            judgeFalse.Size = new System.Drawing.Size(dataWidth / 2 + 3, specification.Height);                        }                        judgeFalse.TabIndex = 2;                        if (!item2.isOk)                        {                            judgeFalse.Text = "V";                        }                        panelResultViewPreview.Controls.Add(judgeFalse);                        judgeFalses.Add(judgeFalse);                    }                    else                    {                        Label judge = new Label();                        judge.AutoSize = false;                        judge.TextAlign = ContentAlignment.MiddleCenter;                        judge.BorderStyle = BorderStyle.FixedSingle;                        judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, specification.Location.Y);                        judge.Size = new System.Drawing.Size(dataWidth + 1, height * k + 1);                        judge.TabIndex = 2;                        judge.Text = "N/A";                        panelResultViewPreview.Controls.Add(judge);                        judges.Add(judge);                    }                    #endregion                    #region [檢驗項目]                    Label testItem = new Label();                    testItem.AutoSize = false;                    testItem.TextAlign = ContentAlignment.MiddleCenter;                    testItem.BorderStyle = BorderStyle.FixedSingle;                    if (testItems.Count == 0)                        testItem.Location = new System.Drawing.Point(3 + (width - 1) * 1, height + 1 );                    else                        testItem.Location = new System.Drawing.Point(3 + (width - 1) * 1, positions[positions.Count - k].Location.Y);                    testItem.Name = item2.TestItems;                    testItem.Size = new System.Drawing.Size(width, height * k + 1);                    testItem.TabIndex = 2;                    testItem.Text = item2.TestItems;                    panelResultViewPreview.Controls.Add(testItem);                    testItems.Add(testItem);                    #endregion                }                #region [孔型]                int itemNum = item.itemTypeList.Count;                int sum = 0;                foreach(var item4 in item.itemTypeList)                {                    sum += item4.LineDataList.Count;                }                                Label holeType = new Label();                holeType.AutoSize = false;                holeType.TextAlign = ContentAlignment.MiddleCenter;                holeType.BorderStyle = BorderStyle.FixedSingle;                if (holeTypes.Count == 0)                    holeType.Location = new System.Drawing.Point(3, height );                else                    holeType.Location = new System.Drawing.Point(3, specifications[specifications.Count - itemNum].Location.Y);                holeType.Name = item.HoleType;                holeType.Size = new System.Drawing.Size(width, height * sum + 1);                holeType.TabIndex = 2;                holeType.Text = item.HoleType;                panelResultViewPreview.Controls.Add(holeType);                holeTypes.Add(holeType);                #endregion            }            #endregion                        this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;//在窗体初始化后添加一句代码            SetStyle(ControlStyles.UserPaint, true);            SetStyle(ControlStyles.AllPaintingInWmPaint, true);//禁止擦除背景.            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);//双缓冲            this.UpdateStyles();        }        private void ReturnView(object sender, EventArgs e)        {            Label label = (Label)sender;            if (label.Tag != null)             {                int index = Convert.ToInt32(label.Tag.ToString());                this.Close();                this.resultsView.returnMatView(index);            }        }            }}
 |