コード例 #1
0
        private void Import_To_Grid(string FilePath, string Extension, string isHDR)
        {
            logger.Debug(String.Format("####### --- Begin Start Load File at {0} --- ####", DateTime.Now));
            int rejected = 0;
            List <TB_SCORE_ROUND_1> stdList         = new List <TB_SCORE_ROUND_1>();
            List <TB_EXAM_ABSENT>   stdAppsentList  = new List <TB_EXAM_ABSENT>();
            List <TB_CONCERN>       stdConcerntList = new List <TB_CONCERN>();

            using (ChinaPhet10Entities context = new ChinaPhet10Entities())
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                using (CsvFileReader reader = new CsvFileReader(FilePath))
                {
                    CsvRow row = new CsvRow();
                    while (reader.ReadRow(row))
                    {
                        try
                        {
                            int stdCode = ((row[0] == null) ? 0 : (row[0].Equals("")) ? 0 : Convert.ToInt32(row[0]));
                            if (!stdList.Any(x => x.STD_CODE == stdCode))
                            {
                                TB_SCORE_ROUND_1 round1 = new TB_SCORE_ROUND_1();
                                round1.STD_CODE    = stdCode;
                                round1.ROUND_SCORE = ((row[1] == null) ? 0 : (row[1].Equals("")) ? 0 : Convert.ToInt32(row[1]));
                                round1.PRIZE_ID    = 0;
                                stdList.Add(round1);
                                //บันทึกขาดสอบ
                                if (row[2].ToString().Equals("F") && round1.ROUND_SCORE == 0)
                                {
                                    if (!stdAppsentList.Any(x => x.STD_CODE == stdCode))
                                    {
                                        TB_EXAM_ABSENT tb_exam_absent = new TB_EXAM_ABSENT();
                                        tb_exam_absent.STD_CODE = stdCode;
                                        stdAppsentList.Add(tb_exam_absent);
                                    }
                                }
                                //สงสัยว่าผิดระดับชั้น
                                if (row[3].ToString().Equals("T"))
                                {
                                    if (!stdConcerntList.Any(x => x.STD_CODE == stdCode))
                                    {
                                        TB_CONCERN concern = new TB_CONCERN();
                                        concern.STD_CODE = stdCode;
                                        stdConcerntList.Add(concern);
                                    }
                                }
                            }
                            else
                            {
                                rejected++;
                                logger.Debug("Reject>>duplicate student code:" + stdCode);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                        }
                    }
                }
                //Begin Insert
                foreach (TB_EXAM_ABSENT _val in stdAppsentList)
                {
                    context.TB_EXAM_ABSENT.Add(_val);
                }
                context.SaveChanges();
                foreach (TB_CONCERN _val in stdConcerntList)
                {
                    context.TB_CONCERN.Add(_val);
                }
                context.SaveChanges();
                int index = 1;
                foreach (TB_SCORE_ROUND_1 _val in stdList)
                {
                    context.TB_SCORE_ROUND_1.Add(_val);
                    index++;
                    if (index % 200 == 0)
                    {
                        context.SaveChanges();
                    }
                }
                context.SaveChanges();
            }
            logger.Debug("######## SUMMARY ########");
            logger.Debug(String.Format("Total {0} (s),Reject {1} (s)>>>> Remain {2} (s)", stdList.Count, rejected, stdList.Count - rejected));
            logger.Debug(String.Format("####### --- Finish Load File at {0} --- ####", DateTime.Now));
        }
コード例 #2
0
        public ActionResult doProcessRound1(ScoreRound1Model model)
        {
            if (Session["USER"] == null)
            {
                return(RedirectToAction("../Account/ManagementLogin"));
            }

            int _levelId = Convert.ToInt16(model.studentLevel);



            var items = from ss in db.TB_STUDENT_SEAT
                        join r in db.TB_SCORE_ROUND_1 on ss.STUDENT_CODE equals r.STD_CODE
                        join s in db.TB_APPLICATION_STUDENT on ss.STUDENT_ID equals s.STD_ID
                        where s.STD_LEVEL_ID == _levelId && s.STD_NATION != 2
                        orderby s.STD_LEVEL_ID ascending, r.ROUND_SCORE descending
                select new
            {
                StdCode      = ss.STUDENT_CODE,
                Score        = r.ROUND_SCORE,
                StudentLevel = _levelId,
                s.STD_NATION,
                r.ROUND_SCORE
            };

            if (items != null)
            {
                StringBuilder sb    = new StringBuilder();
                int           index = 1;
                foreach (var item in items)
                {
                    TB_SCORE_ROUND_1 sr = db.TB_SCORE_ROUND_1.Where(s => s.STD_CODE == item.StdCode).FirstOrDefault();
                    if (sr != null)
                    {
                        if (item.StudentLevel == 5)
                        {
                            //check condition
                            if (index >= 1 && index <= 10)
                            {
                                sr.PRIZE_ID = 1;//เข้ารอบเพชรยอดมงกุฏ
                            }
                            else if (index > 10 && index <= 20)
                            {
                                sr.PRIZE_ID = 2;//รางวัลชอมเชย
                            }
                            else
                            {
                                sr.PRIZE_ID = 4;
                            }
                        }
                        else
                        {
                            if (index >= 1 && index <= 10)
                            {
                                sr.PRIZE_ID = 1;//เข้ารอบเพชรยอดมงกุฏ
                            }
                            else if (index > 10 && index <= 50)
                            {
                                sr.PRIZE_ID = 2;//รางวัลชอมเชย
                            }
                            else if (index > 50 && index <= 100)
                            {
                                sr.PRIZE_ID = 3;//รางวัลผ่านเกณฑ์
                            }
                            else
                            {
                                sr.PRIZE_ID = 4;
                            }
                        }

                        index++;
                        if (index % 200 == 0)
                        {
                            db.SaveChanges();
                        }
                    }
                }

                db.SaveChanges();
            }
            ViewBag.ResultMsg = "ปรับคะแนน 100 อันดับ ระดับชั้นที่ " + model.studentLevel + " รอบเจียรไนเพชรเรียบร้อยแล้ว";
            return(View("ProcessRound1"));
        }