Esempio n. 1
0
        public ActionResult SaveAllData(string[] values)
        {
            EngagementContext db = new EngagementContext();

            try
            {
                if (ModelState.IsValid)
                {
                    var pageCase = Convert.ToInt32(values[9]);
                    if (Convert.ToInt32(values[9]) != 0)                                    //2 คือ section ที่ 2 ตัวเลขนี้ได้มาจากดึงข้อมูลมาจาก DB ว่ามีแล้วหรือไม่
                    {
                        var      userDt     = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"); // return 08/05/2016 12:56 PM
                        DateTime oDate      = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                        int      questionId = Convert.ToInt32(values[7]);
                        for (int i = 0; i < 6; i++, questionId++)
                        {
                            var UID   = int.Parse((values[0]));
                            var SecID = int.Parse((values[8]));

                            var ds = (from c in db.TB_Answer where c.engagepersonal_ID == UID && c.Section == SecID && c.Question_ID == questionId select c).ToList();
                            if (ds.Count > 0)
                            {
                                foreach (var item in ds)
                                {
                                    item.AnswerResult = Convert.ToInt32(values[i + 1]);
                                    item.dtStamp      = oDate;
                                }
                            }
                            db.SaveChanges();
                        }
                    }
                    else // ถ้าไม่มีข้อมูลให้ insert ใหม่เข้าไป
                    {
                        TB_Answer ans          = new TB_Answer();
                        int       latestRecord = 0;
                        int       questionId   = Convert.ToInt32(values[7]);
                        int       SaveSection  = Convert.ToInt32(values[8]);
                        latestRecord = GetLastRecord(1);
                        //chkeck การเคยเข้าทำแบบทดสอบหรือตอบหน้านี้ไปแล้ว
                        //  chkSection = chkInputData(engageid, 3);
                        for (int i = 0; i < 6; i++, questionId++)//วนใส่ทีละ 6 ข้อ
                        {
                            if (latestRecord == 0)
                            {
                                latestRecord = 1;
                            }
                            else
                            {
                                latestRecord = latestRecord + 1;
                            }
                            var      userDt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"); // return 08/05/2016 12:56 PM
                            DateTime oDate  = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                            ans.Question_ID       = questionId;                             //คำถามข้อที่
                            ans.engagepersonal_ID = Convert.ToInt32(values[0]);
                            ans.AnswerEngage_ID   = latestRecord;                           //ตัวเลขที่มันรันไปเรื่อยๆๆด้วยมือเรา
                            ans.AnswerResult      = Convert.ToInt32(values[i + 1]);
                            ans.Section           = SaveSection;
                            ans.dtStamp           = oDate;
                            db.TB_Answer.Add(ans);
                            db.SaveChanges();
                        }
                    }


                    return(Redirect(Request.UrlReferrer.ToString()));
                }


                return(Json(new
                {
                    msg = String.Format("Data: {0}", "Save Complete")
                }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public ActionResult SaveAllDataText(string[] values)
        {
            EngagementContext db = new EngagementContext();

            try
            {
                TB_Answer      ans              = new TB_Answer();
                TB_Answer_Text ansText          = new TB_Answer_Text();
                int            latestRecord     = 0;
                int            latestRecordText = 0;
                int            questionId       = Convert.ToInt32(values[5]);
                int            SaveSection      = Convert.ToInt32(values[6]);
                latestRecord     = GetLastRecord(1);
                latestRecordText = GetLastRecord(2);
                var      userDt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");  // return 08/05/2016 12:56 PM
                DateTime oDate  = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                if (Convert.ToInt32(values[7]) != 0)
                {
                    var UID   = int.Parse((values[0]));
                    var SecID = int.Parse((values[6]));
                    for (int i = 0; i < 3; i++, questionId++)
                    {
                        var ds = (from c in db.TB_Answer where c.engagepersonal_ID == UID && c.Section == SecID && c.Question_ID == questionId select c).ToList();
                        if (ds.Count > 0)
                        {
                            foreach (var item in ds)
                            {
                                item.AnswerResult = Convert.ToInt32(values[i + 2]);
                                item.dtStamp      = oDate;
                            }
                        }
                        db.SaveChanges();
                    }
                    //ไปอัพเดทข้อมูลในตาราง text comment
                    var qtest = int.Parse((values[5]));

                    var dtext = (from c in db.TB_Answer_Text where c.engagepersonal_ID == UID && c.Section == SecID && c.Question_ID == qtest select c).ToList();
                    if (dtext.Count > 0)
                    {
                        foreach (var item in dtext)
                        {
                            item.AnswerResult = (values[1]);
                            item.Section      = SaveSection;
                            item.dtStamp      = oDate;
                        }
                    }
                    db.SaveChanges();

                    if (questionId == 51)
                    {
                        Int32 engagementid   = Convert.ToInt32(values[0]);
                        var   engagementData = db.TB_Email.Where(x => x.engagepersonal_ID == engagementid).FirstOrDefault();
                        if (engagementData != null)
                        {
                            engagementData.StatusAccept    = 1;
                            engagementData.Survey_Commit   = oDate;
                            db.Entry(engagementData).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++, questionId++)//วนใส่ทีละ 3 ข้อ
                    {
                        if (latestRecord == 0)
                        {
                            latestRecord = 1;
                        }
                        else
                        {
                            latestRecord = latestRecord + 1;
                        }


                        ans.Question_ID       = questionId;   //คำถามข้อที่
                        ans.engagepersonal_ID = Convert.ToInt32(values[0]);
                        ans.AnswerEngage_ID   = latestRecord; //ตัวเลขที่มันรันไปเรื่อยๆๆด้วยมือเรา
                        ans.AnswerResult      = Convert.ToInt32(values[i + 2]);
                        ans.Section           = SaveSection;
                        ans.dtStamp           = oDate;
                        db.TB_Answer.Add(ans);
                        db.SaveChanges();
                    }
                    var      qtest  = int.Parse((values[5]));
                    DateTime oDateT = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                    ansText.Question_ID       = qtest;            //คำถามข้อที่
                    ansText.engagepersonal_ID = Convert.ToInt32(values[0]);
                    ansText.AnswerEngage_ID   = latestRecordText; //ตัวเลขที่มันรันไปเรื่อยๆๆด้วยมือเรา
                    ansText.AnswerResult      = values[1];
                    ansText.Section           = SaveSection;
                    ansText.dtStamp           = oDateT;
                    db.TB_Answer_Text.Add(ansText);
                    db.SaveChanges();
                    if (questionId == 51)
                    {
                        Int32 engagementid   = Convert.ToInt32(values[0]);
                        var   engagementData = db.TB_Email.Where(x => x.engagepersonal_ID == engagementid).FirstOrDefault();
                        if (engagementData != null)
                        {
                            engagementData.StatusAccept    = 1;
                            engagementData.Survey_Commit   = oDateT;
                            db.Entry(engagementData).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }



                return(Redirect(Request.UrlReferrer.ToString()));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public ActionResult Add_Information(string[] values)
        {
            EngagementContext db = new EngagementContext();

            try
            {
                if (ModelState.IsValid)
                {
                    if (Convert.ToInt32(values[11]) == 1)
                    {
                        var      userDt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");      // return 08/05/2016 12:56 PM
                        DateTime oDate  = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                        for (int i = 0; i < 8; i++)
                        {
                            var UID   = int.Parse((values[0]));
                            var SecID = 1;
                            var ds    = (from c in db.TB_Answer where c.engagepersonal_ID == UID && c.Section == SecID && c.Question_ID == i + 1 select c).ToList();
                            if (ds.Count > 0)
                            {
                                foreach (var item in ds)
                                {
                                    item.AnswerResult = Convert.ToInt32(values[i + 1]);
                                    item.dtStamp      = oDate;
                                }
                            }
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        TB_Answer ans          = new TB_Answer();
                        int       latestRecord = 0;
                        latestRecord = GetLastRecord(1);
                        var      userDt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");  // return 08/05/2016 12:56 PM
                        DateTime oDate  = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

                        for (int i = 0; i < 8; i++)
                        {
                            if (latestRecord == 0)
                            {
                                latestRecord = 1;
                            }
                            else
                            {
                                latestRecord = latestRecord + 1;
                            }
                            var engagementData = db.TB_Answer.Where(x => x.Question_ID == i + 1).FirstOrDefault();
                            ans.Question_ID       = i + 1;        //i
                            ans.engagepersonal_ID = Convert.ToInt32(values[0]);
                            ans.AnswerEngage_ID   = latestRecord; //ตัวเลขที่มันรันไปเรื่อยๆๆด้วยมือเรา
                            ans.AnswerResult      = Convert.ToInt32(values[i + 1]);
                            ans.Section           = 1;
                            ans.dtStamp           = oDate;
                            db.TB_Answer.Add(ans);
                            db.SaveChanges();
                        }
                    }
                }
                return(Json(new
                {
                    msg = String.Format("Data: {0}", "Save Complete")
                }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }