Exemple #1
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            long barcode = Convert.ToInt64(txbxBarcode.Text);

            if ((barcode < 1000000000000) && (barcode > 9999999999999))
            {
                {
                    MessageBox.Show("Wrong Barcode", "Warning!", MessageBoxButton.OK);
                    txbxBarcode.Focus();
                }
            }
            int count    = Convert.ToInt32(txbxCountInStorage.Text);
            var product1 = dataBase.Products.Where(i => i.Barcode == barcode).FirstOrDefault();

            if (txbxBarcode.Text == "")
            {
                MessageBox.Show("Barcode Should be Filled!", "Warning!", MessageBoxButton.OK);
                txbxBarcode.Focus();
            }
            else if (product1 != null)
            {
                product1.CountInStorage += count;
                dataBase.SaveChanges();
                showData();
                MessageBox.Show("Added quantity to existing product");
                txbxStorekeeperID.Clear();
                txbxName.Clear();
                txbxPrice.Clear();
                txbxCountInStorage.Clear();
                txbxBarcode.Clear();
                txbxCountOnShelf.Clear();
            }
            else
            {
                var product = new Product()
                {
                    StorekeeperId  = Convert.ToInt32(txbxStorekeeperID.Text),
                    Name           = txbxName.Text,
                    Price          = Convert.ToDecimal(txbxPrice.Text),
                    Barcode        = Convert.ToInt64(txbxBarcode.Text),
                    CountInStorage = Convert.ToInt32(txbxCountInStorage.Text),
                };
                dataBase.Products.Add(product);
                dataBase.SaveChanges();
                showData();
                MessageBox.Show("New Product Is Added");
                txbxStorekeeperID.Clear();
                txbxName.Clear();
                txbxPrice.Clear();
                txbxCountInStorage.Clear();
                txbxBarcode.Clear();
                txbxCountOnShelf.Clear();
            }
        }
Exemple #2
0
        private void AddUser_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((chkbx1.IsChecked == true && chkbx2.IsChecked == true) || (chkbx1.IsChecked == true && chkbx3.IsChecked == true) ||
                    (chkbx3.IsChecked == true && chkbx2.IsChecked == true) || (chkbx1.IsChecked == true && chkbx2.IsChecked == true && chkbx3.IsChecked == true))
                {
                    MessageBox.Show("You can choose only one table!", "Caution", MessageBoxButton.OK);
                    txbxUserFirstName.Clear();
                    txbxUserLastName.Clear();
                    txbxEmail.Clear();
                    txbxPassword.Clear();
                    txbxSalary.Clear();
                }

                if (txbxUserFirstName.Text == "" || txbxUserLastName.Text == "" || txbxEmail.Text == "" || txbxPassword.Text == "")
                {
                    MessageBox.Show("Name Should be Filled!", "Warning!", MessageBoxButton.OK);
                    txbxUserFirstName.Focus();
                    txbxUserLastName.Focus();
                    txbxEmail.Focus();
                    txbxPassword.Focus();
                }
                else if (chkbx1.IsChecked == true)
                {
                    txbxSalary.IsEnabled = false;
                    var client = new Client()
                    {
                        FirstName = txbxUserFirstName.Text,
                        LastName  = txbxUserLastName.Text,
                        Email     = txbxEmail.Text,
                        Password  = txbxPassword.Text,
                    };
                    dataBase.Clients.Add(client);
                    dataBase.SaveChanges();
                    showData();
                    MessageBox.Show("New Client Is Added");
                    txbxUserFirstName.Clear();
                    txbxUserLastName.Clear();
                    txbxEmail.Clear();
                    txbxPassword.Clear();
                    txbxSalary.Clear();
                }

                if (chkbx2.IsChecked == true)
                {
                    if (txbxUserFirstName.Text == "" || txbxUserLastName.Text == "" || txbxEmail.Text == "" || txbxPassword.Text == "" || txbxSalary.Text == "")
                    {
                        MessageBox.Show("Name Should be Filled!", "Warning!", MessageBoxButton.OK);
                        txbxUserFirstName.Focus();
                        txbxUserLastName.Focus();
                        txbxEmail.Focus();
                        txbxPassword.Focus();
                        txbxSalary.Focus();
                    }
                    var seller = new Seller()
                    {
                        FirstName = txbxUserFirstName.Text,
                        LastName  = txbxUserLastName.Text,
                        Email     = txbxEmail.Text,
                        Password  = txbxPassword.Text,
                        Salary    = Convert.ToInt32(txbxSalary.Text),
                    };
                    dataBase.Sellers.Add(seller);
                    dataBase.SaveChanges();
                    showData();
                    MessageBox.Show("New Seller Is Added");
                    txbxUserFirstName.Clear();
                    txbxUserLastName.Clear();
                    txbxEmail.Clear();
                    txbxPassword.Clear();
                    txbxSalary.Clear();
                }

                if (chkbx3.IsChecked == true)
                {
                    if (txbxUserFirstName.Text == "" || txbxUserLastName.Text == "" || txbxEmail.Text == "" || txbxPassword.Text == "" || txbxSalary.Text == "")
                    {
                        MessageBox.Show("Name Should be Filled!", "Warning!", MessageBoxButton.OK);
                        txbxUserFirstName.Focus();
                        txbxUserLastName.Focus();
                        txbxEmail.Focus();
                        txbxPassword.Focus();
                        txbxSalary.Focus();
                    }
                    var storekeeper = new Storekeeper()
                    {
                        FirstName = txbxUserFirstName.Text,
                        LastName  = txbxUserLastName.Text,
                        Email     = txbxEmail.Text,
                        Password  = txbxPassword.Text,
                        Salary    = Convert.ToInt32(txbxSalary.Text),
                    };
                    dataBase.Storekeepers.Add(storekeeper);
                    dataBase.SaveChanges();
                    showData();
                    MessageBox.Show("New Storekepper Is Added");
                    txbxUserFirstName.Clear();
                    txbxUserLastName.Clear();
                    txbxEmail.Clear();
                    txbxPassword.Clear();
                    txbxSalary.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Registration_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (NameBox.Text == "" || SurnameBox.Text == "" || EmailBox.Text == "" || PassBox1.Password == "")
                {
                    MessageBox.Show("Fill in blank fields!");
                }
                else
                {
                    if (NameBox.Text.Length > 20)
                    {
                        MessageBox.Show("FirstName too long! Try enter shorter name.");
                    }
                    else if (SurnameBox.Text.Length > 20)
                    {
                        MessageBox.Show("LastName too long! Try enter shorter surname.");
                    }
                    else if (EmailBox.Text.Length > 30)
                    {
                        MessageBox.Show("Email not more 30 symbols!");
                    }
                    else if (EmailBox.Text.Length < 7)
                    {
                        MessageBox.Show("Email not more 7 symbols");
                    }
                    else if (PassBox1.Password.Length > 15)
                    {
                        MessageBox.Show("Password not more 15 symbols");
                    }
                    else if (PassBox1.Password.Length < 5)
                    {
                        MessageBox.Show("Password not shorter 5 symbols!");
                    }
                    else if (PassBox1.Password != PassBox2.Password)
                    {
                        MessageBox.Show("Repeat password correctly!");
                        PassBox2.Password = "";
                    }
                    else
                    {
                        try
                        {
                            MailAddress from = new MailAddress("*****@*****.**", "Vered Shop");

                            MailAddress to = new MailAddress(EmailBox.Text);

                            MailMessage mail = new MailMessage(from, to);

                            mail.Subject = "New Client of Vered Shop!!!";

                            mail.Body = $"<h2>Hello, You are new Client of Vered Shop!!! </h2>";

                            mail.IsBodyHtml = true;

                            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

                            smtp.Credentials = new NetworkCredential("*****@*****.**", "algebra12");
                            smtp.EnableSsl   = true;
                            smtp.Send(mail);

                            MessageBox.Show("Message has been sent.", "Message", MessageBoxButton.OK);

                            var client = new Client()
                            {
                                FirstName = NameBox.Text,
                                LastName  = SurnameBox.Text,
                                Email     = EmailBox.Text,
                                Password  = PassBox1.Password,
                            };
                            dataBase.Clients.Add(client);
                            dataBase.SaveChanges();
                        }

                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Message", MessageBoxButton.OK);
                            EmailBox.Text = "";
                        }
                        MessageBox.Show("You are successfully registred!");

                        context = new Context(new ConcreteStrategyF());
                        context.ContextInterface();
                        this.Close();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Wrong data!!!.");
            }
        }