コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }