private void buttonStatus_Click(object sender, EventArgs e) { if (GridRules.SelectedRows.Count == 1) { rulesContext.frules.Item.Find(x => x.Id == (int)GridRules.CurrentRow.Cells["Id"].Value).Status = !rulesContext.frules.Item.Find(x => x.Id == (int)GridRules.CurrentRow.Cells["Id"].Value).Status; rulesContext.EditRule(); GridRefresh(); } else { MessageBox.Show( "Не выбрано правило для включения/отключения!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } }
private void buttonSave_Click(object sender, EventArgs e) { try { RuleItem rule; if (!Directory.Exists(textBoxDs.Text)) { throw new Exception("Указана неверная папка поиска!"); } if (!Directory.Exists(textBoxDd.Text)) { throw new Exception("Указана неверная поиска назначения!"); } if (textBoxMask.TextLength > textBoxMask.MaxLength || textBoxMask.TextLength == 0 || !Regex.Match(textBoxMask.Text, @"^[a-zA-Zа-яА-Я0-9\*\?\.\\_\-]*$").Success) { throw new Exception("Указана неверная маска поиска!"); } if (textBoxDs.Text.EndsWith(@"\")) { textBoxDs.Text = textBoxDs.Text.Remove(textBoxDs.Text.Length - 1); } if (textBoxDd.Text.EndsWith(@"\")) { textBoxDd.Text = textBoxDd.Text.Remove(textBoxDd.Text.Length - 1); } switch (cv) { case ControlRules.value.add: rule = new RuleItem() { Id = rulesContext.frules.Item.Count > 0 ? rulesContext.frules.Item.Max(f => f.Id) + 1 : 1, Status = checkBoxEnable.Checked, DirStart = textBoxDs.Text, DirDest = textBoxDd.Text, Operation = (op)Enum.Parse(typeof(op), comboBoxOp.SelectedValue.ToString()), IfExist = (ifEx)Enum.Parse(typeof(ifEx), comboBoxIf.SelectedValue.ToString()), FileMask = textBoxMask.Text }; rulesContext.frules.Item.Add(rule); rulesContext.EditRule(); break; case ControlRules.value.edit: rule = rulesContext.frules.Item.Find(x => x.Id == Id); rule.Status = checkBoxEnable.Checked; rule.DirStart = textBoxDs.Text; rule.DirDest = textBoxDd.Text; rule.Operation = (op)Enum.Parse(typeof(op), comboBoxOp.SelectedValue.ToString()); rule.IfExist = (ifEx)Enum.Parse(typeof(ifEx), comboBoxIf.SelectedValue.ToString()); rule.FileMask = textBoxMask.Text; rulesContext.EditRule(); break; } } catch (Exception ex) { MessageBox.Show( "Ошибка сохранения:\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } MessageBox.Show("Правило успешно сохранено!"); this.Close(); }