public static PreTourBooking GetPreBooked(int parResNum, int parPCIID, int parHotelNumber, int FromLive, out int count)
    {
        PreTourBooking retval = new PreTourBooking();

        SqlParameter pOut = new SqlParameter("@Count", SqlDbType.Int, 4);
        pOut.Direction = ParameterDirection.Output;

        SqlParameter[] param = new SqlParameter[]{
            new SqlParameter("@FromLive", FromLive),
            new SqlParameter("@parReservationNum", parResNum),
            new SqlParameter("@parPCIID", parPCIID),
            new SqlParameter("@HotelNumber", parHotelNumber),
            pOut
        };
        using (SqlDataReader reader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, "Select_PreBooked", param))
        {
            if (reader.Read())
            {
                //retval.Add(Read(reader));
                retval = Read(reader);
            }
        }

        count = Helper.ToInt32(pOut.Value);

        return retval;
    }
    public static PreTourBooking Read(SqlDataReader reader)
    {
        PreTourBooking retval = new PreTourBooking();

        for (int i = 0; i < reader.FieldCount; i++)
        {
            switch (reader.GetName(i))
            {
                case "DateContacted":
                    retval.DateContacted = Helper.ToDateTime(reader[i]);
                    break;
                case "ContactedBy":
                    retval.ContactedBy = Helper.ToString(reader[i]);
                    break;
                case "HotelNumber":
                    retval.HN = Helper.ToInt32(reader[i]);
                    break;
                case "InterestedInTour":
                    retval.InterestedInTour = Helper.ToString(reader[i]);
                    break;
                case "Invited":
                    retval.Invited = Helper.ToBoolean(reader[i]);
                    break;
                case "FollowUpDate":
                    retval.FollowUpDate = Helper.ToDateTime(reader[i]);
                    break;
                case "Status":
                    retval.Status = Helper.ToString(reader[i]);
                    break;
                case "FollowUpTime":
                    retval.FollowUpTime = Helper.ToString(reader[i]);
                    break;
                case "NQTypesID":
                    retval.NQTypesID = Helper.ToInt32(reader[i]);
                    break;
                case "NQTypes":
                    retval.NQTypesDesc = Helper.ToString(reader[i]);
                    break;
                case "ProspectId":
                    retval.ProspectID = Helper.ToInt32((reader[i]));
                    break;
                case "TourID":
                    retval.TourID = Helper.ToInt32((reader[i]));
                    break;
            }
           }

        return retval;
    }
    public static PreTourBooking Insert_PreBookedTour(PreTourBooking value)
    {
        //throw new Exception("Writing RSNO: " + value.SubReservationNumber);
        PreTourBooking retval = new PreTourBooking();
        SqlParameter[] param = new SqlParameter[] {
            new SqlParameter("@FromLive", value.FromLive),
            new SqlParameter("@ReservationNum", value.ReservationNumber),
            new SqlParameter("@SubReservationNum", value.SubReservationNumber),

            new SqlParameter("@PCIID", value.PCIID),
            new SqlParameter("@HotelNumber", value.HN),
            new SqlParameter("@DateContacted", value.DateContacted),
            new SqlParameter("@ContactedBy", value.ContactedBy),
            new SqlParameter("@InterestedInTour", value.InterestedInTour),
            new SqlParameter("@FollowUpDate", value.FollowUpDate),
            new SqlParameter("@FollowUpTime", value.FollowUpTime),
            new SqlParameter("@Invited", value.Invited),
            new SqlParameter("@NQTypesID", value.NQTypesID),
            new SqlParameter("@Status", value.Status)
        };

            SqlHelper.ExecuteNonQuery(Helper.ConnectionString, CommandType.StoredProcedure, "Insert_PreBookedTour", param);
        return retval;
    }
    protected void btnBook_Click(object sender, EventArgs e)
    {
        //insert in TSW
        //For the hotel location check the times(time 1, time 2, time 3 it's being used military time) and also if the hotel location has enough presenters
        //Validate that the prospect doesn't exist by(email, name and telephone number)
        //DOB, Marital status,
        //emailid
        //phone numberid
        //Names(Guest1, Guest2)

        //MemberCompany item = new MemberCompany();

        //New Code 10/27/10 Check that the fields are not blanc
        if (ddlTourTime.SelectedValue == string.Empty || ddlTourTime.SelectedValue == string.Empty || ddlTourTime.SelectedValue == string.Empty)
        {

            lblValidation.Text = "Values cannot be blank.";
            return;
        }

        lblValidation.Text = "";
        TSWProspect itemProspect = new TSWProspect();
        TSWProspect itemProspectSrc = new TSWProspect();
        TSWProspect itemProspectType = new TSWProspect();
        TSWProspect itemProspectStatus = new TSWProspect();
        TSWTour itemTour = new TSWTour();
        TSWTour itemTourID = new TSWTour();
        Personnel itemPersonnel = new Personnel();
        Premiums itemPremiums = new Premiums();
        PreTourBooking itemPreTourBooking = new PreTourBooking();

        itemProspect.FromLive = m_FromLive;
        itemProspectSrc.FromLive = m_FromLive;
        itemProspectType.FromLive = m_FromLive;
        itemProspectStatus.FromLive = m_FromLive;
        itemTour.FromLive = m_FromLive;
        itemTourID.FromLive = m_FromLive;
        //dcitemProspect.HN =  SIHOTHotelCode; //Hotel Number from SIHOT
        itemProspect.HN = SiteId; //Hotel Number from SIHOT
        itemProspect.Salutation = hdnSalutation.Value;
        itemProspect.Title = hdnSalutation.Value;
        itemProspect.CN = lblFName.Text;
        itemProspect.SN = lblLastName.Text ;
        itemProspect.Address.Street1 = hdnStreet.Value;
        itemProspect.Address.City = hdnCity.Value;
        itemProspect.Address.State = hdnState.Value;
        itemProspect.Address.Country = hdnCountry.Value;
        itemProspect.Address.Zip = hdnZipCode.Value;
        itemProspect.Phone = hdnPhone1.Value;
        itemProspect.Phone2 = hdnPhone2.Value;
        itemProspect.Fax = hdnFax.Value;
        itemProspect.EMAIL = hdnEmail.Value;

        //throw new Exception(ddlMarital1.SelectedValue);
        itemProspect.MaritalID = Helper.ToInt32(ddlMarital1.SelectedValue);
        //throw new Exception(ddlMarital1.SelectedItem.Text);
        itemProspect.MaritalStatus = ddlMarital1.SelectedItem.Text;
        itemProspect.OccupationID=Helper.ToInt32(ddlOccupation.SelectedValue);
        itemProspect.Occupation=ddlOccupation.SelectedItem.Text;
        itemProspect.IncomeID = Helper.ToInt32(ddlIncome.SelectedValue);
        itemProspect.DOB=txtDOB.Text;

        //Get the SourceID thru stored procedure
        //ws_usp_GetProspectSourcePMSInterface

        itemProspectSrc= TSWProspectDB.GetProspectSource(itemProspect);
        itemProspect.ProspectSourceID = itemProspectSrc.ProspectSourceID;
        itemProspect.ProspectSourceDesc = itemProspectSrc.ProspectSourceDesc;
        //throw new Exception(itemProspect.SN + itemProspect.ProspectSourceID.ToString());

        //Get the ProspectTypeId thru stored procedure
        //ws_usp_GetProspectType
        //itemProspect= TSWProspectDB.GetProspectType(itemProspect.FromLive);
        //itemProspect.ProspectTypeDesc = "";
        itemProspectType= TSWProspectDB.GetProspectType(itemProspect);
        itemProspect.ProspectTypeID = itemProspectType.ProspectTypeID;
        itemProspect.ProspectTypeDesc = itemProspectType.ProspectTypeDesc;
        //Get the prospectStausID thru stored procedure
        //ws_usp_GetProspectStatus
           itemProspectStatus= TSWProspectDB.GetProspectStatus(itemProspect);
           itemProspect.ProspectStatusID = itemProspectStatus.ProspectStatusID;
           itemProspect.ProspectStatusDesc = itemProspectStatus.ProspectStatusDesc;
        //itemProspect.ProspectStatusID = 1;
        //itemProspect.ProspectStatusDesc = "";

        //Step 1. Validate that the prospect doesn't exist
        //SearchEmail and SerachPhone APIsol

        //The fields to validate are Phonenumber, email address, lastname and first name
        //Fill the options the existing ones and give them the chance to select and option in order to make an update later.

        //Code for MiniVacs
           if (lblprospectID.Text != string.Empty && lblTourID.Text!=string.Empty)
           {
        //Process MiniVacs requirements on the side
        //Use ProspectID and TourID already in place for the MiniVacs
        return;
           }

            if (ProspectId == 0 && itemProspect.SN.Trim() != string.Empty && itemProspect.CN.Trim() != string.Empty && (itemProspect.Phone.Trim() != string.Empty || itemProspect.EMAIL.Trim() != string.Empty)) //does't exist the prospect id. I can assign the value of the porspectId from the check dups prospects
            {

                //throw new Exception(ProspectId.ToString() + itemProspect.SN + itemProspect.CN + (itemProspect.Phone.Trim() != string.Empty).ToString() + (itemProspect.EMAIL.Trim() != string.Empty).ToString());

                int count = 0;
                TSWProspectList itemProspectList = TSWProspectDB.SearchUniqueProspect(itemProspect, out count); //check the four fields  this needs to change NOW

                if (count > 0 && count != null)
                {
                    //this needs to change NOW
                    rptDuplicates.DataSource = TSWProspectDB.GetDupsProspects(itemProspect);
                    rptDuplicates.DataBind();

                    //show the prospectId on top. The assignment of the prospectId happens in the the ItemDatabound of the repeater
                    lblprospectID.Text = Helper.ToString(ProspectId);
                    lblProspectDup.Text = "This prospect already exist in TSW and may have attended to the presentation in the past.";
                    PnlDups.Visible = true;
                    //return;
                    lblConfRNumber.Text = " <font color=red><b>" + ProspectId
        + " Pre-Existing ProspectId</b></font>";

                }
                else //if doesn't exist in the dups then Insert
                {
                    ProspectId = TSWProspectDB.InsertTSW_Prospect(itemProspect);
                    lblConfRNumber.Text = " <font color=red><b>" + ProspectId
                + "</b></font>";
                    if (ProspectId == 0)
                    {
                        lblConfRNumber.Text = "Error Creating Prospect";
                        return;
                    }
                }
            }

            else if (lblprospectID.Text == string.Empty)
                {

                    //*****************************************
                    //*****************************************
                    //*****************************************
                    //I still need to check the Search FName & LastName. Insert happens, this means that the prospect doesn't exit
                    //if (SearchEmail() != "true" && SearchPhone() != "true")
                    //{

                    //throw new Exception(itemProspect.ProspectTypeID + " " +  itemProspect.ProspectTypeDesc + " " + itemProspect.ProspectStatusID + " " + itemProspect.ProspectSourceID);

                    ProspectId = TSWProspectDB.InsertTSW_Prospect(itemProspect);
                //call the TUNA here TRANSUNION
                //call the TUNA here TRANSUNION
                    //if (m_FromLive == 1)
                    //{
                    //    ParseStringFWD_TOne_prod();
                        //SaveResults_TUNA_prod();
                    //}
                    //else
                    //{
                        //ParseStringFWD_TOne_test();
                    //    SaveResults_TUNA_test();
                    //}

                    //call the TUNA here TRANSUNION
                    //call the TUNA here TRANSUNION

                lblConfRNumber.Text = " <font color=red><b>" + ProspectId
                + "</b></font>";
                    if (ProspectId == 0)
                    {
                        lblConfRNumber.Text = "Error Creating Prospect";
                        return;
                    }

        }
        //the one that says about the prospect
        phNewProspect.Visible = true;

        //}
        //else
        //{
        ////Step 2.or make an update WebAPI_UpdateTourProspect
        //    lblConfRNumber.Text = " <font color=red><b>" + Helper.ToString(TSWProspectDB.UpdateTSW_Prospect(itemProspect)) + "</b></font>";
        //}
        //*****************************************
        //*****************************************
        //*****************************************
        //Step 3 Create the Tour webapibooked tour
        itemTour.FromLive = m_FromLive;
        itemTour.SiteID=SiteId;
        itemTour.ProspectId = ProspectId;
        itemTour.CampaignID = Helper.ToInt32(ddlCampaign.SelectedValue);

        //Get the tourTypeId New Member addition
        //TourTypeID:7866 TourType: 'Members'
        //case statement
        //throw new Exception(hdnDisplaySegment.Value);
        if (hdnDisplaySegment.Value.ToLower().Contains("members") == true)
        {
            itemTour.TourTypeDesc = "Members";
        }
        else
        {
            itemTour.TourTypeDesc = "In House";
        }

        //itemTour.TourTypeDesc = "In House";
        itemTourID = TSWTourDB.GetTourTypeID(itemTour);

        itemTour.TourTypeID = itemTourID.TourTypeID; //"In House=190" VALUE
        itemTour.TourLocationID = Helper.ToInt32(ddlTourLocation.SelectedValue);
        itemTour.TourDate=Helper.ToDateTime(txtTourDate.Text).Value;
        //itemTour.PreAssignedTo = ddlPromotorName.SelectedValue;
        itemTour.waveID=Helper.ToInt32(ddlTourTime.SelectedValue);
        //Response.Write(itemTour.SiteID + " " + itemTour.ProspectId + " " + itemTour.CampaignID + " " + itemTourID.TourTypeID + " " + itemTour.TourLocationID + " " + itemTour.TourDate + " " + itemTour.waveID);
           //Inserts the Tour in table t_tour. Return string "success or failure" and the tourid
          TSWTourList itemTourReturn = TSWTourDB.InsertTSW_Tour(itemTour);
         foreach (TSWTour item in itemTourReturn)
         {
          lblErrors.Text = "";
          if (item.ReturnValue !=0)
          {
              lblErrorsTour.Visible = true;
              lblErrorsTour.Text += "Error creating Tour: " + item.ReturnValue + ", " + item.ReturnString;
              lblErrors.Text += "Error creating Tour: " + item.ReturnValue + ", " + item.ReturnString;
              PnlError.Visible = true;
          }
          else
          {
              TourId = item.TourID;
              lblErrors.Text += "Tour Created Succesfully:" + TourId;
              PnlError.Visible = true;
          }
          }

        //lblConfRNumber.Text += "TourId AfterCreate: "+ Helper.ToString(TSWTourDB.InsertTSW_Tour(itemTour));

        //*****************************************
        //*****************************************
        //*****************************************
        //This number is generated from the previous line
        itemPersonnel.FromLive = m_FromLive;
        itemPersonnel.TourID = TourId;
        itemPersonnel.PersonnelID = Helper.ToInt32(ddlPromotorName.SelectedValue);
        itemPersonnel.TitleID = varTitleId;//46 Per Angel Torres it's ok to leave it like this

        //itemPersonnel.TitleID = Helper.ToInt32(TitleID);
        //step 4. Assign Personnel
        //Response.Write(itemPersonnel.TourID+ 1+ 1+1);
        Personnel itemRetunPersonnel= PersonnelDB.InsertTSW_Personnel(itemPersonnel);
        if (itemRetunPersonnel.ReturnValue <= 10)
        {
            //lblErrors.Text += "Error Creating Personnel" + itemRetunPersonnel.ReturnValue + itemRetunPersonnel.ReturnString;
            PnlError.Visible = true;
        }
        else
        {
            //lblErrors.Text += "Personnel Created Succesfully: " + itemRetunPersonnel.ReturnValue;
            //varPersonnelIdAssigned= itemRetunPersonnel.ReturnValue;
            PnlError.Visible = true;
        }
        //*****************************************
        //*****************************************
        //*****************************************
        //Step 5. Assign Premium Tours
         //loop for all the grid and premiums. I recommend to create an array and then save the array
        int varQty=0;
        foreach (RepeaterItem item in rptrPremiums.Items)
        {
            //varQty += Helper.ToInt32((TextBox)item.FindControl("txtPremQty"));
            varQty = Helper.ToInt32((string)((TextBox)item.FindControl("txtPremQty")).Text);
            //throw new Exception(varQty.ToString());
            if (varQty>0)
            {
                itemPremiums.FromLive = m_FromLive;
                itemPremiums.SiteID = SiteId;
                itemPremiums.SIHOTPerson.HN = Helper.ToInt32(hdnHNDirectFromSIHOT.Value);
                itemPremiums.SIHOTPerson.PCIID = parPCIID;
                itemPremiums.SIHOTPerson.RNO = paridRNO;
                itemPremiums.Personnel.PersonnelID = Helper.ToInt32(ddlPromotorName.SelectedValue); ;
                itemPremiums.PremInvID =Helper.ToInt32((string)((Literal)item.FindControl("litPremID")).Text);
                itemPremiums.CampaignID = Helper.ToInt32(ddlCampaign.SelectedValue);
                itemPremiums.TourID = TourId;

                itemPremiums.Quantity = Helper.ToInt32((string) ((TextBox) item.FindControl("txtPremQty")).Text);
                //Save the amount of the voucher
                //if (itemPremiums.Catalogs.PremInvTypeID==6)
                //{
                //if (Helper.ToDecimal((string)((TextBox)item.FindControl("txtPremAmt")).Text)!=0)
                    itemPremiums.Amount = Helper.ToDecimal((string)((TextBox)item.FindControl("txtPremAmt")).Text);
                //}

                itemPremiums.PremDate = Helper.ToDateTime(txtTourDate.Text);
                //itemPremiums.Note = valuefromdatagridnotes;
                itemPremiums.AuditUser = varSystemUser;
                itemPremiums.auditDate = Helper.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"));
                itemPremiums.TourLocationID =Helper.ToInt32(ddlTourLocation.SelectedValue);

                Premiums itemRetunPremiums = PremiumsDB.InsertTSW_Premiums(itemPremiums);
                if (itemRetunPremiums.ReturnString != "Success")
                {
                    //lblErrors.Text += "Error Creating the Premium:" +
                    //    itemRetunPremiums.ReturnString + itemRetunPremiums.ReturnValue;
                    PnlError.Visible = true;
                }
                //else
                //{
                    //lblErrors.Text += "Premium Created Succesfully: " + itemRetunPremiums.ReturnValue;
                    //PnlError.Visible = true;
                    //Insert all the PremId generated from TSW in PMS Interface
                    //Verify that the inherid values are being taken witht the current values from the screen
                    //To be tested3/4/2010
                    //PremiumsDB.InsertPMS_Premiums(itemPremiums);
                //}
            }
        }

        //Step6. Save the Status, the prospectId, and tourid and disable the Premiums Grid
        if ((string)Session["AccessLevel"] != "Manager")
          {
          DisableRepeater();
          }

        itemPreTourBooking.ReservationNumber = Helper.ToInt32(lblReservation.Text);
        itemPreTourBooking.Status = "Booked";
        lblStatus.Text = "Booked";
        hdnStatus.Value = "Booked";

        itemPreTourBooking.FromLive = m_FromLive;
        if (TourId != 0)
            itemPreTourBooking.TourID = TourId;
        else
            itemPreTourBooking.TourID = 1111;

        itemPreTourBooking.ProspectID = ProspectId;
        itemPreTourBooking.PCIID = parPCIID;
        itemPreTourBooking.HN = Helper.ToInt32(hdnHNDirectFromSIHOT.Value);
        itemPreTourBooking.SubReservationNumber = Helper.ToInt32(hdnRSNO.Value);
        PreTourBookingDB.Update_PreBooked(itemPreTourBooking);

        btnBook.Visible = false;

        btnPremiums.Visible = false;

        phNewProspect.Visible = false;
        lblprospectID.Text=Helper.ToString(ProspectId);
        lblTourID.Text=Helper.ToString(TourId);
        DisableAll();
        lblErrors.Text = "<font color='blue'>To make changes use TSW.</font>";
        PnlError.Visible = true;

        //Save Notes in TSW Interface for the Booked Status
        if (TxtNotesBooked.Text != "")
        {
            SaveNotesTSW(ddlCommentType, TxtNotesBooked, false);
        }
        SaveAutomaticNotesPMS("Prospect has been Booked");

        ShowComments();

        //Shows THE PREMIUMS HISTORY
        LoadPremiums_TSW();
    }
    protected void btnSavePre_Click(object sender, EventArgs e)
    {
        //Validating NQ's; This validation doesn't work anymore
        //if (ddlNQTypes.SelectedValue != "" && RadInterestedTour.SelectedValue == "yes")
        //{
        //    lblNQTypes.Text = "<font color ='red'>De-Select the NQ to continue..</font>";
        //    lblNQTypes.Visible = true;
        //    return;
        //}

        //Save the prebooking PMS Interface
        //enable the rest of the controls
        PreTourBooking item = new PreTourBooking();
        item.ReservationNumber = Helper.ToInt32(lblReservation.Text);
        item.DateContacted = Helper.ToDateTime(txtDateContacted.Text);
        item.ContactedBy = txtContactedBy.Text;//removeDC
        item.ContactedBy = ddlVCinfo.SelectedValue;
        item.Invited = chkInvited.Checked;
        //OLDitem.HN = SIHOTHotelCode;
        item.HN = Helper.ToInt32(hdnHNDirectFromSIHOT.Value);
        item.SubReservationNumber = Helper.ToInt32(hdnRSNO.Value);

        item.FromLive = m_FromLive;

        //Check if the record already exist in the hidden field with the status
        if (hdnStatus.Value=="Available") //Make an update
        {
            if (RadInterestedTour.SelectedValue == "yes")
            {
                //save PMS Interface and enable the other section
                item.InterestedInTour = "yes";
                if (txtFollowUpDate.Text != "")
                {
                    item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                    item.FollowUpTime = ddlFollowUpTime.SelectedValue;
                }

                item.PCIID = parPCIID;

                // Already Invited
                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "PreBooked";

                EnableBooking();
                hdnStatus.Value = item.Status;
                SaveAutomaticNotesPMS("Prospect has been Pre-Booked.");
            }
            else if (RadInterestedTour.SelectedValue == "no")
            {
                //save PMS Interface and enable the other section
                item.InterestedInTour = RadInterestedTour.SelectedValue;
                item.PCIID = parPCIID;

                //item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "Available"; //Invited

                hdnStatus.Value = item.Status;
            }
            else if (RadInterestedTour.SelectedValue == "maybe")
            {
                //Save the detail information and becomes not available with notes.
                item.InterestedInTour = RadInterestedTour.SelectedValue;
                if (txtFollowUpDate.Text != "")
                {
                    item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                    item.FollowUpTime = ddlFollowUpTime.SelectedValue;
                }

                if (chkInvited.Checked == true)
                    item.Invited = true;

                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "Available";

                item.PCIID = parPCIID;
                hdnStatus.Value = item.Status;
           }
                item.NQTypesID = Helper.ToInt32(ddlNQTypes.SelectedValue);

            PreTourBookingDB.Update_PreBookedTour(item);
        }
        //The status doesn't exist. It's a brand new insert
        else if (hdnStatus.Value=="")
        {
            if (RadInterestedTour.SelectedValue == "yes")
            {
                //save PMS Interface and enable the other section
                item.InterestedInTour = "yes";
                item.PCIID = parPCIID;
                if (txtFollowUpDate.Text != "")
                {
                    item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                    item.FollowUpTime = ddlFollowUpTime.SelectedValue;
                }
                item.Status = "PreBooked"; //Invited
                hdnStatus.Value = item.Status;
                //Save the Status in tblSIHOTPerson
                EnableBooking();
                SaveAutomaticNotesPMS("Prospect has been Pre-Booked.");
            }
            else if (RadInterestedTour.SelectedValue == "no")
            {
                //Save the detail information and becomes not available with notes.
                if (chkDoNOTContact.Checked == true)
                {
                    //save the status for that reservation "DoNOTContact"
                    item.Status = "DoNOTContact";
                }

                item.PCIID = parPCIID;
                item.Status = "Available";
                item.InterestedInTour = "no";
                hdnStatus.Value = item.Status;
            }
            //throw new Exception(RadInterestedTour.SelectedValue);
            else
            {
                if (txtFollowUpDate.Text != "")
                {
                    item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                    item.FollowUpTime = ddlFollowUpTime.SelectedValue;
                }
                //Save the detail information and becomes not available with notes.
                if (chkInvited.Checked == true)
                    item.Invited = true;

                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "Available";

                item.PCIID = parPCIID;
                hdnStatus.Value = item.Status;
                item.InterestedInTour = "maybe";

            }
            item.NQTypesID = Helper.ToInt32(ddlNQTypes.SelectedValue);
            if (txtDateContacted.Text != string.Empty)
            {
                PreTourBookingDB.Insert_PreBookedTour(item);
            }

        }

        lblStatus.Text = item.Status;
        //if the info tab has notes. Save them.
        if (txtNotesPreBooked.Text != "")
        {
            SaveNotesPMS(txtNotesPreBooked, false);
        }
        ShowComments();
        PnlConfirmation.Visible = true;
        PnlDups.Visible = false;
        PnlMain.Visible = false;
        phNewProspect.Visible = false;
        lblConfirmation.Text = "Info saved succesfully.";

        TSWProspect itemProspect = new TSWProspect();
        itemProspect.FromLive = m_FromLive;
        itemProspect.CN = lblFName.Text.Trim();
        itemProspect.SN = lblLastName.Text.Trim();
        itemProspect.Phone = hdnPhone1.Value.Trim();
        itemProspect.EMAIL = hdnEmail.Value.Trim();
        CheckIfProspectExistTSW(itemProspect);
    }
    void SavePreBookingAutomatic()
    {
        //Save the prebooking PMS Interface
        //enable the rest of the controls
        PreTourBooking item = new PreTourBooking();
        item.FromLive = m_FromLive;
        item.ReservationNumber = Helper.ToInt32(lblReservation.Text);
        item.SubReservationNumber =Helper.ToInt32(hdnRSNO.Value);
        item.DateContacted = Helper.ToDateTime(txtDateContacted.Text);
        item.ContactedBy = ddlVCinfo.SelectedValue;
        //item.ContactedBy = txtContactedBy.Text; //removedc
        item.Invited = chkInvited.Checked;
        item.HN = Helper.ToInt32(hdnHNDirectFromSIHOT.Value);
        item.NQTypesID = Helper.ToInt32(ddlNQTypes.SelectedValue);

        //Check if the record already exist in the hidden field with the status
        if (hdnStatus.Value == "Available" || hdnStatus.Value == "PreBooked") //Make an update
        {
            if (RadInterestedTour.SelectedValue == "yes")
            {
                //save PMS Interface and enable the other section
                item.InterestedInTour = "yes";
                if (txtFollowUpDate.Text != "")
                    item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                item.FollowUpTime = ddlFollowUpTime.SelectedValue;
                item.PCIID = parPCIID;

                // Already Invited
                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "PreBooked";

                EnableBooking();
                hdnStatus.Value = item.Status;
                SaveAutomaticNotesPMS("Prospect has been Pre-Booked.");
            }
            else if (RadInterestedTour.SelectedValue == "no")
            {
                //save PMS Interface and enable the other section
                item.InterestedInTour = "no";
                item.PCIID = parPCIID;

                //item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "Available"; //Invited

                hdnStatus.Value = item.Status;
            }
            else if (RadInterestedTour.SelectedValue == "maybe")
            {
                //Save the detail information and becomes not available with notes.
                item.InterestedInTour = "maybe";
                if (chkInvited.Checked == true)
                    item.Invited = true;

                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "Available";

                item.PCIID = parPCIID;
                hdnStatus.Value = item.Status;
            }
            PreTourBookingDB.Update_PreBookedTour(item);
        }
        //The status doesn't exist. It's a brand new insert
        else if (hdnStatus.Value == "")
        {
            if (RadInterestedTour.SelectedValue == "yes")
            {
                //save PMS Interface and enable the other section
                item.InterestedInTour = "yes";
                item.PCIID = parPCIID;
                if (txtFollowUpDate.Text != "")
                {
                    item.FollowUpDate = Helper.ToDateTime(txtFollowUpDate.Text);
                    item.FollowUpTime = ddlFollowUpTime.SelectedValue;
                }
                item.Status = "PreBooked"; //Invited
                //Save the Status in tblSIHOTPerson
                EnableBooking();
                SaveAutomaticNotesPMS("Prospect has been Pre-Booked.");
                hdnStatus.Value = item.Status;
            }
            else if (RadInterestedTour.SelectedValue == "no")
            {
                //Save the detail information and becomes not available with notes.
                if (chkDoNOTContact.Checked == true)
                {
                    //save the status for that reservation "DoNOTContact"
                    item.Status = "DoNOTContact";
                }

                item.PCIID = parPCIID;
                item.Status = "Available";
                item.InterestedInTour = "no";
                hdnStatus.Value = item.Status;
            }
            //throw new Exception(RadInterestedTour.SelectedValue);
            else  if (RadInterestedTour.SelectedValue == "maybe")
            {
                //Save the detail information and becomes not available with notes.
                if (chkInvited.Checked == true)
                    item.Invited = true;

                if (chkDoNOTContact.Checked == true)
                    item.Status = "DoNOTContact";
                else
                    item.Status = "Available";

                item.PCIID = parPCIID;
                hdnStatus.Value = item.Status;
                item.InterestedInTour = "maybe";
            }
            item.NQTypesID = Helper.ToInt32(ddlNQTypes.SelectedValue);
            if (txtDateContacted.Text != string.Empty)
            {
                PreTourBookingDB.Insert_PreBookedTour(item);
            }

        }

        lblStatus.Text = item.Status;
        //if the info tab has notes. Save them.
        if (txtNotesPreBooked.Text != "")
        {
            SaveNotesPMS(txtNotesPreBooked, false);
        }
        ShowComments();
    }
    void PopulatePreBooking(PreTourBooking itemsPreBooking)
    {
        if (itemsPreBooking.DateContacted!=null)
        txtDateContacted.Text = Helper.ToString(itemsPreBooking.DateContacted);
        if (itemsPreBooking.ContactedBy!=null)
            ddlVCinfo.Text = itemsPreBooking.ContactedBy;
        if (ddlVCinfo.SelectedValue == "")
        {
            txtContactedBy.Visible = true;

            txtContactedBy.Text = itemsPreBooking.ContactedBy;//removeDC'
        }
        else
        {
            txtContactedBy.Visible = false;
        }

            //throw new Exception(itemsPreBooking.Invited.ToString());
            if (itemsPreBooking.Invited == true)
                chkInvited.Checked = true;

            if (itemsPreBooking.Status == "DoNOTContact")
            chkDoNOTContact.Checked = true;

        RadInterestedTour.SelectedValue = itemsPreBooking.InterestedInTour;

        if (itemsPreBooking.FollowUpDate!=null)
        txtFollowUpDate.Text = itemsPreBooking.FollowUpDate.Value.ToString("MM/dd/yyyy");
        //throw new Exception(itemsPreBooking.FollowUpTime);
        if (itemsPreBooking.FollowUpTime!=null)
            ddlFollowUpTime.Text = itemsPreBooking.FollowUpTime;
    }
    public static void Update_PreBooked(PreTourBooking value)
    {
        //throw new Exception("Updating PreBooked: " + value.SubReservationNumber);
        SqlParameter[] param = new SqlParameter[] {
        new SqlParameter("@FromLive", value.FromLive),
        new SqlParameter("@ReservationNum", value.ReservationNumber),
        new SqlParameter("@SubReservationNum", value.SubReservationNumber),
        new SqlParameter("@PCIID", value.PCIID),
        new SqlParameter("@HotelNumber", value.HN),
        new SqlParameter("@Status", value.Status),
        new SqlParameter("@TourDate", value.TourDate),
        new SqlParameter("@TourID", value.TourID),
        new SqlParameter("@ProspectID", value.ProspectID)
        };

        SqlHelper.ExecuteNonQuery(Helper.ConnectionString, CommandType.StoredProcedure, "Update_PreBooked_Status", param);
    }