public static TSWTour CancelTourPMS(TSWTour value)
    {
        TSWTour retval = new TSWTour();
        SqlParameter[] param = new SqlParameter[] {
            new SqlParameter("@FromLive", value.FromLive),
            new SqlParameter("@ReservationNum", value.PreTourBooking.ReservationNumber),
            new SqlParameter("@ReservationSubNum", value.PreTourBooking.SubReservationNumber),
            new SqlParameter("@PCIID", value.PreTourBooking.PCIID),
            new SqlParameter("@HN", value.PreTourBooking.HN)
        };

        SqlHelper.ExecuteNonQuery(Helper.ConnectionString, CommandType.StoredProcedure, "ws_usp_CancelTourPMS", param);
        return retval;
    }
    public static TSWTour CancelTour(TSWTour value)
    {
        TSWTour retval = new TSWTour();
        SqlParameter[] param = new SqlParameter[] {
            new SqlParameter("@FromLive", value.FromLive),
            new SqlParameter("@TourID", value.TourID)
        };
        using (SqlDataReader reader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, "ws_usp_CancelTour", param))

        {
            if (reader.Read())
            {
                retval = Read(reader);
            }
        }
        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 btnCancelTour_Click(object sender, EventArgs e)
    {
        //Obtain the TourID
        TSWTour itemCancelTour = new TSWTour();
        TSWTour itemCancelTourPMS = new TSWTour();
        itemCancelTour.TourID=TourId;
        itemCancelTour.FromLive=m_FromLive;
        //Cancel Tour in tSW
        itemCancelTour = TSWTourDB.CancelTour(itemCancelTour);

        itemCancelTourPMS.FromLive = m_FromLive;
        //cancel Tour in PMS Interface
        itemCancelTourPMS.PreTourBooking.ReservationNumber = paridRNO;
        itemCancelTourPMS.PreTourBooking.SubReservationNumber = paridRSNO;
        itemCancelTourPMS.PreTourBooking.PCIID = parPCIID;
        itemCancelTourPMS.PreTourBooking.HN = Helper.ToInt32(hdnHNDirectFromSIHOT.Value);

        itemCancelTourPMS = TSWTourDB.CancelTourPMS(itemCancelTourPMS);

        if (itemCancelTour.ReturnValue == 0)
        {
            SaveAutomaticNotesPMS("Tour has been cancelled by " + varSystemUser);
            lblCancelTour.Text = itemCancelTour.ReturnString + " succesfully.";
            btnContinueCancel.Visible = true;
            btnCancelTour.Visible = false;
        }
        else
        {
            lblCancelTour.Text = "Internal Error[" + itemCancelTour.ReturnValue+"-"+itemCancelTour.ReturnString +"]";
        }
        //Write "Cancel" in the notes
    }
    private void PopulateTourTime()
    {
        TSWTour parItemTour = new TSWTour();

        parItemTour.SiteID=SiteId;
        parItemTour.TourLocationID = Helper.ToInt32(ddlTourLocation.SelectedValue);
        if (m_FromLive == 0)
            parItemTour.DBName = "tswpracticeSP1";
        else
            parItemTour.DBName = "TSWDATA";

        //if (Helper.ToDateTime(txtTourDate.Text).Value!=null)
        parItemTour.TourDate = Helper.ToDateTime(txtTourDate.Text).Value;
        //throw new Exception(Helper.ToDateTime(txtTourDate.Text).ToString("mm/dd/yyyy"));
        ddlTourTime.Items.Clear();
        TSWTourList list = TSWTourDB.GetWaves(parItemTour);

        ddlTourTime.Items.Add(new ListItem("Select..", ""));
        //throw new Exception(list.Count.ToString());
        foreach (TSWTour item in list)
        {
            ddlTourTime.Items.Add(new ListItem(item.wave + " ("+ item.NumberAvailable + ")" , item.waveID.ToString()));

        }
    }
    private void LoadTour_TSW()
    {
        TSWTour retval;
        TSWTour item = new TSWTour();
        item.TourID = Helper.ToInt32(lblTourID.Text);
        item.FromLive = m_FromLive;

        TSWTour itemBack=TSWTourDB.GetTourBackFromTSW(item);
        if (itemBack != null)
        {
            ddlCampaign.SelectedValue = itemBack.CampaignID.ToString();
            ddlTourLocation.SelectedValue = itemBack.TourLocationID.ToString();
            //if (hdnStatus.Value!="PreTour")
            txtTourDate.Text = itemBack.TourDate.ToString();
            if (hdnStatus.Value != "PreTour")
                PopulateTourTime();

            ddlTourTime.SelectedValue = itemBack.waveID.ToString();
            //throw new Exception("Good");
            ddlTourTime.Visible = true;
        }
    }
    //Loads the concierge
    private void LoadPersonnel_TSW()
    {
        TSWTour items = new TSWTour();
        items.TourID = Helper.ToInt32(lblTourID.Text);
        items.FromLive = m_FromLive;

        TSWTour itemsBack = TSWTourDB.GetBackPersonnelFromTSW(items);
        if (itemsBack != null)
        {
            ddlPromotorName.SelectedValue = itemsBack.Catalogs.PersonnelID;
        }
    }
    protected void rptProspects_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HyperLink hlGUID = (HyperLink)e.Item.FindControl("hlGUID");
            CheckBox chkIN = (CheckBox)e.Item.FindControl("chkBoxIn");

            HyperLink hlRoom = (HyperLink)e.Item.FindControl("hlRoom");
            HyperLink hlLastName = (HyperLink)e.Item.FindControl("hlLastName");
            CheckBox chkAvl = (CheckBox)e.Item.FindControl("chkBoxAva");
            CheckBox chkInfo = (CheckBox)e.Item.FindControl("chkBoxInf");
            CheckBox chkInvit = (CheckBox)e.Item.FindControl("chkBoxInv");
            HyperLink hlCheckInDate = (HyperLink)e.Item.FindControl("hlCheckInDate");
            HyperLink hlCheckOutDate = (HyperLink)e.Item.FindControl("hlCheckOutDate");
            HyperLink Status = (HyperLink)e.Item.FindControl("Status");
            HyperLink hlCountry = (HyperLink)e.Item.FindControl("hlCountry");
            HyperLink hlAgency = (HyperLink)e.Item.FindControl("hlAgency");
            HyperLink hlRooms = (HyperLink)e.Item.FindControl("hlRooms");
            HyperLink hlPax = (HyperLink)e.Item.FindControl("hlPax");
            HyperLink hlBookDate = (HyperLink)e.Item.FindControl("hlBookDate");
            HyperLink hlVC = (HyperLink)e.Item.FindControl("hlVC");
            HyperLink hlSegment = (HyperLink)e.Item.FindControl("hlSegment");
            HyperLink hlVIP = (HyperLink)e.Item.FindControl("hlVIP");
            HyperLink hlNQ = (HyperLink)e.Item.FindControl("hlNQ");
            HyperLink hlComments = (HyperLink)e.Item.FindControl("hlComments");
            LinkButton btnCancelTour = (LinkButton)e.Item.FindControl("btnCancelTour");
            Label lblTourID = (Label)e.Item.FindControl("lblTourID");
            ImageButton btnComments = (ImageButton)e.Item.FindControl("btnA");
            HyperLink hlMemberNum = (HyperLink)e.Item.FindControl("hlMemberNum");

            SIHOTPerson item = (SIHOTPerson)e.Item.DataItem;

            btnComments.ToolTip = "View Comments";

            try
            {

            //Shows the cancel tour link
            if ((string)Session["AccessLevel"] == "Manager" && item.Status == "Booked" && DateTime.Compare(item.DEP.Value, DateTime.Now.Date) > 0)
            {
                btnCancelTour.Visible = true;

                //put the text for the label here
                //just helps to debug
                lblTourID.Text = item.TourId.ToString();
                lblTourID.Visible = false;

                btnCancelTour.PostBackUrl = "Allocatetour.aspx?cmd=cancel&idRNO=" + item.RNO + "&idRSNO=" + item.RSNO +  "&PCIID=" + item.PCIID + "&TourID=" + item.TourId;
                //btnCancelTour.PostBackUrl = "registration.aspx?cmd=delete&id=" + item.MemberId; ;
                //hlDelete.NavigateUrl = "member-edit.aspx?cmd=delete&id=" + item.MemberId;

            }

            if ((string)Session["AccessLevel"] == "Manager" && item.Status != "Booked" && item.Status != "PreBooked" && DateTime.Compare(item.DEP.Value, DateTime.Now.Date) >= 0 && item.OC.Trim() == "CI")
            {
                chkAvl.Enabled = true;
                chkAvl.BackColor = System.Drawing.Color.Yellow;
            }

            if ((string)Session["AccessLevel"] == "Manager")
            {
                btnSaveGrid.Visible = true;
            }

            btnComments.PostBackUrl = "Allocatetour.aspx?cmd=notes&idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            //hlGUID.Text = item.PCIID.ToString();//+ (item.RNO.ToString());
            //hlGUID.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&PCIID=" + item.PCIID;
            //hlGUID.Visible = false;

            if (item.OC.Trim() == "CI")
            {
                chkIN.Checked = true;
            }

            if (item.Available == true)
            {
                chkAvl.Checked = true;
            }

            if (item.MATCHCODE != null)
            {

                if (item.MATCHCODE.Length > 3)
                {
                    hlMemberNum.Text = item.MATCHCODE.Substring(0, 4);
                    hlMemberNum.ToolTip = item.MATCHCODE.Trim();
                }
                else
                {
                    hlMemberNum.Text = item.MATCHCODE.Trim();
                }
            }

            hlRoom.Text = item.RN;
            hlRoom.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            if (item.SN.Length > 10)
            {
                hlLastName.Text = item.SN.Substring(0, 10);
            }
            else { hlLastName.Text = item.SN.Trim(); }

            hlLastName.ToolTip = item.SN.Trim() + ", " + item.CN.Trim();
            hlLastName.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            if (item.PreTourBooking.DateContacted != null)
            {
                hlBookDate.Text = Helper.ToString(item.PreTourBooking.DateContacted.Value.ToString("MM/dd/yyyy"));
                hlBookDate.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;
            }

            if (item.PreTourBooking.TourDate != null)
            {
                hlBookDate.Text = Helper.ToString(item.PreTourBooking.TourDate.Value.ToString("MM/dd/yyyy"));
                chkInvit.Checked = true;
                //itemsPreBooking.FollowUpDate.Value.ToString("MM/dd/yyyy");
            }

            if (item.Status == "Booked" && item.TourId != 0)
            {
                TSWTour itemTSWTour = new TSWTour();
                itemTSWTour = TSWTourDB.Select_t_Tour(item.TourId, m_FromLive);
                if (itemTSWTour.TourDate!=null)
                    hlBookDate.Text = itemTSWTour.TourDate.Value.ToString("MM/dd/yyyy");
            }

            if (item.Status == "PreBooked" || item.Status == "Booked")
            {
                chkInvit.Checked = true;
            }

            if (item.PreTourBooking.Invited && item.PreTourBooking.TourDate!=null)
            {
                hlBookDate.Text = Helper.ToString(item.PreTourBooking.TourDate.Value.ToString("MM/dd/yyyy"));
                hlBookDate.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            }
            //vw_TSW_ProspectTour.Wave, vw_TSW_ProspectTour.TourResult, vw_TSW_ProspectTour.VacConsult,DisplayMarket,DisplaySegment

            //switch (m_FilCriteria)
            //{case "pre": break;}

                    if (item.TSWCatalogs.FirstName.Length > 5)//VC Full Name
                    {
                        hlVC.Text = item.TSWCatalogs.FirstName.Substring(0, 4);
                        hlVC.ToolTip = item.TSWCatalogs.FirstName.Trim() + "/" + item.TSWTour.wave + "/" + item.TSWTour.TourResult;
                    }
                    else
                    {
                        hlVC.Text = item.TSWCatalogs.FirstName.Trim();
                    }

            if (item.DisplaySegment != null)
            {
                if (item.DisplaySegment.Length > 3)//Segment Description
                {
                    hlSegment.Text = item.DisplayMarket.Substring(0, 3).ToUpper();
                    hlSegment.ToolTip = item.DisplayMarket.Trim() + "/" + item.DisplaySegment.Trim();
                }
                else
                {
                    hlSegment.Text = item.DisplayMarket.ToUpper().Trim();
                }

            }

            if (item.PreTourBooking.DateContacted!=null)
            {
                chkInfo.Checked = true;
            }

            if ((item.ARR != null))
            {
                //litPostedDate.Text = item.Posted_date.Value.ToString("MM/dd/yyyy");
                hlCheckInDate.Text = item.ARR.Value.ToString("MM/dd/yyyy");
                hlCheckInDate.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

                if (DateTime.Compare(item.ARR.Value, DateTime.Now.Date) <= 0)
                {
                    //hlCheckInDate.Text = "<font color='red'> " + hlCheckInDate.Text + "</color>";
                    hlCheckInDate.Text = hlCheckInDate.Text;
                    hlCheckInDate.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;
                    //hlCheckInDate.ToolTip = "This Reservation is Check Out";
                }
            }

            if ((item.DEP != null))
            {
                //litPostedDate.Text = item.Posted_date.Value.ToString("MM/dd/yyyy");
                hlCheckOutDate.Text = item.DEP.Value.ToString("MM/dd/yyyy");
                hlCheckOutDate.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

                if (DateTime.Compare(item.DEP.Value, DateTime.Now.Date) <= 0)
                {
                    //hlCheckOutDate.Text = "<font color='red'> " + hlCheckOutDate.Text + "</color>";
                    hlCheckOutDate.Text = hlCheckOutDate.Text;
                    hlCheckOutDate.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;
                    //hlCheckOutDate.ToolTip = "This Reservation is Check Out";
                }
            }

            if (item.Status != null )
            {
                if (item.Status.Length > 3 && item.Status=="PreBooked")
                {
                    Status.Text = "PrB";
                    Status.ToolTip = item.Status.Trim();
                }
                else if (item.Status.Length > 3 && item.Status == "PreTour")
                {
                    Status.Text = "PrT";
                    Status.ToolTip = item.Status.Trim();
                }
                else if (item.Status.Length > 3 )
                {
                    Status.Text = item.Status.Substring(0, 3);
                    Status.ToolTip = item.Status.Trim();
                }
                else
                {
                    Status.Text = item.Status.Trim();
                    Status.ToolTip = item.Status.Trim();
                }
            }
            else
            {
                Status.Text = "Ava";
                Status.ToolTip = "Available";
            }

            Status.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            hlCountry.Text = item.Address.Country;
            hlCountry.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;
            //hlRooms.Text = item.ro;
            //hlRooms.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&PCIID=" + item.PCIID;
            if (item.PreTourBooking.NQTypesDesc != null && item.PreTourBooking.NQTypesDesc.Length>4)
            {
                hlNQ.Text = item.PreTourBooking.NQTypesDesc.Substring(0, 4);
                hlNQ.ToolTip = item.PreTourBooking.NQTypesDesc.Trim();
            }
            else if (item.PreTourBooking.NQTypesDesc != null && item.PreTourBooking.NQTypesDesc.Length <= 4)
            {
                hlNQ.Text = item.PreTourBooking.NQTypesDesc.Trim();
            }

            if (item.AgencyName.Length > 10)
            {
                hlAgency.Text = item.AgencyName.Substring(0, 10);
                hlAgency.ToolTip = item.AgencyName.Trim();
            }
            else
            {
                hlAgency.Text = item.AgencyName.Trim();
            }

            hlAgency.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            hlPax.Text = item.NOPAX.ToString();
            hlPax.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;

            hlVIP.Text = item.VIP;
            hlVIP.NavigateUrl = "AllocateTour.aspx?idRNO=" + item.RNO + "&idRSNO=" + item.RSNO + "&PCIID=" + item.PCIID;
            if (item.Notes.NoteDesc.Length > 20)
            {
                hlComments.Text = item.Notes.NoteDesc.Substring(0, 20);
                hlComments.ToolTip = item.Notes.NoteDesc.Trim();
            }
            else
            {
                hlComments.Text = item.Notes.NoteDesc.Trim();
           }

            if (item.PrimaryFlag == false)
            {
                hlComments.Text = "<strong><font color='orange'>NOTPrimary</font></strong>";
            }

            if (item.RT == "3")
            {
                //disable all the links
                hlComments.Text += " <font color='red'>Cancelled</font>";

            }

            //((AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("pop")).Show();
            }
            catch (Exception flaws)
            {
                throw new Exception(flaws.Message);
            }
            finally
            {
            }

        }
    }
 public static TSWTour Select_t_Tour(int TourID, int FromLive)
 {
     TSWTour retval = new TSWTour();
     SqlParameter[] param = new SqlParameter[] {
         new SqlParameter("@FromLive", FromLive),
         new SqlParameter("@TourID", TourID)
     };
     using (SqlDataReader reader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, "Select_t_Tour", param))
     {
         if (reader.Read())
         {
             retval = Read(reader);
         }
     }
     return retval;
 }
    public static TSWTour Read(SqlDataReader reader)
    {
        TSWTour retval = new TSWTour();

        for (int i = 0; i < reader.FieldCount; i++)
        {
            switch (reader.GetName(i))
            {
                case "TourID":
                    retval.TourID = Helper.ToInt32(reader[i]);
                    break;
                case "TourTypeID":
                    retval.TourTypeID = Helper.ToInt32(reader[i]);
                    break;
                case "TourTypeDescription":
                    retval.TourTypeDesc = Helper.ToString(reader[i]);
                    break;
                case "Wave":
                    retval.wave = Helper.ToString(reader[i]);
                    break;
                case "NumberAvailable":
                    retval.NumberAvailable = Helper.ToInt32(reader[i]);
                    break;
                case "TourDate":
                    retval.TourDate = Helper.ToDateTime(reader[i]);
                    break;
                case "WaveID":
                    retval.waveID = Helper.ToInt32(reader[i]);
                    break;
                case "ReturnValue":
                    retval.ReturnValue = Helper.ToInt32(reader[i]);
                    break;
                case "ReturnString":
                    retval.ReturnString = Helper.ToString(reader[i]);
                    break;
                case "CampaignID":
                    retval.CampaignID = Helper.ToInt32(reader[i]);
                    break;
                case "PersonnelID":
                    retval.Catalogs.PersonnelID = Helper.ToString(reader[i]);
                    break;
                case "TourLocationID" :
                    retval.TourLocationID = Helper.ToInt32(reader[i]);
                    break;
                case "TourResult":
                    retval.TourResult = Helper.ToString(reader[i]);
                    break;
            }
        }

        return retval;
    }
    public static TSWTourList InsertTSW_Tour(TSWTour value)
    {
        //string prospectId = "";
        TSWTourList retval = new TSWTourList();
        SqlParameter[] param = new SqlParameter[] {
        new SqlParameter("@FromLive", value.FromLive),
        new SqlParameter("@SiteID", value.SiteID),
        new SqlParameter("@ProspectID", value.ProspectId),
        new SqlParameter("@CampaignID", value.CampaignID),
        new SqlParameter("@TourTypeID", value.TourTypeID),
        new SqlParameter("@TourLocationID", value.TourLocationID),
        new SqlParameter("@TourDate", value.TourDate),
        new SqlParameter("@PreAssignedTo", ""),
        new SqlParameter("@WaveID", value.waveID)
        };

        using (SqlDataReader reader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, "ws_usp_CreateBookedTour", param))
        {
            while (reader.Read())
            {
                retval.Add(Read(reader));
            }
        }
        //count = Helper.ToInt32(pOut.Value);
        return retval;
    }
    public static TSWTourList GetWaves(TSWTour parItem)
    {
        TSWTourList retval = new TSWTourList();

        SqlParameter[] param = new SqlParameter[]{

            new SqlParameter("@inDBName", parItem.DBName),
            new SqlParameter("@inSiteId", parItem.SiteID),

            new SqlParameter("@inTourLocationID", parItem.TourLocationID),
            new SqlParameter("@inDate", parItem.TourDate),
        };

        using (SqlDataReader reader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, "ws_usp_GetWaves", param))
        {
            while (reader.Read())
            {
                retval.Add(Read(reader));
            }
        }
        //count = Helper.ToInt32(pOut.Value);
        return retval;
    }