MetroStatisticAnalysis.cs 19.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dal;
using Comm;

namespace App
{
    public partial class MetroStatisticAnalysis : FrmBase
    {
        Fuction fuction = new Fuction();
        List<string> product;
        bool isInit;
        DataTable dt_ProductTestData;
        Boolean isOpenStandard = false;
        private LoginManager _loginManager;

        private bool isOpenFileCurve=false;
        private bool isOpenFileAdjust=false;

        public MetroStatisticAnalysis(LoginManager loginManager)
        {
            InitializeComponent();
            this.SetLanguage(this);
            LOGGER.Debug("language:" + this.str_LResourse);
            this.WindowState = FormWindowState.Maximized;
            this._loginManager = loginManager;
            Init();

        }

        private void Init()
        {
            GetProductList();
            cmb_SPCType.SelectedIndex = 0;
            this.Text = "  " + getMsg("FrmStatisticAnalysis") + "  ";
            this.curveSuperpositionPage.Text = "  " + getMsg("FrmMDIAuth_4010") + "  ";
            this.statisticalProcessPage.Text = "  " + getMsg("FrmMDIAuth_4020") + "  ";
            this.adjustPage.Text = "  " + getMsg("FrmMDIAuth_4030") + "  ";
            this.AnnotationPage.Text = "  " + getMsg("FrmMDIAuth_4050") + "  ";
            this.showAdjustPanel.Size = new System.Drawing.Size(this.curveSuperpositionPage.Width, this.curveSuperpositionPage.Height);
            this.showAdjustPanel.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.showCurvePanel.Size = new System.Drawing.Size(this.curveSuperpositionPage.Width, this.curveSuperpositionPage.Height);
            this.showCurvePanel.BorderStyle = System.Windows.Forms.BorderStyle.None;
        }
        private void GetProductList()
        {
            this.lb_Product.Items.Clear();
            product = fuction.GetAllProjectName();
            for (int i = 0; i < product.Count; i++)
            {
                this.lb_Product.Items.Add(product[i]);
            }
            this.lb_Product.SelectedIndex = 0;
            GetDataGrid();
        }
        private void GetDataGrid()
        {
            string ProductName = this.lb_Product.SelectedItem.ToString();

            dt_ProductTestData = fuction.GetProductTest(ProductName);

            dataGridView1.DataSource = GetTable(Convert.ToDateTime("1900-1-1"), Convert.ToDateTime("2900-1-1"));

            DataGridViewCellStyle dataGridViewCellStyle0 = CreatDataGridViewCellStyle();
            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                CreatColumn(dataGridView1.Columns[i], dataGridViewCellStyle0, dt_ProductTestData.Columns[i].ColumnName);
            }
            if (dataGridView1.RowCount > 0)
            {
                dataGridView1.Rows[0].Selected = true;
            }
        }
        private DataTable GetTable(DateTime StartTime, DateTime EndTime)
        {
            LOGGER.Debug("test start time is "+Const.TEST_STARTTIME+",start time is "+StartTime+",end time is "+EndTime);
            DataRow[] drTemp = dt_ProductTestData.Select
                (Const.TEST_STARTTIME + ">= #" + StartTime + "# and " + Const.TEST_STARTTIME + "<= #" + EndTime + "#", Const.TEST_STARTTIME);

            //DataTable table1 = new DataTable(Const.PARA_PRODUCT);
            DataTable table1 = new DataTable(Const.PARA_PRODUCT);
            DataColumnCollection columns = table1.Columns;
            columns.Add(Const.TestData, typeof(System.String));
            columns.Add(Const.PARA_PRODUCT, typeof(System.String));
            columns.Add(Const.TEST_STARTTIME, typeof(System.DateTime));
            columns.Add(Const.TEST_MAX, typeof(System.Double));
            columns.Add(Const.TEST_MIN, typeof(System.Double));

            DataRow newRow;
            foreach (DataRow dr in drTemp)
            {
                newRow = table1.NewRow();
                newRow[Const.TestData] = dr[Const.TestData];
                newRow[Const.PARA_PRODUCT] = dr[Const.PARA_PRODUCT];
                newRow[Const.TEST_STARTTIME] = dr[Const.TEST_STARTTIME];
                newRow[Const.TEST_MAX] = Fuction.m_UserResult == Const.RESULT_IN ?
                        Convert.ToDouble(fuction.ChangeAreaUnit(dr[Const.TEST_MAX].ToString())) :
                    Convert.ToDouble(dr[Const.TEST_MAX]);
                newRow[Const.TEST_MIN] = Fuction.m_UserResult == Const.RESULT_IN ?
                            Convert.ToDouble(fuction.ChangeAreaUnit(dr[Const.TEST_MIN].ToString())) :
                        Convert.ToDouble(dr[Const.TEST_MIN]);
                table1.Rows.Add(newRow);
            }
            return table1;
        }
        private void CreatColumn(DataGridViewColumn Column, DataGridViewCellStyle CellStyle, string Name)
        {
            Column.DefaultCellStyle = CellStyle;
            Column.FillWeight = 40F;
            Column.Name = Name;
            Column.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            Column.Width = 366;
            if (Name == Const.TEST_MAX || Name == Const.TEST_MIN)
            {
                Column.Visible = false;
            }
        }

        private void openCurveFileButton_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.openCurveFileButton, getMsg("FrmMDIAuth_4010"));
        }
        private void newCurveFileButton_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.newCurveFileButton, getMsg("FrmMDIrb_New"));
        }

        /**
         * 打开曲线叠加相关文件
         */
        private void openCurveFileButton_Click(object sender, EventArgs e)
        {
            OpenCurve(false);
        }

        FrmCurve newForm;
        FrmTestResult newForm2;
        private void OpenCurve(Boolean isNew)
        {
            this.openCurveFileButton.Visible = true;
            string directory = Fuction.m_CurrentDirectory + Const.TestDataRoot;
            openFileDialog1.InitialDirectory = directory;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                isOpenFileCurve = true;
                if (isNew)
                {
                    this.showCurvePanel.Controls.Clear();
                    newForm = null;
                }
                string XMLFile = openFileDialog1.FileName;

                if (newForm != null)
                {
                    newForm.ReadTestResult(XMLFile);
                    return;
                }

                //this.showCurvePanel.Location = new Point(this.curveSuperpositionPage.Location.X + 45, this.curveSuperpositionPage.Location.Y - 91);
                //this.showCurvePanel.Size = new System.Drawing.Size(this.curveSuperpositionPage.Width, this.curveSuperpositionPage.Height + 20);
                //this.showCurvePanel.BorderStyle = System.Windows.Forms.BorderStyle.None;
                //this.newCurveFileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                //this.openCurveFileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                //this.BtnGoBack1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                //    this.showCurvePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                //| System.Windows.Forms.AnchorStyles.Left)
                //| System.Windows.Forms.AnchorStyles.Right)));
                try
                {
                    newForm = new FrmCurve(XMLFile);
                    newForm.MdiParent = this;//指定当前窗体为顶级Mdi窗体
                    newForm.Parent = this.showCurvePanel;//指定子窗体的父容器为
                    newForm.FormBorderStyle = FormBorderStyle.None; // 无边框
            //        newForm.Location = new Point(0,-90);
            //        newForm.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
            //| System.Windows.Forms.AnchorStyles.Right)));
                    newForm.Dock = System.Windows.Forms.DockStyle.Fill;
                    this.showCurvePanel.Controls.Add(newForm);  // 添加到 Panel中ad
                    newForm.Show();     // 显示
                    newForm.Activate();//激活
                }
                catch (Exception ex)
                {
                    LOGGER.Warn(ex.StackTrace);
                    if (newForm != null)
                    {
                        newForm.Close();
                    }
                }
            }
            else
            {
                this.statisticAnalysisTab.SelectedIndex = 0;
            }

        }
        /**
         * 新建一个曲线叠加
         */
        private void newCurveFileButton_Click(object sender, EventArgs e)
        {
            OpenCurve(true);
        }

        private void newAdjustFileButton_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.newAdjustFileButton, getMsg("FrmMDIrb_New"));
        }
        
        private void openAdjustFileButton_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.openAdjustFileButton, getMsg("FrmMDIAuth_4030"));
        }
        private void standardButton_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.standardButton, getMsg("FrmMDIAuth_4040"));
        }

        /**
         * 打开启点调整相关文件
         */
        private void openAdjustFileButton_Click(object sender, EventArgs e)
        {
            OpenTest(false);
        }
        private void OpenTest(Boolean isNew)
        {
            this.openAdjustFileButton.Visible = true;
            this.standardButton.Visible = true;
            string directory = Fuction.m_CurrentDirectory + Const.TestDataDataRoot;
            openFileDialog1.InitialDirectory = directory;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                isOpenFileAdjust = true;
                if (isNew)
                {
                    this.showAdjustPanel.Controls.Remove(newForm2);
                    newForm2 = null;
                }
                string XMLFile = openFileDialog1.FileName;

                if (newForm2 != null)
                {
                    newForm2.ReadTestResult(XMLFile);
                    return;

                }
                newForm2 = new FrmTestResult(XMLFile);

                //this.showAdjustPanel.Location = new Point(this.curveSuperpositionPage.Location.X + 45, this.curveSuperpositionPage.Location.Y - 91);
                //this.showAdjustPanel.Size = new System.Drawing.Size(this.curveSuperpositionPage.Width, this.curveSuperpositionPage.Height + 20);
                //this.showAdjustPanel.BorderStyle = System.Windows.Forms.BorderStyle.None;
                //    this.showAdjustPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                //| System.Windows.Forms.AnchorStyles.Left)
                //| System.Windows.Forms.AnchorStyles.Right)));

                try
                {
                    newForm2.MdiParent = this;//指定当前窗体为顶级Mdi窗体
                    newForm2.Parent = this.showAdjustPanel;//指定子窗体的父容器为
                    newForm2.FormBorderStyle = FormBorderStyle.None; // 无边框
                    newForm2.Dock = System.Windows.Forms.DockStyle.Fill;
                    //newForm.TopLevel = false; // 不是最顶层窗体
                    this.showAdjustPanel.Controls.Add(newForm2);  // 添加到 Panel中
                    newForm2.Show();// 显示
                    newForm2.Activate();//激活
                }
                catch (Exception e)
                {
                    LOGGER.Warn(e.StackTrace);
                    newForm2.Close();
                }
            }
            else
            {
                this.statisticAnalysisTab.SelectedIndex = 0;
            }

        }

        private void newAdjustFileButton_Click(object sender, EventArgs e)
        {
            OpenTest(true);
        }

        /**
        * 点击标准应用
        */
        private void standardButton_Click(object sender, EventArgs e)
        {
            OpenStandard();
        }

        
        /**
         * 取消按钮
         */
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /**
         * 删除按钮
         */
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.CurrentRow != null)
            {
                ((DataTable)this.dataGridView1.DataSource).Rows.RemoveAt(this.dataGridView1.CurrentRow.Index);
            }
        }
        /**
         * 统计过程分析确定按钮
         */
        private void btn_OK_Click(object sender, EventArgs e)
        {
            #region checkValid
            if (!CheckNull(this.lbl_minValue.Text, txt_minValue) || !CheckNumber(this.lbl_minValue.Text, txt_minValue) ||
                !CheckNull(this.lbl_maxValue.Text, txt_maxValue) || !CheckNumber(this.lbl_maxValue.Text, txt_maxValue) ||
                !CheckNull(this.label1.Text, txt_TargetValue) || !CheckNumber(this.label1.Text, txt_TargetValue))
                return;
            #endregion

            double minValue = Convert.ToDouble(txt_minValue.Text);
            double maxValue = Convert.ToDouble(this.txt_maxValue.Text);
            double targetValue = Convert.ToDouble(this.txt_TargetValue.Text);

            if (minValue > maxValue ||
                minValue > targetValue ||
                targetValue > maxValue)
            {
                ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_GAUGE_DATA);
                return;
            }
            FrmSPCCurve frmSPCCurve = new FrmSPCCurve((DataTable)this.dataGridView1.DataSource, maxValue, targetValue, minValue, cmb_SPCType.SelectedItem.ToString());
            frmSPCCurve.Owner = this.ParentForm;
            frmSPCCurve.MdiParent = this.ParentForm;
            frmSPCCurve.ShowInTaskbar = true;
            frmSPCCurve.StartPosition = FormStartPosition.CenterScreen;
            frmSPCCurve.Show();
            frmSPCCurve.Activate();//激活
            //this.Close();
        }
        /**
         * 数据显示
         */
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                dataGridView1.Rows[e.RowIndex].Selected = true;
                this.btn_Delete.Enabled = true;
            }
            else
            {
                this.btn_Delete.Enabled = false;
            }
        }
        /**
         * 产品选择切换
         */
        private void lb_Product_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!isInit)
            {
                GetDataGrid();
            }
        }
        /**
         * 查询按钮
         */
        private void btn_Query_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = GetTable(Convert.ToDateTime(this.dtp_StartTime.Value.ToShortDateString()), Convert.ToDateTime(this.dtp_EndTime.Value.ToShortDateString()));
        }

        
        
        private void OpenStandard()
        {
            try
            {
                //if (this.newForm2.GetType().FullName == "App.FrmTestResult" ||
                //    this.newForm2.GetType().FullName == "App.FrmTestManage")
                if (this.newForm2.GetType().FullName == "App.FrmTestResult")
                {
                    FrmStandard newForm = new FrmStandard(this.newForm2.GetType().FullName, this);

                    //newForm.Owner = this;
                    //newForm.TopMost = true;
                    //newForm.Parent = this;
                    //newForm.ShowInTaskbar = false;
                    //newForm.StartPosition = FormStartPosition.CenterScreen;
                    //newForm.StartPosition = FormStartPosition.CenterScreen;
                    newForm.Show();
                    newForm.Activate();
                    //this.isOpenStandard = false;
                }
                
            }catch(Exception e)
            {
                LOGGER.Warn(e.StackTrace);
            }
        }
        private void MetroStatisticAnalysis_FormClosed(object sender, EventArgs e)
        {
            MetroMDI mm = new MetroMDI(_loginManager);
            mm.ShowInTaskbar = true;
            mm.Show();
        }

        public void AddStandard(string formName, double m_ParaUserLimit, double m_ParaMIL, double m_ParaDEF)
        {
            if (newForm2.GetType().FullName == "App.FrmTestResult")
            {
                ((FrmTestResult)newForm2).AddStandard(m_ParaUserLimit, m_ParaMIL, m_ParaDEF);
                return;
            }
            //if (newForm2.GetType().FullName == "App.FrmTestManage")
            //{
            //    ((FrmTestManage)newForm2).AddStandard(m_ParaUserLimit, m_ParaMIL, m_ParaDEF);
            //    return;
            //}
        }

        private void statisticAnalysisTab_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.statisticAnalysisTab.SelectedIndex == 1 && !isOpenFileCurve)
            {
                OpenCurve(false);
            }
            else if (this.statisticAnalysisTab.SelectedIndex == 2 && !isOpenFileAdjust)
            {
                OpenTest(false);
            }
        }

        private void MetroStatisticAnalysis_Load(object sender, EventArgs e)
        {
            this.dataGridView1.Height = this.lb_Product.Height;
            this.lbl_ProductList.Text = getMsg("FrmSPClbl_ProductList");
            this.lbl_StartTime.Text = getMsg("FrmSPClbl_StartTime");
            this.lbl_EndTime.Text = getMsg("FrmSPClbl_EndTime");
            this.lbl_maxValue.Text = getMsg("FrmSPClbl_maxValue");
            this.lbl_minValue.Text = getMsg("FrmSPClbl_minValue");
            this.label1.Text = getMsg("FrmSPClabel1");
            this.lbl_SPCType.Text = getMsg("FrmSPClbl_SPCType");
            this.btn_OK.Text = getMsg("FrmSPCbtn_OK");
            this.btn_Cancel.Text = getMsg("back");
            this.btn_Delete.Text = getMsg("FrmSPCbtn_Delete");
            this.btn_Query.Text = getMsg("FrmSPCbtn_Query");
            this.BtnGoBack1.Text = getMsg("back");
            this.BtnGoBack2.Text = getMsg("back");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnGoBack2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}