private void ButtonAddProfile_Click(object sender, RoutedEventArgs e) { try { var form = new AddProfileWpf(); form.ShowDialog(); if (!form.DialogResult.HasValue || !form.DialogResult.Value) { return; } Context.Profile.Add(form.NewProfile); Context.SaveChanges(); ComboBoxProfiles.Items.Add(form.NewProfile); var newProfileNode = (XmlElement)XmlSettingsDocument.DocumentElement?.SelectNodes("Profile")?.Item(0)?.Clone(); if (newProfileNode == null) { return; } newProfileNode.SetAttribute("Name", form.NewProfile.ProfileName); XmlSettingsDocument.DocumentElement.InsertAfter(newProfileNode, XmlSettingsDocument.DocumentElement.LastChild); XmlSettingsDocument.Save("settings.xml"); } catch (Exception ex) { System.Windows.MessageBox.Show($"Ошибка во время созданя профиля!\r\n{ex.Message}", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public void XmlSettingsWrite(string profileName) { try { var root = XmlSettingsDocument.DocumentElement; var profileNode = root?.SelectSingleNode($"Profile[@Name='{profileName}']"); if (profileNode == null) { return; } var isAddNode = profileNode.SelectSingleNode("Add/IsAct"); if (isAddNode != null) { isAddNode.InnerText = CheckBoxIsLetAdd.IsChecked.ToString(); } var addCountNode = profileNode.SelectSingleNode("Add/Count"); if (addCountNode != null) { addCountNode.InnerText = TextBoxAddLimitCount.Text; } var isLikeNode = profileNode.SelectSingleNode("Like/IsAct"); if (isLikeNode != null) { isLikeNode.InnerText = CheckBoxIsLetLike.IsChecked.ToString(); } var likeCountNode = profileNode.SelectSingleNode("Like/Count"); if (likeCountNode != null) { likeCountNode.InnerText = TextBoxLikeLimitCount.Text; } var isWriteNode = profileNode.SelectSingleNode("Write/IsAct"); if (isWriteNode != null) { isWriteNode.InnerText = CheckBoxIsLetWrite.IsChecked.ToString(); } var writeCountNode = profileNode.SelectSingleNode("Write/Count"); if (writeCountNode != null) { writeCountNode.InnerText = TextBoxWriteLimitCount.Text; } var isLetPostNode = profileNode.SelectSingleNode("IsLetPost"); if (isLetPostNode != null) { isLetPostNode.InnerText = CheckBoxIsLetPost.IsChecked.ToString(); } var isSortByRegDateNode = profileNode.SelectSingleNode("IsSortByRegdate"); if (isSortByRegDateNode != null) { isSortByRegDateNode.InnerText = CheckBoxIsSortByRegdate.IsChecked.ToString(); } var isOnlyActionNode = profileNode.SelectSingleNode("IsOnlyAction"); if (isOnlyActionNode != null) { isOnlyActionNode.InnerText = CheckBoxIsOnlyAction.IsChecked.ToString(); } var isFilterNode = profileNode.SelectSingleNode("IsFilter"); if (isFilterNode != null) { isFilterNode.InnerText = CheckBoxIsFilter.IsChecked.ToString(); } var isAntiCaptchaNode = profileNode.SelectSingleNode("IsAntiCaptcha"); if (isAntiCaptchaNode != null) { isAntiCaptchaNode.InnerText = CheckBoxIsAntiCaptcha.IsChecked.ToString(); } var isCheckFriendsNode = profileNode.SelectSingleNode("IsCheckFriends"); if (isCheckFriendsNode != null) { isCheckFriendsNode.InnerText = CheckBoxIsCheckFriends.IsChecked.ToString(); } var isUpdateDataNode = profileNode.SelectSingleNode("IsUpdateData"); if (isUpdateDataNode != null) { isUpdateDataNode.InnerText = CheckBoxIsUpdateData.IsChecked.ToString(); } XmlSettingsDocument.Save("settings.xml"); } catch (Exception ex) { Logger.ErrorLog(ex); } }