Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //populate objects with UI data
            //ORDER
            OrderStatus orderStatus = (OrderStatus)Enum.Parse(typeof(OrderStatus), this.cboxOrderStatus.Text);

            order.OrderStatus = orderStatus;

            //CUSTOMER
            char[]   delimiterChars = { ' ' };
            string[] names          = this.txtCustomer.Text.Split(delimiterChars);

            Address mailingAddress = new Address
            {
                StreetNumber = Convert.ToInt32(this.txtStreetNumber.Text),
                StreetName   = this.txtStreetName.Text,
                AddressCity  = this.txtCity.Text,
                AddressState = this.txtState.Text,
                AddressZip   = this.txtZipcode.Text
            };

            Address billingAddress = new Address
            {
                StreetNumber = Convert.ToInt32(this.txtBillingStreetNumber.Text),
                StreetName   = this.txtBillingStreetName.Text,
                AddressCity  = this.txtBillingCity.Text,
                AddressState = this.txtBillingState.Text,
                AddressZip   = this.txtBillingZipcode.Text
            };

            Customer customer = new Customer
            {
                CustomerId     = Guid.NewGuid(),
                FirstName      = names[0],
                LastName       = names[1],
                PhoneNumber    = this.txtPhoneNumber.Text,
                EmailAddress   = this.txtEmail.Text,
                MailingAddress = mailingAddress,
                BillingAddress = billingAddress
            };

            order.Person = (Person)customer;

            if (order != null && customer != null)
            {
                int returnValue = ApplicationObjects.CreateCustomer(customer);

                if (returnValue == 0)
                {
                    returnValue = ApplicationObjects.CreateOrder(order);
                }

                ApplicationObjects.DisplayDataStatus(returnValue);

                if (returnValue == 0)
                {
                    //Return to order list
                    _loginForm.ShowOrdersForm(userAccount, _loginForm);
                    this.Close();
                }
            }
        }