private void tsbRun_Click(object sender, EventArgs e) { ClearResults(); var entity = (string)cbEntities.SelectedValue; if (!string.IsNullOrEmpty(entity)) { // make sure checkbox is saved dgvFields.CurrentCell = null; var matchAttributes = dgvFields.Rows.Cast <DataGridViewRow>() .Where(r => (bool)(r.Cells["colMatch"] as DataGridViewCheckBoxCell).Value) .Select(r => r.Cells["colLogicalName"].Value.ToString()); var viewAttritues = dgvFields.Rows.Cast <DataGridViewRow>() .Where(r => (bool)(r.Cells["colView"] as DataGridViewCheckBoxCell).Value) .Select(r => r.Cells["colLogicalName"].Value.ToString()); // check at least one column is cheked to match, and view if (matchAttributes.Count() == 0 || viewAttritues.Count() == 0) { MessageBox.Show("Please select at least one field to match and view", "Select Fields", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // add duplicated view columns AddViewColumns(dgvDuplicated, matchAttributes); dgvDuplicated.Columns.Add("count", "Duplicates Count"); dgvDuplicated.Columns["count"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dgvDuplicated.Columns.Add("key", "Key"); dgvDuplicated.Columns["key"].Visible = false; // add duplicates view columns AddViewColumns(dgvDuplicates, viewAttritues); dgvDuplicates.Columns.Add(new DataGridViewLinkColumn() { Name = "url", HeaderText = "Record URL", Text = "Link", UseColumnTextForLinkValue = true }); dgvDuplicates.Columns.Add("hiddenurl", "hiddenurl"); dgvDuplicates.Columns["hiddenurl"].Visible = false; var config = new DuplicationConfiguration(entity, _attributes, matchAttributes, viewAttritues); config.IsCaseSensitive = chkCaseSensitive.Checked; config.ShouldIgnoreWhiteSpace = chkIgnoreWhiteSpace.Checked; config.ShouldIgnoreBlank = chkIgnoreBlank.Checked; ExecuteMethod(LoadData, config); } }
private void LoadData(DuplicationConfiguration config) { _dataProcessor = new DataProcessor(config); WorkAsync(new WorkAsyncInfo { Message = string.Format($"Loading data..."), Work = (worker, args) => { args.Result = _dataProcessor.GetDuplicationGroups(Service); }, PostWorkCallBack = (args) => { if (args.Error != null) { MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var result = args.Result as IEnumerable <DuplicatedDataModel>; if (result != null) { if (!result.Any()) { gbDuplicated.Text = string.Format($"Duplicated Groups"); MessageBox.Show("No duplicates found.", "Process completed", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { gbDuplicated.Text = string.Format($"Duplicated Groups ({result.Count()})"); foreach (var item in result) { var rowIndex = dgvDuplicated.Rows.Add(); var row = dgvDuplicated.Rows[rowIndex]; foreach (var attr in config.MatchAttributes) { row.Cells[attr].Value = item.DuplicatedData[attr]; } row.Cells["count"].Value = item.DuplicatesCount; row.Cells["key"].Value = item.MatchingKey; } dgvDuplicated.ClearSelection(); } dgvDuplicates.Rows.Clear(); dgvDuplicates.Refresh(); } } }); }
public DataProcessor(DuplicationConfiguration config) { Config = config; _selectAttributes = Config.MatchAttributes.Concat(Config.ViewAttributes).Distinct(); }