Example #1
0
        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (IconEdit.Kind == MaterialDesignThemes.Wpf.PackIconKind.Edit)
            {
                setTextBox(true);
                txbIdSup.IsEnabled     = false;
                IconEdit.Kind          = MaterialDesignThemes.Wpf.PackIconKind.ContentSave;
                btnEdit.ToolTip        = "Save change";
                btnAdd.IsEnabled       = false;
                listSupplier.IsEnabled = false;

                IconDelete.Kind   = MaterialDesignThemes.Wpf.PackIconKind.Cancel;
                btnDelete.ToolTip = "Cancel change";
            }
            else
            if (IconEdit.Kind == MaterialDesignThemes.Wpf.PackIconKind.ContentSave)
            {
                Dialog a = new Dialog()
                {
                    Message = "Are you sure to save ?"
                };
                a.Owner = Window.GetWindow(this);
                if (a.ShowDialog() == true)
                {
                    Supplier pro = listSupplier.SelectedItem as Supplier;
                    manage.EditSupplier(txbIdSup.Text, txbNameSup.Text, txbAddress.Text, txbPhone.Text, txbEmail.Text, txbMoreInfo.Text);
                    listSupplier.ItemsSource   = new ObservableCollection <Supplier>(manage.LoadData_Supplier());
                    IconDelete.Kind            = MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle;
                    btnDelete.ToolTip          = "Delete";
                    listSupplier.IsEnabled     = true;
                    IconEdit.Kind              = MaterialDesignThemes.Wpf.PackIconKind.Edit;
                    btnEdit.ToolTip            = "Edit";
                    listSupplier.SelectedIndex = listSupplier.Items.Count - 1;
                    setTextBox(false);
                    btnAdd.IsEnabled = true;

                    if (refreshComboboxSup != null)
                    {
                        refreshComboboxSup.Invoke(true);
                    }
                }
            }
            else
            if (IconEdit.Kind == MaterialDesignThemes.Wpf.PackIconKind.Cancel)
            {
                Dialog a = new Dialog()
                {
                    Message = "Are you sure to cancel ?"
                };
                a.Owner = Window.GetWindow(this);
                if (a.ShowDialog() == true)
                {
                    setTextBox(false);
                    listSupplier.IsEnabled     = true;
                    IconDelete.Kind            = MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle;
                    btnDelete.ToolTip          = "Delete";
                    btnDelete.IsEnabled        = false;
                    btnAdd.IsEnabled           = true;
                    IconEdit.Kind              = MaterialDesignThemes.Wpf.PackIconKind.Edit;
                    btnEdit.ToolTip            = "Edit";
                    btnEdit.IsEnabled          = false;
                    listSupplier.SelectedIndex = -1;
                }
                else
                {
                    txbNameSup.Focus();
                }
            }
        }