using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using Demos.Warden.TagTextEditing; using Demos.Warden.TagTextEditing.SpecificTypeTagElements; namespace Demos.Warden.UserInterface.MainWindow.GeneratedStudyDocuments { public partial class TagElementSelectionWindowGender : Window, DialogHandling.IWindowModel { public bool IsSuccess { get; set; } public GenderInflictedTagElement[] InputValues { get; set; } public DialogHandling.WindowModelResult Result { get; set; } private GenderInflictedTagElement _selectedItem = null; public TagElementSelectionWindowGender() { InitializeComponent(); } public void Initialize() { this.addSelection(); } private void actions_Click(object sender, RoutedEventArgs args) { Button button = (Button)sender; switch(button.Name) { case "btn_infliction_add": this.inflictionActionInsert(); break; case "btn_infliction_update": this.inflictionActionUpdate(); break; case "btn_infliction_delete": this.inflictionActionDelete(); break; } } private void inflictionActionInsert() { if (this.txtbx_TagTitle.Text == "" || this.txtbx_MaleForm.Text == "" || this.txtbx_FemaleForm.Text == "") { MessageBox.Show("Nelze přidat prvek, protože nejsou vyplněny všechny potřebné hodnoty."); return; } GenderInflictedTagElement el = new GenderInflictedTagElement(); el.InitializeState(this.txtbx_TagTitle.Text, this.txtbx_MaleForm.Text, this.txtbx_FemaleForm.Text); this.lstvw_selection.Items.Add(new KeyValuePair(el.TagTitle, el)); } private void inflictionActionUpdate() { GenderInflictedTagElement selectedTag = getCurrentlySelectedTag(); if (selectedTag == null) { return; } if (this.txtbx_TagTitle.Text == "" || this.txtbx_MaleForm.Text == "" || this.txtbx_FemaleForm.Text == "") { MessageBox.Show("Nejsou vyplněny všechny potřebné hodnoty!"); return; } selectedTag.TagTitle = this.txtbx_TagTitle.Text; selectedTag.MaleForm = this.txtbx_MaleForm.Text; selectedTag.FemaleForm = this.txtbx_FemaleForm.Text; } private void inflictionActionDelete() { if (this.lstvw_selection.SelectedItem != null) { this.lstvw_selection.Items.Remove(this.lstvw_selection.SelectedItem); } } private void addSelection() { this.lstvw_selection.SelectionMode = SelectionMode.Single; List> items = new List>(); if (this.InputValues != null) { foreach (GenderInflictedTagElement tag in this.InputValues) { this.lstvw_selection.Items.Add(new KeyValuePair(tag.TagTitle, tag)); } } this.lstvw_selection.DisplayMemberPath = "Key"; } private void OnSelectionChanged(object sender, SelectionChangedEventArgs args) { if (args.AddedItems == null || args.AddedItems.Count == 0) { return; } KeyValuePair selectedItem = (KeyValuePair)args.AddedItems[0]; this._selectedItem = selectedItem.Value; this.txtbx_TagTitle.Text = this._selectedItem.TagTitle; this.txtbx_MaleForm.Text = this._selectedItem.MaleForm; this.txtbx_FemaleForm.Text = this._selectedItem.FemaleForm; } private void closingButtons_Click(object sender, RoutedEventArgs args) { Button btn = (Button)sender; switch (btn.Name) { case "btn_Cancel": this._selectedItem = null; this.Conclude(); break; case "btn_OK": this.Conclude(); break; } } private void Conclude() { this.trySaveCustomGenderTags(); if (this._selectedItem == null) { this.IsSuccess = false; this.Result = null; } else { DialogHandling.WindowModelResult res = new DialogHandling.WindowModelResult(); res.ReturnObject = new GenderInflictedTagElement[] { this._selectedItem }; this.IsSuccess = true; this.Result = res; } this.Close(); } private void trySaveCustomGenderTags() { try { List tags = new List(); foreach (object item in this.lstvw_selection.Items) { if (item is KeyValuePair && ((KeyValuePair)item).Value is GenderInflictedTagElement) { KeyValuePair curItem = (KeyValuePair)item; GenderInflictedTagElement genTag = (GenderInflictedTagElement)curItem.Value; tags.Add(genTag); } } FlowDocumentTagManager man = new FlowDocumentTagManager(); man.saveGenderInflectionTagData(tags.ToArray()); } catch(Exception ex) { MessageBox.Show("Proběhl neúspěšný pokus o uložení uživatelem nadefinovanch položek."); } } private GenderInflictedTagElement getCurrentlySelectedTag() { GenderInflictedTagElement tag = null; try { KeyValuePair selectedItem = (KeyValuePair)this.lstvw_selection.SelectedItem; tag = selectedItem.Value; } catch (Exception ex) { } return tag; } } }