コード例 #1
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            addCustomerView            = AddCustomerView.Instance;
            addCustomerView.Text       = "Add Customer";
            addCustomerView.TextButton = "Add";
            var data = addCustomerView.data;

            if (AddCustomerView._addClicked && addCustomerView.TextButton != "Save" && data != null)
            {
                var cus = from c in context.Customers
                          orderby c.Id descending
                          select c.Id;
                int count = cus.Count();
                if (count == 0)
                {
                    data.Id = "CUS" + 1.ToString("D6");
                }
                else
                {
                    data.Id = "CUS" + (Int32.Parse(cus.First().Split('S')[1]) + 1).ToString("D6");
                }
                context.Customers.Add(data);
                context.SaveChanges();
                using WaitDialog fr = new WaitDialog(AssignDataToDataGrid);
                fr.ShowDialog();
            }
        }
コード例 #2
0
        /// <summary>
        /// Invokes the update customer window.
        /// </summary>
        internal void UpdateCustomer()
        {
            try
            {
                // Make a copy of the current customer to avoid directly editing the customer in the data grid.
                // The customer will be modified in the cache and in the database
                // and the grid view will be updated from the cache or the database.
                Customer c = new Customer();
                c.Copy(this.SelectedCustomer);

                AddCustomerView      addCustomerView      = new AddCustomerView();
                AddCustomerViewModel addCustomerViewModel = new AddCustomerViewModel(c);
                addCustomerViewModel.SaveCompleted += (s, e) =>
                {
                    // Get latest data after save.
                    this.SelectedCustomer = null;
                    addCustomerView.Close();
                    this.GetData();
                };
                addCustomerViewModel.Cancelled += (s, e) =>
                {
                    this.SelectedCustomer = null;
                    addCustomerView.Close();
                };
                addCustomerView.DataContext = addCustomerViewModel;
                addCustomerView.ShowDialog();
                this.SelectedCustomer = null;
            }
            catch (Exception ex)
            {
                InfoDialogViewModel.ShowDialog(ex.Message, "Unhandled Exception");
                Log.LogException(ex, "MainViewModel.cs");
            }
        }
コード例 #3
0
 /// <summary>
 /// Invokes the add new customer window .
 /// </summary>
 internal void AddCustomer()
 {
     try
     {
         AddCustomerView addCustomerView = new AddCustomerView();
         // Set the date of birth to today, so it's not set to default 01/01/0001
         Customer customer = new Customer()
         {
             DateOfBirth = DateTime.Now
         };
         AddCustomerViewModel addCustomerViewModel = new AddCustomerViewModel(customer);
         addCustomerViewModel.SaveCompleted += (s, e) =>
         {
             // Get latest data after save.
             this.SelectedCustomer = null;
             addCustomerView.Close();
             this.GetData();
         };
         addCustomerViewModel.Cancelled += (s, e) =>
         {
             this.SelectedCustomer = null;
             addCustomerView.Close();
         };
         addCustomerView.DataContext = addCustomerViewModel;
         addCustomerView.ShowDialog();
     }
     catch (Exception ex)
     {
         InfoDialogViewModel.ShowDialog(ex.Message, "Unhandled Exception");
         Log.LogException(ex, "MainViewModel.cs");
     }
 }
コード例 #4
0
        private void OnAddCustomerCommand(object obj)
        {
            var newCustomerDialog = new AddCustomerView();

            newCustomerDialog.Closed += (s, e) =>
            {
                LoadData();
            };
            newCustomerDialog.ShowDialog();
        }
コード例 #5
0
        private void BtnEdit_Click(object sender, EventArgs e)
        {
            addCustomerView            = AddCustomerView.Instance;
            addCustomerView.Text       = "Edit Customer Details";
            addCustomerView.data       = customer;
            addCustomerView.TextButton = "Save";
            var data = addCustomerView.data;

            if (AddCustomerView._saveClicked)
            {
                var customer = (from c in context.Customers
                                where c.Id == data.Id
                                select c).FirstOrDefault();
                customer = data;
                context.SaveChanges();
                MessageBox.Show("Updated");
                AddCustomerView._saveClicked = false;
                using WaitDialog fr          = new WaitDialog(AssignDataToDataGrid);
                fr.ShowDialog();
            }
        }
コード例 #6
0
        /*
         * FUNCTION:		btnAddCustomer_Click(object sender, RoutedEventArgs e)
         * DESCRIPTION:	Open the view to create a new customer
         * PARAMETERS:		object sender       - The object that is responsible for firing the event
         *              RoutedEventArgs e   - The arguments to be manipulated due to the event
         * RETURNS:		NONE
         * DEV:
         */
        private void btnAddCustomer_Click(object sender, RoutedEventArgs e)
        {
            AddCustomerView addCustomer = new AddCustomerView();

            addCustomer.ShowDialog();
        }