partial void DeleteClientAddress(ClientAddress instance);
 partial void InsertClientAddress(ClientAddress instance);
 partial void UpdateClientAddress(ClientAddress instance);
예제 #4
0
        /// <summary>
        /// Funkcja dodająca do bazy danych nowe zamówienie, a wraz z nim wszystkie pozostałe informacje o kliencie
        /// oraz zamówieniu. W przypadku nie wypełnienia wszystkich pól, lub wypełnienia ich niepoprawnie,
        /// zostaje wyświetlony komunikat
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddData_Click(object sender, EventArgs e)
        {
            try
            {
                var contact = new Contact
                {
                    PhoneNumber = Int32.Parse(textBoxClientPhoneNumber.Text),
                    Mail        = textBoxClientMailAddress.Text
                };

                context.Contacts.InsertOnSubmit(contact);
                context.SubmitChanges();

                var clientAddress = new ClientAddress
                {
                    City           = textBoxClientCity.Text,
                    Street         = textBoxClientStreet.Text,
                    BuildingNumber = Int32.Parse(textBoxClientBuildingNumber.Text)
                };

                context.ClientAddresses.InsertOnSubmit(clientAddress);
                context.SubmitChanges();

                var client = new Client
                {
                    ContactID = contact.ID,
                    AddressID = clientAddress.ID,
                    Name      = textBoxClientName.Text,
                    Surname   = textBoxClientSurname.Text
                };

                context.Clients.InsertOnSubmit(client);
                context.SubmitChanges();

                var placeToGetProduct = new PlacesToGetProduct
                {
                    City           = textBoxOrderCity.Text,
                    Street         = textBoxOrderStreet.Text,
                    BuildingNumber = Int32.Parse(textBoxOrderBuildingNumber.Text)
                };

                context.PlacesToGetProducts.InsertOnSubmit(placeToGetProduct);
                context.SubmitChanges();

                var order = new Order
                {
                    PlaceToGetProductID = placeToGetProduct.ID,
                    ClientID            = client.ID,
                    DateToGetProduct    = dateTimePickerOrderDate.Value,
                    OrderNumber         = Int32.Parse(textBoxOrderNumber.Text)
                };

                context.Orders.InsertOnSubmit(order);
                context.SubmitChanges();

                MessageBox.Show("Dane dodano poprawnie");

                ShowOrders();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Należy wypełnić wszystkie pola lub w poprawnym formacie. Błąd: " + exception.Message);
            }
        }