コード例 #1
0
        /// <summary>
        /// tạo đề thi cho một đợt thi với cấu trúc đề thi cho trươcs.
        /// create by cucpt
        /// </summary>
        /// <param name="examTimeCode"></param>
        /// <param name="testStructCode"></param>
        public ArrayList CreateExamForm(string examTimeCode, string testStructCode)
        {
            ArrayList result = new ArrayList();
            string    code   = "";
            // xóa toàn bộ đề thi cũ
            var ret = DeleteAll(examTimeCode);

            if (ret >= 0)
            {
                // get examtime
                EXAMTIME_BUS examTimeBus = new EXAMTIME_BUS();
                EXAMTIME_OBJ examtime    = examTimeBus.GetByID(new EXAMTIME_OBJ.BusinessObjectID(examTimeCode));
                int          testcount   = examtime.TESTCOUNT; // số đề thi
                EXAMFORM_BUS bus         = new EXAMFORM_BUS();
                for (int i = 0; i < testcount; i++)
                {
                    // tạo 1 đề thi mới. với mỗi đề thi, sinh ra cấu trúc đề thi tương ứng
                    EXAMFORM_OBJ obj = new EXAMFORM_OBJ
                    {
                        EXAMTIMECODE   = examTimeCode,
                        SUBJECTCODE    = examtime.SUBJECTCODE,
                        TESTSTRUCTCODE = testStructCode,
                        EDITTIME       = DateTime.Now,
                        EDITUSER       = _ses.loginCode,
                        LOCK           = 0,
                        NAME           = "Đề " + (i + 1) + " " + examtime.NAME
                    };
                    obj.CODE     = bus.genNextCode(obj);
                    obj.CODEVIEW = obj.CODE;
                    code         = obj.CODE;
                    obj.LOCKDATE = DateTime.Now;
                    ret          = bus.insert(obj);
                    if (ret >= 0) // nếu tạo đề thành công thì đi tạo chi tiết đề
                    {
                        ret = CreateExamFormDetail(obj.CODE, testStructCode);
                    }
                    if (ret < 0)
                    {
                        break; // nếu tạo đề không thành công thì thoát luôn, báo lỗi cho người dùng
                    }
                }
            }
            // sau khi tạo đề thành công thì đi chia đề cho sinh viên
            if (ret >= 0)
            {
                // chia đề thi
                ret = DevideExam(examTimeCode);
            }
            result.Add(ret);
            result.Add(code);
            return(result);
        }
コード例 #2
0
        public JsonResult Update(EXAMFORM_OBJ obj)
        {
            EXAMFORM_BUS bus = new EXAMFORM_BUS();
            int          ret;
            int          add = 0;
            EXAMFORM_OBJ objTemp;

            //kiểm tra tồn tại cho trường hợp sửa
            if (!string.IsNullOrEmpty(obj.CODE))//edit
            {
                objTemp = bus.GetByID(new EXAMFORM_OBJ.BusinessObjectID(obj.CODE));
                if (objTemp == null)
                {
                    ret = -4;
                    bus.CloseConnection();
                    //ban ghi sửa đã bị xóa
                    return(Json(new { sussess = ret }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                objTemp = new EXAMFORM_OBJ();
            }

            //hết kiểm tra tồn tại bản ghi
            objTemp.EDITTIME       = DateTime.Now;   //Thời điểm sủa bản ghi
            objTemp.EDITUSER       = _ses.loginCode; //Người sửa bản ghi
            objTemp.CODEVIEW       = obj.CODEVIEW;
            objTemp.NAME           = obj.NAME;
            objTemp.SUBJECTCODE    = obj.SUBJECTCODE;
            objTemp.EXAMTIMECODE   = obj.EXAMTIMECODE;
            objTemp.NOTE           = obj.NOTE;
            objTemp.TESTSTRUCTCODE = obj.TESTSTRUCTCODE;
            //Kiểm tra tình trạng sửa hay là thêm mới
            if (string.IsNullOrEmpty(obj.CODE))
            {
                //Thêm mới
                add = 1;
                //Sinh mã
                objTemp.CODE     = bus.genNextCode(obj);
                objTemp.LOCKDATE = DateTime.Now;
            }
            if (add == 1)
            {
                ret = bus.insert(objTemp);
            }
            else
            {
                //gán _ID để xác định bản ghi sẽ được cập nhật
                objTemp._ID.CODE = obj.CODE;
                ret = bus.update(objTemp);
            }
            int pagecount   = 0;
            int currentpage = 0;

            if (ret >= 0)
            {
                objTemp._ID.CODE = objTemp.CODE;
                ret = bus.checkPage(objTemp._ID, "CODE", AppConfig.item4page(), out pagecount, out currentpage);
            }
            bus.CloseConnection();
            //some thing like that
            return(Json(new { ret, pagecount, currentpage }, JsonRequestBehavior.AllowGet));
        }