コード例 #1
0
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (Page.User.IsInRole("Super"))
            {
                GridViewRow row = GridView1.Rows[e.RowIndex];

                Label   lblId      = row.FindControl("lblId") as Label;
                TextBox txtName    = row.FindControl("txtName") as TextBox;
                TextBox txtType    = row.FindControl("txtType") as TextBox;
                TextBox txtEmail   = row.FindControl("txtEmail") as TextBox;
                TextBox txtLogonId = row.FindControl("txtLogonId") as TextBox;
                TextBox txtEndDate = row.FindControl("txtEndDate") as TextBox;

                if (txtName != null && txtLogonId != null && txtEmail != null)
                {
                    using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                    {
                        int     biostatId = Convert.ToInt32(lblId.Text);
                        BioStat biostat   = context.BioStats.First(x => x.Id == biostatId);
                        biostat.Name    = txtName.Text;
                        biostat.Type    = txtType.Text;
                        biostat.Email   = txtEmail.Text;
                        biostat.LogonId = txtLogonId.Text;
                        biostat.EndDate = DateTime.Parse(txtEndDate.Text);

                        WriteInvest(context, biostat);

                        GridView1.EditIndex = -1;
                        BindGrid();
                    }
                }
            }
        }
コード例 #2
0
        private void WriteInvest(ProjectTrackerContainer context, BioStat biostat)
        {
            var result = context.Entry(biostat).GetValidationResult();

            if (!result.IsValid)
            {
                lblMsg.Text = result.ValidationErrors.First().ErrorMessage;
            }
            else
            {
                context.SaveChanges();
                lblMsg.Text = "Saved successfully.";
            }
        }
コード例 #3
0
        /// <summary>
        /// For adding new entries, if the current user is a super user (that has access to
        /// "Admin" tab on tracking system), a new QHS faculty/staff member is added
        /// to the "Biostat" table.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (Page.User.IsInRole("Super"))
            {
                if (e.CommandName == "InsertNew")
                {
                    GridViewRow row = GridView1.FooterRow;

                    TextBox txtName    = row.FindControl("txtNameNew") as TextBox;
                    TextBox txtType    = row.FindControl("txtTypeNew") as TextBox;
                    TextBox txtEmail   = row.FindControl("txtEmailNew") as TextBox;
                    TextBox txtLogonId = row.FindControl("txtLogonIdNew") as TextBox;
                    TextBox txtEndDate = row.FindControl("txtEndDateNew") as TextBox;

                    if (txtName != null && txtEmail != null && txtLogonId != null)
                    {
                        using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                        {
                            int largestId = context.BioStats.OrderByDescending(b => b.Id).FirstOrDefault(g => g.Id != 99).Id + 1;


                            using (var transaction = context.Database.BeginTransaction())
                            {
                                BioStat biostat = new BioStat()
                                {
                                    Id       = largestId,
                                    Name     = txtName.Text,
                                    Type     = txtType.Text,
                                    Email    = txtEmail.Text,
                                    LogonId  = txtLogonId.Text,
                                    EndDate  = DateTime.Parse(txtEndDate.Text),
                                    BitValue = (long)Math.Pow(2, largestId)
                                };

                                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT BioStats ON");

                                context.BioStats.Add(biostat);
                                WriteInvest(context, biostat);
                                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT BioStats OFF");

                                transaction.Commit();
                            }

                            BindGrid();
                        }
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// NOTE: Currently NOT being used. Populates repeater of checkboxes in "User Rights" section.
        /// </summary>
        /// <param name="enable">Boolean value whether or not the checkboxes should be enabled or disabled for use.</param>
        //private void EnableUserRights(bool enable)
        //{

        //}

        /// <summary>
        /// Checks to see if a valid Biostat entry has been entered into the tracking
        /// system based on the entry saved on the Staff form.
        /// </summary>
        /// <param name="context">Database being referred to.</param>
        /// <param name="biostat">Instance of the BioStat table in the tracking system.</param>
        private void WriteInvest(ProjectTrackerContainer context, BioStat biostat)
        {
            var result = context.Entry(biostat).GetValidationResult();

            if (!result.IsValid)
            {
                lblMsg.Text = result.ValidationErrors.First().ErrorMessage;
            }
            else
            {
                context.SaveChanges();
                //lblMsg.Text = "Saved successfully.";

                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Faculty/staff saved successfully.');", true);
            }
        }
コード例 #5
0
ファイル: StaffForm.aspx.cs プロジェクト: jasndr/QHS_PM
        /// <summary>
        /// For adding new entries, if the current user is a super user (that has access to
        /// "Admin" tab on tracking system), a new QHS faculty/staff member is added
        /// to the "Biostat" table.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (Page.User.IsInRole("Super"))
            {
                if (e.CommandName == "InsertNew")
                {
                    GridViewRow row = GridView1.FooterRow;

                    TextBox txtName    = row.FindControl("txtNameNew") as TextBox;
                    TextBox txtType    = row.FindControl("txtTypeNew") as TextBox;
                    TextBox txtEmail   = row.FindControl("txtEmailNew") as TextBox;
                    TextBox txtLogonId = row.FindControl("txtLogonIdNew") as TextBox;
                    TextBox txtEndDate = row.FindControl("txtEndDateNew") as TextBox;

                    if (txtName != null && txtEmail != null && txtLogonId != null)
                    {
                        using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                        {
                            int largestId = context.BioStats.OrderByDescending(b => b.Id).FirstOrDefault(g => g.Id != 99).Id + 1;

                            BioStat biostat = new BioStat()
                            {
                                //Id = largestId, // <- Ignored by the system!!!
                                Name    = txtName.Text,
                                Type    = txtType.Text,
                                Email   = txtEmail.Text,
                                LogonId = txtLogonId.Text,
                                EndDate = DateTime.Parse(txtEndDate.Text),
                                //BitValue = (long)Math.Pow(2, largestId) // <- To be added once Id can be inserted via Identity Insert
                            };

                            //context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT BioStats ON");

                            context.BioStats.Add(biostat);

                            //context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT BioStats OFF");

                            WriteInvest(context, biostat);

                            BindGrid();
                        }
                    }
                }
            }
        }
コード例 #6
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (Page.User.IsInRole("Super"))
            {
                if (e.CommandName == "InsertNew")
                {
                    GridViewRow row = GridView1.FooterRow;

                    TextBox txtName    = row.FindControl("txtNameNew") as TextBox;
                    TextBox txtType    = row.FindControl("txtTypeNew") as TextBox;
                    TextBox txtEmail   = row.FindControl("txtEmailNew") as TextBox;
                    TextBox txtLogonId = row.FindControl("txtLogonIdNew") as TextBox;
                    TextBox txtEndDate = row.FindControl("txtEndDateNew") as TextBox;

                    if (txtName != null && txtEmail != null && txtLogonId != null)
                    {
                        using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                        {
                            BioStat biostat = new BioStat()
                            {
                                Name    = txtName.Text,
                                Type    = txtType.Text,
                                Email   = txtEmail.Text,
                                LogonId = txtLogonId.Text,
                                EndDate = DateTime.Parse(txtEndDate.Text)
                            };

                            context.BioStats.Add(biostat);

                            WriteInvest(context, biostat);

                            BindGrid();
                        }
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Upon updates the Biostat table in the database based on the
        /// values used in the tracking system.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (Page.User.IsInRole("Super"))
            {
                GridViewRow row = GridView1.Rows[e.RowIndex];

                Label   lblId      = row.FindControl("lblId") as Label;
                TextBox txtName    = row.FindControl("txtName") as TextBox;
                TextBox txtType    = row.FindControl("txtType") as TextBox;
                TextBox txtEmail   = row.FindControl("txtEmail") as TextBox;
                TextBox txtLogonId = row.FindControl("txtLogonId") as TextBox;
                TextBox txtEndDate = row.FindControl("txtEndDate") as TextBox;

                Repeater rptUserRights = row.FindControl("rptUserRights") as Repeater;


                if (txtName != null && txtLogonId != null && txtEmail != null)
                {
                    using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                    {
                        int     biostatId = Convert.ToInt32(lblId.Text);
                        BioStat biostat   = context.BioStats.First(x => x.Id == biostatId);
                        biostat.Name    = txtName.Text;
                        biostat.Type    = txtType.Text;
                        biostat.Email   = txtEmail.Text;
                        biostat.LogonId = txtLogonId.Text;
                        biostat.EndDate = DateTime.Parse(txtEndDate.Text);



                        // Update the user privileges
                        // (Replace or Add/Delete as necessary

                        //var selectedRights = rptUserRights.check

                        AspNetUser biostatUserAcct = context.AspNetUsers.FirstOrDefault(x => x.UserName == biostat.LogonId);

                        if (biostatUserAcct != null)
                        {
                            var qRightsOfCurrUser = context.AspNetUsers
                                                    .Where(x => x.UserName == txtLogonId.Text)
                                                    .Select(y => y.AspNetRoles.Select(z => z.Name)).ToList();

                            // For each of the user rights (Super, Admin, Biostat, ...),
                            // If there is a match in qRightsOfCurrentUser
                            // If there is not already in database
                            foreach (RepeaterItem item in rptUserRights.Items)
                            {
                                CheckBox checkbox = item.FindControl("chkId") as CheckBox;
                                if (checkbox != null)
                                {
                                    var  currRights   = checkbox.Text;
                                    bool markedRights = checkbox.Checked == true ? true : false;

                                    /*AspNetUser */ biostatUserAcct = context.AspNetUsers.First(x => x.UserName == biostat.LogonId);
                                    AspNetRole currAcctRole = context.AspNetRoles.First(x => x.Name == currRights);

                                    if (markedRights)
                                    {
                                        //Add Role if doesn't exist.
                                        if (biostatUserAcct.AspNetRoles.FirstOrDefault(x => x.Name == currRights) == null)
                                        {
                                            biostatUserAcct.AspNetRoles.Add(currAcctRole);
                                        }
                                    }
                                    else
                                    {
                                        // Delete Role if currently exists.
                                        if (biostatUserAcct.AspNetRoles.FirstOrDefault(x => x.Name == currRights) != null)
                                        {
                                            biostatUserAcct.AspNetRoles.Remove(currAcctRole);
                                        }
                                    }
                                }
                            }


                            // Make appropriate user rights checked.
                            foreach (RepeaterItem item in rptUserRights.Items)
                            {
                                CheckBox checkbox = item.FindControl("chkId") as CheckBox;
                                if (checkbox != null)
                                {
                                    // Checks checkbox if the current checkbox exist in rights of current user.
                                    var currRights = checkbox.Text;

                                    bool doesBiostathaveRights = (currRights != null && qRightsOfCurrUser.Where(x => x.Contains(currRights)).FirstOrDefault() != null)
                                                                    ? true : false;

                                    if (qRightsOfCurrUser.Count > 0 && doesBiostathaveRights == true)
                                    {
                                        checkbox.Checked = true;
                                    }
                                }
                            }
                            /****/
                        }

                        WriteInvest(context, biostat);

                        GridView1.EditIndex = -1;
                        BindGrid();
                    }
                }
            }
        }