Esempio n. 1
0
        private void showViOperatorDetails_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = sourceTable;

            Color rowCol = Color.LightBlue;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.Style.BackColor = rowCol;
                }


                if (row.Cells["Data"].Value != null)
                {
                    if (row.Cells["Data"].Value.ToString() != "")
                    {
                        if (rowCol == Color.LightBlue)
                        {
                            rowCol = Color.White;
                        }
                        else
                        {
                            rowCol = Color.LightBlue;
                        }
                    }
                }
            }

            SMTOperations.autoSizeGridColumns(dataGridView1);
        }
Esempio n. 2
0
        private void LedWasteDetails_Load(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            double usedA    = 0;
            double usedB    = 0;
            double droppedA = 0;
            double droppedB = 0;

            for (int i = 1; i < sourceTable.Rows.Count; i++)
            {
                usedA    += double.Parse(sourceTable.Rows[i]["Mont.A"].ToString());
                usedB    += double.Parse(sourceTable.Rows[i]["Mont.B"].ToString());
                droppedA += double.Parse(sourceTable.Rows[i]["Odp_A"].ToString());
                droppedB += double.Parse(sourceTable.Rows[i]["Odp_B"].ToString());
            }

            labelTitle.Text  = sourceTable.Rows[0][0].ToString() + Environment.NewLine;
            labelTitle.Text += "odpad A=" + Math.Round(droppedA / usedA * 100, 2) + "% odpad B=" + Math.Round(droppedB / usedB * 100, 2) + "%";

            sourceTable.Rows.RemoveAt(0);
            Charting.DrawLedWasteForDetailView(sourceTable, chartLedWasteDetails);
            dataGridView1.DataSource = sourceTable;
            sourceTable.Rows.Add("Total", "", "", "", usedA, droppedA, usedB, droppedB);

            SMTOperations.autoSizeGridColumns(dataGridView1);
        }
        public static void FillOutBoxingLedQty(Dictionary <DateTime, SortedDictionary <int, Dictionary <string, DataTable> > > boxingData, Dictionary <string, MesModels> mesModels, DataGridView grid)
        {
            grid.Rows.Clear();
            grid.Columns.Clear();
            Color rowColor = Color.White;

            grid.Columns.Add("Tydz", "Tydz");
            grid.Columns.Add("Data", "Data");
            grid.Columns.Add("Zmiana", "Zmiana");
            grid.Columns.Add("IloscWszystkie", "IloscWszystkie");
            grid.Columns.Add("IloscKwadrat", "IloscKwadrat");

            foreach (DataGridViewColumn col in grid.Columns)
            {
                col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }

            foreach (var dateEntry in boxingData)
            {
                if (rowColor == System.Drawing.Color.LightBlue)
                {
                    rowColor = System.Drawing.Color.White;
                }
                else
                {
                    rowColor = System.Drawing.Color.LightBlue;
                }

                foreach (var shiftEntry in dateEntry.Value)
                {
                    Int32 ledCountAll    = 0;
                    Int32 ledCountSquare = 0;

                    foreach (var modelEntry in shiftEntry.Value)
                    {
                        int    ledPerModel = mesModels[modelEntry.Key].LedSumQty;
                        string type        = mesModels[modelEntry.Key].Type;
                        ledCountAll += ledPerModel * modelEntry.Value.Rows.Count;
                        if (type == "square")
                        {
                            ledCountSquare += ledPerModel * modelEntry.Value.Rows.Count;
                        }
                    }

                    grid.Rows.Add(GetIso8601WeekOfYear(dateEntry.Key), dateEntry.Key.ToString("dd-MM-yyyy"), shiftEntry.Key, ledCountAll, ledCountSquare);
                    foreach (DataGridViewCell cell in grid.Rows[grid.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowColor;
                        if (cell.ColumnIndex > 2)
                        {
                            cell.Tag = cell.Value.ToString();
                        }
                    }
                }
            }
            SMTOperations.autoSizeGridColumns(grid);
            grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1;
        }
Esempio n. 4
0
        public static void ReLoadSmtTab(
            DataGridView dataGridViewSmtProduction,
            DataGridView dataGridViewChangeOvers,
            DataGridView dataGridViewSmtLedDropped,
            DataGridView dataGridViewSmtLedWasteByModel,
            DataGridView dataGridViewSmtWasteTotal,
            DataGridView dataGridViewSmtLedWasteTotalPerLine,
            DataGridView dataGridViewSmtStencilUsage,
            DataTable smtRecords,
            ref Dictionary <string, Dictionary <string, List <durationQuantity> > > smtModelLineQuantity,
            RadioButton radioButtonSmtShowAllModels,
            Dictionary <string, MesModels> mesModels,
            ComboBox comboBoxSmtModels,
            ComboBox comboBoxSmtLedWasteLine,
            ComboBox comboBoxSmtLewWasteFreq,
            ComboBox comboBoxSmtLedWasteLines,
            Dictionary <string, Color> lineColors,
            Chart chartLedWasteChart,
            Panel panelSmtLedWasteCheckContainer)
        {
            SortedDictionary <DateTime, SortedDictionary <int, DataTable> > sortedTableByDayAndShift = SMTOperations.sortTableByDayAndShift(smtRecords, "DataCzasKoniec");

            SMTOperations.shiftSummaryDataSource(sortedTableByDayAndShift, dataGridViewSmtProduction);

            smtModelLineQuantity = SMTOperations.smtQtyPerModelPerLine(smtRecords, radioButtonSmtShowAllModels.Checked, mesModels);
            comboBoxSmtModels.Items.AddRange(smtModelLineQuantity.Select(m => m.Key).OrderBy(m => m).ToArray());

            ChangeOverTools.BuildSmtChangeOverGrid(ChangeOverTools.BuildDateShiftLineDictionary(smtRecords), dataGridViewChangeOvers);

            ledWasteDictionary = LedWasteDictionary(sortedTableByDayAndShift, mesModels);
            SMTOperations.FillOutDailyLedWaste(ledWasteDictionary, dataGridViewSmtLedDropped);
            SMTOperations.FillOutLedWasteByModel(ledWasteDictionary, dataGridViewSmtLedWasteByModel, comboBoxSmtLedWasteLine.Text);
            SMTOperations.FillOutLedWasteTotalWeekly(ledWasteDictionary, dataGridViewSmtWasteTotal);
            Dictionary <string, bool> lineOptions = new Dictionary <string, bool>();

            lineColors = new Dictionary <string, Color>();

            foreach (Control c in panelSmtLedWasteCheckContainer.Controls)
            {
                if ((c is CheckBox))
                {
                    lineOptions.Add(c.Text.Trim(), ((CheckBox)c).Checked);
                    lineColors.Add(c.Text.Trim(), c.BackColor);
                }
            }

            Charting.DrawLedWasteChart(ledWasteDictionary, chartLedWasteChart, comboBoxSmtLewWasteFreq.Text, lineOptions, lineColors);

            comboBoxSmtLedWasteLine.Items.Add("Wszystkie");
            comboBoxSmtLedWasteLine.Items.AddRange(smtModelLineQuantity.SelectMany(m => m.Value).Select(l => l.Key).Distinct().OrderBy(l => l).ToArray());
            comboBoxSmtLedWasteLine.Text = "Wszystkie";
            comboBoxSmtLedWasteLines.Items.AddRange(ledWasteDictionary.SelectMany(date => date.Value).SelectMany(shift => shift.Value).Select(l => l.model).Distinct().OrderBy(l => l).ToArray());
            comboBoxSmtLedWasteLines.Items.Insert(0, "Wszystkie");
            comboBoxSmtLedWasteLines.Text = "Wszystkie";
            SMTOperations.FillOutLedWasteTotalByLine(ledWasteDictionary, dataGridViewSmtLedWasteTotalPerLine, comboBoxSmtLedWasteLines.Text);
            FillOutStencilTable(dataGridViewSmtStencilUsage, mesModels);
        }
        public static void FillOutGrid(DataGridView grid, DataTable table, bool attachImages)
        {
            grid.Columns.Clear();
            grid.Columns.Add("Nazwa", "Nazwa");

            for (int r = 0; r < table.Rows.Count; r++)
            {
                grid.Columns.Add("Wartosc" + r, "Wartosc" + r);

                for (int c = 0; c < table.Columns.Count; c++)
                {
                    grid.Rows.Add(table.Columns[c].ColumnName, table.Rows[r][c]);
                }
                if (attachImages)
                {
                    DataGridViewImageButtonSaveColumn columnImage = new DataGridViewImageButtonSaveColumn();

                    columnImage.Name       = "Images";
                    columnImage.HeaderText = "";
                    grid.Columns.Add(columnImage);

                    string date        = table.Rows[r]["Data_czas"].ToString().Substring(0, 10).Replace(".", "-");
                    string lot         = table.Rows[r]["numerZlecenia"].ToString();
                    var    fileImgList = VIOperations.TryGetFileInfoOfImagesForLot(lot, date);

                    if (fileImgList.Count > 0)
                    {
                        foreach (DataGridViewRow row in grid.Rows)
                        {
                            string rowFailureName             = row.Cells[0].Value.ToString();
                            List <System.IO.FileInfo> tagList = new List <System.IO.FileInfo>();
                            foreach (var img in fileImgList)
                            {
                                string failureName = img.Name.Split('_')[1];


                                if (failureName == rowFailureName)
                                {
                                    tagList.Add(img);
                                }
                            }
                            if (tagList.Count > 0)
                            {
                                ((DataGridViewImageButtonSaveCell)(row.Cells[r + 2])).Enabled     = true;
                                ((DataGridViewImageButtonSaveCell)(row.Cells[r + 2])).ButtonState = PushButtonState.Normal;

                                row.Cells[r + 2].Tag = tagList;
                            }
                        }
                    }
                }
            }



            SMTOperations.autoSizeGridColumns(grid);
        }
Esempio n. 6
0
        private void SimpleDetailsDT_Load(object sender, EventArgs e)
        {
            if (hyperlinkPcb & !Directory.Exists(@"P:\"))
            {
                Network.ConnectPDrive();
            }

            dataGridView1.DataSource = sourceTable;

            label1.Text = title;
            SMTOperations.autoSizeGridColumns(dataGridView1);
            MakeInterlacedColors();
            MakeImageHyperlinks();
        }
Esempio n. 7
0
        public static void FillGridWorkReport(DataTable lotTable, DataGridView grid)
        {
            DataTable dt = lotTable.Copy();

            dt.Columns.Remove("LiniaProdukcyjna");
            SortedDictionary <DateTime, SortedDictionary <int, DataTable> > tablesPerDayPerShift = SMTOperations.sortTableByDayAndShift(dt, "DataCzasWydruku");


            System.Drawing.Color rowColor = System.Drawing.Color.LightBlue;

            grid.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            foreach (var dayEntry in tablesPerDayPerShift)
            {
                if (rowColor == System.Drawing.Color.LightBlue)
                {
                    rowColor = System.Drawing.Color.White;
                }
                else
                {
                    rowColor = System.Drawing.Color.LightBlue;
                }
                var week = dateTools.GetIso8601WeekOfYear(dayEntry.Key);

                foreach (var shiftEntry in dayEntry.Value)
                {
                    double qty = 0;
                    foreach (DataRow row in shiftEntry.Value.Rows)
                    {
                        qty += double.Parse(row["Ilosc_wyrobu_zlecona"].ToString());
                    }

                    grid.Rows.Add(dayEntry.Key.ToShortDateString(), week, shiftEntry.Key.ToString(), qty);
                    foreach (DataGridViewCell cell in grid.Rows[grid.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowColor;
                        if (cell.OwningColumn.HeaderText == "Ilość")
                        {
                            cell.Tag = shiftEntry.Value;
                        }
                    }
                }
            }
            grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1;
            SMTOperations.autoSizeGridColumns(grid);
        }
        public static void FilloutBoxingSummary(DataGridView grid, List <string> pcbs)
        {
            if (pcbs.Count > 0)
            {
                Dictionary <string, List <string> > boxes = SQLoperations.GetBoxingInfo(pcbs);

                grid.Columns.Clear();
                grid.Columns.Add("Pole", "");
                grid.Columns.Add("Wartość", "");

                foreach (var boxEntry in boxes)
                {
                    grid.Rows.Add(boxEntry.Key, boxEntry.Value.Count + "szt.");
                }

                SMTOperations.autoSizeGridColumns(grid);
            }
        }
Esempio n. 9
0
        public static void BuildSmtChangeOverGrid(SortedDictionary <DateTime, Dictionary <int, Dictionary <string, HashSet <string> > > > smtModels, DataGridView grid)
        {
            grid.Rows.Clear();
            grid.Columns.Clear();
            grid.Columns.Add("Dzien", "Dzien");
            grid.Columns.Add("Zmiana", "Zmiana");
            grid.Columns.Add("SMT1", "SMT1");
            grid.Columns.Add("SMT2", "SMT2");
            grid.Columns.Add("SMT3", "SMT3");
            grid.Columns.Add("SMT5", "SMT5");
            grid.Columns.Add("SMT6", "SMT6");
            grid.Columns.Add("SMT7", "SMT7");
            grid.Columns.Add("SMT8", "SMT8");
            System.Drawing.Color rowColor = System.Drawing.Color.LightBlue;

            grid.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            foreach (var dayEntry in smtModels)
            {
                if (rowColor == System.Drawing.Color.LightBlue)
                {
                    rowColor = System.Drawing.Color.White;
                }
                else
                {
                    rowColor = System.Drawing.Color.LightBlue;
                }

                foreach (var shiftEntry in dayEntry.Value)
                {
                    grid.Rows.Add(dayEntry.Key.Date.ToString("dd-MM-yyyy"), shiftEntry.Key);
                    foreach (var lineEntry in shiftEntry.Value)
                    {
                        grid.Rows[grid.Rows.Count - 1].Cells[lineEntry.Key].Value = lineEntry.Value.Count;
                    }

                    foreach (DataGridViewCell cell in grid.Rows[grid.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowColor;
                    }
                }
            }
            SMTOperations.autoSizeGridColumns(grid);
            grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1;
        }
        public static void FillOutBoxingTable(Dictionary <DateTime, SortedDictionary <int, Dictionary <string, DataTable> > > boxingData, DataGridView grid)
        {
            grid.Rows.Clear();
            grid.Columns.Clear();
            Color rowColor = Color.White;

            grid.Columns.Add("Data", "Data");
            grid.Columns.Add("Tydz", "tydz");
            grid.Columns.Add("Zmiana", "Zmiana");
            grid.Columns.Add("Ilosc", "Ilosc");


            foreach (DataGridViewColumn col in grid.Columns)
            {
                col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }

            foreach (var dateEntry in boxingData)
            {
                if (rowColor == System.Drawing.Color.LightBlue)
                {
                    rowColor = System.Drawing.Color.White;
                }
                else
                {
                    rowColor = System.Drawing.Color.LightBlue;
                }
                var week = dateTools.GetIso8601WeekOfYear(dateEntry.Key);
                foreach (var shiftEntry in dateEntry.Value)
                {
                    string date  = dateEntry.Key.Date.ToString("yyyy-MM-dd");
                    string shift = shiftEntry.Key.ToString();


                    DataTable shiftTable = new DataTable();
                    shiftTable.Columns.Add("Data");
                    shiftTable.Columns.Add("Zmiana");
                    shiftTable.Columns.Add("Ilosc");
                    shiftTable.Columns.Add("Model");
                    double shiftQty = 0;
                    Dictionary <string, double> qtyPerModel = new Dictionary <string, double>();
                    foreach (var modelEntry in shiftEntry.Value)
                    {
                        if (!qtyPerModel.ContainsKey(modelEntry.Key))
                        {
                            qtyPerModel.Add(modelEntry.Key, 0);
                        }
                        qtyPerModel[modelEntry.Key] = modelEntry.Value.Rows.Count;
                    }

                    foreach (var modelEntry in qtyPerModel)
                    {
                        shiftTable.Rows.Add(dateEntry.Key, shiftEntry.Key, modelEntry.Value, modelEntry.Key);
                        shiftQty += modelEntry.Value;
                    }

                    grid.Rows.Add(date, week, shift, shiftQty);
                    foreach (DataGridViewCell cell in grid.Rows[grid.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowColor;
                        if (cell.ColumnIndex > 1)
                        {
                            string tester = cell.OwningColumn.Name;
                            cell.Tag = shiftTable;
                        }
                    }
                }
            }
            SMTOperations.autoSizeGridColumns(grid);
            grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1;
        }
        private void SmtShiftDetails_Load(object sender, EventArgs e)
        {
            dataGridViewShiftDetails.DataSource = dtSource;
            if (dtSource.Columns.Count > 2 & dtSource.Columns.Contains("model"))
            {
                Dictionary <string, double> qtyPerModel = new Dictionary <string, double>();
                Dictionary <string, double> qtyPerLine  = new Dictionary <string, double>();

                double totalQty = 0;
                foreach (DataRow row in dtSource.Rows)
                {
                    string model = row["model"].ToString();

                    string line = "";
                    if (dtSource.Columns.Contains("LiniaSMT"))
                    {
                        line = row["LiniaSMT"].ToString();
                    }

                    if (!qtyPerModel.ContainsKey(model))
                    {
                        qtyPerModel.Add(model, 0);
                    }

                    if (!qtyPerLine.ContainsKey(line))
                    {
                        qtyPerLine.Add(line, 0);
                    }

                    double qty = double.Parse(row["Ilosc"].ToString());

                    qtyPerModel[model] += qty;
                    qtyPerLine[line]   += qty;
                    totalQty           += qty;
                }

                dataGridViewModelSummary.Columns.Add("Model", "Model");
                dataGridViewModelSummary.Columns.Add("Ilosc", "Ilosc");
                dataGridViewLinesSummary.Columns.Add("Linia", "Linia");
                dataGridViewLinesSummary.Columns.Add("Ilosc", "Ilosc");

                foreach (var modelEntry in qtyPerModel)
                {
                    dataGridViewModelSummary.Rows.Add(modelEntry.Key, modelEntry.Value);
                }
                foreach (var lineEntry in qtyPerLine)
                {
                    dataGridViewLinesSummary.Rows.Add(lineEntry.Key, lineEntry.Value);
                }

                dataGridViewModelSummary.Rows.Add("Razem", totalQty);
                dataGridViewModelSummary.Sort(dataGridViewModelSummary.Columns["Ilosc"], ListSortDirection.Descending);

                SMTOperations.autoSizeGridColumns(dataGridViewModelSummary);
            }
            else
            {
                double sum = 0;
                foreach (DataRow row in dtSource.Rows)
                {
                    sum += double.Parse(row["Ilosc"].ToString());
                }
                dtSource.Rows.Add("Razem", sum);
            }

            SMTOperations.autoSizeGridColumns(dataGridViewShiftDetails);
            label1.Text = description;
        }
Esempio n. 12
0
        public static void FillOutTesterTable(Dictionary <DateTime, SortedDictionary <int, Dictionary <string, Dictionary <string, DataTable> > > > testerData, DataGridView grid, Dictionary <string, string> lotModelDictionary)
        {
            grid.Rows.Clear();
            grid.Columns.Clear();
            Color rowColor = Color.White;

            grid.Columns.Add("Data", "Data");
            grid.Columns.Add("Tydzt", "Tydz");
            grid.Columns.Add("Zmiana", "Zmiana");
            grid.Columns.Add("Optical", "Optical");
            grid.Columns.Add("Manual-1", "Manual-1");
            grid.Columns.Add("Manual-2", "Manual-2");
            grid.Columns.Add("test_SMT5", "test_SMT5");
            grid.Columns.Add("test_SMT6", "test_SMT6");

            foreach (DataGridViewColumn col in grid.Columns)
            {
                col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }

            foreach (var dateEntry in testerData)
            {
                if (rowColor == System.Drawing.Color.LightBlue)
                {
                    rowColor = System.Drawing.Color.White;
                }
                else
                {
                    rowColor = System.Drawing.Color.LightBlue;
                }
                var week = dateTools.GetIso8601WeekOfYear(dateEntry.Key);
                foreach (var shiftEntry in dateEntry.Value)
                {
                    string date  = dateEntry.Key.Date.ToString("yyyy-MM-dd");
                    string shift = shiftEntry.Key.ToString();

                    Dictionary <string, double> qtyPerMachine = new Dictionary <string, double>();
                    qtyPerMachine.Add("Optical", 0);
                    qtyPerMachine.Add("Manual-1", 0);
                    qtyPerMachine.Add("Manual-2", 0);
                    qtyPerMachine.Add("test_SMT5", 0);
                    qtyPerMachine.Add("test_SMT6", 0);


                    DataTable shiftTable = new DataTable();
                    shiftTable.Columns.Add("Data Start");
                    shiftTable.Columns.Add("Data Koniec");
                    shiftTable.Columns.Add("LOT");
                    shiftTable.Columns.Add("Model");
                    shiftTable.Columns.Add("Tester");
                    shiftTable.Columns.Add("Ilosc");
                    shiftTable.Columns.Add("Ilość cykli");
                    Dictionary <string, DataTable> tagPerMachine = new Dictionary <string, DataTable>();
                    tagPerMachine.Add("Optical", shiftTable.Clone());
                    tagPerMachine.Add("Manual-1", shiftTable.Clone());
                    tagPerMachine.Add("Manual-2", shiftTable.Clone());
                    tagPerMachine.Add("test_SMT5", shiftTable.Clone());
                    tagPerMachine.Add("test_SMT6", shiftTable.Clone());

                    foreach (var machineEntry in shiftEntry.Value)
                    {
                        if (!qtyPerMachine.ContainsKey(machineEntry.Key))
                        {
                            continue;
                        }
                        HashSet <string> pcbPerMachine = new HashSet <string>();

                        foreach (var lotEntry in machineEntry.Value)
                        {
                            List <string> pcbPerLot = new List <string>();
                            DateTime      start     = DateTime.Now;
                            DateTime      koniec    = new DateTime(1970, 1, 1);
                            string        model     = "";
                            lotModelDictionary.TryGetValue(lotEntry.Key, out model);

                            foreach (DataRow row in lotEntry.Value.Rows)
                            {
                                DateTime testDate = DateTime.Parse(row["Data"].ToString());
                                if (testDate > koniec)
                                {
                                    koniec = testDate;
                                }
                                if (testDate < start)
                                {
                                    start = testDate;
                                }
                                pcbPerMachine.Add(row["PCB"].ToString());
                                pcbPerLot.Add(row["PCB"].ToString());
                            }
                            tagPerMachine[machineEntry.Key].Rows.Add(start, koniec, lotEntry.Key, model, machineEntry.Key, pcbPerLot.Distinct().Count(), pcbPerLot.Count);
                        }

                        qtyPerMachine[machineEntry.Key] += pcbPerMachine.Count;
                    }
                    grid.Rows.Add(date, week, shift, qtyPerMachine["Optical"], qtyPerMachine["Manual-1"], qtyPerMachine["Manual-2"], qtyPerMachine["test_SMT5"], qtyPerMachine["test_SMT6"]);
                    foreach (DataGridViewCell cell in grid.Rows[grid.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowColor;
                        if (cell.ColumnIndex > 2)
                        {
                            string tester = cell.OwningColumn.Name;
                            cell.Tag = tagPerMachine[tester];
                        }
                    }
                }
            }
            SMTOperations.autoSizeGridColumns(grid);
            grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1;
        }
Esempio n. 13
0
        public static void FillGridReadyLots(DataGridView grid, DataTable lotTable, DataTable smtRecords)
        {
            Dictionary <string, Int32>     qtyModulesPerModel = new Dictionary <string, int>();
            Dictionary <string, Int32>     qtyLotsPerModel    = new Dictionary <string, int>();
            Dictionary <string, DataTable> tagPerModel        = new Dictionary <string, DataTable>();
            DataTable tagTemplate = new DataTable();

            tagTemplate.Columns.Add("Data_Poczatku_Zlecenia");
            tagTemplate.Columns.Add("DataCzasWydruku");
            tagTemplate.Columns.Add("LOT");
            tagTemplate.Columns.Add("NC12_wyrobu");
            tagTemplate.Columns.Add("Ilosc_wyrobu_zlecona");
            DateTime      oldestLot = DateTime.Now;
            List <string> smtLots   = new List <string>();

            foreach (DataRow row in smtRecords.Rows)
            {
                smtLots.Add(row["NrZlecenia"].ToString());
                DateTime date = DateTime.Parse(row["DataCzasKoniec"].ToString());
                if (date < oldestLot)
                {
                    oldestLot = date;
                }
            }


            foreach (DataRow row in lotTable.Rows)
            {
                string lot       = row["Nr_Zlecenia_Produkcyjnego"].ToString();
                string endDate   = row["Data_Konca_Zlecenia"].ToString();
                string startDate = row["Data_Poczatku_Zlecenia"].ToString();
                if (endDate != "")
                {
                    continue;
                }
                string dateString = row["DataCzasWydruku"].ToString();
                if (dateString == "")
                {
                    continue;
                }
                DateTime lotDate = DateTime.Parse(dateString);
                if (lotDate < oldestLot)
                {
                    continue;
                }

                if (!smtLots.Contains(lot))
                {
                    string model = row["NC12_wyrobu"].ToString();
                    if (!qtyModulesPerModel.ContainsKey(model))
                    {
                        qtyModulesPerModel.Add(model, 0);
                        qtyLotsPerModel.Add(model, 0);
                        tagPerModel.Add(model, tagTemplate.Clone());
                    }
                    string qtyString = row["Ilosc_wyrobu_zlecona"].ToString();
                    qtyModulesPerModel[model] += Int32.Parse(qtyString);
                    qtyLotsPerModel[model]++;
                    tagPerModel[model].Rows.Add(startDate, dateString, lot, model, qtyString);
                }
            }

            grid.Columns.Clear();
            grid.Columns.Add("Model", "Model");
            grid.Columns.Add("Ilosc KITow", "Ilosc KITow");
            grid.Columns.Add("Ilosc wyrobow", "Ilosc wyrobow");

            foreach (var modelEntry in qtyLotsPerModel)
            {
                grid.Rows.Add(modelEntry.Key, modelEntry.Value, qtyModulesPerModel[modelEntry.Key]);
                foreach (DataGridViewCell cell in grid.Rows[grid.Rows.Count - 1].Cells)
                {
                    cell.Tag = tagPerModel[modelEntry.Key];
                }
            }
            SMTOperations.autoSizeGridColumns(grid);
        }
        public static void ReLoadViTab(
            ref Dictionary <string, string> lotModelDictionary,
            ref List <WasteDataStructure> inspectionData,
            ref List <excelOperations.order12NC> mstOrders,
            ComboBox comboBoxViOperatorsCapa,
            ComboBox comboBoxModel,
            ComboBox comboBoxViModelAnalFamily,
            ComboBox comboBoxViModelAnalModel,

            CheckedListBox checkedListBoxViWasteLevelSmtLines,
            CheckedListBox checkedListBoxViReasons,
            CheckedListBox cBListViReasonAnalysesSmtLines,
            CheckedListBox cBListViModelAnalysesSmtLines,
            CheckedListBox cBListViReasonList,

            DateTimePicker dateTimePickerPrzyczynyOdpaduOd,
            DateTimePicker dateTimePickerWasteLevelBegin,
            DataGridView dataGridViewDuplikaty,
            DataGridView dataGridViewPomylkiIlosc,
            DataGridView dataGridViewPowyzej50,
            DataGridView dataGridViewBledyNrZlec,
            DataGridView dataGridViewMstOrders,
            DataGridView dataGridViewViOperatorsTotal,
            DataGridView gridLatestLots,
            DateTimePicker dateTimePickerViOperatorEfiiciencyStart,
            DateTimePicker dateTimePickerViOperatorEfiiciencyEnd,
            NumericUpDown numericUpDownMoreThan50Scrap,
            NumericUpDown numericUpDownMoreThan50Ng,
            Dictionary <string, string> lotToOrderedQty,

            //rework
            DataGridView dataGridViewReworkDailyReport,
            DataGridView dataGridViewReworkByOperator,
            DataGridView dataGridViewServiceVsNg,
            Chart chartServiceVsNg,
            bool chartDaily
            )
        {
            mstOrders = excelOperations.loadExcel(ref lotModelDictionary);

            if (masterVITable.Rows.Count < 1)
            {
                masterVITable = SQLoperations.DownloadVisInspFromSQL(120);
            }

            //textBox1.Text += "SQL table: " + masterVITable.Rows.Count + " rows" + Environment.NewLine;
            comboBoxViOperatorsCapa.Items.AddRange(CreateOperatorsList(masterVITable).ToArray());
            lotToSmtLine   = SQLoperations.lotToSmtLine(80); // to remove???
            inspectionData = ViDataLoader.LoadData(masterVITable, lotToSmtLine, lotModelDictionary);

            string[] smtLines = lotToSmtLine.Select(l => l.Value).Distinct().OrderBy(o => o).ToArray();

            foreach (var smtLine in smtLines)
            {
                checkedListBoxViWasteLevelSmtLines.Items.Add(smtLine, true);

                checkedListBoxViReasons.Items.Add(smtLine, true);
                cBListViReasonAnalysesSmtLines.Items.Add(smtLine, true);
                cBListViModelAnalysesSmtLines.Items.Add(smtLine, true);
            }

            comboBoxModel.Items.AddRange(lotModelDictionary.Select(m => m.Value.Replace("LLFML", "")).Distinct().OrderBy(o => o).ToArray());

            dateTimePickerPrzyczynyOdpaduOd.Value = DateTime.Now.AddDays(-30);
            dateTimePickerWasteLevelBegin.Value   = DateTime.Now.AddDays(-30);
            comboBoxViOperatorsCapa.SelectedIndex = comboBoxViOperatorsCapa.Items.IndexOf("Wszyscy");

            dataGridViewDuplikaty.DataSource = SzukajDuplikatow(inspectionData);
            dgvTools.ColumnsAutoSize(dataGridViewDuplikaty, DataGridViewAutoSizeColumnMode.AllCells);
            dataGridViewDuplikaty.Sort(dataGridViewDuplikaty.Columns[0], ListSortDirection.Descending);
            dgvTools.ColumnsAutoSize(dataGridViewDuplikaty, DataGridViewAutoSizeColumnMode.AllCells);

            dataGridViewPomylkiIlosc.DataSource = PomylkiIlosci(lotToOrderedQty, inspectionData);
            dgvTools.ColumnsAutoSize(dataGridViewPomylkiIlosc, DataGridViewAutoSizeColumnMode.AllCellsExceptHeader);

            dataGridViewPowyzej50.DataSource = MoreThan50(numericUpDownMoreThan50Scrap, numericUpDownMoreThan50Ng, lotModelDictionary, inspectionData);
            dgvTools.ColumnsAutoSize(dataGridViewPowyzej50, DataGridViewAutoSizeColumnMode.AllCells);
            dataGridViewPowyzej50.Sort(dataGridViewPowyzej50.Columns["Ile"], ListSortDirection.Descending);


            HashSet <string> wasteReasonList = new HashSet <string>();

            foreach (var wasteReason in inspectionData)
            {
                foreach (var r in wasteReason.WastePerReason)
                {
                    wasteReasonList.Add(r.Key.Replace("ng", "").Replace("scrap", ""));
                }
                break;
            }

            cBListViReasonList.Items.AddRange(wasteReasonList.ToArray());



            comboBoxViModelAnalFamily.Items.AddRange(modelFamilyList(inspectionData, lotModelDictionary));
            comboBoxViModelAnalModel.Items.AddRange(uniqueModelsList(inspectionData, lotModelDictionary));

            dataGridViewBledyNrZlec.DataSource = UnknownOrderNumberTable(lotModelDictionary, inspectionData);

            VIOperations.ngRatePerOperator(inspectionData, dateTimePickerViOperatorEfiiciencyStart.Value, dateTimePickerViOperatorEfiiciencyEnd.Value, dataGridViewViOperatorsTotal);

            SMTOperations.autoSizeGridColumns(dataGridViewViOperatorsTotal);

            dataGridViewMstOrders.DataSource = VIOperations.checkMstViIfDone(mstOrders, inspectionData);

            Rework.FillOutGridDailyProdReport(dataGridViewReworkDailyReport, dataGridViewReworkByOperator, SQLoperations.GetLedRework());
            RefreshReworkChart(inspectionData, chartServiceVsNg, chartDaily, dataGridViewServiceVsNg);

            FillOutGridLatestLots(gridLatestLots, inspectionData);
        }
        private void WasteReasonDetails_Load(object sender, EventArgs e)
        {
            DataTable sourceTable = new DataTable();

            sourceTable.Columns.Add("Dobrych");
            sourceTable.Columns.Add("Ng");
            sourceTable.Columns.Add("LOT");
            sourceTable.Columns.Add("Model");
            sourceTable.Columns.Add("Data");
            sourceTable.Columns.Add("LiniaSMT");
            sourceTable.Columns.Add("Operator");
            //sourceTable.Columns.Add("Zdjecia");


            sourceTable.Columns["Dobrych"].DataType = typeof(Int32);

            Dictionary <string, Int32> qtyPerModel = new Dictionary <string, int>();
            Dictionary <string, Int32> qtyPerLine  = new Dictionary <string, int>();

            foreach (var lot in inputWasteData.Lots)
            {
                string model = lot.Model;
                string line  = lot.SmtLine;

                if (!qtyPerLine.ContainsKey(line))
                {
                    qtyPerLine.Add(line, 0);
                }
                if (!qtyPerModel.ContainsKey(model))
                {
                    qtyPerModel.Add(model, 0);
                }

                Int32 qty = lot.WastePerReason[title];
                qtyPerLine[line]   += qty;
                qtyPerModel[model] += qty;

                var imageList = VIOperations.TryGetFileInfoOfImagesForLot(lot.NumerZlecenia, lot.RealDateTime.ToString("dd-MM-yyyy"));
                if (imageList.Count > 0)
                {
                    if (!imagesPerLot.ContainsKey(lot.NumerZlecenia))
                    {
                        imagesPerLot.Add(lot.NumerZlecenia, new List <FileInfo>());
                    }
                    imagesPerLot[lot.NumerZlecenia].AddRange(imageList);
                }

                sourceTable.Rows.Add(lot.GoodQty, lot.WastePerReason[title], lot.NumerZlecenia, lot.Model, lot.RealDateTime, lot.SmtLine, lot.Oper);
            }

            DataView dv = sourceTable.DefaultView;

            dv.Sort = "Dobrych desc";
            dataGridView1.DataSource = dv.ToTable();

            label1.Text = title;

            DataTable modelSource = new DataTable();

            modelSource.Columns.Add("Model");
            modelSource.Columns.Add("Ilość", typeof(Int32));

            DataTable lineSource = new DataTable();

            lineSource.Columns.Add("Linia");
            lineSource.Columns.Add("Ilość", typeof(Int32));

            foreach (var modelEntry in qtyPerModel)
            {
                modelSource.Rows.Add(modelEntry.Key, modelEntry.Value);
            }

            foreach (var lineEntry in qtyPerLine)
            {
                lineSource.Rows.Add(lineEntry.Key, lineEntry.Value);
            }

            dataGridViewModel.DataSource = modelSource;
            dataGridViewLine.DataSource  = lineSource;

            SMTOperations.autoSizeGridColumns(dataGridView1);
            SMTOperations.autoSizeGridColumns(dataGridViewLine);
            SMTOperations.autoSizeGridColumns(dataGridViewModel);

            dataGridViewLine.Sort(this.dataGridViewLine.Columns["Ilość"], ListSortDirection.Descending);
            dataGridViewModel.Sort(this.dataGridViewModel.Columns["Ilość"], ListSortDirection.Descending);
        }
        public static void FillOutGridDailyProdReport(DataGridView dailyReportGrid, DataGridView reportByOperatorGrid, DataTable sqlTable)
        {
            reworkDataByDate = SortSqlTableBydateShiftPcb(sqlTable);
            FillOutGridReworkByOperator(reworkDataByDate, reportByOperatorGrid);

            dailyReportGrid.Columns.Clear();
            dailyReportGrid.Columns.Add("Data", "Data");
            dailyReportGrid.Columns.Add("Tydz", "Tydz");
            dailyReportGrid.Columns.Add("Zmiana", "Zmiana");
            dailyReportGrid.Columns.Add("PCB", "PCB");
            dailyReportGrid.Columns.Add("Operacji", "Operacji");

            Color rowColor = Color.White;

            foreach (var dateEntry in reworkDataByDate)
            {
                if (rowColor == Color.White)
                {
                    rowColor = Color.LightBlue;
                }
                else
                {
                    rowColor = Color.White;
                }

                foreach (var shiftEntry in dateEntry.Value)
                {
                    DataTable shiftTagTable = new DataTable();

                    shiftTagTable.Columns.Add("#pcb");
                    shiftTagTable.Columns.Add("#operacja");
                    shiftTagTable.Columns.Add("Data");
                    shiftTagTable.Columns.Add("Model");
                    shiftTagTable.Columns.Add("serialNo");
                    shiftTagTable.Columns.Add("Operator");
                    shiftTagTable.Columns.Add("Naprawa");
                    shiftTagTable.Columns.Add("Komponent");
                    shiftTagTable.Columns.Add("Wynik");

                    int operationCount = shiftEntry.Value.Count;
                    int pcbCount       = 0;

                    string prevPcb = "";

                    for (int op = 0; op < shiftEntry.Value.Count; op++)
                    {
                        if (shiftEntry.Value[op].pcbId != prevPcb)
                        {
                            pcbCount++;
                            prevPcb = shiftEntry.Value[op].pcbId;
                        }

                        string wynik = "OK";
                        if (!shiftEntry.Value[op].result)
                        {
                            wynik = "NG";
                        }

                        shiftTagTable.Rows.Add(pcbCount, op + 1, shiftEntry.Value[op].realDate.ToString("dd.MM.yyyy hh:mm"), shiftEntry.Value[op].model, shiftEntry.Value[op].pcbId, shiftEntry.Value[op].oper, shiftEntry.Value[op].operation, shiftEntry.Value[op].compRef, wynik);
                    }



                    dailyReportGrid.Rows.Add(dateEntry.Key.ToString("dd-MM-yyyy"), dateTools.GetIso8601WeekOfYear(dateEntry.Key), shiftEntry.Key, pcbCount, operationCount);
                    foreach (DataGridViewCell cell in dailyReportGrid.Rows[dailyReportGrid.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowColor;
                        if (cell.OwningColumn.HeaderText.ToLower() != "data" & cell.OwningColumn.HeaderText.ToLower() != "tydz" & cell.OwningColumn.HeaderText.ToLower() != "zmiana")
                        {
                            cell.Tag = shiftTagTable;
                        }
                    }
                }
            }
            SMTOperations.autoSizeGridColumns(dailyReportGrid);
            dailyReportGrid.FirstDisplayedCell = dailyReportGrid.Rows[dailyReportGrid.Rows.Count - 1].Cells[0];
        }
        public static void ngRatePerOperator(List <WasteDataStructure> inspectionData, DateTime startDate, DateTime endDate, DataGridView gridNgRate)
        {
            gridNgRate.Columns.Clear();

            Dictionary <string, List <WasteDataStructure> > inspectionDataPerOperator = inspectionData.GroupBy(op => op.Oper).ToDictionary(op => op.Key, op => op.ToList());

            //result.Columns.Add("Operator");
            //result.Columns.Add("Sprawdzone", typeof (double));
            //result.Columns.Add("Śr.na zmianę", typeof (double));
            //result.Columns.Add("h/zmiane", typeof (double));
            //result.Columns.Add("śr/h", typeof (double));
            //result.Columns.Add("NG", typeof(double));
            //result.Columns.Add("NG%", typeof(double));
            //result.Columns.Add("Scrap", typeof(double));
            //result.Columns.Add("Scrap%", typeof(double));

            gridNgRate.Columns.Add("Operator", "Operator");
            gridNgRate.Columns.Add("Sprawdzone", "Sprawdzone");
            gridNgRate.Columns.Add("Śr.na zmianę", "Śr.na zmianę");
            gridNgRate.Columns.Add("h/zmiane", "h/zmiane");
            gridNgRate.Columns.Add("na godz.", "na godz.");
            gridNgRate.Columns.Add("NG", "NG");
            gridNgRate.Columns.Add("NG%", "NG%");
            gridNgRate.Columns.Add("Scrap", "Scrap");
            gridNgRate.Columns.Add("Scrap%", "Scrap % ");


            foreach (var operatorEntry in inspectionDataPerOperator)
            {
                //double totalInspected = operatorEntry.Value.Select(t => t.AllQty).Sum();
                //double totalNg = operatorEntry.Value.Select(t => t.AllNg).Sum();
                //double ngPercent = Math.Round(totalNg / totalInspected * 100, 2);
                //double totalScrap = operatorEntry.Value.Select(t => t.AllScrap).Sum();
                //double scrapPercent = Math.Round(totalScrap / totalInspected * 100, 2);
                Dictionary <DateTime, Dictionary <string, List <WasteDataStructure> > > operatorperDay = new Dictionary <DateTime, Dictionary <string, List <WasteDataStructure> > >();

                double             totalInspected = 0;
                double             totalNg        = 0;
                double             totalScrap     = 0;
                HashSet <DateTime> daysOfWork     = new HashSet <DateTime>();


                foreach (var wasteEntry in operatorEntry.Value)
                {
                    if (wasteEntry.FixedDateTime.Date < startDate.Date || wasteEntry.FixedDateTime.Date > endDate.Date)
                    {
                        continue;
                    }
                    totalInspected += wasteEntry.AllQty;
                    totalNg        += wasteEntry.AllNg;
                    totalScrap     += wasteEntry.AllScrap;
                    daysOfWork.Add(wasteEntry.FixedDateTime.Date);

                    if (!operatorperDay.ContainsKey(wasteEntry.FixedDateTime.Date))
                    {
                        operatorperDay.Add(wasteEntry.FixedDateTime.Date, new Dictionary <string, List <WasteDataStructure> >());
                    }
                    if (!operatorperDay[wasteEntry.FixedDateTime.Date].ContainsKey(wasteEntry.Model))
                    {
                        operatorperDay[wasteEntry.FixedDateTime.Date].Add(wasteEntry.Model, new List <WasteDataStructure>());
                    }
                    operatorperDay[wasteEntry.FixedDateTime.Date][wasteEntry.Model].Add(wasteEntry);
                }
                if (totalInspected == 0)
                {
                    continue;
                }

                double   ngPercent    = Math.Round(totalNg / totalInspected * 100, 2);
                double   scrapPercent = Math.Round(totalScrap / totalInspected * 100, 2);
                double   avg          = Math.Round(totalInspected / (double)daysOfWork.Count, 1);
                string[] operators12h = Load12hOperatorsList();

                DataTable tagTable = new DataTable();
                tagTable.Columns.Add("Data");
                tagTable.Columns.Add("Model");
                tagTable.Columns.Add("Ilość");
                tagTable.Columns.Add("NG");
                tagTable.Columns.Add("Scrap");

                foreach (var dateEntry in operatorperDay)
                {
                    double dayTotal      = 0;
                    double dayTotalNg    = 0;
                    double dayTotalScrap = 0;
                    foreach (var modelEnry in dateEntry.Value)
                    {
                        double total    = modelEnry.Value.Select(q => q.AllQty).Sum();
                        double totNg    = modelEnry.Value.Select(q => q.AllNg).Sum();
                        double totScrap = modelEnry.Value.Select(q => q.AllScrap).Sum();
                        dayTotal      += total;
                        dayTotalNg    += totNg;
                        dayTotalScrap += totScrap;

                        tagTable.Rows.Add("", modelEnry.Key, total, totNg, totScrap);
                    }

                    tagTable.Rows.Add(dateEntry.Key.ToString("dd-MM-yyyy"), "Total", dayTotal, dayTotalNg, dayTotalScrap);
                }
                double h = 8;
                System.Drawing.Color rowClr = System.Drawing.Color.White;
                if (operators12h.Length > 0)
                {
                    if (operators12h.Contains(operatorEntry.Key))
                    {
                        h      = 12;
                        rowClr = System.Drawing.Color.LightBlue;
                    }
                }


                gridNgRate.Rows.Add(operatorEntry.Key, totalInspected, avg, h, Math.Round(avg / h, 0), totalNg, ngPercent, totalScrap, scrapPercent);
                gridNgRate.Rows[gridNgRate.Rows.Count - 1].Cells["Operator"].Tag = tagTable;

                if (h == 12)
                {
                    foreach (DataGridViewCell cell in gridNgRate.Rows[gridNgRate.Rows.Count - 1].Cells)
                    {
                        cell.Style.BackColor = rowClr;
                    }
                }
            }

            SMTOperations.autoSizeGridColumns(gridNgRate);
            //grid.DataSource = result;
            // grid.Columns.Add(hoursCol);
        }