private void menuItemDelSys_Click(object sender, EventArgs e = null) { string system; DataGridViewRow clickedRow; if (!menuItem_GetActionInfo(sender, out system, out clickedRow)) { return; } try { // just try to remove the system from any row of this country, thus move can be realised as del+add string country = clickedRow.Cells[colCountry.Name].Value.ToString().ToLower(); foreach (DataGridViewRow row in dgvRates.Rows) { if (row.Cells[colCountry.Name].Value.ToString().ToLower() != country || row.Cells[colValidFor.Name].Value == null) { continue; } bool calledFromMove = e == null; // if called from Move suppress storing undo action, to store it together with the following Add if (!dgvRates.SetCellValue(row, colValidFor.Name, ExchangeRate.RemoveFromValidFor(row.Cells[colValidFor.Name].Value.ToString(), system), !calledFromMove)) { ShowGridLastError(); } } } catch (Exception exception) { UserInfoHandler.ShowException(exception); } }
internal bool HasDifferences() // find out whether there are differences, if not the dialog does not need to be shown { // at the same time prepare dialog (for the case that there are differences) // remove all 'questionable systems' (systems for which exchange-rate differs) from ratesGlobal // and put them into the data-grid (for further treatment by the user) // also add exchange-rates from ratesCountry which do not (yet) exist in ratesGlobal to the data-grid foreach (ExchangeRate rateCountry in ratesCountry) { foreach (string system in rateCountry.ValidForToList()) { ExchangeRate matchingGlobal = null; foreach (ExchangeRate rateGlobal in ratesGlobal) { if (rateCountry.Country.ToLower() != rateGlobal.Country.ToLower()) { continue; } if (!rateGlobal.ValidForToList().Contains(system)) { continue; } matchingGlobal = rateGlobal; break; } if (matchingGlobal != null && matchingGlobal.DefaultRate() == rateCountry.DefaultRate()) { continue; // exchange-rate exists and is equal } if (matchingGlobal == null) // exchange-rate does not (yet) exist in global table { if (rateCountry.DefaultRate() == 1) { continue; // euro-country } int iRow = dgvDiff.Rows.Add(rateCountry.Country, system, rateCountry.DefaultRate(), "n/a", true, false, ExchangeRate.JUNE30, "Rate does not (yet) exist in global table."); DataGridViewCheckBoxCell check = dgvDiff.Rows[iRow].Cells[colTakeGlobal.Index] as DataGridViewCheckBoxCell; check.ReadOnly = true; check.Style.BackColor = Color.LightGray; } else // exchange-rate exists, but is different { string hint = string.Empty; if (matchingGlobal.June30 == rateCountry.DefaultRate()) { hint = ExchangeRate.JUNE30; } else if (matchingGlobal.YearAverage == rateCountry.DefaultRate()) { hint = ExchangeRate.YEARAVERAGE; } else if (matchingGlobal.FirstSemester == rateCountry.DefaultRate()) { hint = ExchangeRate.FIRSTSEMESTER; } else if (matchingGlobal.SecondSemester == rateCountry.DefaultRate()) { hint = ExchangeRate.SECONDSEMESTER; } if (hint != string.Empty) { hint = string.Format("Country exchange rate matches with global table '{0}': consider changing 'Rate Type'.", hint); } int iRow = dgvDiff.Rows.Add(matchingGlobal.Country, system, rateCountry.DefaultRate(), matchingGlobal.DefaultRate(), false, true, matchingGlobal.Default, hint); dgvDiff.Rows[iRow].Tag = matchingGlobal; matchingGlobal.RemoveFromValidFor(system); // remove the system (to add on OK in the way user choses) } } } return(dgvDiff.Rows.Count > 0); }