예제 #1
0
        private void gridClasses_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            // Underlying row must have been edited
            TrophyDataSet.tblClassesRow r = ((e.Row.DataBoundItem as DataRowView).Row as TrophyDataSet.tblClassesRow);

            long count;

            using (TrophyDataSetTableAdapters.tblTrophiesTableAdapter adapter = new LDYC_Trophies.TrophyDataSetTableAdapters.tblTrophiesTableAdapter()) {
                count = (long)adapter.GetTrophyCountByClass(r.fldClassID);
                if (count > 0)
                {
                    MessageBox.Show(this,
                                    string.Format("'{0}' cannot be deleted as it's being used by {1} trophies.", r.fldName, count),
                                    Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                    return;
                }
            }

            using (TrophyDataSetTableAdapters.tblWinnersTableAdapter adapter = new LDYC_Trophies.TrophyDataSetTableAdapters.tblWinnersTableAdapter()) {
                count = (long)adapter.GetWinnerCountByClass(r.fldClassID);
                if (count > 0)
                {
                    MessageBox.Show(this,
                                    string.Format("'{0}' cannot be deleted as it's being used by {1} winners.", r.fldName, count),
                                    Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                    return;
                }
            }
        }
예제 #2
0
        private void gridClasses_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            // Underlying row must have been edited
              TrophyDataSet.tblClassesRow r = ((e.Row.DataBoundItem as DataRowView).Row as TrophyDataSet.tblClassesRow);

              long count;

              using (TrophyDataSetTableAdapters.tblTrophiesTableAdapter adapter = new LDYC_Trophies.TrophyDataSetTableAdapters.tblTrophiesTableAdapter()) {
            count = (long)adapter.GetTrophyCountByClass(r.fldClassID);
            if (count > 0) {
              MessageBox.Show(this,
            string.Format("'{0}' cannot be deleted as it's being used by {1} trophies.", r.fldName, count),
            Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
              e.Cancel = true;
              return;
            }
              }

              using (TrophyDataSetTableAdapters.tblWinnersTableAdapter adapter = new LDYC_Trophies.TrophyDataSetTableAdapters.tblWinnersTableAdapter()) {
            count = (long)adapter.GetWinnerCountByClass(r.fldClassID);
            if (count > 0) {
              MessageBox.Show(this,
            string.Format("'{0}' cannot be deleted as it's being used by {1} winners.", r.fldName, count),
            Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
              e.Cancel = true;
              return;
            }
              }
        }