Exemplo n.º 1
0
        private void SaveExecute(string isValidData)
        {
            try
            {
                var client = new ERPModuleServiceClient();
                client.UpdateCustomerCompleted += delegate(object sender, AsyncCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ((VMCustomer)((MainPage)App.Current.RootVisual).viewCustomer.DataContext).Customer = Customer;
                        ((VMCustomerListView)((MainPage)App.Current.RootVisual).viewListCustomers.DataContext).GetCustomers();
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("SaveExecute: Error at Service:" + e.Error.ToString());
                    }

                    ((MainPage)App.Current.RootVisual).GoBackEditCustomer.Begin();
                };

                client.UpdateCustomerAsync(Customer);
            }
            catch (FaultException <ServiceError> excep)
            {
                Debug.WriteLine("SaveExecute: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VMEditCustomer"/> class.
        /// </summary>
        /// <param name="customerCode">The customer code of the current user.</param>
        public VMEditCustomer(Guid customerCode)
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomerCompleted += delegate(object sender, FindCustomerCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        if (e.Result != null)
                        {
                            Customer = e.Result;
                        }
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("VMEditCustomer: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomerAsync(customerCode);
            }
            catch (FaultException <ServiceError> excep)
            {
                Debug.WriteLine("VMEditCustomer: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///    Gets the country list.
 /// </summary>
 private void GetCountries()
 {
     try
     {
         var client = new ERPModuleServiceClient();
         client.FindCountriesInPageCompleted += delegate(object sender, FindCountriesInPageCompletedEventArgs e)
         {
             if (e.Error == null)
             {
                 Countries = e.Result;
             }
             else if (e.Error is FaultException <ServiceError> )
             {
                 var fault = e.Error as FaultException <ServiceError>;
                 MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
             }
             else
             {
                 Debug.WriteLine("GetCountries: Error at Service:" + e.Error.ToString());
             }
         };
         client.FindCountriesInPageAsync(0, 100);
     }
     catch (FaultException <ServiceError> excep) {
         Debug.WriteLine("GetCountries: Error at Service:" + excep.ToString());
     }
 }
Exemplo n.º 4
0
        /// <summary>
        ///    Gets the orders by date filter.
        /// </summary>
        private void GetOrdersByFilter()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindOrdersByFilterCompleted += delegate(object sender, FindOrdersByFilterCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        Orders = e.Result;
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("GetOrders: Error at Service:" + e.Error.ToString());
                    }
                };
                if (FilterFrom.HasValue && FilterTo.HasValue)
                {
                    client.FindOrdersByFilterAsync(FilterFrom.Value, FilterTo.Value);
                }
                else
                {
                    GetOrders();
                }
            }
            catch (FaultException <ServiceError> excep) {
                Debug.WriteLine("GetOrders: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///    Search a customer by name.
        /// </summary>
        /// <param name="name">The customer name or part of them.</param>
        public void SearchCustomers(string name)
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomersByFilterCompleted += delegate(object sender, FindCustomersByFilterCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        var listCustomers = e.Result;
                        if (listCustomers != null && listCustomers.Count > 0)
                        {
                            Customers = listCustomers;
                        }
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("SearchCustomers: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomersByFilterAsync(name);
            }
            catch (FaultException <ServiceError> excep) {
                Debug.WriteLine("SearchCustomers: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///    Deletes the current selected customer.
        /// </summary>
        /// <param name="customer">The current customer to delete.</param>
        public void DeleteCustomers(CustomerDTO customer)
        {
            try
            {
                //remove customer
                var client = new ERPModuleServiceClient();

                client.RemoveCustomerCompleted += delegate(object o, AsyncCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        //refresh customer list
                        this.GetCustomers();
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("DeleteCustomers: Error at Service:" + e.Error.ToString());
                    }
                };

                client.RemoveCustomerAsync(customer.Id);
            }
            catch (FaultException <ServiceError> ex) {
                Debug.WriteLine("DeleteCustomers: Error at Service:" + ex.ToString());
            }
        }
Exemplo n.º 7
0
      /// <summary>
      ///    Gets the country list.
      /// </summary>
      private void GetCountries()
      {
         try
         {
            var client = new ERPModuleServiceClient();
            client.FindCountriesInPageCompleted += delegate(object sender, FindCountriesInPageCompletedEventArgs e)
            {
               if (e.Error == null)
               {
                  Countries = e.Result;
                  SelectedCountry = Countries.Where(c => c.Id == _currentCustomer.CountryId).FirstOrDefault();
               }
               else if (e.Error is FaultException<ServiceError>)
               {
                  var fault = e.Error as FaultException<ServiceError>;
                  MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
               }
               else
               {
                  Debug.WriteLine("GetCountries: Error at Service:" + e.Error.ToString());
               }

            };
            client.FindCountriesInPageAsync(0, 100);

         }
         catch (FaultException<ServiceError> excep) {
            Debug.WriteLine("GetCountries: Error at Service:" + excep.ToString());
         }
      }
        /// <summary>
        /// Initializes a new instance of the <see cref="VMEditCustomer"/> class.
        /// </summary>
        /// <param name="customerCode">The customer code of the current user.</param>
        public VMEditCustomer(Guid customerCode)
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomerCompleted += delegate(object sender, FindCustomerCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        if (e.Result != null)
                        {
                            Customer = e.Result;
                        }
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("VMEditCustomer: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomerAsync(customerCode);
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("VMEditCustomer: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 9
0
        private void CancelExecute()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomerCompleted += delegate(object sender, FindCustomerCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        if (e.Result != null)
                        {
                            Customer = e.Result;
                        }
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("CancelExecute: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomerAsync(Customer.Id);
            }
            catch (FaultException <ServiceError> excep)
            {
                Debug.WriteLine("CancelExecute: Error at Service:" + excep.ToString());
            }

            ((MainPage)App.Current.RootVisual).GoBackEditCustomer.Begin();
        }
Exemplo n.º 10
0
 private void SaveExecute()
 {
     if (SelectedCountry == null)
     {
         return;
     }
     try
     {
         var client = new ERPModuleServiceClient();
         client.AddNewCustomerCompleted += delegate(object sender, AddNewCustomerCompletedEventArgs e)
         {
             if (e.Error == null)
             {
                 ((VmCustomerListView)((MainPage)App.Current.RootVisual).ViewListCustomers.DataContext).GetCustomers(
                     );
                 ((MainPage)App.Current.RootVisual).GoBackAddCustomer.Begin();
                 Customer = null;
             }
             else if (e.Error is FaultException <ServiceError> )
             {
                 var fault = e.Error as FaultException <ServiceError>;
                 MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
             }
             else
             {
                 Debug.WriteLine("SaveExecute: Error at Service:" + e.Error.ToString());
             }
         };
         client.AddNewCustomerAsync(_currentCustomer);
     }
     catch (FaultException <ServiceError> excep) {
         Debug.WriteLine("SaveExecute: Error at Service:" + excep.ToString());
     }
 }
Exemplo n.º 11
0
        private void SaveExecute()
        {
            if (SelectedCustomer == null)
            {
                return;
            }

            try
            {
                var client = new ERPModuleServiceClient();

                client.AddNewOrderCompleted += delegate(object sender, AddNewOrderCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        if (e.Result == null)
                        {
                            MessageBox.Show(
                                "Order exceeds the maximum allowed amount",
                                "Unable to perform the order",
                                MessageBoxButton.OK);
                        }
                        else
                        {
                            Order            = new OrderDTO();
                            SelectedCustomer = null;
                            VisualStateManager.GoToState(((MainPage)App.Current.RootVisual), "ToOrderList", true);
                            MessageDispatcher.NotifyColleagues(DispatcherMessages.RefreshOrders, null);
                        }
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("GetOrders: Error at Service:" + e.Error.ToString());
                    }
                };

                Order.CustomerId = SelectedCustomer.Id;
                Order.OrderDate  = DateTime.Now;

                client.AddNewOrderAsync(Order);
            }
            catch (FaultException <ServiceError> excep) {
                Debug.WriteLine("GetOrders: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the customer list.
        /// </summary>
        public void GetCustomers()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomersInPageCompleted += delegate(object sender, FindCustomersInPageCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ObservableCollection <CustomerListDTO> listCustomers = e.Result;
                        if (listCustomers != null)
                        {
                            if (listCustomers.Count > 0)
                            {
                                Customers = listCustomers;
                            }
                            if (listCustomers.Count == 0)
                            {
                                if (this.CurrentPage > 1)
                                {
                                    this.CurrentPage--;
                                }
                            }
                        }
                        else
                        {
                            if (this.CurrentPage > 1)
                            {
                                this.CurrentPage--;
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("GetCustomers: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomersInPageAsync(this.CurrentPage, 4);
            }
            catch (Exception excep)
            {
                Debug.WriteLine("GetCustomers: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 13
0
        private void DeleteExecute(Object o)
        {
            if (o == null)
            {
                return;
            }

            try
            {
                if (o is CustomerListDTO)
                {
                    var current = (CustomerListDTO)o;
                    var client  = new ERPModuleServiceClient();
                    client.RemoveCustomerCompleted += delegate(object sender, AsyncCompletedEventArgs e)
                    {
                        if (e.Error == null)
                        {
                            GetCustomers();
                        }
                        else if (e.Error is FaultException <ServiceError> )
                        {
                            var fault = e.Error as FaultException <ServiceError>;
                            MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                        }
                        else
                        {
                            Debug.WriteLine("DeleteExecute: Error at Service:" + e.Error.ToString());
                        }
                    };

                    client.RemoveCustomerAsync(current.Id);
                }
                Debug.WriteLine("Delete Customer.");
            }
            catch (FaultException <ServiceError> excep)
            {
                Debug.WriteLine("DeleteExecute: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 14
0
        private void ViewExecute(Object o)
        {
            try
            {
                if (o is CustomerListDTO)
                {
                    var current = (CustomerListDTO)o;
                    var client  = new ERPModuleServiceClient();

                    client.FindCustomerCompleted += delegate(object sender, FindCustomerCompletedEventArgs e)
                    {
                        if (e.Error == null)
                        {
                            if (e.Result != null)
                            {
                                ((MainPage)App.Current.RootVisual).viewCustomer.DataContext = new VMCustomer(e.Result);
                                ((MainPage)App.Current.RootVisual).ViewCustomer.Begin();
                            }
                        }
                        else if (e.Error is FaultException <ServiceError> )
                        {
                            var fault = e.Error as FaultException <ServiceError>;
                            MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                        }
                        else
                        {
                            Debug.WriteLine("ViewExecute: Error at Service:" + e.Error.ToString());
                        }
                    };

                    client.FindCustomerAsync(current.Id);
                }
            }
            catch (FaultException <ServiceError> excep)
            {
                Debug.WriteLine("ViewExecute: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the first customer.
        /// </summary>
        private void GetFirstCustomer()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomersInPageAsync(0, 10);

                client.FindCustomersInPageCompleted += delegate(object sender, FindCustomersInPageCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ObservableCollection <CustomerListDTO> listCustomers = e.Result;
                        if (listCustomers != null && listCustomers.Count > 0)
                        {
                            if (listCustomers.Any())
                            {
                                var id = listCustomers.First().Id;
                                GetCustomerInfoById(id);
                            }
                        }
                    }
                    else if (e.Error is FaultException <ServiceError> )
                    {
                        var fault = e.Error as FaultException <ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("GetFirstCustomer: Error at Service:" + e.Error.ToString());
                    }
                };
            }
            catch (FaultException <ServiceError> excep)
            {
                Debug.WriteLine("GetFirstCustomer: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the customer info by id.
        /// </summary>
        /// <param name="id">The current customer id.</param>
        private void GetCustomerInfoById(Guid id)
        {
            var client = new ERPModuleServiceClient();

            client.FindCustomerAsync(id);
            client.FindCustomerCompleted += delegate(object s, FindCustomerCompletedEventArgs args)
            {
                if (args.Error == null)
                {
                    Customer = args.Result;
                    GetCustomerOrders();
                }
                else if (args.Error is FaultException <ServiceError> )
                {
                    var fault = args.Error as FaultException <ServiceError>;
                    Debug.WriteLine("GetFirstCustomer: Error at Service:" + fault.ToString());
                }
                else
                {
                    Debug.WriteLine("GetFirstCustomer: Error at Service:" + args.Error.ToString());
                }
            };
        }
Exemplo n.º 17
0
      private void SaveExecute()
      {
         if (SelectedCountry == null) { return; }
         try
         {
            var client = new ERPModuleServiceClient();
            client.AddNewCustomerCompleted += delegate(object sender, AddNewCustomerCompletedEventArgs e)
            {
               if (e.Error == null)
               {
                  ((VmCustomerListView) ((MainPage) App.Current.RootVisual).ViewListCustomers.DataContext).GetCustomers(
                     );
                  ((MainPage) App.Current.RootVisual).GoBackAddCustomer.Begin();
                  Customer = null;
               }
               else if (e.Error is FaultException<ServiceError>)
               {
                  var fault = e.Error as FaultException<ServiceError>;
                  MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
               }
               else
               {
                  Debug.WriteLine("SaveExecute: Error at Service:" + e.Error.ToString());
               }

            };
            client.AddNewCustomerAsync(_currentCustomer);

         }
         catch (FaultException<ServiceError> excep) {
            Debug.WriteLine("SaveExecute: Error at Service:" + excep.ToString());
         }
      }
        private void SaveExecute(string isValidData)
        {
            try
            {
                var client = new ERPModuleServiceClient();
                client.UpdateCustomerCompleted += delegate(object sender, AsyncCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ((VMCustomer)((MainPage)App.Current.RootVisual).viewCustomer.DataContext).Customer = Customer;
                        ((VMCustomerListView)((MainPage)App.Current.RootVisual).viewListCustomers.DataContext).GetCustomers();
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("SaveExecute: Error at Service:" + e.Error.ToString());
                    }

                    ((MainPage)App.Current.RootVisual).GoBackEditCustomer.Begin();
                };

                client.UpdateCustomerAsync(Customer);

            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("SaveExecute: Error at Service:" + excep.ToString());
            }
        }
        private void CancelExecute()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomerCompleted += delegate(object sender, FindCustomerCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        if (e.Result != null)
                        {
                            Customer = e.Result;
                        }
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("CancelExecute: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomerAsync(Customer.Id);
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("CancelExecute: Error at Service:" + excep.ToString());
            }

            ((MainPage)App.Current.RootVisual).GoBackEditCustomer.Begin();
        }
        private void ViewExecute(Object o)
        {
            try
            {
                if (o is CustomerListDTO)
                {
                    var current = (CustomerListDTO)o;
                    var client = new ERPModuleServiceClient();

                    client.FindCustomerCompleted += delegate(object sender, FindCustomerCompletedEventArgs e)
                    {
                        if (e.Error == null)
                        {
                            if (e.Result != null)
                            {
                                ((MainPage)App.Current.RootVisual).viewCustomer.DataContext = new VMCustomer(e.Result);
                                ((MainPage)App.Current.RootVisual).ViewCustomer.Begin();
                            }
                        }
                        else if (e.Error is FaultException<ServiceError>)
                        {
                            var fault = e.Error as FaultException<ServiceError>;
                            MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                        }
                        else
                        {
                            Debug.WriteLine("ViewExecute: Error at Service:" + e.Error.ToString());
                        }
                    };

                    client.FindCustomerAsync(current.Id);
                }
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("ViewExecute: Error at Service:" + excep.ToString());
            }
        }
        private void DeleteExecute(Object o)
        {
            if (o == null) return;

            try
            {
                if (o is CustomerListDTO)
                {
                    var current = (CustomerListDTO)o;
                    var client = new ERPModuleServiceClient();
                    client.RemoveCustomerCompleted += delegate(object sender, AsyncCompletedEventArgs e)
                    {
                        if (e.Error == null)
                        {
                            GetCustomers();
                        }
                        else if (e.Error is FaultException<ServiceError>)
                        {
                            var fault = e.Error as FaultException<ServiceError>;
                            MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                        }
                        else
                        {
                            Debug.WriteLine("DeleteExecute: Error at Service:" + e.Error.ToString());
                        }
                    };

                    client.RemoveCustomerAsync(current.Id);
                }
                Debug.WriteLine("Delete Customer.");
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("DeleteExecute: Error at Service:" + excep.ToString());
            }
        }
        /// <summary>
        /// Search a customer by name.
        /// </summary>
        /// <param name="name">The customer name or part of them.</param>
        public void SearchCustomers(string name)
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomersByFilterCompleted += delegate(object sender, FindCustomersByFilterCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ObservableCollection<CustomerListDTO> listCustomers = e.Result;
                        if (listCustomers != null && listCustomers.Count > 0)
                        {
                            Customers = listCustomers;
                        }
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("SearchCustomers: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomersByFilterAsync(name);
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("SearchCustomers: Error at Service:" + excep.ToString());
            }
        }
        /// <summary>
        /// Gets the customer list.
        /// </summary>
        public void GetCustomers()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomersInPageCompleted += delegate(object sender, FindCustomersInPageCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ObservableCollection<CustomerListDTO> listCustomers = e.Result;
                        if (listCustomers != null)
                        {
                            if (listCustomers.Count > 0)
                            {
                                Customers = listCustomers;
                            }
                            if (listCustomers.Count == 0)
                            {
                                if (this.CurrentPage > 1)
                                {
                                    this.CurrentPage--;
                                }
                            }
                        }
                        else
                        {
                            if (this.CurrentPage > 1)
                            {
                                this.CurrentPage--;
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("GetCustomers: Error at Service:" + e.Error.ToString());
                    }
                };

                client.FindCustomersInPageAsync(this.CurrentPage, 4);
            }
            catch (Exception excep)
            {
                Debug.WriteLine("GetCustomers: Error at Service:" + excep.ToString());
            }
        }
        /// <summary>
        /// Deletes the current selected customer.
        /// </summary>
        /// <param name="customer">The current customer to delete.</param>
        public void DeleteCustomers(CustomerDTO customer)
        {
            try
            {
                //remove customer
                var client = new ERPModuleServiceClient();

                client.RemoveCustomerCompleted += delegate(object o, AsyncCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        //refresh customer list
                        this.GetCustomers();
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("DeleteCustomers: Error at Service:" + e.Error.ToString());
                    }
                };

                client.RemoveCustomerAsync(customer.Id);
            }
            catch (FaultException<ServiceError> ex)
            {
                Debug.WriteLine("DeleteCustomers: Error at Service:" + ex.ToString());
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Gets the current customer orders.
        /// </summary>
        private void GetCustomerOrders()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindOrdersByCustomerAsync(Customer.Id);

                client.FindOrdersByCustomerCompleted += delegate(object sender, FindOrdersByCustomerCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        CustomerOrders = e.Result;
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("GetCustomerOrders: Error at Service:" + e.Error.ToString());
                    }
                };
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("GetCustomerOrders: Error at Service:" + excep.ToString());
            }

        }
Exemplo n.º 26
0
 /// <summary>
 /// Gets the customer info by id.
 /// </summary>
 /// <param name="id">The current customer id.</param>
 private void GetCustomerInfoById(Guid id)
 {
     var client = new ERPModuleServiceClient();
     client.FindCustomerAsync(id);
     client.FindCustomerCompleted += delegate(object s, FindCustomerCompletedEventArgs args)
     {
         if (args.Error == null)
         {
             Customer = args.Result;
             GetCustomerOrders();
         }
         else if (args.Error is FaultException<ServiceError>)
         {
             var fault = args.Error as FaultException<ServiceError>;
             Debug.WriteLine("GetFirstCustomer: Error at Service:" + fault.ToString());
         }
         else
         {
             Debug.WriteLine("GetFirstCustomer: Error at Service:" + args.Error.ToString());
         }
     };
 }
Exemplo n.º 27
0
        /// <summary>
        /// Gets the first customer.
        /// </summary>
        private void GetFirstCustomer()
        {
            try
            {
                var client = new ERPModuleServiceClient();

                client.FindCustomersInPageAsync(0, 10);

                client.FindCustomersInPageCompleted += delegate(object sender, FindCustomersInPageCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        ObservableCollection<CustomerListDTO> listCustomers = e.Result;
                        if (listCustomers != null && listCustomers.Count > 0)
                        {
                            if (listCustomers.Any())
                            {
                                var id = listCustomers.First().Id;
                                GetCustomerInfoById(id);
                            }
                        }
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("GetFirstCustomer: Error at Service:" + e.Error.ToString());
                    }

                };
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("GetFirstCustomer: Error at Service:" + excep.ToString());
            }
        }
Exemplo n.º 28
0
        private void SaveExecute()
        {
            if (SelectedCustomer == null) return;

            try
            {
                var client = new ERPModuleServiceClient();

                client.AddNewOrderCompleted += delegate(object sender, AddNewOrderCompletedEventArgs e)
                {
                    if (e.Error == null)
                    {
                        if (e.Result == null)
                        {
                            MessageBox.Show("Order exceeds the maximum allowed amount", "Unable to perform the order", MessageBoxButton.OK);
                        }
                        else
                        {
                            Order = new OrderDTO();
                            SelectedCustomer = null;
                            VisualStateManager.GoToState(((MainPage)App.Current.RootVisual), "ToOrderList", true);
                            MessageDispatcher.NotifyColleagues(DispatcherMessages.RefreshOrders,null);
                        }
                    }
                    else if (e.Error is FaultException<ServiceError>)
                    {
                        var fault = e.Error as FaultException<ServiceError>;
                        MessageBox.Show(fault.Detail.ErrorMessage, "Error", MessageBoxButton.OK);
                    }
                    else
                    {
                        Debug.WriteLine("GetOrders: Error at Service:" + e.Error.ToString());
                    }
                };

                Order.CustomerId = SelectedCustomer.Id;
                Order.OrderDate = DateTime.Now;

                client.AddNewOrderAsync(Order);
            }
            catch (FaultException<ServiceError> excep)
            {
                Debug.WriteLine("GetOrders: Error at Service:" + excep.ToString());
            }
        }