Esempio n. 1
0
        private void dBTestToolStripMenuItem_Click(object sender, EventArgs e)
        {
            db mydb = new db();

            dgvData.DataSource = mydb.GetGoldenData("5348","1");
        }
Esempio n. 2
0
        } //end of topFailParetoToolStripMenuItem_Click

        // *** KGU verify
        private void kGUVerifyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            #region *** Variable Define ***

            db mydb = new db();

            DataTable tblGolden = new DataTable();
            DataTable tblKGURaw = new DataTable();

            DataRow drTemp;

            string strGoldenPath = "";
            string strKGUPath = "";
            string strKGUNumber = "";
            string strKGUNumberTemp = "";
            string strExtension = "";

            string[] strSafeFileName; ;
            string[] arrayKGU;
            string[] arrayKGUTemp;

            int intTotalKGU = 0;
            //int intSiteNumber = 0;

            bool cancelKGU = false;

            #endregion *** Variable Define ***

            #region *** Selected file ***
            OpenFileDialog OpenFile = new OpenFileDialog();
            OpenFile.RestoreDirectory = true;
            OpenFile.Filter = "STDF Files(*.std/*.stdf)|*.std|All Files|*.*";
            //OpenFile.Filter = "STDF data file(*.std)|*.std|TXT data file(*.txt)|*.txt";
            if (OpenFile.ShowDialog() != DialogResult.OK) return;
            strKGUPath = OpenFile.FileName;
            strExtension = Path.GetExtension(strKGUPath);
            //Import KGU data
            if (strExtension.ToLower() == ".txt")
                tblKGURaw = _DataParse.GetDataFromTxt(strKGUPath);
            else if (strExtension.ToLower() == ".std" || strExtension.ToLower() == ".stdf")
                tblKGURaw = _DataParse.GetDataFromStdfviewer(strKGUPath);

            string[] tmp = _DataParse.Header.ProgramRev.Split('.');
            //strGoldenPath = Application.StartupPath + @".\GoldenSample\" + _DataParse.Header.Product.ToString() + "_" + _DataParse.Header.ProgramRev.Substring(0, 2)
            strGoldenPath = Application.StartupPath + @".\GoldenSample\" + _DataParse.Header.Product.ToString() + "_" + tmp[0].ToString();

            string vStrPath = Path.GetFullPath(strGoldenPath);
            intTotalKGU = _DataParse.Header.TestQuantity;

            strSafeFileName = OpenFile.SafeFileName.Split('_');
            for (int i = 0; i < strSafeFileName.Length; i++)
            {
                if (strSafeFileName[i].ToUpper() == "KGU")
                {
                    strKGUNumber = strSafeFileName[i + 1].ToString();
                }
            }
            strKGUNumberTemp = Microsoft.VisualBasic.Interaction.InputBox(
                "Please verify the KGU number is correct,                   if not, input the correct KGU number", "KGU Number",
                 strKGUNumber, 100, 100);
            if (strKGUNumberTemp == "") return;
            strKGUNumber = strKGUNumberTemp.Replace(" ", "");
            arrayKGU = strKGUNumber.Split('.');

            //intSiteNumber = _DataParse.GetSiteNumber(strKGUPath);

            if (arrayKGU.Length == intTotalKGU / 2)
            {
                arrayKGUTemp = strKGUNumber.Split('.');
                arrayKGU = new string[intTotalKGU];
                arrayKGU[0] = arrayKGUTemp[0];
                arrayKGU[1] = arrayKGUTemp[1];
                arrayKGU[2] = arrayKGUTemp[1];
                arrayKGU[3] = arrayKGUTemp[0];
            }
            else if (arrayKGU.Length != intTotalKGU)
            {
                while (arrayKGU.Length != intTotalKGU && !cancelKGU)
                {
                    //MessageBox.Show("KGU number is not in correct format", "KGU Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    strKGUNumberTemp = Microsoft.VisualBasic.Interaction.InputBox(
                        "KGU test data does not match with the KGU quantity , please check the KGU number or test data. \r\neach number must be seperated by dot (.)", "KGU Number", strKGUNumberTemp, 100, 100);
                    strKGUNumber = strKGUNumberTemp.Replace(" ", "");
                    arrayKGU = strKGUNumber.Split('.');
                    if (strKGUNumberTemp == "") cancelKGU = true;
                }
            }
            if (cancelKGU == true) return;

            #endregion *** Selected file ***

            lblBar.Text = "KGU analysising";
            this.Refresh();
            Application.DoEvents();
            #region *** Import KGU***
            //tblKGURaw = _DataParse.GetDataFromTxt(strKGUPath);
            //strGoldenPath = @".\GoldenSample\" + _DataParse.Header.Product.ToString() + "_" + _DataParse.Header.ProgramRev + ".raw";
            //string vStrPath = Path.GetFullPath(strGoldenPath);
            #endregion *** Import KGU***

            #region *** Import Golden data ***

            string t_Product = _DataParse.Header.Product.ToString();
            string t_Rev = tmp[0].Substring(1).ToString();
            try
            {
                tblGolden = mydb.GetGoldenData(t_Product, t_Rev);

                foreach (string strKGUSN in arrayKGU)
                {
                    string filterCriteria = "[..]='" + strKGUSN + "'";
                    DataRow[] dataRows = tblGolden.Select(filterCriteria);
                    if (dataRows.Length != 1) throw new Exception("KGU " + strKGUSN + " is not is database");
                }
            }
            catch //DataBase is not available, use csv file instead
            {
                lblBar.Text = "Can not find Golden Data in database, use ascii file instead.";
                tblGolden = _DataParse.GetDataFromCsv(strGoldenPath);
            }

            //Update header information
            if (strExtension.ToLower() == "txt")
                tblKGURaw = _DataParse.GetDataFromTxt(strKGUPath);
            else if (strExtension.ToLower() == "std")
                tblKGURaw = _DataParse.GetDataFromStd(strKGUPath);
            #endregion *** Import Golden data ***

            #region *** Merge DataTable ***

            #region Import used golden data into tblCaculate
            tblKGU = tblGolden.Clone();

            tblKGU.PrimaryKey = null;
            tblKGURaw.PrimaryKey = null;

            bool isHeaderAdded = false;
            foreach (string sKGU in arrayKGU)
            {
                foreach (DataRow dr in tblGolden.Rows)
                {
                    if (!isHeaderAdded)
                    {
                        if (tblGolden.Rows.IndexOf(dr) < 4)
                        {
                            tblKGU.ImportRow(dr);
                        }
                        if (tblGolden.Rows.IndexOf(dr) == 4)
                        {
                            drTemp = tblKGU.NewRow();
                            drTemp[0] = "Golden Sample Data";
                            tblKGU.Rows.Add(drTemp);
                            isHeaderAdded = true;
                        }
                    }
                    if (tblGolden.Rows.IndexOf(dr) > 3 && Convert.ToInt32(dr[0]) == Convert.ToInt32(sKGU))
                    {
                        dr[dr.ItemArray.Length - 1] = "";
                        tblKGU.ImportRow(dr);

                    }//end of if else
                }//end of foreach tblGolden
            }// end of foreach arrayKGU 

            #endregion *** Import used golden data into tblCaculate

            #region Import KGU data into tblCaculate and verify
            drTemp = tblKGU.NewRow();
            drTemp[0] = "KGU Test Data";
            tblKGU.Rows.Add(drTemp);
            int indexKGU = 0;

            // delete the soft bin and hard bin column
            if (tblKGU.Columns.Count == tblKGURaw.Columns.Count - 2)
            {
                tblKGURaw.Columns.RemoveAt(3);
                tblKGURaw.Columns.RemoveAt(2);
            }

            foreach (DataRow dr in tblKGURaw.Rows)
            {
                if (tblKGURaw.Rows.IndexOf(dr) > 3)
                {
                    dr[0] = arrayKGU[indexKGU];
                    dr[tblKGURaw.Columns.Count - 1] = "";

                    DataRow newRow = tblKGU.NewRow();
                    for (int i = 0; i < tblKGURaw.Columns.Count; i++)
                    {
                        newRow[i] = dr[i];
                    }
                    tblKGU.Rows.Add(newRow);
                    indexKGU++;
                }
            }
            #endregion Import KGU data into tblCaculate and verify

            #region Caculate delta
            drTemp = tblKGU.NewRow();
            drTemp[0] = "Delta";
            tblKGU.Rows.Add(drTemp);
            for (int i = 0; i < intTotalKGU; i++)
            {
                drTemp = tblKGU.NewRow();
                drTemp[0] = arrayKGU[i];
                drTemp[1] = Convert.ToDouble(tblKGU.Rows[i + intTotalKGU + 6][1]);
                drTemp[2] = arrayKGU[i];
                for (int j = 3; j < tblKGU.Columns.Count - 1; j++)
                {
                    double dblKGU = Convert.ToDouble(tblKGU.Rows[i + intTotalKGU + 6][j]);
                    double dblGolden = Convert.ToDouble(tblKGU.Rows[i + 5][j]);
                    drTemp[j] = Math.Round(dblKGU - dblGolden, 3);
                }
                tblKGU.Rows.Add(drTemp);
            }
            #endregion Caculate delta

            #endregion *** Merge DataTable ***

            #region *** Display ***
            //Display
            this.UpdateSessionInfomation();
            this.RemoveTab(strKGUTabName);
            TabPage tabKGU = new TabPage(strKGUTabName);
            tabcontrol.Controls.Add(tabKGU);
            tabcontrol.SelectedTab = tabKGU;

            DataGridView dgvKGU = new DataGridView();
            tabKGU.Controls.Add(dgvKGU);
            dgvKGU.Dock = DockStyle.Fill;

            dgvKGU.DataSource = tblKGU;

            float currentSize = dgvKGU.Font.SizeInPoints - 1;
            for (int i = 0; i < dgvKGU.Columns.Count; i++)
            {
                //dgvKGU.Columns[i].Width = 60;
                dgvKGU.Columns[i].ReadOnly = true;
                dgvKGU.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                dgvKGU.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                dgvKGU.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

                dgvKGU.EnableHeadersVisualStyles = true;
                dgvKGU.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
                DataGridViewCellStyle style = dgvKGU.ColumnHeadersDefaultCellStyle;
                style.Font = new Font(dgvKGU.Font, FontStyle.Bold);
                style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }
            for (int i = 0; i < 4; i++)
            {
                dgvKGU.Rows[i].DefaultCellStyle.BackColor = Color.LightGray;
                dgvKGU.Rows[i].DefaultCellStyle.Font = new Font("Microsoft Sans Serif", currentSize, FontStyle.Bold);
            }
            dgvKGU.Columns[0].Width = 130;
            dgvKGU.Columns[1].Width = 50;
            dgvKGU.Columns[2].Width = 60;
            dgvKGU.Columns[0].DefaultCellStyle.Font = new Font("Microsoft Sans Serif", currentSize, FontStyle.Bold);
            dgvKGU.Columns[0].DefaultCellStyle.BackColor = Color.LightGray;
            dgvKGU.Columns[1].DefaultCellStyle.BackColor = Color.LightGray;
            dgvKGU.Columns[2].DefaultCellStyle.BackColor = Color.LightGray;
            dgvKGU.RowHeadersVisible = false;
            dgvKGU.Rows[3].Frozen = true;
            dgvKGU.Columns[2].Frozen = true;
            dgvKGU.ReadOnly = true;
            dgvKGU.AllowUserToAddRows = false;
            dgvKGU.AllowUserToResizeRows = false;

            //return;
            #endregion *** Display ***

            #region *** Caculate Pass Fail ***
            foreach (DataGridViewRow dgvr in dgvKGU.Rows)
            {
                if (dgvKGU.Rows.IndexOf(dgvr) > 2 * intTotalKGU + 6)
                {
                    bool isKGUFail = false;
                    foreach (DataGridViewCell dgvc in dgvr.Cells)
                    {
                        string enable = dgvKGU.Rows[3].Cells[dgvc.ColumnIndex].Value.ToString();
                        if (enable == "1")
                        {
                            double lowTolerance = 0 - Convert.ToDouble(dgvKGU.Rows[1].Cells[dgvc.ColumnIndex].Value);
                            double UpperTolerance = Convert.ToDouble(dgvKGU.Rows[2].Cells[dgvc.ColumnIndex].Value);
                            double delta = Convert.ToDouble(dgvc.Value);

                            if (delta < lowTolerance || delta > UpperTolerance)
                            {
                                //dgvr.DefaultCellStyle.BackColor = Color.Red;
                                dgvc.Style.BackColor = Color.Red;
                                isKGUFail = true;
                            }
                        }
                    } // end of foreach DataGridViewCell dgvc
                    if (isKGUFail)
                    {
                        dgvr.Cells[dgvKGU.ColumnCount - 1].Value = "Fail";
                        dgvr.Cells[0].Style.BackColor = Color.Red;
                    }
                    else
                    {
                        dgvr.Cells[dgvKGU.ColumnCount - 1].Value = "Pass";
                        dgvr.Cells[0].Style.BackColor = Color.Green;
                    }
                }//end of if (dgvKGU.Rows.IndexOf(dgvr) > 16)
            }//end of  foreach (DataGridViewRow dgvr

            #endregion *** Caculate Pass Fail ***
            lblBar.Text = "Done";
            this.Refresh();

        } // end of kGUToolStripMenuItem_Click