Exemple #1
0
        public bool SaveData()
        {
            Bus.Customer customer = ModelFromView();

            if (this.HasChanged())
            {
                if (this.ValidateData(customer))
                {
                    try {
                        customer.Update();

                        CustomerSaveEventArgs args = new CustomerSaveEventArgs();
                        args.CustomerId  = this.CustomerId;
                        args.NewFullName = customer.Model.LastName + ", " + customer.Model.FirstName;
                        OnCustomerSave(this, args);

                        customer = null;

                        return(true);
                    } catch (Exception x) {
                        //KF: This is only very basic exception handling, a full solution would look for inner exceptions, particular types and much more
                        g.LogEvent("Save Error: " + x.Message, EventLogging.Events.EventLevel.Exception);
                    }
                }
                return(false);
            }
            else
            {
                //If nothing to do return true
                return(true);
            }
        }
        private void CustomerHasBeenSaved(Object sender, CustomerSaveEventArgs e)
        {
            //Update the grid with the new data

            SortedDictionary <Guid, Grids.Order> .ValueCollection data = (SortedDictionary <Guid, Grids.Order> .ValueCollection)gcOrders.DataSource;

            foreach (Grids.Order order in data)
            {
                if (order.CustomerId == e.CustomerId)
                {
                    order.CustomerName = e.NewFullName;
                }
            }

            //Refresh all the rows in case the data has been sorted and just the one column for speed
            for (int i = 0; i < data.Count; i++)
            {
                gvOrders.RefreshRowCell(i, gvOrders.Columns["CustomerName"]);
            }
        }
Exemple #3
0
 protected virtual void OnCustomerSave(Object sender, CustomerSaveEventArgs e)
 {
     CustomerSave?.Invoke(this, e);
 }