Пример #1
0
        private static void SetRowBackgroundColor(object iRowID, object nvMatchType, bool bDeleteRowFlag)
        {
            if (iRowID == null) return;

            System.Windows.Forms.DataGridViewRow row = NAVForm.GetSheetDataGridView().Rows.Cast<System.Windows.Forms.DataGridViewRow>()
                .Where(x => !x.IsNewRow)
                .Where(x => ((DataRowView)x.DataBoundItem).Row.Field<int>(Constants.KEY_COLUMN).Equals(iRowID))
                .FirstOrDefault();

            if (GetResetPending(row)) return;

            switch (nvMatchType)
            {
                case Constants.MATCH_ASSOCIATE:
                    row.DefaultCellStyle.BackColor = (bDeleteRowFlag) ? Constants.COLOR_MATCH_ASSOCIATE_DELETE : Constants.COLOR_MATCH_ASSOCIATE;
                    break;

                case Constants.MATCH_PRINCIPLE:
                    row.DefaultCellStyle.BackColor = (bDeleteRowFlag) ? Constants.COLOR_MATCH_PRINCIPLE_DELETE : Constants.COLOR_MATCH_PRINCIPLE;
                    break;

                default:
                    row.DefaultCellStyle.BackColor = Constants.COLOR_DEFAULT;
                    break;
            }

        }
Пример #2
0
        internal static void DeleteDuplicateRows(DataTable datatable)
        {
            if (NAVForm.GetSheetDataGridView().RowCount == 0 || datatable == null)
            {
                return;
            }

            datatable.AcceptChanges();

            object[] rows = SelectDuplicateRows();

            if (rows.Any())
            {
                DeleteSelectedRows();
            }

            void DeleteSelectedRows()
            {
                for (int i = rows.Length - 1; i > -1; i--)
                {
                    int j = 0;

                    while (j < datatable.Rows.Count)
                    {
                        DataRow row = datatable.Rows[j];

                        if (row.HasVersion(DataRowVersion.Current))
                        {
                            if (row[Constants.COLUMN_PARENT_ID].Equals(rows[i]))
                            {
                                row.Delete();
                            }
                        }

                        j++;
                    }
                }

                datatable.AcceptChanges();
            }

            object[] SelectDuplicateRows()
            {
                datatable.AcceptChanges();

                return(datatable.Rows.Cast <DataRow>()
                       .Where(x => x[Constants.COLUMN_DELETE_FLAG].Equals(1) || x[Constants.COLUMN_COMPARISON].Equals(100))
                       .Select(x => x[Constants.COLUMN_PARENT_ID])
                       .Distinct()
                       .ToArray());
            }
        }
Пример #3
0
        internal static DataTable BuildParentTable()
        {
            using (DataTable table = new DataTable())
            {
                DataColumn column = new DataColumn
                {
                    DataType   = System.Type.GetType("System.Int32"),
                    ColumnName = Constants.COLUMN_ROW_ID,
                    ReadOnly   = true,
                    Unique     = true
                };

                table.Columns.Add(column);

                column = new DataColumn
                {
                    DataType   = System.Type.GetType("System.String"),
                    ColumnName = Constants.COLUMN_DATA
                };

                table.Columns.Add(column);

                DataColumn[] PrimaryKeyColumns = new DataColumn[1];
                PrimaryKeyColumns[0] = table.Columns[Constants.KEY_COLUMN];
                table.PrimaryKey     = PrimaryKeyColumns;

                if (NAVForm.GetSheetDataGridView() != null)
                {
                    PopulateParentTable();
                }

                return(table);

                void PopulateParentTable()
                {
                    int SheetDataGridViewColumnCount = NAVForm.GetSheetDataGridView().Columns.GetColumnCount(System.Windows.Forms.DataGridViewElementStates.Visible);

                    if (SheetDataGridViewColumnCount > 0)
                    {
                        foreach (System.Windows.Forms.DataGridViewRow row in NAVForm.GetSheetDataGridView().Rows)
                        {
                            if (row.IsNewRow)
                            {
                                break;
                            }

                            if (row.Cells[Constants.KEY_COLUMN].Value != null)
                            {
                                System.Text.StringBuilder ConcatenateRow = new System.Text.StringBuilder();

                                foreach (System.Windows.Forms.DataGridViewCell cell in row.Cells)
                                {
                                    if ((cell.OwningColumn.Visible == true) && (cell.OwningColumn.Name != Constants.KEY_COLUMN))
                                    {
                                        ConcatenateRow.Append(cell.Value + " ");
                                    }
                                }

                                string ConcatenateRowToString = ConcatenateRow.ToString().TrimEnd((char)32);

                                while (ConcatenateRowToString.Contains("  "))
                                {
                                    ConcatenateRowToString = ConcatenateRowToString.Replace("  ", " ");
                                }

                                DataRow tableRow = table.NewRow();
                                tableRow[Constants.COLUMN_ROW_ID] = row.Cells[Constants.KEY_COLUMN].Value;
                                tableRow[Constants.COLUMN_DATA]   = ConcatenateRowToString.TrimEnd();
                                table.Rows.Add(tableRow);
                            }
                        }

                        table.AcceptChanges();
                    }
                }
            }
        }
Пример #4
0
        internal static void AcceptDataGridViewChanges()
        {
            foreach (DataTable table in NAVForm.DataTableCollection)
            {
                table.AcceptChanges();
            }

            NAVForm.SetSheetCurrentTotal(value: string.Format(UserHelper.culture, Properties.Resources.NOTIFY_CURRENT_TOTAL, NAVForm.GetSheetDataGridView().RowCount - 1));
            NAVForm.SetSpreadsheetChanges(true);
            SetSheetDataGridViewFocus();
        }
Пример #5
0
 internal static void SetSheetDataGridViewFocus()
 {
     NAVForm.GetSheetDataGridView().CurrentCell = NAVForm.GetSheetDataGridView().FirstDisplayedCell;
     NAVForm.GetSheetDataGridView().Focus();
 }