private void btnUpdate_Click(object sender, EventArgs e) { using (var context = new BookLotEntities()) { try { int bookId = Int32.Parse(txtBookId.Text); Books booksToUpdate = context.BookCategories.Find(bookId); if (booksToUpdate != null) { booksToUpdate.BookId = Int32.Parse(txtBookId.Text); booksToUpdate.AuthorId = Int32.Parse(txtAuthorId.Text); booksToUpdate.PublisherId = Int32.Parse(txtAuthorId.Text); booksToUpdate.Title = txtTitle.Text; booksToUpdate.ISBN = txtISBN.Text; booksToUpdate.Genre = txtGenre.Text; booksToUpdate.Type = txtType.Text; booksToUpdate.PublicationYear = txtPubYear.Text; booksToUpdate.Price = Int32.Parse(txtPrice.Text); booksToUpdate.Condition = txtCondition.Text; context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Empty format, try again"); } } }
public bool Register(User buf) { BookLotEntities context = new BookLotEntities(); var user = context.Users.FirstOrDefault(item => item.Login == buf.Login); if (user != null) { return(false); } //else //{ // if (buf.Photo != null && buf.PhotoName != null) // { // FtpWebRequest requestFind = (FtpWebRequest)WebRequest.Create(localpath); // requestFind.Method = WebRequestMethods.Ftp.ListDirectory; // requestFind.Credentials = new NetworkCredential("OlegKret", "26021982OlegKret"); // FtpWebResponse responseFind = (FtpWebResponse)requestFind.GetResponse(); // Stream streamFind = responseFind.GetResponseStream(); // StreamReader readerFind = new StreamReader(streamFind); // string files = readerFind.ReadToEnd(); // readerFind.Close(); // streamFind.Close(); // responseFind.Close(); // if (files.Contains(buf.PhotoName)) // { // return false; // } // else // { // FtpWebRequest requestCreate = (FtpWebRequest)WebRequest.Create(localpath + buf.PhotoName); // requestCreate.Method = WebRequestMethods.Ftp.UploadFile; // requestCreate.Credentials = new NetworkCredential("OlegKret", "26021982OlegKret"); // Stream streamCreate = requestCreate.GetRequestStream(); // streamCreate.Write(buf.Photo, 0, buf.Photo.Length); // streamCreate.Close(); // FtpWebResponse responseCreate = (FtpWebResponse)requestCreate.GetResponse(); // responseCreate.Close(); // } // } context.Users.Add(buf); context.SaveChanges(); return(true); }
private void btnDelete_Click(object sender, EventArgs e) { int bookId = Int32.Parse(txtBookId.Text); using (var context = new BookLotEntities()) { Books booksToDelete = new Books() { BookId = bookId }; context.Entry(booksToDelete).State = EntityState.Deleted; context.SaveChanges(); } }
//private void btnEnter_Click(object sender, EventArgs e) //{ // try // { // if (txtLogin.Text == "") // { // throw new EmptyLoginException("Введіть логін!"); // } // if (txtPassword.Text == "") // { // throw new EmptyPasswordException("Введіть пароль!"); // } // AccountClient accountClient = new AccountClient(); // User input = accountClient.Login(txtLogin.Text, txtPassword.Text); // if (input != null) // { // MessageBox.Show("Вхід успішний!"); // //if (input.PhotoName != null) // //{ // // Form2 form2 = new Form2(accountClient.GetImage(input.PhotoName)); // // form2.ShowDialog(); // //} // //else // //{ // // Form2 form2 = new Form2(null); // // form2.ShowDialog(); // //} // } // if (input == null) // { // MessageBox.Show("Ви НЕ ввійшли в особистий кабінет! \n Перевірте логін і пароль!"); // } // accountClient.Close(); // } // catch (EmptyLoginException emptyLoginException) // { // MessageBox.Show(emptyLoginException.Message); // } // catch (EmptyPasswordException emptyPasswordException) // { // MessageBox.Show(emptyPasswordException.Message); // } // catch (Exception exception) // { // MessageBox.Show(exception.Message); // } //} private void btnSave_Click(object sender, EventArgs e) { //Service1Client client = new Service1Client(); Books books = new Books(); //client.Add(books); //client.Save(books); books.AuthorId = Int32.Parse(txtAuthorId.Text); books.PublisherId = Int32.Parse(txtPublisherId.Text); books.Title = txtTitle.Text; books.ISBN = txtISBN.Text; books.Genre = txtGenre.Text; books.Type = txtType.Text; books.PublicationYear = txtPubYear.Text; books.Price = Int32.Parse(txtPrice.Text); books.Condition = txtCondition.Text; BookLotEntities lotEntities = new BookLotEntities(); lotEntities.BookCategories.Add(books); lotEntities.SaveChanges(); }