Example #1
0
        protected void Button5_Click(object sender, EventArgs e)
        {
            try
            {
                var selectedCandidate = long.Parse(DropDownList1.SelectedValue);
                var selectedIndex     = DropDownList1.SelectedIndex;

                var Stdate   = B_StartDate.Text;
                var duration = Duration.Text;
                // var actv = Active.Checked;

                var cand = _db.T_Candidate.FirstOrDefault(s => s.Id == selectedCandidate);


                var batch = new T_Batch
                {
                    Name        = cand.Code + " - " + cand.LastName + " " + cand.FirstName,
                    Description = cand.Code + " - " + cand.LastName + " " + cand.FirstName,
                    StartDate   = ErecruitHelper.GetCurrentDateFromDateStringWithHM(Stdate),
                    Duration    = int.Parse(duration),
                    IsActive    = false,
                    BatchType   = ErecruitHelper.BatchType.Single.ToString(),
                    SessionOn   = false,
                    AddedBy     = SessionHelper.FetchEmail(Session),
                    DateAdded   = DateTime.Now
                };

                _db.T_Batch.Add(batch);
                _db.SaveChanges();

                _db.T_BatchSet.Add(new T_BatchSet
                {
                    CandidateId = selectedCandidate,
                    BatchId     = batch.Id,
                    Finished    = false,
                    IsLive      = false
                });
                _db.SaveChanges();
                var ip = Page.Request.UserHostAddress;
                ErecruitHelper.sendTestInviteMail(cand, batch, Page.Session, ip);
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
        protected bool UpdateTime(string TeacherID)
        {
            bool flag = false;

            var timelist = from T_Batch in db.T_Batch where (T_Batch.TeacherID == TeacherID) select T_Batch;

            if (timelist.Any())
            {
                foreach (T_Batch batch in timelist.ToList())
                {
                    DateTime _lastTime = batch.Datetime;
                    if (DateTime.Now > _lastTime)
                    {
                        //晚点名已过期
                        T_Batch newBatch = db.T_Batch.Find(batch.ID);
                        string  time     = _lastTime.ToString("yyyy-MM-dd HH:mm:ss").Substring(10, 9);

                        int weeknow = Convert.ToInt32(DateTime.Now.DayOfWeek);
                        weeknow = (weeknow == 0 ? 7 : weeknow);
                        int    daydiff = (7 - weeknow);
                        string LastDay = "";
                        if (daydiff == 0)
                        {
                            LastDay = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            LastDay = DateTime.Now.AddDays(daydiff).ToString("yyyy-MM-dd");
                        }
                        string newTime = LastDay + time;

                        newBatch.Datetime = Convert.ToDateTime(newTime);
                        db.SaveChanges();
                        flag = true;
                    }
                }
                //db.SaveChanges();
                ShowNotify("已完成晚点名时间更新!");
            }
            else
            {
                //无数据
                ShowNotify("无晚点名数据!");
            }
            return(flag);
        }
        protected void BindScoreGrid(long id, T_Batch bid)
        {
            //var b_id = _db.T_BatchSet.Where(s => s.CandidateId == id).Select(x => x.BatchId);
            //var candBatch = _db.T_Batch.FirstOrDefault(s => b_id.Contains(s.Id) && s.IsActive.Value);
            var candBatch  = bid;
            var b_question = _db.T_BatchQuestions.Where(s => s.BatchId == candBatch.Id).Select(s => s.QuestionId);

            var quests = _db.T_CandidateAnswers.Where(s => s.CandidateId == id && s.BatchId == candBatch.Id).Select(a => new TestScoreGridModel
            {
                QuestionNo       = a.QuestionId.Value,
                OptionType       = ErecruitHelper.getQOptionTypeName(a.QuestionId.Value),
                CandidateOptions = ErecruitHelper.GetCandidateOptions(id, candBatch.Id, a.QuestionId.Value),
                Url = a.Correct.Value == true ? "../Images/accept.png" : "../Images/delete.png",
                Alt = a.Correct.Value == true ? "Correct":"Wrong"
            }).Distinct().ToList();
            var answered   = quests.Select(s => s.QuestionNo);
            var unanswered = _db.T_Question.Where(s => b_question.Contains(s.Id) && !answered.Contains(s.Id)).Select(a => new TestScoreGridModel
            {
                QuestionNo       = a.Id,
                OptionType       = ErecruitHelper.getQOptionTypeName(a.Id),
                CandidateOptions = "Unanswered",
                Url = "../Images/help.png",
                Alt = "?"
            }).Distinct().ToList();

            int i = quests.Count();

            if (i > 0)
            {
                quests.InsertRange(quests.Count() - 1, unanswered);
            }
            else
            {
                quests.InsertRange(0, unanswered);
            }

            ScoreList.DataSource = quests;
            ScoreList.DataBind();
            ScoreListPanel.Visible = true;
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;

            var PermMgr = new PermissionManager(Session);

            if (PermMgr.IsAdmin || PermMgr.CanManageTestBatches)
            {
                if (!IsPostBack)
                {
                    //Bind Active Batch DropDownList
                    var activeBatches = _db.T_Batch.Where(s => (s.BatchType == ErecruitHelper.BatchType.Multiple.ToString() || s.BatchType == null) && s.IsActive.Value == true).ToList();
                    Batches.DataSource = activeBatches;
                    if (Session["ToBeSelected"] != null)
                    {
                        Batches.SelectedIndex = int.Parse(Session["ToBeSelected"].ToString());
                    }
                    Batches.DataBind();

                    //Bind Active Candidate ListBox
                    var cands = _db.T_Candidate.Where(s => s.ApprovalStatus == ErecruitHelper.ApprovalStatus.APPROVED.ToString() && s.IsActive.Value == true).Select(a => new CandidateDropDownModel
                    {
                        ID   = a.Id,
                        Name = a.Code + " - " + a.LastName + " " + a.FirstName
                    }).ToList();
                    ActiveCandidateList.DataSource = cands;
                    ActiveCandidateList.DataBind();

                    //Bind Active Batch Content ListBox

                    var x             = string.IsNullOrEmpty(Batches.SelectedValue) ? "0" : Batches.SelectedValue;
                    var selectedBatch = long.Parse(x);
                    var batch         = new T_Batch();
                    if (selectedBatch == 0)
                    {
                        batch = new T_Batch
                        {
                            Id   = 0,
                            Name = "No Active batch."
                        };
                    }
                    else
                    {
                        batch = _db.T_Batch.FirstOrDefault(s => s.Id == selectedBatch);
                    }

                    List <BatchContentDropDownModel> activeContent = _db.T_BatchSet.Where(s => s.BatchId == selectedBatch).Select(a => new BatchContentDropDownModel
                    {
                        ID   = a.CandidateId.Value,
                        Name = _db.T_Candidate.FirstOrDefault(s => s.Id == a.CandidateId).Code + " - " + _db.T_Candidate.FirstOrDefault(s => s.Id == a.CandidateId).FirstName + " " + _db.T_Candidate.FirstOrDefault(s => s.Id == a.CandidateId).LastName
                    }).ToList();

                    if (activeContent.Count > 0)
                    {
                        ActiveContentList.DataSource = activeContent;
                        ActiveContentList.DataBind();
                        SendInvite.Enabled = true;
                    }
                    else
                    {
                        activeContent = new List <BatchContentDropDownModel>();
                        activeContent.Add(new BatchContentDropDownModel
                        {
                            ID   = 0,
                            Name = "---" + batch.Name + " is Empty---"
                        });
                        ActiveContentList.DataSource = activeContent;
                        ActiveContentList.DataBind();
                        SendInvite.Enabled = false;
                    }

                    //Bind DropDownList1 ListBox
                    var cs = _db.T_Candidate.Where(s => s.ApprovalStatus == ErecruitHelper.ApprovalStatus.APPROVED.ToString() && s.IsActive.Value == true).Select(a => new CandidateDropDownModel
                    {
                        ID   = a.Id,
                        Name = a.Code + " - " + a.LastName + " " + a.FirstName
                    }).ToList();
                    DropDownList1.DataSource = cs;
                    DropDownList1.DataBind();
                }
            }
            else
            {
                Response.Redirect("NoPermission.aspx", false);
            }
        }
Example #5
0
        public ActionResult btnSubmit_Click(FormCollection form, JArray first, JArray second, JArray third)
        {
            string teacherid  = Session["UserID"].ToString();
            string date       = form["dpDate"];
            string time_one   = form["tpFirst"];
            string time_two   = form["tpSecond"];
            string time_three = form["tpThird"];

            DateTime dt_one   = Convert.ToDateTime(date + " " + time_one + ":00");
            DateTime dt_two   = Convert.ToDateTime(date + " " + time_two + ":00");
            DateTime dt_three = Convert.ToDateTime(date + " " + time_three + ":00");

            T_Batch batch;
            T_Class t_class;
            Guid    id;

            #region 清除该辅导员管理的班级的批次信息
            var classes = from c in db.T_Class
                          where c.TeacherID == teacherid
                          select c;
            foreach (var item in classes)
            {
                item.Batch           = null;
                db.Entry(item).State = EntityState.Modified;
            }
            db.SaveChanges();
            #endregion

            #region 第一批
            if ((time_one != null) && (first.Count > 0))
            {
                batch = new T_Batch();

                var batch_id = from b in db.T_Batch
                               where b.Batch == 1 && b.TeacherID == teacherid
                               select b.ID;

                //辅导员是否设置过晚点名通知
                if (batch_id.Count() == 0)
                {
                    batch.ID        = Guid.NewGuid();
                    batch.Batch     = 1;
                    batch.TeacherID = teacherid;
                    batch.Datetime  = dt_one;
                    db.T_Batch.Add(batch);
                }
                else
                {
                    id                    = batch_id.ToList().First();
                    batch                 = db.T_Batch.Find(id);
                    batch.Datetime        = dt_one;
                    db.Entry(batch).State = EntityState.Modified;
                }
                db.SaveChanges();

                batch_id = from b in db.T_Batch
                           where b.Batch == 1 && b.TeacherID == teacherid
                           select b.ID;
                id = batch_id.ToList().First();
                foreach (JObject item in first)
                {
                    t_class                 = db.T_Class.Find(item["ID"].ToString());
                    t_class.Batch           = id;
                    db.Entry(t_class).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            #endregion

            #region 第二批
            if ((time_two != null) && (second.Count > 0))
            {
                batch = new T_Batch();
                var batch_id = from b in db.T_Batch
                               where b.Batch == 2 && b.TeacherID == teacherid
                               select b.ID;

                //辅导员是否设置过晚点名通知
                if (batch_id.Count() == 0)
                {
                    batch.ID        = Guid.NewGuid();
                    batch.Batch     = 2;
                    batch.TeacherID = teacherid;
                    batch.Datetime  = dt_two;
                    db.T_Batch.Add(batch);
                }
                else
                {
                    id                    = batch_id.ToList().First();
                    batch                 = db.T_Batch.Find(id);
                    batch.Datetime        = dt_two;
                    db.Entry(batch).State = EntityState.Modified;
                }
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                }


                batch_id = from b in db.T_Batch
                           where b.Batch == 2 && b.TeacherID == teacherid
                           select b.ID;
                id = batch_id.ToList().First();
                foreach (JObject item in second)
                {
                    t_class                 = db.T_Class.Find(item["ID"].ToString());
                    t_class.Batch           = id;
                    db.Entry(t_class).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            #endregion

            #region 第三批
            if ((time_three != null) && (third.Count > 0))
            {
                batch = new T_Batch();
                var batch_id = from b in db.T_Batch
                               where b.Batch == 3 && b.TeacherID == teacherid
                               select b.ID;

                //辅导员是否设置过晚点名通知
                if (batch_id.Count() == 0)
                {
                    batch.ID        = Guid.NewGuid();
                    batch.Batch     = 3;
                    batch.TeacherID = teacherid;
                    batch.Datetime  = dt_three;
                    db.T_Batch.Add(batch);
                }
                else
                {
                    id                    = batch_id.ToList().First();
                    batch                 = db.T_Batch.Find(id);
                    batch.Datetime        = dt_three;
                    db.Entry(batch).State = EntityState.Modified;
                }
                db.SaveChanges();

                batch_id = from b in db.T_Batch
                           where b.Batch == 3 && b.TeacherID == teacherid
                           select b.ID;
                id = batch_id.ToList().First();
                foreach (JObject item in third)
                {
                    t_class                 = db.T_Class.Find(item["ID"].ToString());
                    t_class.Batch           = id;
                    db.Entry(t_class).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            #endregion

            Alert alert = new Alert();
            alert.Message     = "晚点名通知设置成功";
            alert.EnableClose = false;
            alert.Show();
            return(UIHelper.Result());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;
            var    PermMgr             = new PermissionManager(Session);

            if (PermMgr.IsAdmin || PermMgr.CanManageTestResults)
            {
                var c = SessionHelper.FetchCandidateCode(Session);
                if (!string.IsNullOrEmpty(c))
                {
                    var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == c);
                    if (!(cand == null))
                    {
                        var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId).ToList();

                        if (b_id.Count() != 0)
                        {
                            var bs        = new T_BatchSet();
                            var candBatch = new T_Batch();

                            if (Session["BatchSetId"] != null)
                            {
                                bs        = _db.T_BatchSet.FirstOrDefault(s => s.Id == long.Parse(Session["BatchSetId"].ToString()));
                                candBatch = _db.T_Batch.FirstOrDefault(s => s.Id == bs.BatchId);
                                var b_set  = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).ToList();
                                var quests = b_set.Select(a => new PrevBatchGridModel
                                {
                                    ID        = a.Id,
                                    BatchName = ErecruitHelper.getBatchName((long)a.BatchId),
                                    Code      = a.Finished == true ? ErecruitHelper.getCandidateCode((long)a.CandidateId) + "," + a.Id : ErecruitHelper.getCandidateCode((long)a.CandidateId),
                                    DateTaken = a.Finished == true ? a.TimeStarted.ToString() : "Not Finished."
                                }).Distinct().ToList();
                                batchHistory.DataSource = quests;
                                batchHistory.DataBind();
                                batchHistoryPanel.Visible = true;
                            }
                            else
                            {
                                bs        = _db.T_BatchSet.FirstOrDefault(s => s.CandidateId == cand.Id);
                                candBatch = _db.T_Batch.FirstOrDefault(s => s.Id == bs.BatchId);
                            }

                            if (bs.Finished == true)
                            {
                                int    totalQuestions = _db.T_BatchQuestions.Count(s => s.BatchId == candBatch.Id);
                                int    correct        = _db.T_CandidateAnswers.Count(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id && s.Correct == true);
                                double percentage     = (double)correct / totalQuestions;
                                percentage = Math.Round((percentage * 100), 2);

                                var rsltTxt = "Candidate Name: " + cand.FirstName + " " + cand.LastName + "<br /><br />Got " + correct + " question(s)  out of " + totalQuestions + " questions.<br /><br />Percentage Score: " + percentage + " %";

                                name.Text = rsltTxt;
                                CID.Value = cand.Code;
                                BID.Value = candBatch.Id.ToString();
                                BindScoreGrid(cand.Id, candBatch);
                            }
                            else
                            {
                                var rsltTxt = "The candidate has not concluded the test.";

                                name.Text = rsltTxt;
                                batchHistoryPanel.Visible = false;
                                ScoreListPanel.Visible    = false;
                            }
                        }
                        else
                        {
                            resultLbl.Text            = "The candidate has not been assigned to a test batch.";
                            batchHistoryPanel.Visible = false;
                            ScoreListPanel.Visible    = false;
                        }
                    }
                    else
                    {
                        resultLbl.Text            = "This is not a valid candidate code";
                        batchHistoryPanel.Visible = false;
                        ScoreListPanel.Visible    = false;
                    }
                }
            }
            else
            {
                batchHistoryPanel.Visible = false;
                ScoreListPanel.Visible    = false;
                Response.Redirect("NoPermission.aspx", false);
            }
        }