public int SaveUpdateBookingCust(PlaneBook planeBook)
 {
     try
     {
         return(_planeBookRepo.SaveUpdateBookingCust(planeBook));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public int SaveUpdateBookingCust(PlaneBook planeBook)
        {
            DataTable dataTable = CheckBookStatus(planeBook.PlaneId, planeBook.Departure);

            if (dataTable.Rows.Count > 0)
            {
                return(0);
            }
            else
            {
                if (planeBook.Id > 0)
                {
                    string         sqlQuery2 = "Update PlaneBook set PlaneId = @PlaneId, BookedBy = @BookedBy, CustomerId = @CustomerId, Departure = @Departure, Arrival = @Arrival where Id = @Id";
                    SqlParameter[] param2    = new SqlParameter[]
                    {
                        new SqlParameter("@Id", planeBook.Id),
                        new SqlParameter("@BookedBy", planeBook.BookedBy),
                        new SqlParameter("@PlaneId", planeBook.PlaneId),
                        new SqlParameter("@CustomerId", planeBook.CustomerId),
                        new SqlParameter("@Departure", planeBook.Departure),
                        new SqlParameter("@Arrival", planeBook.Arrival)
                    };
                    return(_dBO.IUD(sqlQuery2, param2, CommandType.Text));
                }
                else
                {
                    string         sqlQuery = "Insert into PlaneBook(BookedBy, PlaneId, CustomerId, Departure, Arrival) values(@BookedBy, @PlaneId, @CustomerId, @Departure, @Arrival)";
                    SqlParameter[] param    = new SqlParameter[]
                    {
                        new SqlParameter("@BookedBy", planeBook.BookedBy),
                        new SqlParameter("@PlaneId", planeBook.PlaneId),
                        new SqlParameter("@CustomerId", planeBook.CustomerId),
                        new SqlParameter("@Departure", planeBook.Departure),
                        new SqlParameter("@Arrival", planeBook.Arrival)
                    };
                    return(_dBO.IUD(sqlQuery, param, CommandType.Text));
                }
            }
        }
Beispiel #3
0
 private void btnSavePlaneBooking_Click(object sender, EventArgs e)
 {
     try
     {
         int    custId = 0, cargoId = 0;
         string bookedBy = txtBookedBy.Text.Trim();
         int.TryParse(ddlPlaneName.SelectedValue.ToString(), out int planeId);
         DateTime departure = dtPDeparture.Value;
         DateTime arrival   = dtPArrival.Value;
         if (ddlPlaneType.Text == "Cargo")
         {
             int.TryParse(ddlCargoItem.SelectedValue.ToString(), out cargoId);
             if (bookedBy == "" && planeId == 0 && cargoId == 0)
             {
                 MessageBox.Show("Enter booked by and select plane and cargo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 if (bookedBy == "")
                 {
                     MessageBox.Show("Booked by field is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else if (planeId == 0)
                 {
                     MessageBox.Show("Select a plane", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else if (cargoId == 0)
                 {
                     MessageBox.Show("Select a cargo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     PlaneBook planeBook = new PlaneBook
                     {
                         BookedBy  = bookedBy,
                         PlaneId   = planeId,
                         CargoId   = cargoId,
                         Departure = departure
                     };
                     if (btnSavePlaneBooking.Text == "Save")
                     {
                         int bookSucc = _planeBookService.SaveUpdateBookingCargo(planeBook);
                         if (bookSucc > 0)
                         {
                             MessageBox.Show("Plane booked successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             LoadAllBookingsCurrentDate();
                             BookingClearance();
                         }
                         else if (bookSucc == 0)
                         {
                             MessageBox.Show("Plane already booked for this time", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                     else
                     {
                         planeBook.Id = bookId;
                         int bookSucc = _planeBookService.SaveUpdateBookingCargo(planeBook);
                         if (bookSucc > 0)
                         {
                             MessageBox.Show("Plane booking updated successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             LoadAllBookingsCurrentDate();
                             BookingClearance();
                         }
                         else if (bookSucc == 0)
                         {
                             MessageBox.Show("Plane already booked for this time", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                 }
             }
         }
         else
         {
             int.TryParse(ddlCustName.SelectedValue.ToString(), out custId);
             if (bookedBy == "" && planeId == 0 && custId == 0)
             {
                 MessageBox.Show("Select plane and customer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 if (bookedBy == "")
                 {
                     MessageBox.Show("Booked by field is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else if (planeId == 0)
                 {
                     MessageBox.Show("Select a plane", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else if (custId == 0)
                 {
                     MessageBox.Show("Select a customer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     PlaneBook planeBook = new PlaneBook
                     {
                         BookedBy   = bookedBy,
                         PlaneId    = planeId,
                         CustomerId = custId,
                         Departure  = departure,
                         Arrival    = arrival
                     };
                     if (btnSavePlaneBooking.Text == "Save")
                     {
                         int bookSucc = _planeBookService.SaveUpdateBookingCust(planeBook);
                         if (bookSucc > 0)
                         {
                             MessageBox.Show("Plane booked successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             BookingClearance();
                             LoadAllBookingsCurrentDate();
                         }
                         else if (bookSucc == 0)
                         {
                             MessageBox.Show("Plane already booked for this time", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                     else
                     {
                         planeBook.Id = bookId;
                         int bookSucc = _planeBookService.SaveUpdateBookingCust(planeBook);
                         if (bookSucc > 0)
                         {
                             MessageBox.Show("Plane booking updated successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             BookingClearance();
                             LoadAllBookingsCurrentDate();
                         }
                         else if (bookSucc == 0)
                         {
                             MessageBox.Show("Plane already booked for this time", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }