private async void buttonCustumerAChange_Click(object sender, EventArgs e) { if (dataGridViewCustumers.SelectedRows.Count > 0) { int index = dataGridViewCustumers.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridViewCustumers[0, index].Value.ToString(), out id); if (converted == false) { return; } CustomerInformation prod = db.CustomersInformations.Find(id); CustumerInfoForm pFormChange = new CustumerInfoForm(); string[] spliter = prod.DataOfBirth.Split(','); pFormChange.dataTimeBirth.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.Phone; pFormChange.textBoxFullName.Text = prod.ContactFio; DialogResult result = pFormChange.ShowDialog(this); if (result == DialogResult.Cancel) { return; } prod.Address = pFormChange.textBoxAddres.Text; prod.ContactFio = pFormChange.textBoxFullName.Text; prod.Phone = pFormChange.textBoxPhone.Text; prod.UserLoginId = Convert.ToInt32(pFormChange.numericUpDownUserID.Value); prod.DataOfBirth = pFormChange.dataTimeBirth.Value.Day + "," + pFormChange.dataTimeBirth.Value.Month + "," + pFormChange.dataTimeBirth.Value.Year; await db.SaveChangesAsync(); dataGridViewCustumers.Refresh(); MessageBox.Show("object updated"); } }
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; } } } } } }
private async void buttonCustumerAdd_Click(object sender, EventArgs e) { 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 uL = db.UsersLogins.FirstOrDefault(u => u.Id == prod.UserLoginId); if (uL == null) { MessageBox.Show("To add customer 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.CustomersInformations.Add(prod); await db.SaveChangesAsync(); MessageBox.Show("New client and information about him"); return; } } } else { db.CustomersInformations.Add(prod); await db.SaveChangesAsync(); MessageBox.Show("New Object Added"); return; } } } }