//подгрузка требуемых данных private async void LoadData() { var queryCategory = await (from c in context.Categories where c.CategoryName == prevCategory select c).FirstOrDefaultAsync(); currentCategory = queryCategory; //проверка на режим доступа if (currentCategory.EnableModeRequired) checkBoxEnableMode.CheckState = CheckState.Checked; else checkBoxEnableMode.CheckState = CheckState.Unchecked; //проверка на анонимный вход if (currentCategory.AnonymousLogin) checkBoxAnonymLogin.Checked = true; else checkBoxAnonymLogin.Checked = false; }
//вставка данных по умолчанию private void FirstInsert() { using (RconfigContext context = new RconfigContext()) { //проверяем данные в БД //если данных нет инициализируем их if (context.Protocols.Count<Protocol>() == 0) { //PROTOCOLS context.Protocols.Add(new Protocol { Name = "SSH", DefaultPort = 22 }); context.Protocols.Add(new Protocol { Name = "Telnet", DefaultPort = 23 }); //CATEGORIES Category routers = new Category { CategoryName = "Routers" }; Category switches = new Category { CategoryName = "Switches" }; Category servers = new Category { CategoryName = "Servers" }; context.Categories.Add(routers); context.Categories.Add(switches); context.Categories.Add(servers); //COMMANDS ICollection<Category> cisco = new HashSet<Category>(); cisco.Add(routers); cisco.Add(switches); context.Commands.Add(new Command { Name = "terminal length 0", Order = 0, Categories = cisco }); context.Commands.Add(new Command { Name = "show running-config", Order = 1, Categories = cisco }); ICollection<Category> vlan = new HashSet<Category>(); vlan.Add(switches); context.Commands.Add(new Command { Name = "show ip vlan brief", Order = 2, Categories = vlan }); //CREDENTIALS context.Credentials.Add(new Credential { CredentialName = "Default", Username = "******", Domain = "domain.com", Password = "******" }); //LOCATIONS context.Locations.Add(new Location { LocationName = "Syslocation" }); context.SaveChanges(); } } }
//подтверждение операции private void buttonOK_Click(object sender, EventArgs e) { if (CheckData()) { switch (mode) { case WindowsMode.ADD: currentCategory = new Category(); currentCategory.CategoryName = textBoxCategory.Text.Trim(); currentCategory.EnableModeRequired = checkBoxEnableMode.Checked; currentCategory.AnonymousLogin = checkBoxAnonymLogin.Checked; //if (checkBoxEnableMode.CheckState == CheckState.Checked) //{ // currentCategory.EnableModeRequired = true; //} //else //{ // currentCategory.EnableModeRequired = false; //} context.Categories.Add(currentCategory); context.SaveChanges(); break; case WindowsMode.EDIT: currentCategory.CategoryName = textBoxCategory.Text.Trim(); currentCategory.EnableModeRequired = checkBoxEnableMode.Checked; currentCategory.AnonymousLogin = checkBoxAnonymLogin.Checked; //if (checkBoxEnableMode.CheckState == CheckState.Checked) //{ // currentCategory.EnableModeRequired = true; //} //else //{ // currentCategory.EnableModeRequired = false; //} context.Entry(currentCategory).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); break; } this.DialogResult = DialogResult.OK; } else { switch (validateInput) { case CategoryInputValidate.CategoryEmpty: NotifyWarning("Category Name is empty!"); break; case CategoryInputValidate.CategoryNotUnique: NotifyWarning("Category Name is already exist!"); break; } } }