コード例 #1
0
        private void btnPeriodDelete_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection dr = gvPeriodSetting.SelectedRows;
            List <string> modifyAlertRule        = new List <string>();
            DialogResult  result =
                MessageBox.Show(
                    "Confirm delete this record?",
                    "Confirm",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                for (int i = 0; i < dr.Count; i++)
                {
                    string periodName = dr[i]
                                        .Cells[AttributeHelper.GetColumnIndex <ConfigModel.PeriodRule>("PeriodName")].Value.ToString();
                    _config.Alert.Where(x =>
                                        x.PeriodName.Contains(periodName) || x.EnablePeriodName.Contains(periodName))
                    .ToList()
                    .ForEach(x =>
                    {
                        x.EnablePeriodName = x.EnablePeriodName.Where(w => w != periodName).ToArray();
                        x.PeriodName       = x.PeriodName.Where(w => w != periodName).ToArray();
                        ConfigUtil.InsertUpdateAlertRule(x);
                        modifyAlertRule.Add(x.alertName);
                    });

                    ConfigUtil.DeletePeriodRuleByName(periodName);
                }
            }

            RefreshConfig();
            BindPeriodGridView();
            gvPeriodSetting.Update();
            gvPeriodSetting.Refresh();
            if (modifyAlertRule.Count > 0)
            {
                MessageBox.Show("Below alert rule has been modified:\n" + string.Join(",", modifyAlertRule));
                initAlertRuleDataView();
                gvAlertRule.Update();
                gvAlertRule.Refresh();
            }
        }