Ejemplo n.º 1
0
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (IconDelete.Kind == MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle)
            {
                Dialog a = new Dialog()
                {
                    Message = "Are you sure to save ?"
                };
                a.Owner = Window.GetWindow(this);
                if (a.ShowDialog() == false)
                {
                    return;
                }
                Dialog b = new Dialog()
                {
                    Message = "If you delete this supplier, you will delete \n all product of this supplier.  Are you sure?"
                };
                b.Owner = Window.GetWindow(this);
                if (b.ShowDialog() == false)
                {
                    return;
                }
                Supplier sup = listSupplier.SelectedItem as Supplier;
                manage.DeleteSupplier(sup);
                listSupplier.ItemsSource   = new ObservableCollection <Supplier>(manage.LoadData_Supplier());
                listSupplier.SelectedIndex = -1;
                //xóa các textbox
                txbAddress.Clear();
                txbIdSup.Clear();
                txbEmail.Clear();
                txbMoreInfo.Clear();
                txbNameSup.Clear();
                txbPhone.Clear();
                btnDelete.IsEnabled = false;
                btnEdit.IsEnabled   = false;

                if (refreshComboboxSup != null)
                {
                    refreshComboboxSup.Invoke(true);
                }
            }
            else
            if (IconDelete.Kind == MaterialDesignThemes.Wpf.PackIconKind.ContentSave)
            {
                if (CheckInput())
                {
                    Dialog b = new Dialog()
                    {
                        Message = "Are you sure to add this Supplier?"
                    };
                    b.Owner = Window.GetWindow(this);
                    if (b.ShowDialog() == true)
                    {
                        btnAdd.IsEnabled = true;
                        manage.AddnewSupplier(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 Supplier";
                        IconEdit.Kind              = MaterialDesignThemes.Wpf.PackIconKind.Edit;
                        listSupplier.SelectedIndex = listSupplier.Items.Count - 1;
                        txbIdSup.Clear();
                        txbAddress.Clear();
                        txbIdSup.Clear();
                        txbEmail.Clear();
                        txbMoreInfo.Clear();
                        txbNameSup.Clear();
                        txbPhone.Clear();
                        listSupplier.IsEnabled = true;
                        setTextBox(false);
                    }
                }
            }
        }