/// <summary>
        /// The Page_Load event handler on this User Control populates the comboboxes
        /// for portals and module types for the ContentManager.
        /// It uses the Rainbow.ContentManagerDB()
        /// data component to encapsulate all data functionality.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                //populate module types dropdownlist.
                ContentManagerDB contentDB = new ContentManagerDB();

                //populate moduleTypes list
                ModuleTypes.DataSource     = contentDB.GetModuleTypes();
                ModuleTypes.DataValueField = "ItemID";
                ModuleTypes.DataTextField  = "FriendlyName";
                ModuleTypes.DataBind();

                //populate source portal list
                SourcePortal.DataValueField = "PortalID";
                SourcePortal.DataTextField  = "PortalAlias";
                SourcePortal.DataSource     = contentDB.GetPortals();
                SourcePortal.DataBind();

                //destination portal list.
                DestinationPortal.DataValueField = "PortalID";
                DestinationPortal.DataTextField  = "PortalAlias";
                DestinationPortal.DataSource     = contentDB.GetPortals();
                DestinationPortal.DataBind();

                //Function to set visibility for Portal dropdowns and select current portal
                //as default
                MultiPortalSupport();

                //functions to load the modules in the currently selected portal.
                LoadSourceModules();
                LoadDestinationModules();
            }
        }
        private void LoadDestinationModules()
        {
            if (SourceInstance.SelectedIndex > -1)
            {
                DestinationInstance.Items.Clear();

                //Get the Module Type(ex announcements) and the Source ModuleID
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);
                int SourceModID  = Int32.Parse(SourceInstance.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();

                DestinationInstance.DataValueField = "ModuleID";
                DestinationInstance.DataTextField  = "TabModule";
                DestinationInstance.DataSource     = contentDB.GetModuleInstancesExc(ModuleTypeID,
                                                                                     SourceModID, Int32.Parse(DestinationPortal.SelectedItem.Value));
                DestinationInstance.DataBind();

                //if any items exist in destination instance dropdown, select first and
                //load data for that instance.
                if (DestinationInstance.Items.Count > 0)
                {
                    DestinationInstance.SelectedIndex = 0;
                    LoadDestinationModuleData();
                }
            }
        }
        private void DeleteRight_Click(object sender, System.EventArgs e)
        {
            if (DestListBox.SelectedIndex > -1)
            {
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);
                int ItemToDelete = Int32.Parse(DestListBox.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();
                contentDB.DeleteItem(ModuleTypeID, ItemToDelete);
                LoadDestinationModuleData();
            }
        }
        private void CopyAll_Click(object sender, System.EventArgs e)
        {
            if (SourceListBox.Items.Count > 0 && SourceInstance.SelectedIndex > -1 &&
                DestinationInstance.SelectedIndex > -1)
            {
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);
                int DestModID    = Int32.Parse(DestinationInstance.SelectedItem.Value);
                int SourceModID  = Int32.Parse(SourceInstance.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();
                contentDB.CopyAll(ModuleTypeID, SourceModID, DestModID);
                LoadDestinationModuleData();
            }
        }
        private void LoadDestinationModuleData()
        {
            if (DestinationInstance.SelectedIndex > -1)
            {
                int DestModID    = Int32.Parse(DestinationInstance.SelectedItem.Value);
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();
                DestListBox.DataValueField = "ItemID";
                DestListBox.DataTextField  = "ItemDesc";
                DestListBox.DataSource     = contentDB.GetModuleData(ModuleTypeID, DestModID);
                DestListBox.DataBind();
            }
        }
        private void LoadSourceModuleData()
        {
            //check to be sure that a source instance has been selected before proceeding.
            //this can cause errors if not checked for!
            if (SourceInstance.SelectedIndex > -1)
            {
                int SourceModID  = Int32.Parse(SourceInstance.SelectedItem.Value);
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();
                SourceListBox.DataValueField = "ItemID";
                SourceListBox.DataTextField  = "ItemDesc";
                SourceListBox.DataSource     = contentDB.GetModuleData(ModuleTypeID, SourceModID);
                SourceListBox.DataBind();
            }
        }
        private void MoveRight_Click(object sender, System.EventArgs e)
        {
            if (SourceListBox.SelectedIndex > -1 && SourceInstance.SelectedIndex > -1 &&
                DestinationInstance.SelectedIndex > -1)
            {
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);

                //these two lines opposite in MoveLeft_Click
                int DestModID  = Int32.Parse(DestinationInstance.SelectedItem.Value);
                int ItemToMove = Int32.Parse(SourceListBox.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();
                contentDB.MoveItem(ModuleTypeID, ItemToMove, DestModID);
                LoadSourceModuleData();
                LoadDestinationModuleData();
            }
        }
        private void LoadSourceModules()
        {
            if (ModuleTypes.SelectedIndex > -1)
            {
                int ModuleTypeID = Int32.Parse(ModuleTypes.SelectedItem.Value);

                ContentManagerDB contentDB = new ContentManagerDB();

                SourceInstance.DataValueField = "ModuleID";
                SourceInstance.DataTextField  = "TabModule";

                //if a destination module has been picked, exclude that item.
                //otherwise, show all.
                if (DestinationInstance.SelectedIndex > -1)
                {
                    SourceInstance.DataSource = contentDB.GetModuleInstancesExc(
                        ModuleTypeID,
                        Int32.Parse(DestinationInstance.SelectedItem.Value),
                        Int32.Parse(SourcePortal.SelectedItem.Value));
                    SourceInstance.DataBind();
                }
                else
                {
                    SourceInstance.DataSource = contentDB.GetModuleInstances(ModuleTypeID,
                                                                             Int32.Parse(SourcePortal.SelectedItem.Value));
                    SourceInstance.DataBind();
                }


                //if items exist in the sourceinstance, select the first item
                if (SourceInstance.Items.Count > 0)
                {
                    SourceInstance.SelectedIndex = 0;
                    LoadSourceModuleData();
                }
                else
                {
                    //if there are no instances, there can be no data!!
                    SourceListBox.Items.Clear();
                }
            }
        }