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 lbnUpdateTotal_Click(object sender, EventArgs e)
        {
            RegistrationProductController ctrlReg = new RegistrationProductController();
            _regProduct.TotalKeys = Int32.Parse(txtNewTotal.Text);
            ctrlReg.Update(_regProduct);

            Response.Redirect(EditUrl("RegID", _regID.ToString()));
        }
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                #region Get parameter and registration
                //Get Reg ID
                if (this.Request.QueryString["RegID"] != null) //if none, then _regID = -1
                {
                    _regID = Int32.Parse(this.Request.QueryString["RegID"]);
                    RegistrationProductController ctrl = new RegistrationProductController();
                    _regProduct = ctrl.Get(_regID, ModuleId);
                }

                if (this.Request.QueryString["Message"] != null)
                {
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, this.Request.QueryString["Message"].ToString(), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
                }

                if (this.Request.QueryString["Success"] != null)
                {
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, this.Request.QueryString["Success"].ToString(), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess);
                }

                //get if current user can edit module
                _currentUserHasEdit = DotNetNuke.Security.Permissions.ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, "EDIT", ModuleConfiguration);
                #endregion

                #region Return if not allowed to see registration
                if (_regProduct != null)
                {
                    //registration found
                    //verify it belongs to current user or current user
                    //Has edit permission
                    if (_regProduct.UserID != UserId && !_currentUserHasEdit)
                    {
                        //todo add log and email notification
                        Response.Redirect(Globals.NavigateURL());
                    }
                    _registrationKeysUsed = _regProduct.KeysUsed();
                }

                #endregion

                this.lbnAddHostName.Attributes.Add("onClick", "javascript:return confirm('Are you sure this is the correct site alias?  Once the key has been generated, site alias can not be changed.');");

                //new reg
                if (_regID == -1)
                {
                    labelKeysRemaining.Visible = false;
                    lblKeysRemaining.Visible = false;
                    lblAddHostName.Visible = false;
                    txtAddHostName.Visible = false;
                    lbnAddHostName.Visible = false;

                    string strProducts = Settings["ProductNames"].ToString();
                    List<string> products = strProducts.Split(';').ToList<string>();
                    if (products.Count > 1)
                    {
                        ddlProductNames.Visible = true;
                        if (!Page.IsPostBack)
                        {
                            ddlProductNames.DataSource = products;
                            ddlProductNames.DataBind();
                        }
                    }
                    else
                    {
                        lblProduct.Text = products[0];
                    }

                    lbnDelete.Visible = false;
                    lbnOK.Text = "Next >";
                }
                //existing reg product
                else
                {
                    //update form
                    ddlProductNames.Visible = false;
                    lblProduct.Text = _regProduct.ProductName;
                    HasKeysAvailable();
                    txtOrderNumber.Visible = false;
                    lblOrderNumber.Text = _regProduct.OrderNumber;
                    lbnCancel.Visible = false;
                    lbnOK.Text = "Close";
                    BindKeys();

                    //current user is module editor
                    if (_currentUserHasEdit)
                    {
                        lbnUpdateTotal.Visible = true;
                        txtNewTotal.Visible = true;
                        lblUpdateKeys.Visible = true;
                        chkApproved.Visible = true;
                        lblApproved.Visible = true;
                        chkApproved.Checked = _regProduct.Approved;
                        if (_regProduct.Approved)
                        {
                            lbnApprove.Visible = false;
                        }
                        else
                        {
                            lbnApprove.Visible = true;
                        }
                    }
                    //current user is customer for existing registration
                    else
                    {

                    }

                    //allow delete for existing prod if no reg keys
                    if (_registrationKeysUsed == 0)
                    {
                        lbnDelete.Visible = true;
                    }
                    else
                    {
                        lbnDelete.Visible = false;
                    }
                }

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void lbnDelete_Click(object sender, EventArgs e)
        {
            RegistrationProductController ctrlReg = new RegistrationProductController();
            RegistrationProduct regProd = ctrlReg.Get(_regID, ModuleId);
            ctrlReg.Delete(regProd);

            Response.Redirect(Globals.NavigateURL());
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            RegistrationProductController ctrlReg = new RegistrationProductController();
            if (_regID == -1)
            {
                RegistrationProduct newProd = new RegistrationProduct();
                newProd.LastUpdateDate = System.DateTime.Now;
                newProd.LastUpdateUserID = UserId;
                newProd.LastUpdateUserName = UserInfo.DisplayName;
                newProd.ModuleID = ModuleId;
                newProd.OrderNumber = txtOrderNumber.Text;
                newProd.PortalID = PortalId;
                if (ddlProductNames.Visible)
                {
                    newProd.ProductName = ddlProductNames.SelectedItem.Text;
                }
                else
                {
                    newProd.ProductName = lblProduct.Text;
                }
                newProd.StartDate = System.DateTime.Now;
                newProd.Status = "New Request";
                newProd.UserID = UserId;
                newProd.TotalKeys = Int32.Parse(Settings["NumberOfKeysPerProduct"].ToString());
                ctrlReg.Create(newProd);

                Response.Redirect(EditUrl("RegID", newProd.ID.ToString(), "Edit", "Success=Your product has been registered!  Add Site Aliases on this form to get registration keys."));
            }
            else
            {
                Response.Redirect(Globals.NavigateURL());
            }
        }
        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" ));
        }
        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));
        }
Пример #8
0
        /// -----------------------------------------------------------------------------
        /// <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);
            }
        }
        private void BindData(bool blShowAll, string strSearch)
        {
            RegistrationProductController registrations = new RegistrationProductController();
            List<RegistrationProduct> regs;

            if (blShowAll)
            {
                if (strSearch == "" || string.IsNullOrEmpty(strSearch))
                {
                    regs = registrations.GetItemsAll(ModuleId);
                }
                else
                {
                    regs = registrations.GetItemsAll(ModuleId, strSearch);
                }

            }
            else
            {
                regs = registrations.GetItemsByUser(UserId, ModuleId);
            }

            gridRegistrations.DataSource = regs;
            gridRegistrations.DataBind();

            if (regs.Count == 0)
            {
                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "You have no registered products.  Click the 'Request New Product Key' button to begin.", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.BlueInfo);
            }
        }
        protected void gridRegistrations_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                string strID = DataBinder.Eval(e.Row.DataItem, "ID").ToString();
                HyperLink link = (HyperLink)e.Row.Cells[0].Controls[0];
                link.NavigateUrl = EditUrl("RegID", strID);

                RegistrationProductController ctrlReg = new RegistrationProductController();
                RegistrationProduct prod = ctrlReg.Get(Int32.Parse(strID), ModuleId);

                e.Row.Cells[4].Text = String.Format("{0} of {1}", prod.KeysUsed(), prod.TotalKeysText());
            }
            catch { }
        }