void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvSwitchablePolicies.SelectedRows.Count != 1)
            {
                return;
            }

            try
            {
                //deleting an existing switchable policy may need to require an update of country files (which is too complex here)
                //example: delete bun*_??: all switches defined for the matching policies of the country would have to be changed from 'switch' to 'toggle'
                //removal in the country files however only takes place on closing the SetPolicySwitchesForm with 'OK' - thus this warning
                VarConfig.SwitchablePolicyRow switchablePolicyRow = (dgvSwitchablePolicies.SelectedRows[0].Tag as VarConfig.SwitchablePolicyRow);
                if (switchablePolicyRow.RowState != DataRowState.Added && UserInfoHandler.GetInfo(_noUpdateInCountriesWarning, MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }

                switchablePolicyRow.Delete();
                dgvSwitchablePolicies.Rows.Remove(dgvSwitchablePolicies.SelectedRows[0]);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }

            dgvSwitchablePolicies.Update(); //if gridview is not updated it looks weired (text of two rows are displayed in one)
        }
        void dgvSwitchablePolicies_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0 || dgvSwitchablePolicies.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
            {
                return;
            }

            try
            {
                string newValue = dgvSwitchablePolicies.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                VarConfig.SwitchablePolicyRow switchablePolicy = dgvSwitchablePolicies.Rows[e.RowIndex].Tag as VarConfig.SwitchablePolicyRow;

                //changing the name pattern (e.g. yem_??) of an existing switchable policy may need to require an update of country files (which is too complex here)
                //example: change yem_?? to yem*_??: the switches already set for this country would apply to more policies (the long name is not visible, therefore no problem changing it)
                //updating in the country files however only takes place on closing the SetPolicySwitchesForm with 'OK' - thus this warning
                if (e.ColumnIndex == colNamePattern.Index &&
                    switchablePolicy.RowState != DataRowState.Added &&
                    newValue != switchablePolicy.NamePattern &&
                    UserInfoHandler.GetInfo(_noUpdateInCountriesWarning, MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
                {
                    dgvSwitchablePolicies.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = switchablePolicy.NamePattern;
                    return;
                }

                if (e.ColumnIndex == colLongName.Index)
                {
                    switchablePolicy.LongName = newValue;
                }
                else if (e.ColumnIndex == colNamePattern.Index)
                {
                    switchablePolicy.NamePattern = newValue;
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
コード例 #3
0
 internal static VarConfig.SwitchablePolicyRow CopySwitchPolicyFromAnotherConfig(VarConfig varConfig, VarConfig.SwitchablePolicyRow originalSP)
 {
     return(varConfig.SwitchablePolicy.AddSwitchablePolicyRow(originalSP.ID, originalSP.NamePattern, originalSP.LongName));
 }