private void btn_Edit_Click(object sender, EventArgs e) { if (dataGridView_Books.SelectedRows.Count == 1) { int index = dataGridView_Books.SelectedRows[0].Index; int ID = 0; if (Int32.TryParse(dataGridView_Books[0, index].Value.ToString(), out ID)) { var editObj = db.Books.Where(g => g.ID_BOOK == ID).Select(g => g).FirstOrDefault(); EditForm editForm = new EditForm(editObj); if (editForm.ShowDialog() == DialogResult.OK) { db.SaveChanges(); dataGridView_Books.DataSource = db.Books.ToList(); dataGridView_Books.Refresh(); dataGridView_Books.Update(); } } } else { MessageBox.Show("Chose one book"); } }
private void btn_Buy_Click(object sender, EventArgs e) { string nameOfBook = ""; var deleteObj = from item in db.Books where item.ID_BOOK == BOOK_ID select item; foreach (var item in deleteObj) { db.Books.Remove(item); nameOfBook = item.NameBook; Sale new_sale = new Sale() { ID_BOOK = BOOK_ID, Login = currUser.Login, DateOfSale = DateTime.Now, Price = item.SalePrice }; db.Sales.Add(new_sale); } db.SaveChanges(); //Send to message string msg = "City: " + txtBox_City.Text + ", Post office: " + txtBox_Post.Text + ", Phone number: " + txtBox_Phone.Text + ", Book: " + nameOfBook; MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "order", msg); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new NetworkCredential("*****@*****.**", "KORZIK19"); client.EnableSsl = true; client.Send(message); /////////////////////////////////////////////////////////////////////// dataGridView_Cart.DataSource = (from item in db.Books join item2 in db.Carts on item.ID_BOOK equals item2.Book_ID where item2.User_Login == currUser.Login select item).ToList(); dataGridView_Books.DataSource = db.Books.ToList(); dataGridView_Cart.Refresh(); dataGridView_Cart.Update(); groupBox1.Visible = false; }
private void btn_Add_Click(object sender, EventArgs e) { Book new_bok = new Book() { Fio = txtBox_Fio.Text, PublishName = txtBox_PublishName.Text, NameBook = txtBox_BookName.Text, Price = Convert.ToInt32(txtBox_Price.Text), Pages = Convert.ToInt32(txtBox_Pages.Text), SalePrice = Convert.ToInt32(txtBox_SalePrice.Text), DateOfPublishing = dateTimePicker.Value.Date }; db.Books.Add(new_bok); db.SaveChanges(); this.DialogResult = DialogResult.OK; }
private void Btn_SignIn_Click(object sender, EventArgs e) { Regex regex = new Regex("^[a-zA-Z0-9]+([._]?[a-zA-Z0-9]+){5}$"); string input_login = txtBox_login.Text; string input_password = txtBox_password.Text; if (regex.Match(input_login).Success&& regex.Match(input_password).Success) { txtBox_password.BackColor = Color.White; txtBox_login.BackColor = Color.White; if (signInForm) //SIGN IN { //ADMIN if (input_login == admin_login && input_password == admin_pass) { Admin adminForm = new Admin(); this.Hide(); if (adminForm.ShowDialog() == DialogResult.OK) { this.Show(); } else { Application.Exit(); } } else { int corect_login = db.Users.Where(user => user.Login == input_login).Count(); if (corect_login == 1) { var corect_password = db.Users.Where(user => user.Login == input_login).Where(user => user.Password == input_password.ToString()).Count(); if (corect_password == 1) { this.DialogResult = DialogResult.OK; currentUser = new User() { Login = input_login, Password = password }; } else { txtBox_password.BackColor = Color.PaleVioletRed; MessageBox.Show("Incorrect password"); } } else { txtBox_login.BackColor = Color.PaleVioletRed; MessageBox.Show("Incorrect username"); } } //END } //END else //Create Acount { using (BookStoreEntities db = new BookStoreEntities()) { User newUser = new User() { Login = txtBox_login.Text, Password = txtBox_password.Text }; db.Users.Add(newUser); db.SaveChanges(); MessageBox.Show("Created new user"); } }//End } else { if (!regex.Match(input_password).Success) { txtBox_password.BackColor = Color.PaleVioletRed; } if (!regex.Match(input_login).Success) { txtBox_login.BackColor = Color.PaleVioletRed; } } }