Ejemplo n.º 1
0
        private async void buttonMenegerChange_Click(object sender, EventArgs e)
        {
            if (dataGridViewMenegers.SelectedRows.Count > 0)
            {
                int  index     = dataGridViewMenegers.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridViewMenegers[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                MenedjerInformation prod        = db.MenedjersInformations.Find(id);
                MenegerInfoForm     pFormChange = new MenegerInfoForm();
                string[]            spliter     = prod.DataOfBirth.Split(',');
                pFormChange.dateTimeCreated.Value     = new DateTime(Convert.ToInt32(spliter[2]), Convert.ToInt32(spliter[1]), Convert.ToInt32(spliter[0]));
                pFormChange.numericUpDownUserID.Value = Convert.ToDecimal(prod.UserLoginId);
                pFormChange.textBoxAddres.Text        = prod.Address;
                pFormChange.textBoxPhone.Text         = prod.PhoneNumber;
                pFormChange.textBoxFullName.Text      = prod.FullName;
                pFormChange.textBoxStatus.Text        = prod.Status;
                DialogResult result = pFormChange.ShowDialog(this);

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

                await db.SaveChangesAsync();

                dataGridViewMenegers.Refresh();
                MessageBox.Show("object updated");
            }
        }
Ejemplo n.º 2
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;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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;
                    }
                }
            }
        }