private static Dictionary <DateTime, Dictionary <int, List <ReworkOperationDetails> > > SortSqlTableBydateShiftPcb(DataTable sqlTable)
        {
            Dictionary <DateTime, Dictionary <int, List <ReworkOperationDetails> > > result = new Dictionary <DateTime, Dictionary <int, List <ReworkOperationDetails> > >();

            foreach (DataRow row in sqlTable.Rows)
            {
                string   pcbId        = row["SerialNo"].ToString();
                DateTime realDate     = DateTime.Parse(row["Data"].ToString());
                DateTime fixedDate    = ViDataLoader.FixedShiftDate(realDate);
                string   operation    = row["OpisNaprawy"].ToString();
                string   compRef      = row["NaprawianyKomponent"].ToString();
                string   oper         = row["Operator"].ToString();
                string   model        = row["Model"].ToString();
                bool     repairResult = true;

                if (row["WynikNaprawy"].ToString() != "OK")
                {
                    repairResult = false;
                }

                if (!result.ContainsKey(fixedDate.Date))
                {
                    result.Add(fixedDate.Date, new Dictionary <int, List <ReworkOperationDetails> >());
                }
                dateShiftNo shiftInfo = dateTools.whatDayShiftIsit(realDate);
                if (!result[fixedDate.Date].ContainsKey(shiftInfo.shift))
                {
                    result[fixedDate.Date].Add(shiftInfo.shift, new List <ReworkOperationDetails>());
                }



                PcbReworkData reworkItem = new PcbReworkData();
                reworkItem.operations = new List <ReworkOperationDetails>();
                reworkItem.id         = pcbId;
                ReworkOperationDetails newOperation = new ReworkOperationDetails();

                newOperation.fixedDate = fixedDate;
                newOperation.realDate  = realDate;
                newOperation.operation = operation;
                newOperation.model     = model;
                newOperation.compRef   = compRef;
                newOperation.oper      = oper;
                newOperation.result    = repairResult;
                newOperation.pcbId     = pcbId;
                reworkItem.operations.Add(newOperation);

                result[fixedDate.Date][shiftInfo.shift].Add(newOperation);
            }

            return(result);
        }
        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);
        }