//Edit. private void btnOK_Click(object sender, RoutedEventArgs e) { if (pswdNew.Password != pswdConfirm.Password) { MessageBox.Show("Passwords do not match! Try again.", "Wrong", MessageBoxButton.OK, MessageBoxImage.Error); return; } _proxy.EditData(id, pswdNew.Password, EngServRef.ServerData.User, EngServRef.PropertyData.Password); Close(); }
//Change. private void btnOK_Click(object sender, RoutedEventArgs e) { Task.Run(new Action(() => { Dispatcher.Invoke(new Action(() => { string file = $"{id}{Path.GetExtension(lPath.Content.ToString())}"; if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), file, EngServRef.FilesType.Avatars)) { MessageBox.Show($"The file is too large!", "Choose another file", MessageBoxButton.OK, MessageBoxImage.Error); return; } FormData.EditUsers.Add(id); _proxy.EditData(id, file, EngServRef.ServerData.User, EngServRef.PropertyData.Imgpath); Close(); })); })); }
//Add a new word. private void btnOK_Click(object sender, RoutedEventArgs e) { int edit = 0; if (txtName.Text == "" || txtBritish.Text == "" || txtCanadian.Text == "" || txtAmerican.Text == "" || txtAustralian.Text == "") { MessageBox.Show("You should fill all fiels marked with '*'!", "Empty strings are not allowed", MessageBoxButton.OK, MessageBoxImage.Stop); return; } bool catChecked = false; foreach (CheckBox item in lstCategory.Items) { if (item.IsChecked == true) { catChecked = true; break; } } if (!catChecked) { MessageBox.Show("You should choose category.", "Choose category", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Task.Run(new Action(() => { Dispatcher.Invoke(new Action(() => { if (!editForm) { int?id = _proxy.AddWord(txtName.Text, null, user); if (id == null) { MessageBox.Show("Something went wrong.", "Operation denied", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } edit = Convert.ToInt32(id); if (lPath.Content.ToString() != "...") { if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.FilesType.WordsImages)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); _proxy.RemoveItem(edit, EngServRef.ServerData.Word); return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.ServerData.Word, EngServRef.PropertyData.Imgpath); } string past = null, plural = null, pastTh = null; if (stPast.Visibility == Visibility.Visible) { past = txtPast.Text == "" ? null : txtPast.Text; } if (stPastParticiple.Visibility == Visibility.Visible) { pastTh = txtPastTh.Text == "" ? null : txtPastTh.Text; } if (stPlural.Visibility == Visibility.Visible) { plural = txtPlural.Text == "" ? null : txtPlural.Text; } _proxy.AddWordsForm(edit, past, plural, pastTh); _proxy.AddWordsTranscription(edit, txtBritish.Text, txtCanadian.Text, txtAmerican.Text, txtAustralian.Text); if (item != null) { _proxy.AddItemsWord(edit, Convert.ToInt32(item), data); } } else { _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Translation); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Definition); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.WordCategory); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Group); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Example); _proxy.EditData(wordsId, txtName.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.Name); if (lPath.Content.ToString() != "...") { FormData.EditWords.Add(wordsId); string file = $"{wordsId}{Path.GetExtension(lPath.Content.ToString())}"; if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), file, EngServRef.FilesType.WordsImages)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); return; } _proxy.EditData(wordsId, file, EngServRef.ServerData.Word, EngServRef.PropertyData.Imgpath); } _proxy.EditData(wordsId, txtPast.Text == ""? null: txtPast.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.PastForm); _proxy.EditData(wordsId, txtPlural.Text == "" ? null : txtPlural.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.PluralForm); _proxy.EditData(wordsId, txtPastTh.Text == "" ? null : txtPastTh.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.PastThForm); _proxy.EditData(wordsId, txtBritish.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.British); _proxy.EditData(wordsId, txtCanadian.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.Canadian); _proxy.EditData(wordsId, txtAmerican.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.American); _proxy.EditData(wordsId, txtAustralian.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.Australian); edit = wordsId; } foreach (CheckBox item in lstCategory.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.WordCategory); } } foreach (CheckBox item in lstDefinitions?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Definition); } } foreach (CheckBox item in lstTranslations?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Translation); } } foreach (CheckBox item in lstGroups?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Group); } } foreach (CheckBox item in lstExamples?.Items) { if (item.IsChecked == true) { int itemsId = Convert.ToInt32(item.Tag); if (editForm && !_proxy.CheckExistence(item.Content.ToString(), EngServRef.ServerData.Example)) { itemsId = Convert.ToInt32(_proxy.AddData(item.Content.ToString(), EngServRef.ServerData.Example)); } _proxy.AddItemDataAsync(edit, itemsId, EngServRef.ServerData.Example); } } Close(); })); })); }
//Change. private void btnOK_Click(object sender, RoutedEventArgs e) { _proxy.EditData(id, txtName.Text, EngServRef.ServerData.User, EngServRef.PropertyData.Name); Close(); }
//Add a new video. private void btnOK_Click(object sender, RoutedEventArgs e) { int?year = null; if (txtYear.Text != "") { year = Convert.ToInt32(txtYear.Text); } int edit = 0; if (txtPath.Text == "") { MessageBox.Show("Choose file!", "No file chosen", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Task.Run(new Action(() => { Dispatcher.Invoke(new Action(() => { stMain.Visibility = Visibility.Collapsed; if (video == null) { int?id = _proxy.AddVideo(txtName.Text, txtDesc.Text == "" ? null : txtDesc.Text, txtPath.Text, txtSubs.Text, "WolfV.png", chCopy.IsChecked == true ? false : true, mark, user, year, DateTime.Now); if (id == null) { MessageBox.Show("Something went wrong.", "Operation denied", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } edit = Convert.ToInt32(id); if (lPath.Content.ToString() != "...") { if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.FilesType.VideosImages)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); _proxy.RemoveItem(edit, EngServRef.ServerData.Video); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.ServerData.Video, EngServRef.PropertyData.Imgpath); } if (chCopy.IsChecked == true) { try { if (!_proxy.Upload(File.ReadAllBytes(txtPath.Text), $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.FilesType.Videos)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); _proxy.RemoveItem(edit, EngServRef.ServerData.Video); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.Path); } catch (OutOfMemoryException) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); _proxy = new EngServRef.EngServiceClient(); _proxy.RemoveItem(edit, EngServRef.ServerData.Video); stMain.Visibility = Visibility.Visible; return; } } if (txtSubs.Text != "") { if (!_proxy.Upload(File.ReadAllBytes(txtSubs.Text), $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.FilesType.Subtitles)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); _proxy.RemoveItem(edit, EngServRef.ServerData.Video); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.SubPath); } } else { edit = Convert.ToInt32(video); string path = _proxy.GetItemProperty(Convert.ToInt32(video), EngServRef.ServerData.Video, EngServRef.PropertyData.Path); if (txtPath.Text != path && chCopy.IsChecked == true) { if (!_proxy.Upload(File.ReadAllBytes(txtPath.Text), $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.FilesType.Videos)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.Path); } else if (txtPath.Text == path && txtPath.Text.Contains(":") && chCopy.IsChecked == true) { if (!File.Exists(txtPath.Text)) { MessageBox.Show("This file does not exist!", "Wrong", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } if (!_proxy.Upload(File.ReadAllBytes(txtPath.Text), $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.FilesType.Videos)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.Path); } else if (chCopy.IsChecked == false) { _proxy.EditData(edit, txtPath.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Path); } string subs = _proxy.GetItemProperty(Convert.ToInt32(video), EngServRef.ServerData.Video, EngServRef.PropertyData.SubPath); if (txtSubs.Text != subs) { if (!File.Exists(txtSubs.Text)) { MessageBox.Show("This file does not exist!", "Wrong", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } if (!_proxy.Upload(File.ReadAllBytes(txtSubs.Text), $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.FilesType.Subtitles)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.SubPath); } if (lPath.Content.ToString() != "...") { FormData.EditVideos.Add(edit); string file = $"{edit}{Path.GetExtension(lPath.Content.ToString())}"; if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), file, EngServRef.FilesType.VideosImages)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } _proxy.EditData(edit, file, EngServRef.ServerData.Video, EngServRef.PropertyData.Imgpath); } _proxy.EditData(edit, chCopy.IsChecked != true ? "True" : null, EngServRef.ServerData.Video, EngServRef.PropertyData.IsAbsolute); _proxy.EditData(edit, txtYear.Text == "" ? null : txtYear.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Year); _proxy.RemoveFullItemData(edit, EngServRef.ServerData.VideoCategory); _proxy.EditData(edit, txtName.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Name); _proxy.EditData(edit, txtDesc.Text == "" ? null : txtDesc.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Description); } foreach (CheckBox item in lstCategory.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.VideoCategory); } } Close(); })); })); }
//Add a new grammar. private void btnOK_Click(object sender, RoutedEventArgs e) { int edit = 0; if (txtName.Text == "") { MessageBox.Show("You should fill all fiels marked with '*'!", "Empty strings are not allowed", MessageBoxButton.OK, MessageBoxImage.Stop); return; } bool ruleChecked = false; foreach (CheckBox item in lstRules.Items) { if (item.IsChecked == true) { ruleChecked = true; break; } } if (!ruleChecked) { MessageBox.Show("You should add rules.", "Choose rule", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Task.Run(new Action(() => { Dispatcher.Invoke(new Action(() => { if (grammarId == null) { int?id = _proxy.AddGrammar(txtName.Text, txtDescription.Text == "" ? null : txtDescription.Text); if (id == null) { MessageBox.Show("Something went wrong.", "Operation denied", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } edit = Convert.ToInt32(id); } else { _proxy.RemoveFullItemData(Convert.ToInt32(grammarId), EngServRef.ServerData.Rule); _proxy.RemoveFullItemData(Convert.ToInt32(grammarId), EngServRef.ServerData.GrammarExample); _proxy.RemoveFullItemData(Convert.ToInt32(grammarId), EngServRef.ServerData.GrammarException); _proxy.EditData(Convert.ToInt32(grammarId), txtName.Text, EngServRef.ServerData.Grammar, EngServRef.PropertyData.Name); _proxy.EditData(Convert.ToInt32(grammarId), txtDescription.Text == "" ? null : txtDescription.Text, EngServRef.ServerData.Grammar, EngServRef.PropertyData.Description); edit = Convert.ToInt32(grammarId); } foreach (CheckBox item in lstRules?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Rule); } } foreach (CheckBox item in lstExceptions?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.GrammarException); } } foreach (CheckBox item in lstExamples?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.GrammarExample); } } Close(); })); })); }