private void btnDelete_Click(object sender, EventArgs e) { if (dgvEditBooks.SelectedRows.Count > 0) { int id = Convert.ToInt32(dgvEditBooks.SelectedCells[0].Value); var deleted = (from b in _db.Books where b.BookID == id select b).SingleOrDefault(); DialogResult result = MessageBox.Show("Are you sure want to delete the selected reservation?", "Warning !", MessageBoxButtons.YesNo); var change = _db.Books.Where(b => b.BookID == id).FirstOrDefault(); if (result == DialogResult.Yes && change.IsDeleted == false) { change.IsDeleted = true; change.CreatedBy = _kullanici; _db.SaveChanges(); dgvEditBooks.DataSource = ListBooks(); MessageBox.Show("The selected reservation deleted successfully."); } else if (change.IsDeleted == true) { MessageBox.Show("The selected reservation has already deleted."); } } }
private void btnSave_Click(object sender, EventArgs e) { try { var update = _db.Guests.First(g => g.GuestID == _guestID); update.GuestFirstName = txtFirstName.Text; update.GuestLastName = txtLastName.Text; update.GuestPersonelID = txtPersonelID.Text; DialogResult result = MessageBox.Show("Are you sure want to save ?", "Warning !", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { _db.SaveChanges(); MessageBox.Show("The selected guest registration completed successfully."); } else { this.Close(); } } catch (Exception ex) { MessageBox.Show("An error accured."); } finally { this.Close(); } }
private void btnUpdateSave_Click(object sender, EventArgs e) { bool emailKontrol = EmailKontrol(txtEmail.Text); if (emailKontrol != true) { // Tüm KOdlar Burada MessageBox.Show("Mail Adresi Doğru Değil"); return; } bool bosVarMi = false; foreach (var item in grpbxUpdate.Controls) { if (item is TextBox) { if ((item as TextBox).Text == "") { bosVarMi = true; } } } if (bosVarMi == true) { MessageBox.Show("Lütfen müşteri bilgileriyle alakalı tüm alanları doldurunuz"); return; } var secilenKisi = _db.Customers.Where(b => b.CustomerID == _id).FirstOrDefault(); secilenKisi.FirstName = txtFirstName.Text; secilenKisi.LastName = txtLastName.Text; secilenKisi.Phone = txtPhoneNum.Text; secilenKisi.Eposta = txtEmail.Text; secilenKisi.CreatedBy = _kullanici; _db.SaveChanges(); CustomersShow(); }
private void btnCreateBook_Click(object sender, EventArgs e) { //BEGİN TRAN #region Validations bool emailKontrol = EmailKontrol(txtEmail.Text); if (emailKontrol != true) { // Tüm KOdlar Burada MessageBox.Show("Mail Adresi Doğru Değil"); return; } if (mtxtPersonID == null || mtxtPersonID.TextLength != 11) { MessageBox.Show("Tc Numarasını eksik ve ya hatalı girdiniz...."); return; } if (mtxtPhone == null || mtxtPhone.TextLength != 10) { MessageBox.Show("Telefon Numarası eksik ve ya hatalı girdiniz...."); return; } #endregion using (var transaction = _db.Database.BeginTransaction()) { try { Customer customer = new Customer(); var sorgu2 = _db.Customers.Select(x => x.PersonID).ToList(); if (sorgu2.Contains(mtxtPersonID.Text)) { var CustomerID = _db.Customers .Where(x => x.PersonID == mtxtPersonID.Text) .Select(x => x.CustomerID).FirstOrDefault(); customer.CustomerID = CustomerID; MessageBox.Show(customer.CustomerID + " ID numarası ile müşteri işlemleri devam ediyor"); } else { customer.CreatedBy = _kullanici; customer.FirstName = txtFirstName.Text; customer.LastName = txtLastName.Text; customer.Eposta = txtEmail.Text; customer.PersonID = mtxtPersonID.Text; customer.Phone = mtxtPhone.Text; _db.Customers.Add(customer); _db.SaveChanges(); MessageBox.Show(customer.CustomerID + " ID numarası ile müşteri kaydı başarıyla oluşturuldu"); } Book book = new Book(); book.CreatedBy = _kullanici; book.CreatedDate = DateTime.Now; book.CustomerID = customer.CustomerID; book.CheckInDate = _checkInDate.Date; book.CheckOutDate = _checkOutDate; book.NightStay = (short)(_checkOutDate - _checkInDate).Days; book.TotalCost = _totalCost; book.IsDeleted = false; _db.SaveChanges(); _db.Books.Add(book); _db.SaveChanges(); foreach (int item in _selectedRoomss) { BookDetail bd1 = new BookDetail(); //Odanın Fiyatı var RoomPrice = _db.Rooms .Join(_db.RoomDetails, x => x.RoomTypeID, x => x.RoomTypeID, (x, y) => new { x.RoomNumber, y.RoomPrice }) .Where(x => x.RoomNumber == item).Select(x => x.RoomPrice).FirstOrDefault(); bd1.BookID = book.BookID; bd1.RoomNumber = item; bd1.RoomPayment = RoomPrice * ((short)(_checkOutDate - _checkInDate).Days); _db.BookDetails.Add(bd1); _db.SaveChanges(); _bookDetailsIDs.Add(bd1.BookDetailsID); } transaction.Commit(); MessageBox.Show("Reservation completed successfully..."); } catch (Exception ex) { transaction.Rollback(); MessageBox.Show("Warning ! Reservation cancelled."); return; } } cmbRooms.DataSource = _selectedRoomss; cmbRooms.SelectedItem = _selectedRoomss[0]; grpGuestsAdd.Visible = true; }