Ejemplo n.º 1
0
        private void Btn_Insert_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (TextBox_Name.Text == "" || TextBox_Address.Text == "" || TextBox_Email.Text == "")
                {
                    if (TextBox_Name.Text == "")
                    {
                        MessageBox.Show("Name is required", "Warning", MessageBoxButton.OK);
                        TextBox_Name.Focus();
                    }
                    else if (TextBox_Address.Text == "")
                    {
                        MessageBox.Show("Address is required", "Warning", MessageBoxButton.OK);
                        TextBox_Address.Focus();
                    }
                    else if (TextBox_Email.Text == "")
                    {
                        MessageBox.Show("Email is required", "Warning", MessageBoxButton.OK);
                        TextBox_Email.Focus();
                    }
                }


                else
                {
                    var check_email = connection.Suppliers.FirstOrDefault(S => S.Email == TextBox_Email.Text);
                    if (check_email == null)
                    {
                        MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are You Sure?", "Insert Confirmation", System.Windows.MessageBoxButton.YesNo);

                        if (messageBoxResult == MessageBoxResult.Yes)
                        {
                            var input_supplier = new Supplier(TextBox_Name.Text, TextBox_Address.Text, TextBox_Email.Text);


                            connection.Suppliers.Add(input_supplier);
                            var insert = connection.SaveChanges();
                            if (insert >= 1)
                            {
                                MessageBox.Show(insert + " Supplier has been inserted");
                            }

                            TB_M_Supplier.ItemsSource = connection.Suppliers.ToList();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Email has been used");
                    }
                }
            }

            catch (Exception)
            {
            }

            reset_supplier();
            Combo_Supplier.ItemsSource = connection.Suppliers.ToList();
        }
Ejemplo n.º 2
0
        private void ItemInfoUpdate(EditMode mode)
        {
            bool addItem = false;
            bool isNull  = false;

            switch (mode)
            {
            case EditMode.EditTab:
                TabItemModel tab = (TabItemModel)this.ListBox_Tab.SelectedItem;
                if (tab != null)
                {
                    this.TextBox_Command.Text       = null;
                    this.TextBox_Command.Visibility = Visibility.Hidden;
                    this.TextBox_Name.Text          = tab.Data.Name;
                    this.TextBox_Description.Text   = tab.Data.Description;
                }
                else
                {
                    isNull = true;
                }
                break;

            case EditMode.EditString:
                StrItemModel str = (StrItemModel)this.ListBox_Str.SelectedItem;
                if (str != null)
                {
                    this.TextBox_Command.Text       = str.Data.Text;
                    this.TextBox_Command.Visibility = Visibility.Visible;
                    this.TextBox_Name.Text          = str.Data.Name;
                    this.TextBox_Description.Text   = str.Data.Description;
                }
                else
                {
                    isNull = true;
                }
                break;

            case EditMode.AddTab:
                addItem = true;

                this.TextBox_Command.Text       = "";
                this.TextBox_Command.Visibility = Visibility.Hidden;
                this.TextBox_Name.Text          = "New Tab";
                this.TextBox_Description.Text   = "無";
                break;

            case EditMode.AddString:
                addItem = true;
                this.TextBox_Command.Text       = "";
                this.TextBox_Command.Visibility = Visibility.Visible;
                this.TextBox_Name.Text          = "New String";
                this.TextBox_Description.Text   = "無";
                break;
            }
            if (addItem)
            {
                TextBox_Name.Focus();
                EditApplyIcon.Kind  = MaterialDesignThemes.Wpf.PackIconKind.AddThick;
                EditCancelIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.CloseThick;
            }
            else
            {
                EditApplyIcon.Kind  = MaterialDesignThemes.Wpf.PackIconKind.CheckBold;
                EditCancelIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.ArrowRotateLeft;
            }
            if (!isNull)
            {
                editMode = mode;
            }

            InfoChangeCheck();
        }
Ejemplo n.º 3
0
 private RenamingNodeItemView()
 {
     InitializeComponent();
     this.WhenActivated(d =>
     {
         this.Bind(ViewModel, vm => vm.NewName, v => v.TextBox_Name.Text).DisposeWith(d);
         this.BindCommand(ViewModel, vm => vm.RenameCommand, v => v.TextBox_Name, vm => vm.ChangedName, nameof(TextBox_Name.LostKeyboardFocus)).DisposeWith(d);
         this.OneWayBind(ViewModel, vm => vm.NewNameErrors, v => v.ShowErrorsBehavior_TextBox_Name.Errors).DisposeWith(d);
         this.WhenAnyObservable(v => v.ViewModel.IsFocus).ObserveOnDispatcher(DispatcherPriority.Background).Subscribe(u => TextBox_Name.Focus()).DisposeWith(d);
     });
 }
Ejemplo n.º 4
0
 public Win()
 {
     InitializeComponent();
     TextBox_Name.Focus();
 }