Ejemplo n.º 1
0
        public int ProcessExamFormAuto(string examtimecode, string coursecode, int testcount)
        {
            int ret = 0;
            //Lấy được đợt thi
            EXAMTIME_BUS        bus        = new EXAMTIME_BUS();
            EXAMTIME_OBJ        obj        = bus.GetByID(new EXAMTIME_OBJ.BusinessObjectID(examtimecode));
            EXAMFORM_BUS        busExamfom = new EXAMFORM_BUS();
            List <EXAMFORM_OBJ> liExamform = new List <EXAMFORM_OBJ>();

            bus.CloseConnection();
            if (obj == null)
            {
                ret = -1;
            }
            //Lấy được lớp học
            MARK_BUS        busMark = new MARK_BUS();
            List <MARK_OBJ> liMark  = busMark.getAllBy2(new fieldpara("COURSECODE", coursecode));

            busMark.CloseConnection();

            if (ret >= 0)
            {
                liExamform = CreateExamForm(obj, testcount, out ret);
            }
            EXAMFORMDETAIL_BUS        busExamformdetail = new EXAMFORMDETAIL_BUS();
            EXAMFORMDETAIL_OBJ        objExamformdetail = new EXAMFORMDETAIL_OBJ();
            List <EXAMFORMDETAIL_OBJ> liExamformdetail  = new List <EXAMFORMDETAIL_OBJ>();
            //Danh sách cấu trúc đề
            TESTSTRUCTDETAIL_BUS        busTeststructdetail = new TESTSTRUCTDETAIL_BUS();
            List <TESTSTRUCTDETAIL_OBJ> liTestStructDetail  = busTeststructdetail.getByTestStruct(obj.TESTSTRUCTCODE, _ses.gUNIVERSITYCODE);

            busTeststructdetail.CloseConnection();

            string currentCode = busExamformdetail.genNextCode(objExamformdetail);

            if (ret >= 0)
            {
                foreach (EXAMFORM_OBJ objtem in liExamform)
                {
                    ret = CreateExamFormDetail(ref liExamformdetail, objtem, liTestStructDetail, ref currentCode);
                    if (ret < 0)
                    {
                        break;
                    }
                }
            }
            //Gán sinh viên vào danh sách đề
            List <EXAMHALLSTUDENT_OBJ> liExamhallstudent  = new List <EXAMHALLSTUDENT_OBJ>();
            EXAMHALLSTUDENT_BUS        busExamhallstudent = new EXAMHALLSTUDENT_BUS();
            EXAMHALLSTUDENT_OBJ        objExamhallstudent = new EXAMHALLSTUDENT_OBJ();

            currentCode = busExamhallstudent.genNextCode(objExamhallstudent);
            int i = 0;

            //Thêm tất cả sinh viên
            foreach (MARK_OBJ objMar in liMark)
            {
                //Gán sinh viên vào examhall student
                objExamhallstudent              = new EXAMHALLSTUDENT_OBJ();
                objExamhallstudent.CODE         = currentCode;
                currentCode                     = busExamhallstudent.genNextCode(objExamhallstudent, currentCode);
                objExamhallstudent.COURSECODE   = coursecode;
                objExamhallstudent.EDITTIME     = DateTime.Now;
                objExamhallstudent.EDITUSER     = _ses.loginCode;
                objExamhallstudent.EXAMFORMCODE = liExamform[i % testcount].CODE;
                objExamhallstudent.EXAMTIMECODE = examtimecode;
                i++;
                objExamhallstudent.EXAMHALLCODE   = "";
                objExamhallstudent.MARKCODE       = objMar.CODE;
                objExamhallstudent.UNIVERSITYCODE = _ses.gUNIVERSITYCODE;
                liExamhallstudent.Add(objExamhallstudent);
            }
            if (ret >= 0)
            {
                busExamfom.BeginTransaction();
                busExamformdetail.setConnection(busExamfom);
                busExamhallstudent.setConnection(busExamfom);
                ret = busExamfom.InsertMultiItems(liExamform);
                if (ret >= 0)
                {
                    ret = busExamformdetail.InsertMultiItems(liExamformdetail);
                }
                if (ret >= 0)
                {
                    ret = busExamhallstudent.InsertMultiItems(liExamhallstudent);
                }
                if (ret >= 0)
                {
                    busExamfom.CommitTransaction();
                }
                else
                {
                    busExamfom.RollbackTransaction();
                }
            }
            busExamfom.CloseConnection();
            return(ret);
        }