protected void btnAddNew_Click(object sender, EventArgs e)
        {
            Validate("vgAddRating");
            if (!Page.IsValid)
            {
                return; // let the validation do its thing?
            }
            CustomRatingProgress crp = new CustomRatingProgress()
            {
                Title = txtNewTitle.Text, FARLink = string.Empty, GeneralDisclaimer = txtNewDisclaimer.Text, Username = Page.User.Identity.Name
            };

            List <CustomRatingProgress> lst = new List <CustomRatingProgress>(CustomRatingProgress.CustomRatingsForUser(Page.User.Identity.Name))
            {
                crp
            };

            CustomRatingProgress.CommitRatingsForUser(Page.User.Identity.Name, lst);

            txtNewDisclaimer.Text = txtNewDisclaimer.Text = string.Empty;

            RefreshCustomRatings();

            UpdateMilestones();
        }
Exemplo n.º 2
0
        public CustomRatingsGroup(string szUser) : base()
        {
            GroupName = Resources.MilestoneProgress.CustomProgressSection;
            IEnumerable <MilestoneProgress> rg = CustomRatingProgress.CustomRatingsForUser(szUser);

            foreach (MilestoneProgress rating in rg)
            {
                m_ratings.Add(rating);
            }
        }
        protected void btnAddMilestone_Click(object sender, EventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            mpeEditMilestones.Show();   // keep this visible

            int rowIndex = Convert.ToInt32(hdnCpeIndex.Value, CultureInfo.InvariantCulture);

            Validate("vgMilestone");
            if (!Page.IsValid)
            {
                return;
            }

            // Additional validations
            if (decThreshold.Value <= 0)
            {
                lblErrThreshold.Visible = true;
                return;
            }

            List <CustomRatingProgress> lst = new List <CustomRatingProgress>(CustomRatingProgress.CustomRatingsForUser(Page.User.Identity.Name));
            CustomRatingProgress        crp = lst[rowIndex];

            crp.AddMilestoneItem(new CustomRatingProgressItem()
            {
                Title             = txtMiTitle.Text,
                FARRef            = txtMiFARRef.Text,
                Note              = txtMiNote.Text,
                Threshold         = decThreshold.Value,
                QueryName         = cmbQueries.SelectedValue,
                FieldName         = cmbFields.SelectedValue,
                FieldFriendlyName = cmbFields.SelectedItem.Text
            });
            CustomRatingProgress.CommitRatingsForUser(Page.User.Identity.Name, lst);

            gvCustomRatingItems.DataSource = crp.ProgressItems;
            gvCustomRatingItems.DataBind();
            UpdateMilestones();

            // Set up for the next one.
            cmbQueries.SelectedValue = txtMiFARRef.Text = txtMiTitle.Text = txtMiNote.Text = string.Empty;
            cmbFields.SelectedIndex  = 0;
            decThreshold.Value       = 0;
        }
        protected void gvCustomRatings_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            GridView gv = sender as GridView;
            List <CustomRatingProgress> lst = new List <CustomRatingProgress>(CustomRatingProgress.CustomRatingsForUser(Page.User.Identity.Name));

            if (e.CommandName.CompareCurrentCultureIgnoreCase("_DeleteRating") == 0)
            {
                lst.RemoveAll(crp => crp.Title.CompareCurrentCulture((string)e.CommandArgument) == 0);
                gvCustomRatings.EditIndex = -1;
                CustomRatingProgress.CommitRatingsForUser(Page.User.Identity.Name, lst);
                RefreshCustomRatings();

                UpdateMilestones();
            }
            else if (e.CommandName.CompareCurrentCultureIgnoreCase("_DeleteMilestone") == 0)
            {
                CustomRatingProgress crp = lst[Convert.ToInt32(hdnCpeIndex.Value, CultureInfo.InvariantCulture)];
                crp.RemoveMilestoneAt(Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture));
                mpeEditMilestones.Show();   // keep the dialog open
                CustomRatingProgress.CommitRatingsForUser(Page.User.Identity.Name, lst);
                gv.DataSource = crp.ProgressItems;
                gv.DataBind();
                UpdateMilestones();
            }
            else if (e.CommandName.CompareCurrentCultureIgnoreCase("_EditMilestones") == 0)
            {
                int row = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture);
                CustomRatingProgress crp = lst[row];
                hdnCpeIndex.Value = row.ToString(CultureInfo.InvariantCulture);

                if (cmbFields.Items.Count == 0)
                {
                    // initialize the editing drop-downs, if needed
                    cmbFields.DataSource = HistogramableValues;
                    cmbFields.DataBind();
                    cmbQueries.DataSource = CannedQuery.QueriesForUser(User.Identity.Name);
                    cmbQueries.DataBind();
                }

                lblEditMilestonesForProgress.Text = String.Format(CultureInfo.InvariantCulture, Resources.MilestoneProgress.CustomProgressMilestonesForCustomRating, HttpUtility.HtmlEncode(crp.Title));
                gvCustomRatingItems.DataSource    = crp.ProgressItems;
                gvCustomRatingItems.DataBind();
                mpeEditMilestones.Show();
            }
            else if (e.CommandName.CompareCurrentCultureIgnoreCase("Update") == 0)
            {
                // Find the existing item
                CustomRatingProgress crp = lst[gv.EditIndex];
                if (crp != null)
                {
                    string szNewTitle = ((TextBox)gv.Rows[0].Cells[1].Controls[0]).Text;
                    if (String.IsNullOrWhiteSpace(szNewTitle))
                    {
                        return;
                    }
                    crp.Title             = szNewTitle;
                    crp.GeneralDisclaimer = ((TextBox)gv.Rows[0].Cells[2].Controls[0]).Text;
                }
                CustomRatingProgress.CommitRatingsForUser(Page.User.Identity.Name, lst);
                gvCustomRatings.EditIndex = -1;

                RefreshCustomRatings();
                UpdateMilestones();
            }
        }
 protected void RefreshCustomRatings()
 {
     gvCustomRatings.DataSource = CustomRatingProgress.CustomRatingsForUser(TargetUser);
     gvCustomRatings.DataBind();
 }