protected void gridRegKeys_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridViewRow gvr = this.gridRegKeys.Rows[Convert.ToInt32(e.CommandArgument)];
            var hiddenID = gvr.FindControl("hiddenID") as HtmlInputHidden;
            RegistrationKeyController ctrlKey = new RegistrationKeyController();
            RegistrationKey key = ctrlKey.Get(Int32.Parse(hiddenID.Value), _regID);

            switch (e.CommandName)
            {
                case "Delete":
                    ctrlKey.Delete(key);
                    break;
                case "Select": //gen key
                    key.RegKey = ctrlKey.GenerateRegistrationKey(Settings["Seed"].ToString(), key, _regProduct);
                    ctrlKey.Update(key);

                    SendCustomerNotification(key.HostName, key.RegKey);

                    RegistrationProductController ctrlProd = new RegistrationProductController();
                    _regProduct.Status = "Keys Generated";
                    ctrlProd.Update(_regProduct);

                    Response.Redirect(EditUrl("RegID", _regID.ToString()));
                    break;
            }
        }
        protected void lbnAddHostName_Click(object sender, EventArgs e)
        {
            if (txtAddHostName.Text == "")
            {
                Response.Redirect(EditUrl("RegID", _regID.ToString(), "Edit", "Error=Site Alias is required."));
            }

            RegistrationKeyController ctrlKey = new RegistrationKeyController();
            RegistrationKey key = new RegistrationKey();
            key.HostName = txtAddHostName.Text;
            key.LastUpdateDate = System.DateTime.Now;
            key.LastUpdateUserID = UserId;
            key.LastUpdateUserName = UserInfo.DisplayName;
            key.RegistrationProductID = _regID;

            ctrlKey.Create(key);
            string strMessage;

            //auto gen key
            if (_regProduct.Approved)
            {
                key.RegKey = ctrlKey.GenerateRegistrationKey(Settings["Seed"].ToString(), key, _regProduct);
                ctrlKey.Update(key);
                strMessage = "Success=New site alias requested and registration key generated!";
                SendCustomerNotification(key.HostName, key.RegKey);
                _regProduct.Status = "Keys Generated";
            }
            else
            {
                //TODO send notification to admin
                strMessage = "Message=New site alias requested and sent for approval.  You will receive an email notification when the key is generated.";
                SendAdminNotification(key.ID, key.HostName);
                _regProduct.Status = "Key Requested";
            }

            RegistrationProductController ctrlProd = new RegistrationProductController();

            ctrlProd.Update(_regProduct);

            txtAddHostName.Text = "";

            Response.Redirect(EditUrl("RegID", _regID.ToString(), "Edit", strMessage));
        }
        protected void lbnApprove_Click(object sender, EventArgs e)
        {
            RegistrationProductController ctrlReg = new RegistrationProductController();
            _regProduct.Approved = true;

            RegistrationKeyController ctrlKey = new RegistrationKeyController();
            foreach (var key in ctrlKey.GetItems(_regProduct.ID))
            {
                if (key.RegKey == null)
                {
                    key.RegKey = ctrlKey.GenerateRegistrationKey(Settings["Seed"].ToString(), key, _regProduct);
                    ctrlKey.Update(key);
                    SendCustomerNotification(key.HostName, key.RegKey);
                    _regProduct.Status = "Keys Generated";
                }
            }

            ctrlReg.Update(_regProduct);

            Response.Redirect(EditUrl("RegID", _regID.ToString(), "Edit", "Success=Existing key requests have been processed and future requests will be processed automatically" ));
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                //Get Reg ID
                if (this.Request.QueryString["RegKeyID"] != null) //if none, then _regID = -1
                {
                    _regKeyID = Int32.Parse(this.Request.QueryString["RegKeyID"]);
                }

                if (this.Request.QueryString["RegProdID"] != null) //if none, then _regID = -1
                {
                    _regProdID = Int32.Parse(this.Request.QueryString["RegProdID"]);
                }

                if (_regProdID == -1 || _regKeyID == -1)
                {
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "No key ID or product ID provided", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                if (!Page.IsPostBack)
                {
                    RegistrationProductController ctrlProd = new RegistrationProductController();
                    RegistrationKeyController ctrlKey = new RegistrationKeyController();
                    UserController ctrlUser = new UserController();

                    _regKey = ctrlKey.Get(_regKeyID, _regProdID );
                    _regProduct = ctrlProd.Get(_regProdID, ModuleId);
                    _customer = ctrlUser.GetUser(PortalId, _regProduct.UserID);

                    if (_regKey == null || _regProduct == null || _customer == null)
                    {
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Product, Key, or Customer not found.", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    linkGoToList.NavigateUrl = Globals.NavigateURL();
                    linkGoToRegistration.NavigateUrl = Globals.NavigateURL("Edit", "RegID=" + _regProdID.ToString(), "mid=" + ModuleId.ToString());

                    if (_regKey.RegKey != null)
                    {
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "A registration key has already been generated for the site.", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }
                    else
                    {
                        _regKey.RegKey = ctrlKey.GenerateRegistrationKey(Settings["Seed"].ToString(), _regKey, _regProduct);
                        ctrlKey.Update(_regKey);

                        SendCustomerNotification(_regKey.HostName, _regKey.RegKey);

                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Key generated for site.", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess);
                    }

                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }