Example #1
0
        private async void buttonUsersAdd_Click(object sender, EventArgs e)
        {
            UserForm     uFAdd = new UserForm();
            DialogResult ress;

            while (true)
            {
                ress = uFAdd.ShowDialog(this);
                if (ress == DialogResult.Cancel)
                {
                    return;
                }
                if (CheckUser(uFAdd.EmailTextBox.Text))
                {
                    UsersLogin user = new UsersLogin();
                    user.Login    = uFAdd.LoginTextBox.Text;
                    user.Password = uFAdd.PasswordTextBox.Text;
                    user.Mail     = uFAdd.EmailTextBox.Text;
                    user.Admin    = uFAdd.AdminCheck.Checked;
                    db.UsersLogins.Add(user);
                    await db.SaveChangesAsync();

                    MessageBox.Show("New Object Added");
                    if (user.Admin == true)
                    {
                        MenegerInfoForm pFormAdd = new MenegerInfoForm();
                        DialogResult    result;
                        while (true)
                        {
                            result = pFormAdd.ShowDialog(this);

                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                            if (CheckUser(pFormAdd.textBoxFullName.Text, pFormAdd.textBoxAddres.Text, pFormAdd.textBoxPhone.Text))
                            {
                                MenedjerInformation prod = new MenedjerInformation();
                                prod.Status      = pFormAdd.textBoxStatus.Text;
                                prod.Address     = pFormAdd.textBoxAddres.Text;
                                prod.FullName    = pFormAdd.textBoxFullName.Text;
                                prod.PhoneNumber = pFormAdd.textBoxPhone.Text;
                                UsersLogin us = db.UsersLogins.FirstOrDefault(u => (u.Login == user.Login || u.Mail == user.Mail) && u.Password == user.Password);
                                if (us != null)
                                {
                                    prod.UserLoginId = us.Id;
                                }
                                prod.DataOfBirth = pFormAdd.dateTimeCreated.Value.Day + "," + pFormAdd.dateTimeCreated.Value.Month + "," + pFormAdd.dateTimeCreated.Value.Year;
                                db.MenedjersInformations.Add(prod);
                                await db.SaveChangesAsync();

                                MessageBox.Show("New Object Added");
                                return;
                            }
                        }
                    }
                    else if (user.Admin == false)
                    {
                        CustumerInfoForm pFormAdd = new CustumerInfoForm();
                        DialogResult     result;
                        while (true)
                        {
                            result = pFormAdd.ShowDialog(this);

                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                            if (CheckUser(pFormAdd.textBoxFullName.Text, pFormAdd.textBoxAddres.Text, pFormAdd.textBoxPhone.Text))
                            {
                                CustomerInformation prod = new CustomerInformation();

                                prod.Address     = pFormAdd.textBoxAddres.Text;
                                prod.ContactFio  = pFormAdd.textBoxFullName.Text;
                                prod.Phone       = pFormAdd.textBoxPhone.Text;
                                prod.UserLoginId = Convert.ToInt32(pFormAdd.numericUpDownUserID.Value);
                                prod.DataOfBirth = pFormAdd.dataTimeBirth.Value.Day + "," + pFormAdd.dataTimeBirth.Value.Month + "," + pFormAdd.dataTimeBirth.Value.Year;
                                UsersLogin us = db.UsersLogins.FirstOrDefault(u => (u.Login == user.Login || u.Mail == user.Mail) && u.Password == user.Password);
                                if (us != null)
                                {
                                    prod.UserLoginId = us.Id;
                                }
                                db.CustomersInformations.Add(prod);
                                await db.SaveChangesAsync();

                                MessageBox.Show("New Object Added");
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private async void buttonMenegerAdd_Click(object sender, EventArgs e)
        {
            MenegerInfoForm pFormAdd = new MenegerInfoForm();
            DialogResult    result;

            while (true)
            {
                result = pFormAdd.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (CheckUser(pFormAdd.textBoxFullName.Text, pFormAdd.textBoxAddres.Text, pFormAdd.textBoxPhone.Text))
                {
                    MenedjerInformation prod = new MenedjerInformation();
                    prod.Status      = pFormAdd.textBoxStatus.Text;
                    prod.Address     = pFormAdd.textBoxAddres.Text;
                    prod.FullName    = pFormAdd.textBoxFullName.Text;
                    prod.PhoneNumber = pFormAdd.textBoxPhone.Text;
                    prod.UserLoginId = Convert.ToInt32(pFormAdd.numericUpDownUserID.Value);
                    prod.DataOfBirth = pFormAdd.dateTimeCreated.Value.Day + "," + pFormAdd.dateTimeCreated.Value.Month + "," + pFormAdd.dateTimeCreated.Value.Year;

                    UsersLogin uL = db.UsersLogins.FirstOrDefault(u => u.Id == prod.UserLoginId);
                    if (uL == null)
                    {
                        MessageBox.Show("To add manager information you need to create an account");
                        UserForm     uFAdd = new UserForm();
                        DialogResult ress;
                        while (true)
                        {
                            ress = uFAdd.ShowDialog(this);
                            if (ress == DialogResult.Cancel)
                            {
                                return;
                            }
                            if (CheckUser(uFAdd.EmailTextBox.Text))
                            {
                                UsersLogin user = new UsersLogin();

                                user.Login    = uFAdd.LoginTextBox.Text;
                                user.Password = uFAdd.PasswordTextBox.Text;
                                user.Mail     = uFAdd.EmailTextBox.Text;
                                user.Admin    = true;

                                db.UsersLogins.Add(user);
                                prod.UserLogin = user;
                                db.MenedjersInformations.Add(prod);
                                await db.SaveChangesAsync();

                                MessageBox.Show("New manager and information about him");
                                return;
                            }
                        }
                    }
                    else
                    {
                        db.MenedjersInformations.Add(prod);
                        await db.SaveChangesAsync();

                        MessageBox.Show("New Object Added");
                        return;
                    }
                }
            }
        }