Exemplo n.º 1
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (!suspendCellVelueChangedEvent)
            {
                int ngIndex    = dataGridViewLg.Columns.IndexOf(dataGridViewLg.Columns["Ng"]);
                int scrapIndex = dataGridViewLg.Columns.IndexOf(dataGridViewLg.Columns["Scrap"]);
                // Debug.WriteLine("Cell value changed: " + e.RowIndex + " " + e.ColumnIndex);
                //calculate good qty
                if (dataGridViewLg.Rows.Count > 0 & (e.ColumnIndex == ngIndex || e.ColumnIndex == scrapIndex))
                {
                    int rowIndex = e.RowIndex;

                    DataGridViewCell ngCell    = dataGridViewLg.Rows[rowIndex].Cells["Ng"];
                    DataGridViewCell scrapCell = dataGridViewLg.Rows[rowIndex].Cells["Scrap"];

                    double ngValue    = -9999;
                    double scrapValue = -9999;

                    if (ngCell.Value != null)
                    {
                        if (!(double.TryParse(ngCell.Value.ToString(), out ngValue)))
                        {
                            dataGridViewLg.Rows[e.RowIndex].Cells[ngIndex].Value = null;
                            ngValue = -9999;
                        }
                        else
                        {
                            //ng ,0 will be 0
                            dataGridViewLg.Rows[e.RowIndex].Cells[ngIndex].Value = ngValue;
                        }
                    }

                    if (dataGridViewLg.Columns["Scrap"].Visible)
                    {
                        if (scrapCell.Value != null)
                        {
                            if (!(double.TryParse(scrapCell.Value.ToString(), out scrapValue)))
                            {
                                dataGridViewLg.Rows[e.RowIndex].Cells[scrapIndex].Value = null;
                                scrapValue = -9999;
                            }
                        }
                    }
                    else
                    {
                        scrapValue = 0;
                    }

                    if (ngValue > -9999 & scrapValue > -9999 & dataGridViewLg.Rows[e.RowIndex].Cells["ColumnQty"].Value != null)
                    {
                        double orderedQty = double.Parse(dataGridViewLg.Rows[e.RowIndex].Cells["ColumnQty"].Value.ToString());
                        double goodQty    = orderedQty - ngValue - scrapValue;
                        dataGridViewLg.Rows[e.RowIndex].Cells["goodQty"].Value = goodQty;
                    }
                    else
                    {
                        dataGridViewLg.Rows[e.RowIndex].Cells["goodQty"].Value = "";
                    }
                }

                //saving finished LOT
                foreach (DataGridViewRow row in dataGridViewLg.Rows)
                {
                    //Debug.WriteLine("Checking chkBox row:" + row.Index + " " + Convert.ToBoolean(row.Cells["ColumnSaved"].Value));
                    if (!Convert.ToBoolean(row.Cells["ColumnSaved"].Value))
                    {
                        if (IsRowReadyToBeSaved(row))
                        {
                            //Debug.WriteLine("Saving row:" + row.Index);
                            DataGridViewCheckBoxCell ch = (DataGridViewCheckBoxCell)row.Cells["ColumnSaved"];
                            suspendCellVelueChangedEvent = true;
                            lotFinished(ch, row.Index);
                            suspendCellVelueChangedEvent = false;

                            DateTime startDate       = (DateTime)row.Cells["StartDate"].Value;
                            DateTime endDate         = (DateTime)row.Cells["EndDate"].Value;
                            string   firstPieceCheck = "";

                            string stencil = Tools.getCellValue(row.Cells["Stencil"]);

                            LedLeftovers ledLeftovers  = (LedLeftovers)row.Cells["ColumnButtonLed"].Tag;
                            double       totalLedsUsed = 0;
                            string       leftovers     = ledLeftovers.RankA[0].ID + ":" + ledLeftovers.RankA[0].Nc12 + ":" + ledLeftovers.RankA[0].QtyLeft + "|" + ledLeftovers.RankB[0].ID + ":" + ledLeftovers.RankB[0].Nc12 + ":" + ledLeftovers.RankB[0].QtyLeft;
                            for (int i = 0; i < ledLeftovers.RankA.Count; i++)
                            {
                                totalLedsUsed += ledLeftovers.RankA[i].StartQty - ledLeftovers.RankA[i].QtyLeft;
                                totalLedsUsed += ledLeftovers.RankB[i].StartQty - ledLeftovers.RankB[i].QtyLeft;
                                if (i > 0)
                                {
                                    leftovers += "#" + ledLeftovers.RankA[i].ID + ":" + ledLeftovers.RankA[i].Nc12 + ":" + ledLeftovers.RankA[i].QtyLeft + "|" + ledLeftovers.RankB[i].ID + ":" + ledLeftovers.RankB[i].Nc12 + ":" + ledLeftovers.RankB[i].QtyLeft;
                                }
                            }

                            if (row.Cells["ColumnQualityCheck"].Tag != null)
                            {
                                firstPieceCheck = row.Cells["ColumnQualityCheck"].Tag.ToString();
                            }

                            string scrap = "0";
                            if (dataGridViewLg.Columns["Scrap"].Visible)
                            {
                                scrap = row.Cells["Scrap"].Value.ToString();
                            }

                            SqlOperations.SaveRecordToDb(
                                startDate,
                                endDate,
                                smtLine,
                                row.Cells["Operator"].Value.ToString(),
                                row.Cells["ColumnLot"].Value.ToString(),
                                row.Cells["ColumnModel"].Value.ToString(),
                                row.Cells["goodQty"].Value.ToString(),
                                row.Cells["Ng"].Value.ToString(),
                                scrap,
                                firstPieceCheck,
                                leftovers,
                                stencil,
                                "LG",
                                totalLedsUsed);
                            // Debug.WriteLine("Saved");
                            DgvTools.CleanUpLgiDgv(dataGridViewLg);
                        }
                    }
                }
                dataGridViewLg.HorizontalScrollingOffset = 0;
            }
        }
Exemplo n.º 2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string stencil = "";

            if (radioButtonNewStencil.Checked)
            {
                using (var dial = new ScanStencilQr(currentLotData.Model))
                {
                    dial.ShowDialog();
                    if (dial.DialogResult == DialogResult.OK)
                    {
                        stencil = dial.stencil;
                    }
                }
                //Stencil QR reading
                //    ScanStencilQr fm = new ScanStencilQr(ref stencil, currentLotData.Model);
                //fm.ShowDialog();
            }
            else
            {
                stencil = (string)radioButtonCurrentStencil.Tag;
            }



            if (buttonOK.Text == "OK" & stencil.Trim() != "")
            {
                grid.SuspendLayout();

                string       lotNo    = textBoxLotNo.Text;
                LedLeftovers ledsLeft = new LedLeftovers(new List <RankStruc>(), new List <RankStruc>(), lotNo);

                foreach (DataGridViewRow rowA in dataGridViewRankA.Rows)
                {
                    string rankA        = labelRankA.Text.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None)[1];
                    string rankAId      = rowA.Cells["RankAId"].Value.ToString();
                    string rankA12NC    = rowA.Cells["RankANc12"].Value.ToString();
                    string iloscAString = rowA.Cells["RankAIlosc"].Value.ToString();
                    double rankAIlosc   = double.Parse(iloscAString);
                    ledsLeft.RankA.Add(new RankStruc(rankA, rankAId, rankA12NC, -1, rankAIlosc));
                }

                foreach (DataGridViewRow rowB in dataGridViewRankB.Rows)
                {
                    string rankB        = labelRankB.Text.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None)[1];
                    string rankBId      = rowB.Cells["rankBId"].Value.ToString();
                    string rankB12NC    = rowB.Cells["RankBNc12"].Value.ToString();
                    string iloscBString = rowB.Cells["rankBIlosc"].Value.ToString();
                    double rankBIlosc   = double.Parse(iloscBString);
                    ledsLeft.RankB.Add(new RankStruc(rankB, rankBId, rankB12NC, -1, rankBIlosc));
                }

                grid.Rows.Insert(0, 1);
                int lastRow = 0;
                grid.Rows[lastRow].Cells["ColumnSaved"].Style.BackColor = Color.Red;
                grid.Rows[lastRow].Cells["ColumnLot"].Value             = textBoxLotNo.Text;
                grid.Rows[lastRow].Cells["ColumnModel"].Value           = currentLotData.Model;
                grid.Rows[lastRow].Cells["ColumnQty"].Value             = currentLotData.OrderedQty;
                grid.Rows[lastRow].Cells["ColumnRankA"].Value           = currentLotData.RankA;
                grid.Rows[lastRow].Cells["ColumnRankB"].Value           = currentLotData.RankB;
                grid.Rows[lastRow].Cells["Rank12NC"].Value                  = ledsLeft.RankA[0].Nc12;
                grid.Rows[lastRow].Cells["ColumnButtonLed"].Value           = "BRAK";
                grid.Rows[lastRow].Cells["ColumnButtonLed"].Style.BackColor = Color.Red;
                grid.Rows[lastRow].Cells["ColumnQualityCheck"].Value        = "";
                grid.Rows[lastRow].Cells["StartDate"].Value                 = DateTime.Now;
                grid.Rows[lastRow].Cells["ColumnButtonLed"].Tag             = ledsLeft;
                grid.Rows[lastRow].Cells["Operator"].Value                  = comboBoxOperator.Text;
                grid.Rows[lastRow].Cells["Stencil"].Value = stencil;
                grid.Rows[lastRow].Cells["connQty"].Value = Tools.GetNumberOfConnectors(currentLotData.Model);

                if (grid.Rows[lastRow].Cells["connQty"].Value.ToString() == "4")
                {
                    //grid.Rows[lastRow].Cells["connQty"].Style.ForeColor = System.Drawing.Color.Red;
                    grid.Rows[lastRow].Cells["connQty"].Style.ForeColor = Color.White;
                    grid.Rows[lastRow].Cells["connQty"].Style.BackColor = Color.DarkCyan;
                }

                if (grid.Rows.Count == 1)
                {
                    foreach (DataGridViewColumn col in grid.Columns)
                    {
                        col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    }
                    grid.Rows[lastRow].Cells["ColumnQualityCheck"].Style.BackColor = Color.Red;
                    grid.Rows[lastRow].Cells["ColumnQualityCheck"].Value           = "BRAK";
                }
                else
                {
                    if (Tools.getCellValue(grid.Rows[lastRow + 1].Cells["ColumnModel"]) != "")
                    {
                        if (grid.Rows[lastRow].Cells["ColumnModel"].Value.ToString() != grid.Rows[lastRow + 1].Cells["ColumnModel"].Value.ToString())
                        {
                            grid.Rows[lastRow].Cells["ColumnQualityCheck"].Style.BackColor = Color.Red;
                            grid.Rows[lastRow].Cells["ColumnQualityCheck"].Value           = "BRAK";
                        }
                    }
                }



                DgvTools.CleanUpLgiDgv(grid);
                grid.FirstDisplayedScrollingRowIndex = 0;
                this.Close();
                grid.ResumeLayout();
            }
            else
            {
            #if DEBUG
                grid.Columns["Stencil"].Visible = true;
                grid.Rows.Insert(0, 1);
                grid.Rows[0].Cells["StartDate"].Value             = System.DateTime.Now;
                grid.Rows[0].Cells["ColumnSaved"].Style.BackColor = Color.Red;
                ScanStencilQr fm = new ScanStencilQr(currentLotData.Model);
                fm.ShowDialog();
            #endif
            }
        }