void btnControl_Click(object sender, EventArgs e) { actionInProgress = true; string actionName = ((Button)sender).Text; if (ClientConfiguration.Actions.Find(a => a.ActionName == actionName) != null) { AbstractEasyAction aea = ClientConfiguration.Actions.Find(a => a.ActionName == actionName).CreateAction(); List <DataRow> dataRows = new List <DataRow>(); foreach (DataGridViewRow dgvRow in dataGrid.SelectedRows) { if (dgvRow.DataBoundItem != null) { dataRows.Add(((DataRowView)dgvRow.DataBoundItem).Row); } } if (dataRows.Count == 0) { if (dataGrid.SelectedCells.Count > 0) { List <int> lstRowIndex = new List <int>(); foreach (DataGridViewCell cell in dataGrid.SelectedCells) { if (!lstRowIndex.Contains(cell.RowIndex)) { lstRowIndex.Add(cell.RowIndex); } } foreach (int rowIndex in lstRowIndex) { if (dataGrid.Rows[rowIndex].DataBoundItem != null) { dataRows.Add(((DataRowView)dataGrid.Rows[rowIndex].DataBoundItem).Row); } } } } pbProgress.Maximum = dataRows.Count; aea.OnProgress += aea_OnProgress; pbProgress.Visible = true; lblProgress.Visible = true; aea.Execute(dataRows.ToArray()); lblProgress.Visible = false; pbProgress.Visible = false; } actionInProgress = false; EnableActionButtonsAsNeeded(); }
private void EnableActionButtonsAsNeeded(DataRow dataRow = null) { if (actionInProgress) { return; } List <DataRow> dataRows = null; foreach (Control c in fpActions.Controls) { if (c is Button b) { fpActions.Visible = true; b.Enabled = false; if ((b.Visible) && (ClientConfiguration.Actions.Find(a => a.ActionName == b.Text) != null)) { if (dataRows == null) { dataRows = new List <DataRow>(); if (dataRow == null) { foreach (DataGridViewRow dRow in dataGrid.SelectedRows) { if (dRow.DataBoundItem != null) { dataRows.Add(((DataRowView)dRow.DataBoundItem).Row); } } if (dataRows.Count == 0) { if (dataGrid.SelectedCells.Count > 0) { List <int> lstRowIndex = new List <int>(); foreach (DataGridViewCell cell in dataGrid.SelectedCells) { if (!lstRowIndex.Contains(cell.RowIndex)) { lstRowIndex.Add(cell.RowIndex); } } foreach (int rowIndex in lstRowIndex) { if (dataGrid.Rows[rowIndex].DataBoundItem != null) { dataRows.Add(((DataRowView)dataGrid.Rows[rowIndex].DataBoundItem).Row); } } } } } else { dataRows.Add(dataRow); } } AbstractEasyAction ea = ClientConfiguration.Actions.Where(a => a.ActionName == b.Text).First().CreateAction(); //(AbstractEasyAction)Activator.CreateInstance(dctActionClassMapping[b.Text].Class); //foreach (KeyValuePair<string, string> kvPair in dctActionFieldSettings[b.Text]) //{ // ea.SettingsDictionary.Add(kvPair.Key, kvPair.Value); //} b.Enabled = ea.CanExecute(dataRows.ToArray()); } } } }