Exemplo n.º 1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //questionIdList = (List<int>)Session["questionIdList"];
            //choiceList = (List<int>)Session["choiceList"];

            IIdentity id       = User.Identity;
            dynamic   profile  = ProfileBase.Create(id.Name);
            string    username = id.Name;

            foreach (GridViewRow row in gvQuestions.Rows)
            {
                RadioButtonList rblOptions    = (RadioButtonList)row.FindControl("rblOptions");
                Label           lblQuestionId = (Label)row.FindControl("lblQuestionId");
                Label           lblQuestion   = (Label)row.FindControl("lblQuestion");

                if (rblOptions.SelectedItem != null)
                {
                    int qId      = Convert.ToInt32(lblQuestionId.Text);
                    int choiceId = Convert.ToInt32(rblOptions.SelectedValue);
                    questionIdList.Add(qId);
                    choiceList.Add(choiceId);
                }
            }

            string confirmValue = Request.Form["confirm_value"];

            if (confirmValue == "Yes")
            {
                QuizResult qr     = new QuizResult();
                int        quizId = Convert.ToInt32(Session["QuizId"]);
                qr.QuizId        = quizId;
                qr.Username      = username;
                qr.Name          = context.Employees.Where(x => x.UserName == username).Select(x => x.Name).First();
                qr.TimeSubmitted = DateTime.Now;
                context.QuizResults.Add(qr);
                context.SaveChanges();

                QuizResult qr2          = context.QuizResults.Where(x => x.Username == username).Where(x => x.QuizId == quizId).OrderByDescending(x => x.ResultId).First();
                int        quizResultId = qr2.ResultId;

                for (int i = 0; i < questionIdList.Count; i++)
                {
                    QuestionResponse qresp = new QuestionResponse();
                    qresp.ResultId      = qr2.ResultId;
                    qresp.QuestionId    = questionIdList.ElementAt(i);
                    qresp.OptionId      = choiceList.ElementAt(i);
                    qresp.TimeSubmitted = DateTime.Now;
                    context.QuestionResponses.Add(qresp);
                    context.SaveChanges();
                }

                Session["ResultId"] = quizResultId;
                Response.Redirect("~/Users/ViewQuizResult.aspx");
            }
        }
Exemplo n.º 2
0
 public void UpdateObservation(Observation obs)
 {
     try
     {
         using (context = new QHSEEntities())
         {
             Observation observation = context.Observations.Where(x => x.CardId == obs.CardId).First <Observation>();
             observation.Date            = obs.Date;
             observation.Location        = obs.Location;
             observation.Others          = obs.Others;
             observation.Classification  = obs.Classification;
             observation.Description     = obs.Description;
             observation.ImmediateAction = obs.ImmediateAction;
             observation.FurtherAction   = obs.FurtherAction;
             observation.PositiveComment = obs.PositiveComment;
             observation.PhotoPath       = obs.PhotoPath;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
         //}
     }
 }
Exemplo n.º 3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            IIdentity      id       = User.Identity;
            dynamic        profile  = ProfileBase.Create(id.Name);
            string         username = id.Name;
            MembershipUser m        = Membership.GetUser(id.Name);

            string password         = context.Employees.Where(x => x.UserName == username).Select(x => x.Password).First();
            string encryptedPwInput = FormsAuthentication.HashPasswordForStoringInConfigFile(tbxCurrentPw.Text, "MD5");

            try
            {
                if (encryptedPwInput == password)
                {
                    if (tbxNewPw.Text != "")
                    {
                        m.ChangePassword(m.ResetPassword(), tbxNewPw.Text);
                    }
                    Employee emp = context.Employees.Where(x => x.UserName == username).First();
                    emp.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(tbxNewPw.Text, "MD5");

                    context.SaveChanges();
                    Response.Redirect("~/Admin/ReportList.aspx");
                }
            }

            catch (Exception ex)
            {
                Response.Write(ex);
                lblError.Text = "Error! Password hasn't been changed.";
            }
        }
Exemplo n.º 4
0
 public void UpdateEmployee(Employee emp)
 {
     try
     {
         using (context = new QHSEEntities())
         {
             Employee employee = context.Employees.Where(x => x.UserName == emp.UserName).First <Employee>();
             employee.UserName = emp.UserName;
             employee.Name     = emp.Name;
             if (emp.HRMS != null)
             {
                 employee.HRMS = emp.HRMS;
             }
             employee.Title      = emp.Title;
             employee.Department = emp.Department;
             employee.Email      = emp.Email;
             employee.Role       = emp.Role;
             if (emp.Password != null)
             {
                 employee.Password = emp.Password;
             }
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 5
0
        protected void btnSubmit_Click(object sned, EventArgs e)
        {
            Observation o = new Observation();

            //Take submitter name from cookies
            o.Name           = Session["username"].ToString();
            o.Date           = DateTime.Today.Date;
            o.Location       = ddlLocation.Text;
            o.Classification = ddlClassification.Text;
            o.Description    = tbxDescription.Text;
            string fileName  = DateTime.Now.ToString("ddMMyyyy-hhmmss") + Path.GetExtension(UploadPhoto.FileName);
            string photopath = Server.MapPath("~/Pictures/") + fileName;

            if (UploadPhoto.PostedFile.FileName == "" || UploadPhoto.PostedFile.FileName == null)
            {
                photopath   = null;
                o.PhotoPath = null;
            }
            else
            {
                //string fileName = tbxReportNo.Text + Path.GetExtension(UploadPhoto.FileName);
                //string photopath = Server.MapPath("~/Pictures/") + fileName;
                UploadPhoto.SaveAs(photopath);
                o.PhotoPath = fileName;
            }

            o.ImmediateAction = tbxImmAction.Text;
            o.FurtherAction   = tbxFurtherAction.Text;
            o.PositiveComment = tbxComment.Text;

            context.Observations.Add(o);
            context.SaveChanges();
            Response.Redirect("~/ObservationList.aspx");
        }
Exemplo n.º 6
0
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            string createdUsername = CreateUserWizard1.UserName;
            string createdPassword = CreateUserWizard1.Password;
            //dynamic profile = ProfileBase.Create(createdUsername);
            CreateUserWizardStep step1 = (CreateUserWizardStep)CreateUserWizard1.FindControl("Step1");
            DropDownList         k1    = (DropDownList)step1.ContentTemplateContainer.FindControl("ddlDept");
            DropDownList         k2    = (DropDownList)step1.ContentTemplateContainer.FindControl("ddlRole");
            TextBox k3       = (TextBox)step1.ContentTemplateContainer.FindControl("tbxName");
            TextBox k4       = (TextBox)step1.ContentTemplateContainer.FindControl("UserName");
            TextBox tbxTitle = (TextBox)step1.ContentTemplateContainer.FindControl("tbxTitle");
            TextBox tbxEmail = (TextBox)step1.ContentTemplateContainer.FindControl("tbxEmail");
            TextBox tbxHRMS  = (TextBox)step1.ContentTemplateContainer.FindControl("tbxHRMS");

            Roles.AddUserToRole(createdUsername, k2.Text);

            //profile.dept = k1.Text;
            //profile.role = k2.SelectedItem.Text;
            //profile.name = k3.Text;
            //profile.username = k4.Text;
            //profile.Save();

            string encryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(createdPassword, "MD5");

            try
            {
                Employee emp = new Employee();

                if (tbxHRMS.Text != "")
                {
                    emp.HRMS = tbxHRMS.Text;
                }

                emp.Name       = k3.Text;
                emp.Title      = tbxTitle.Text;
                emp.HRMS       = tbxHRMS.Text;
                emp.Department = k1.Text;
                emp.UserName   = createdUsername;
                emp.Password   = encryptedPassword;
                emp.Email      = tbxEmail.Text;
                emp.Role       = k2.SelectedItem.Text;

                context.Employees.Add(emp);
                context.SaveChanges();
            }

            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}",
                                                                  validationError.PropertyName,
                                                                  validationError.ErrorMessage);
                    }
                }
            }
        }
Exemplo n.º 7
0
        protected void btnSubmit_Click(object sned, EventArgs e)
        {
            Observation o = new Observation();

            string username = context.Employees.Where(x => x.Name == ddlName.Text).Select(x => x.UserName).First();
            string HRMS     = context.Employees.Where(x => x.UserName == o.Name).Select(x => x.HRMS).First();

            try
            {
                o.Name           = username;
                o.HRMS           = HRMS;
                o.Date           = DateTime.Today.Date;
                o.Location       = ddlLocation.Text;
                o.Classification = ddlClassification.Text;
                o.Description    = tbxDescription.Text;
                string fileName  = DateTime.Now.ToString("ddMMyyyy-hhmmss") + Path.GetExtension(UploadPhoto.FileName);
                string photopath = Server.MapPath("~/Pictures/") + fileName;
                if (UploadPhoto.PostedFile.FileName == "" || UploadPhoto.PostedFile.FileName == null)
                {
                    photopath   = null;
                    o.PhotoPath = null;
                }
                else
                {
                    //string fileName = tbxReportNo.Text + Path.GetExtension(UploadPhoto.FileName);
                    //string photopath = Server.MapPath("~/Pictures/") + fileName;
                    UploadPhoto.SaveAs(photopath);
                    o.PhotoPath = fileName;
                }

                o.ImmediateAction = tbxImmAction.Text;
                o.FurtherAction   = tbxFurtherAction.Text;
                o.PositiveComment = tbxComment.Text;

                context.Observations.Add(o);
                context.SaveChanges();
                Response.Redirect("~/Admin/ObservationReport.aspx");
            }
            catch (Exception ex)
            {
                Response.Write(ex);
                lblError.Text = "Error! Observation card hasn't been created.";
            }
        }
Exemplo n.º 8
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                IIdentity id      = User.Identity;
                dynamic   profile = ProfileBase.Create(id.Name);

                string username = id.Name;

                Report r = new Report();
                r.ReportNo       = tbxReportNo.Text;
                r.Date           = Convert.ToDateTime(tbxDate.Text);
                r.Location       = ddlLocation.Text;
                r.Classification = ddlClassification.Text;
                r.Description    = tbxDescription.Text;
                r.Memo           = tbxMemo.Text;

                //Submitter name value will be added from cookies later
                r.SubmitterName = username;
                string fileName  = tbxReportNo.Text + Path.GetExtension(UploadPhoto.FileName);
                string photopath = Server.MapPath("~/Pictures/") + fileName;
                if (UploadPhoto.PostedFile.FileName == "" || UploadPhoto.PostedFile.FileName == null)
                {
                    photopath   = null;
                    r.PhotoPath = null;
                }
                else
                {
                    //string fileName = tbxReportNo.Text + Path.GetExtension(UploadPhoto.FileName);
                    //string photopath = Server.MapPath("~/Pictures/") + fileName;
                    UploadPhoto.SaveAs(photopath);
                    r.PhotoPath = fileName;
                }
                context.Reports.Add(r);
                context.SaveChanges();
                Response.Redirect("~/Admin/ReportList.aspx");
            }
            catch (Exception ex)
            {
                Response.Write("Error:" + ex);
            }
        }
Exemplo n.º 9
0
        protected void btnSubmit_Click(object sned, EventArgs e)
        {
            IIdentity id      = User.Identity;
            dynamic   profile = ProfileBase.Create(id.Name);

            string username = id.Name;
            string HRMS     = context.Employees.Where(x => x.UserName == username).Select(x => x.HRMS).First();

            Observation o = new Observation();

            //Take submitter name from cookies
            o.Name           = username;
            o.HRMS           = HRMS;
            o.Date           = DateTime.Today.Date;
            o.Location       = ddlLocation.Text;
            o.Others         = tbxOthers.Text;
            o.Classification = ddlClassification.Text;
            o.Description    = tbxDescription.Text;
            string fileName  = DateTime.Now.ToString("ddMMyyyy-hhmmss") + Path.GetExtension(UploadPhoto.FileName);
            string photopath = Server.MapPath("~/Pictures/") + fileName;

            if (UploadPhoto.PostedFile.FileName == "" || UploadPhoto.PostedFile.FileName == null)
            {
                photopath   = null;
                o.PhotoPath = null;
            }
            else
            {
                //string fileName = tbxReportNo.Text + Path.GetExtension(UploadPhoto.FileName);
                //string photopath = Server.MapPath("~/Pictures/") + fileName;
                UploadPhoto.SaveAs(photopath);
                o.PhotoPath = fileName;
            }

            o.ImmediateAction = tbxImmAction.Text;
            o.FurtherAction   = tbxFurtherAction.Text;
            o.PositiveComment = tbxComment.Text;

            context.Observations.Add(o);
            context.SaveChanges();
            Response.Redirect("~/Users/ObservationList.aspx");
        }
Exemplo n.º 10
0
        protected void gvDept_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row      = gvDept.Rows[e.RowIndex];
            string      admin    = (row.FindControl("ddlAdmin") as DropDownList).Text;
            string      deptName = (row.FindControl("tbxDeptName") as TextBox).Text;
            //using (context = new QHSEEntities())
            //{

            Department d = context.Departments.Where(x => x.Name == deptName).First <Department>();

            d.Name      = deptName;
            d.DeptAdmin = admin;

            context.SaveChanges();
            //}
            gvDept.EditIndex  = -1;
            gvDept.DataSource = context.Departments.Where(x => x.Name.Contains("Hub")).ToList();
            gvDept.DataBind();
            //this.BindGrid();
        }
Exemplo n.º 11
0
        protected void gvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string username = gvUser.Rows[e.RowIndex].Cells[1].Text;

            string query = "SELECT DISTINCT UserId FROM aspnet_Users WHERE UserName = '******'";

            con = new SqlConnection(conStr);
            SqlDataAdapter adapter = new SqlDataAdapter(query, con);
            DataTable      dt      = new DataTable();

            adapter.Fill(dt);
            //DataSet dataset = new DataSet();
            //adapter.Fill(dataset);

            Guid userId = Guid.Parse(dt.Rows[0][0].ToString());



            using (QHSEEntities context = new QHSEEntities())
            {
                Employee emp = context.Employees.Where(x => x.UserName == username).First <Employee>();
                context.Employees.Remove(emp);

                //aspnet_Profile profile = context.aspnet_Profile.Where(x => x.PropertyValuesString == username).First();
                //context.aspnet_Profile.Remove(profile);

                aspnet_Users user = context.aspnet_Users.Where(x => x.UserName == username).First();
                context.aspnet_Users.Remove(user);

                aspnet_Membership mem = context.aspnet_Membership.Where(x => x.UserId == userId).First();
                context.aspnet_Membership.Remove(mem);

                aspnet_UsersInRoles userInRole = context.aspnet_UsersInRoles.Where(x => x.UserId == userId).First();
                context.aspnet_UsersInRoles.Remove(userInRole);


                context.SaveChanges();
                Response.Redirect("~/Admin/ManageUsers.aspx");
            }
        }
Exemplo n.º 12
0
        protected void btnCreateDept_Click(object sender, EventArgs e)
        {
            Department dept = new Department();

            dept.Name = tbxDeptName.Text;
            if (ddlAdmin.SelectedValue != "")

            {
                try
                {
                    dept.DeptAdmin = ddlAdmin.Text;

                    context.Departments.Add(dept);
                    context.SaveChanges();
                    Response.Redirect("~/Admin/ManageDepartments.aspx");
                }
                catch (Exception ex)
                {
                    lblError.Text = "Error! New department hasn't been added.";
                }
            }
        }
Exemplo n.º 13
0
 public void UpdateReport(Report r)
 {
     try
     {
         using (context = new QHSEEntities())
         {
             Report report = context.Reports.Where(x => x.ReportNo == r.ReportNo).First <Report>();
             report.ReportNo       = r.ReportNo;
             report.Date           = r.Date;
             report.Location       = r.Location;
             report.Classification = r.Classification;
             report.Description    = r.Description;
             report.Memo           = r.Memo;
             if (report.PhotoPath == null)
             {
                 report.PhotoPath = r.PhotoPath;
             }
             else
             {
                 if (r.PhotoPath != null && r.PhotoPath != "")
                 {
                     report.PhotoPath = r.PhotoPath;
                 }
                 else
                 {
                     report.PhotoPath = report.PhotoPath;
                 }
             }
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 14
0
        protected void gvQuestions_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            int quizResultId = Convert.ToInt32(Session["ResultId"]);

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                QuizControl qc = new QuizControl();

                Label lblQuestionId    = (Label)e.Row.FindControl("lblQuestionId");
                Label lblRightWrong    = (Label)e.Row.FindControl("lblRightWrong");
                Label lblYourAnswer    = (Label)e.Row.FindControl("lblYourAnswer");
                Label lblCorrectAnswer = (Label)e.Row.FindControl("lblCorrectAnswer");

                int questionId = Convert.ToInt32(lblQuestionId.Text);


                lblYourAnswer.Text    = qc.GetOwnAnswer(questionId, quizResultId);
                lblCorrectAnswer.Text = qc.GetCorrectAnswer(questionId);

                if (lblYourAnswer.Text == lblCorrectAnswer.Text)
                {
                    lblRightWrong.ForeColor = System.Drawing.Color.Green;
                    lblRightWrong.Text      = "Correct! 正确!";
                    correctCount++;
                }

                else if (lblYourAnswer.Text == null || lblYourAnswer.Text == "")
                {
                    lblYourAnswer.Visible    = false;
                    lblCorrectAnswer.Visible = false;
                    lblRightWrong.ForeColor  = System.Drawing.Color.Red;
                    lblRightWrong.Text       = "Cannot mark. This question might have been added after your quiz attempt. - 不能标记. 您的测验尝试后可能会添加此问题。";
                }

                else
                {
                    lblRightWrong.ForeColor = System.Drawing.Color.Red;
                    lblRightWrong.Text      = "Incorrect! 不正确!";
                    incorrectCount++;
                }

                decimal percentage = 100 * correctCount / (correctCount + incorrectCount);
                lblScore.Text = percentage.ToString() + "%";
                if (percentage >= 80)
                {
                    lblScore.ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    lblScore.ForeColor = System.Drawing.Color.Red;
                }

                QuizResult qr = context.QuizResults.Where(x => x.ResultId == quizResultId).First();
                //if (qr.Correct == null || qr.Incorrect == null || qr.Result == null)
                //{
                qr.Correct   = correctCount;
                qr.Incorrect = incorrectCount;
                if (percentage >= 80)
                {
                    qr.Result = "Pass - 通过";
                }
                else
                {
                    qr.Result = "Fail - 失败";
                }
                context.SaveChanges();
                //}
            }
        }