コード例 #1
0
        private void Delete_button(object sender, RoutedEventArgs e)
        {
            WarningWindow warning = new WarningWindow();

            warning.Owner = this;
            warning.Message_show(1);
            warning.object_content.Text = "";
            if (this.WindowState == WindowState.Normal)
            {
                warning.Width  = Width / 1.5;
                warning.Left   = Left + warning.Width / 4;
                warning.Height = Height / 2;
                warning.Top    = Top + warning.Height / 2;
            }
            this.Opacity = 0.5;
            BlurEffect blur;

            blur        = new BlurEffect();
            blur.Radius = 15;
            this.Effect = blur;
            warning.ShowDialog();
            this.Opacity = 1;
            this.Effect  = null;
        }
コード例 #2
0
        private void Save_library_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(name.Text))
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(2);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            if (name.Text.Length > 24)
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(3);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            if (name.Text.All(char.IsLetterOrDigit) == false)
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(4);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            if (libraryManager.Libraries.Select(x => x.Nom).Contains(name.Text) && (!edition || name.Name != name.Text))
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(5);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            if (textBoxes.Count == 0)
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(6);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            List <int> emptyTextBoxes = Enumerable.Range(0, textBoxes.Count).Where(i => String.IsNullOrEmpty(textBoxes[i].Text)).ToList();

            emptyTextBoxes = emptyTextBoxes.Select(x => { x += 1; return(x); }).ToList();
            if (emptyTextBoxes.Count > 0)
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(7);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.object_content.Text = "Ligne " + String.Join(", ", emptyTextBoxes);
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            List <String> attributeNames = textBoxes.Select(x => x.Text).ToList();

            if (attributeNames.Count != attributeNames.Distinct().Count())
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(8);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            foreach (String name in attributeNames)
            {
                if (name.All(char.IsLetterOrDigit) == false)
                {
                    WarningWindow warning = new WarningWindow();//start
                    warning.Owner = this;
                    warning.Message_show(9);
                    if (this.WindowState == WindowState.Normal)
                    {
                        warning.Width  = Width / 1.5;
                        warning.Left   = Left + warning.Width / 4;
                        warning.Height = Height / 2;
                        warning.Top    = Top + warning.Height / 2;
                    }
                    this.Opacity = 0.5;
                    BlurEffect blur;
                    blur        = new BlurEffect();
                    blur.Radius = 15;
                    this.Effect = blur;
                    warning.ShowDialog();
                    this.Opacity = 1;
                    this.Effect  = null;//end
                    return;
                }
            }
            if (!edition)
            {
                List <DataType> dataTypes = comboBoxes.Select(x => dataTypesNames[(String)x.SelectedItem]).ToList();
                Dictionary <String, DataType> attributeType = attributeNames.Zip(dataTypes, (k, v) => new { Key = k, Value = v }).ToDictionary(x => x.Key, x => x.Value);
                Library tempLibrary = new Library(name.Text, attributeNames, attributeType);
                libraryManager.AddLibrary(tempLibrary);
                tempLibrary.Save(LibraryManager.DefaultLibrariesPath);
            }
            else
            {
                for (int i = 0; i < textBoxes.Count; i++)
                {
                    if (String.IsNullOrEmpty(textBoxes[i].Name))
                    {
                        library.AddAttribute(textBoxes[i].Text, dataTypesNames[(String)comboBoxes[i].SelectedItem]);
                    }
                    else if (textBoxes[i].Name != textBoxes[i].Text)
                    {
                        library.RenameAttribute(textBoxes[i].Name, textBoxes[i].Text);
                    }
                }
                library.Save(LibraryManager.DefaultLibrariesPath);
            }

            this.Close();
            var mainWindow = (Application.Current.MainWindow as MainWindow);

            mainWindow.Content_Visibility();
            Owner.Focus();
        }
コード例 #3
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            List <Attribute> attributes = new List <Attribute>();

            foreach (TextBox textBox in textBoxes)
            {
                String value = textBox.Text;
                if (String.IsNullOrEmpty(value))
                {
                    WarningWindow warning = new WarningWindow();//start
                    warning.Owner = this;
                    warning.Message_show(10);
                    if (this.WindowState == WindowState.Normal)
                    {
                        warning.Width  = Width / 1.5;
                        warning.Left   = Left + warning.Width / 4;
                        warning.Height = Height / 2;
                        warning.Top    = Top + warning.Height / 2;
                    }
                    this.Opacity = 0.5;
                    BlurEffect blur;
                    blur        = new BlurEffect();
                    blur.Radius = 15;
                    this.Effect = blur;
                    warning.ShowDialog();
                    warning.object_content.Text = textBox.Name;
                    this.Opacity = 1;
                    this.Effect  = null;//end
                    return;
                }
                if (value.Length > 24)
                {
                    WarningWindow warning = new WarningWindow();//start
                    warning.Owner = this;
                    warning.Message_show(11);
                    if (this.WindowState == WindowState.Normal)
                    {
                        warning.Width  = Width / 1.5;
                        warning.Left   = Left + warning.Width / 4;
                        warning.Height = Height / 2;
                        warning.Top    = Top + warning.Height / 2;
                    }
                    this.Opacity = 0.5;
                    BlurEffect blur;
                    blur        = new BlurEffect();
                    blur.Radius = 15;
                    this.Effect = blur;
                    warning.ShowDialog();
                    warning.object_content.Text = textBox.Name;
                    this.Opacity = 1;
                    this.Effect  = null;//end
                    return;
                }
                switch (library.AttributeTypes[textBox.Name])
                {
                case DataType.STRING:
                    attributes.Add(new Attribute(value));
                    break;

                case DataType.INTEGER:
                    try {
                        attributes.Add(new Attribute(Int32.Parse(value)));
                    } catch (Exception) {
                        attributes.Add(null);
                    }
                    break;

                case DataType.BOOLEAN:
                    try {
                        attributes.Add(new Attribute(Boolean.Parse(value)));
                    } catch (Exception) {
                        attributes.Add(null);
                    }
                    break;

                case DataType.DATE:
                    try {
                        attributes.Add(new Attribute(DateTime.Parse(value)));
                    } catch (Exception) {
                        attributes.Add(null);
                    }
                    break;
                }
            }
            List <String> badTextBoxes = new List <String>();

            for (int i = 0; i < attributes.Count; i++)
            {
                if (attributes[i] == null)
                {
                    badTextBoxes.Add(textBoxes[i].Name);
                }
            }
            if (badTextBoxes.Count > 0)
            {
                WarningWindow warning = new WarningWindow();//start
                warning.Owner = this;
                warning.Message_show(12);
                if (this.WindowState == WindowState.Normal)
                {
                    warning.Width  = Width / 1.5;
                    warning.Left   = Left + warning.Width / 4;
                    warning.Height = Height / 2;
                    warning.Top    = Top + warning.Height / 2;
                }
                this.Opacity = 0.5;
                BlurEffect blur;
                blur        = new BlurEffect();
                blur.Radius = 15;
                this.Effect = blur;
                warning.ShowDialog();
                warning.object_content.Text = String.Join(", ", badTextBoxes);
                this.Opacity = 1;
                this.Effect  = null;//end
                return;
            }
            try {
                if (edition)
                {
                    if (item.ImagePath != imagePath)
                    {
                        library.ModifyItem(item, new Item(attributes, imagePath));
                    }
                    else
                    {
                        library.ModifyItem(item, new Item(attributes, item.ImagePath));
                    }
                }
                else
                {
                    if (imagePath != null)
                    {
                        library.AddItem(new Item(attributes, imagePath));
                    }
                    else
                    {
                        library.AddItem(new Item(attributes));
                    }
                }
            } catch (Exception) {
                String action = edition ? "édition" : "ajout";
                MessageBox.Show($"Une erreur s'est produite lors de l'{action} de l'objet.", "Erreur", MessageBoxButton.OK);
                return;
            }
            library.Save(LibraryManager.DefaultLibrariesPath);
            this.Close();
            Owner.Focus();
        }