Ejemplo n.º 1
0
        private void buttonGO_Click(object sender, EventArgs e)
        {
            try
            {
                ClientsSet clientsSet = new ClientsSet();
                if (comboBoxBook.SelectedItem != null)
                {
                    clientsSet.IdBooks = Convert.ToInt32(comboBoxBook.SelectedItem.ToString().Split('.')[0]);
                }
                else
                {
                    throw new Exception("Обязательные данные не заполнены");
                }

                if (textBoxEmail.Text != "")
                {
                    clientsSet.Email = textBoxEmail.Text;
                }
                else
                {
                    clientsSet.Email = null;
                }

                if (textBoxLastName.Text == "" || textBoxFirstName.Text == "" || textBoxPhone.Text == "" || textBoxAddress.Text == "")
                {
                    throw new Exception("Обязательные данные не заполнены");
                }
                else
                {
                    clientsSet.LastName  = textBoxLastName.Text;
                    clientsSet.FirstName = textBoxFirstName.Text;
                    clientsSet.Phone     = textBoxPhone.Text;
                    clientsSet.Address   = textBoxAddress.Text;
                }
                MessageBox.Show("Ваш заказ успешно оформлен! Ожидайте SMS сообщение по вашему номеру телефона с" +
                                " информацией об оплате и доставке вашей книги.", "Заказ оформлен",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();

                Program.lab.ClientsSet.Add(clientsSet);
                Program.lab.SaveChanges();
            }
            catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); }
        }
Ejemplo n.º 2
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewClients.SelectedItems.Count == 1)
                {
                    ClientsSet clientsSet = listViewClients.SelectedItems[0].Tag as ClientsSet;
                    if (comboBoxBook.SelectedItem != null)
                    {
                        clientsSet.IdBooks = Convert.ToInt32(comboBoxBook.SelectedItem.ToString().Split('.')[0]);
                    }
                    else
                    {
                        throw new Exception("Обязательные данные не заполнены");
                    }

                    if (textBoxEmail.Text != "")
                    {
                        clientsSet.Email = textBoxEmail.Text;
                    }
                    else
                    {
                        clientsSet.Email = null;
                    }

                    if (textBoxLastName.Text == "" || textBoxFirstName.Text == "" || textBoxPhone.Text == "" || textBoxAddress.Text == "")
                    {
                        throw new Exception("Обязательные данные не заполнены");
                    }
                    else
                    {
                        clientsSet.LastName  = textBoxLastName.Text;
                        clientsSet.FirstName = textBoxFirstName.Text;
                        clientsSet.Phone     = textBoxPhone.Text;
                        clientsSet.Address   = textBoxAddress.Text;
                    }

                    Program.lab.SaveChanges();
                    ShowClients();
                }
            }
            catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); }
        }
Ejemplo n.º 3
0
        private void listViewClients_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewClients.SelectedItems.Count == 1)
            {
                ClientsSet clientsSet = listViewClients.SelectedItems[0].Tag as ClientsSet;

                textBoxFirstName.Text = clientsSet.FirstName;
                textBoxLastName.Text  = clientsSet.LastName;
                textBoxPhone.Text     = clientsSet.Phone;
                textBoxEmail.Text     = clientsSet.Email;
                textBoxAddress.Text   = clientsSet.Address;
                comboBoxBook.Text     = clientsSet.IdBooks.ToString()
                                        + "." + clientsSet.BooksSet.Name + " - " + clientsSet.BooksSet.Author;
            }
            else
            {
                textBoxFirstName.Text     = "";
                textBoxLastName.Text      = "";
                textBoxPhone.Text         = "";
                textBoxEmail.Text         = "";
                textBoxAddress.Text       = "";
                comboBoxBook.SelectedItem = null;
            }
        }
Ejemplo n.º 4
0
        private void buttonDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewClients.SelectedItems.Count == 1)
                {
                    ClientsSet clientsSet = listViewClients.SelectedItems[0].Tag as ClientsSet;

                    Program.lab.ClientsSet.Remove(clientsSet);
                    Program.lab.SaveChanges();
                    ShowClients();
                }
                textBoxLastName.Text  = "";
                textBoxFirstName.Text = "";
                textBoxPhone.Text     = "";
                textBoxEmail.Text     = "";
                textBoxAddress.Text   = "";
                comboBoxBook.Text     = "";
            }
            catch
            {
                MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);;
            }
        }