private void SAVE_GUEST() { try { CONNECTION.open_connection(); using (MySqlCommand da = new MySqlCommand("INSERT INTO guest ( guest_id, id_no, first_name, last_name, mobile_no, gender, passport_no, address, email, country_id ) VALUES ( @guest_id, @id_no, @first_name, @last_name, @mobile_no, @gender, @passport_no, @address, @email, @country_id )", CONNECTION.CON)) { da.Parameters.Clear(); da.Parameters.AddWithValue("@guest_id", CLS_GENERATE_ID.GEN_NEXT_GUEST_NO()); da.Parameters.AddWithValue("@id_no", TXT_ID_NUMBER.Text); da.Parameters.AddWithValue("@first_name", TXT_FNAME.Text); da.Parameters.AddWithValue("@last_name", TXT_LNAME.Text); da.Parameters.AddWithValue("@mobile_no", TXT_MOBILENO.Text); da.Parameters.AddWithValue("@gender", CMB_GENDER.Text); da.Parameters.AddWithValue("@passport_no", TXT_PASSPORT.Text); da.Parameters.AddWithValue("@address", TXT_ADDRESS.Text); da.Parameters.AddWithValue("@email", TXT_EMAIL.Text); da.Parameters.AddWithValue("@country_id", CMB_COUNTRY.SelectedValue); if (da.ExecuteNonQuery() > 0) { LBL_GUEST.Text = CLS_METHODS.GET_MAX_STRING_ID("SELECT MAX(guest_id) FROM guest"); MSGBOX mdg = new MSGBOX(MessageAlertHeder.Success(), "GUEST ADDED SUCCESFULLY!", MessageAlertImage.Success()); mdg.ShowDialog(); } else { MSGBOX mdg = new MSGBOX(MessageAlertHeder.Alert(), "GUEST ADDED FAILED!", MessageAlertImage.Alert()); mdg.ShowDialog(); } } } catch (Exception ex) { MSGBOX mdg = new MSGBOX(MessageAlertHeder.Error(), ex.Message, MessageAlertImage.Error()); mdg.ShowDialog(); } finally { CONNECTION.close_connection(); } }
private void SAVE_RESERVATION() { try { Cursor.Current = Cursors.WaitCursor; LOCK_CONTROLLERS(); CONNECTION.open_connection(); myTrans = CONNECTION.CON.BeginTransaction(); cmd.Connection = CONNECTION.CON; cmd.Transaction = myTrans; string GUESTID = string.Empty; string RES = CHECK_GUEST_DATA(); string RESERVATION_ID = CLS_GENERATE_ID.GEN_NEXT_RESERVATION_NO(); if (RES != "N") { GUESTID = RES; } else { GUESTID = CLS_GENERATE_ID.GEN_NEXT_GUEST_NO(); cmd.CommandText = "INSERT INTO guest ( guest_id, id_no, first_name, last_name, mobile_no, gender, passport_no, address, email, country_id ) VALUES ( @guest_id, @id_no, @first_name, @last_name, @mobile_no, @gender, @passport_no, @address, @email, @country_id )"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@guest_id", GUESTID); cmd.Parameters.AddWithValue("@id_no", TXT_NIC_NO.Text); cmd.Parameters.AddWithValue("@first_name", TXT_F_NAME.Text); cmd.Parameters.AddWithValue("@last_name", TXT_L_NAME.Text); cmd.Parameters.AddWithValue("@mobile_no", TXT_TEL.Text); cmd.Parameters.AddWithValue("@gender", "MALE"); cmd.Parameters.AddWithValue("@passport_no", "N/A"); cmd.Parameters.AddWithValue("@address", "N/A"); cmd.Parameters.AddWithValue("@email", TXT_EMAIL.Text); cmd.Parameters.AddWithValue("@country_id", 199); cmd.ExecuteNonQuery(); } TEMP_GUEST_ID = CLS_METHODS.GET_MAX_STRING_ID("SELECT MAX(guest_id) FROM guest"); cmd.CommandText = "INSERT INTO reservation ( reservation_id, guest_id, no_of_adult, no_of_child, arrival_date, depature_Date, no_of_nights, reserved_by, agent_id, additional_note,added_date,added_time,added_by,no_of_rooms,tax_status ) VALUES ( @reservation_id, @guest_id, @no_of_adult, @no_of_child, @arrival_date, @depature_Date, @no_of_nights, @reserved_by, @agent_id, @additional_note,@added_date,CURTIME(),@added_by,@no_of_rooms,@tax_status )"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@reservation_id", RESERVATION_ID); cmd.Parameters.AddWithValue("@guest_id", GUESTID); cmd.Parameters.AddWithValue("@no_of_adult", Convert.ToInt16(TXT_ADULT.Text)); cmd.Parameters.AddWithValue("@no_of_child", Convert.ToInt16(TXT_CHILD.Text)); cmd.Parameters.AddWithValue("@arrival_date", DTP_ARRIVAL_DATE.Value.ToShortDateString()); cmd.Parameters.AddWithValue("@depature_Date", DTP_DEPATURE_DATE.Value.ToShortDateString()); cmd.Parameters.AddWithValue("@no_of_nights", (DTP_DEPATURE_DATE.Value - DTP_ARRIVAL_DATE.Value).TotalDays); cmd.Parameters.AddWithValue("@reserved_by", CMB_RESERVE_BY.Text); cmd.Parameters.AddWithValue("@no_of_rooms", Convert.ToInt16(TXT_NO_OF_ROOMS.Text)); if (CMB_TAX.SelectedIndex == 0) { cmd.Parameters.AddWithValue("@tax_status", "1"); } else { cmd.Parameters.AddWithValue("@tax_status", "0"); } if (CMB_RESERVE_BY.SelectedIndex == 3) { cmd.Parameters.AddWithValue("@agent_id", CMB_AGENT.SelectedValue); } else { cmd.Parameters.AddWithValue("@agent_id", "0"); } cmd.Parameters.AddWithValue("@additional_note", TXT_NOTE.Text); cmd.Parameters.AddWithValue("@added_date", DateTime.Now.ToShortDateString()); cmd.Parameters.AddWithValue("@added_by", CLS_CURRENT_LOGGER.LOGGED_IN_USERID); cmd.ExecuteNonQuery(); foreach (ListViewItem lvi in LST_SELECTED_ROOM.Items) { cmd.CommandText = "INSERT INTO recerved_rooms ( reservation_no, room_id, room_charge ) VALUES ( @reservation_no, @room_id, @room_charge)"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@reservation_no", RESERVATION_ID); cmd.Parameters.AddWithValue("@room_id", Convert.ToInt32(lvi.SubItems[0].Text)); cmd.Parameters.AddWithValue("@room_charge", Convert.ToDouble(lvi.SubItems[3].Text)); cmd.ExecuteNonQuery(); cmd.CommandText = "UPDATE room SET current_status=@current_status WHERE room_id=@room_id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@room_id", Convert.ToInt32(lvi.SubItems[0].Text)); cmd.Parameters.AddWithValue("@current_status", "RESERVED"); cmd.ExecuteNonQuery(); } myTrans.Commit(); LBL_RESERVATION_ID.Text = RESERVATION_ID; MSGBOX mdg = new MSGBOX(MessageAlertHeder.Success(), "RESERVATION ADDED SUCCESFULLY" + Environment.NewLine + Environment.NewLine + "RESERVATION NO IS : " + RESERVATION_ID, MessageAlertImage.Success()); mdg.ShowDialog(); BTN_NEW.Focus(); } catch (Exception EX) { Cursor.Current = Cursors.Default; UNLOCK_CONTROLLERS(); myTrans.Rollback(); MSGBOX mdg = new MSGBOX(MessageAlertHeder.Error(), EX.Message, MessageAlertImage.Error()); mdg.ShowDialog(); } finally { UNLOCK_CONTROLLERS(); Cursor.Current = Cursors.Default; CONNECTION.close_connection(); } }