public static bool UpdateLedLeftovers(LedLeftovers ledLeft) { bool release = true; #if DEBUG release = false; #endif bool result = true; if (release) { try { List <Tuple <string, string, string> > flatList = new List <Tuple <string, string, string> >(); foreach (var led in ledLeft.RankA) { flatList.Add(new Tuple <string, string, string>(led.Nc12, led.ID, led.QtyLeft.ToString())); } foreach (var led in ledLeft.RankB) { flatList.Add(new Tuple <string, string, string>(led.Nc12, led.ID, led.QtyLeft.ToString())); } string lotNo = ledLeft.LotNo; using (SqlConnection conn = new SqlConnection(@"Data Source=MSTMS010;Initial Catalog=MES;User Id=mes;Password=mes;")) { conn.Open(); foreach (var led in flatList) { SqlCommand cmd = new SqlCommand("sp_Spg_DaneBierzaceKompAktualneFULL_UPD_ilosc", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@NC12", led.Item1)); cmd.Parameters.Add(new SqlParameter("@ID", led.Item2)); cmd.Parameters.Add(new SqlParameter("@Ilosc", led.Item3)); //cmd.Parameters.Add(new SqlParameter("@ZlecenieString", lotNo); cmd.ExecuteNonQuery(); } } } catch (SqlException ex) { MessageBox.Show(ex.Message); result = false; } } return(result); }
public Add_LED_leftovers(DataGridView grid, DataGridViewCell cell, List <LedLeftovers> ledLeftSaveBuffer) { InitializeComponent(); this.grid = grid; this.cell = cell; this.ledLeftSaveBuffer = ledLeftSaveBuffer; ledsLeft = (LedLeftovers)cell.Tag; foreach (var reel in ledsLeft.RankA) { string qty = ""; if (reel.QtyLeft < 0) { qty = ""; } else { qty = reel.QtyLeft.ToString(); } dataGridViewRankA.Rows.Add(reel.Nc12, reel.Rank, reel.ID, qty); } foreach (var reel in ledsLeft.RankB) { string qty = ""; if (reel.QtyLeft < 0) { qty = ""; } else { qty = reel.QtyLeft.ToString(); } dataGridViewRankB.Rows.Add(reel.Nc12, reel.Rank, reel.ID, qty); } Tools.AutoSizeColumnsWidth(dataGridViewRankA); Tools.AutoSizeColumnsWidth(dataGridViewRankB); this.ActiveControl = textBoxQr; }
private void UpdateCurrentModelEffNorm() { if (dataGridViewLg.Rows.Count > 0) { LedLeftovers ledLeftovers = (LedLeftovers)dataGridViewLg.Rows[0].Cells["ColumnButtonLed"].Tag; int headsUsed = 2; if (ledLeftovers.RankA.Count() > 0) { headsUsed = ledLeftovers.RankA.Count * 2; } string model = dataGridViewLg.Rows[0].Cells["ColumnModel"].Value.ToString(); double orderedQty = double.Parse(dataGridViewLg.Rows[0].Cells["ColumnQty"].Value.ToString()); var norm = EfficiencyCalculation.CalculateModelNormPerHour(model, smtLine, headsUsed); labelLgModelName.Text = $"Czas cyklu: {norm.lineCT}sek"; labelLgNormPerH.Text = $"Norma szt/h: {norm.outputPerHour}"; labelLgLotNorm.Text = $"Norma na LOT: {Math.Round(orderedQty * 60 / norm.outputPerHour,0)}min"; labelLgHeadCount.Text = $"Używane głowice: {headsUsed}"; labelLgNormModelName.Text = $"Norma modelu: {norm.modelSpec.model12Nc}"; } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex > 0 & e.RowIndex >= 0) { DataGridViewCell cell = dataGridViewLg.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (dataGridViewLg.Columns[e.ColumnIndex].CellType.ToString() == "System.Windows.Forms.DataGridViewButtonCell") { if (dataGridViewLg.Columns[e.ColumnIndex].Name == "ColumnButtonLed") { LedLeftovers clickedLeftovers = (LedLeftovers)cell.Tag; Add_LED_leftovers editLeftovers = new Add_LED_leftovers(dataGridViewLg, cell, ledLeftSaveBuffer); editLeftovers.ShowInTaskbar = false; editLeftovers.ShowDialog(); } if (dataGridViewLg.Columns[e.ColumnIndex].Name == "ColumnQualityCheck") { //DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; ChangeOverConfirmationCard changeOverForm = new ChangeOverConfirmationCard(cell); changeOverForm.ShowDialog(); } } } }
private void LoadLgRecordsFromDb() { suspendCellVelueChangedEvent = true; //DataCzasStart,DataCzasKoniec,LiniaSMT,OperatorSMT,NrZlecenia,Model,IloscWykonana,NGIlosc,ScrapIlosc,Kontrola1szt,KoncowkiLED DataTable sqlTable = SqlOperations.GetLgSmtRecordsFromDb(22, smtLine); List <string> lotsList = new List <string>(); foreach (DataRow row in sqlTable.Rows) { lotsList.Add(row["NrZlecenia"].ToString().Trim()); } Dictionary <string, string[]> lotToRankABQty = SqlOperations.lotToRankABQty(lotsList.ToArray()); //dataGridView1.SuspendLayout(); foreach (DataRow row in sqlTable.Rows) { string model = row["Model"].ToString(); if (model[2] == '-') { if (lotToRankABQty.ContainsKey(row["NrZlecenia"].ToString())) { dataGridViewLg.Rows.Insert(0); string lotNo = row["NrZlecenia"].ToString().Trim(); string stencil = row["StencilQR"].ToString(); LedLeftovers ledLeft = CreateLedLeftovers(row["KoncowkiLED"].ToString(), lotNo, lotToRankABQty); DataGridViewCheckBoxCell chbCell = (DataGridViewCheckBoxCell)dataGridViewLg.Rows[0].Cells[0]; chbCell.Value = true; dataGridViewLg.Rows[0].Cells[1].Value = lotNo; string connQty = Tools.GetNumberOfConnectors(row["Model"].ToString().Trim()); dataGridViewLg.Rows[0].Cells[3].Value = connQty; if (connQty == "4") { dataGridViewLg.Rows[0].Cells[3].Style.ForeColor = Color.White; dataGridViewLg.Rows[0].Cells[3].Style.BackColor = Color.DarkCyan; } dataGridViewLg.Rows[0].Cells[2].Value = row["Model"].ToString().Trim(); //dataGridView1.Rows[0].Cells[4].Value = kontrola pierwszej dataGridViewLg.Rows[0].Cells[5].Value = lotToRankABQty[lotNo][2]; dataGridViewLg.Rows[0].Cells[6].Value = ledLeft.RankA[0].Nc12; dataGridViewLg.Rows[0].Cells[7].Value = lotToRankABQty[lotNo][0]; dataGridViewLg.Rows[0].Cells[8].Value = lotToRankABQty[lotNo][1]; dataGridViewLg.Rows[0].Cells[9].Value = row["IloscWykonana"].ToString().Trim(); dataGridViewLg.Rows[0].Cells[10].Value = row["NGIlosc"].ToString().Trim(); dataGridViewLg.Rows[0].Cells[11].Value = row["ScrapIlosc"].ToString().Trim(); dataGridViewLg.Rows[0].Cells[12].Tag = ledLeft; dataGridViewLg.Rows[0].Cells[12].Value = "OK"; dataGridViewLg.Rows[0].Cells[13].Value = DateTime.Parse(row["DataCzasStart"].ToString().Trim()); dataGridViewLg.Rows[0].Cells[14].Value = DateTime.Parse(row["DataCzasKoniec"].ToString().Trim()); Color cellColor = Tools.GetShiftColor((DateTime)row["DataCzasKoniec"]); dataGridViewLg.Rows[0].Cells[13].Style.BackColor = cellColor; dataGridViewLg.Rows[0].Cells[14].Style.BackColor = cellColor; dataGridViewLg.Rows[0].Cells[15].Style.BackColor = cellColor; dataGridViewLg.Rows[0].Cells[15].Value = row["OperatorSMT"].ToString().Trim(); dataGridViewLg.Rows[0].Cells[16].Value = stencil; } } } Tools.AutoSizeColumnsWidth(dataGridViewLg); //dataGridView1.ResumeLayout(); if (dataGridViewLg.Rows.Count > 0) { dataGridViewLg.CurrentCell = dataGridViewLg.Rows[0].Cells[0]; } suspendCellVelueChangedEvent = false; }
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; } }
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 } }
///<summary> ///<para>double[diodeWaste, moduleWaste]</para> ///</summary> public static double[] CalculateLedDiodeWasteLevel(DataGridView grid, Dictionary <string, EfficiencyNormsPerModel> modelNorm) { List <double> percentageLotWaste = new List <double>(); List <string> lotsList = new List <string>(); double moduleWasteSum = 0; double goodModuleSum = 0; foreach (DataGridViewRow row in grid.Rows) { if (row.Cells["ColumnLot"].Value == null) { continue; } lotsList.Add(row.Cells["ColumnLot"].Value.ToString().Trim()); } //Dictionary<string, string[]> lotToRankABQty = SqlOperations.lotToRankABQty(lotsList.ToArray()); Dictionary <string, string[]> lotToRankABQty = new Dictionary <string, string[]>(); foreach (DataGridViewRow row in grid.Rows) { if (row.Cells["Ng"].Value == null) { continue; } string lotNo = row.Cells["ColumnLot"].Value.ToString().Trim(); //string ledLeftRaw = row.Cells["ColumnButtonLed"].Value.ToString().Trim(); string model = row.Cells["ColumnModel"].Value.ToString().Trim(); if (!modelNorm.ContainsKey(model)) { continue; } LedLeftovers ledLeft = (LedLeftovers)row.Cells["ColumnButtonLed"].Tag; double goodQty = Int32.Parse(row.Cells["GoodQty"].Value.ToString().Trim()); double ngQty = Int32.Parse(row.Cells["Ng"].Value.ToString().Trim()); double allQty = goodQty + ngQty; moduleWasteSum += ngQty; goodModuleSum += goodQty; //if (row.Cells["ColumnLot"].Value.ToString() == "1327848") // Debug.WriteLine("tada"); model = model.Substring(0, 6) + "XXX" + model.Substring(9, 1); double rankAQty = modelNorm[model].QtyRankA; double rankBQty = modelNorm[model].QtyRankB; double ledQty = rankAQty + rankBQty; double ledPerLotNorm = allQty * ledQty; double ledPerReel = 3000; if (row.Cells["Rank12NC"].Value.ToString().Length < 11) { ledPerReel = 3500; } double ledPerLot = ledLeft.RankA.Count * 2 * ledPerReel; double expectedLedLeft = ledPerLot - ledPerLotNorm; if (expectedLedLeft < 0) { continue; } double realLedLeft = 0; foreach (var led in ledLeft.RankA) { realLedLeft += led.QtyLeft; } foreach (var led in ledLeft.RankB) { realLedLeft += led.QtyLeft; } double wasteDifference = expectedLedLeft - realLedLeft; percentageLotWaste.Add(((expectedLedLeft - realLedLeft) / ledPerLot) * 100); } if (goodModuleSum > 0) { return(new double[] { Math.Round(percentageLotWaste.Average(), 2), Math.Round(moduleWasteSum / goodModuleSum, 4) * 100 }); } else { return(new double[] { 0, 0 }); } }