Exemplo n.º 1
0
        /// <summary>
        /// update danh sách sinh viên lớp môn học
        /// </summary>
        /// <param name="listStudentCode">danh sách mã sinh viên</param>
        /// <param name="coursecode">mã lớp môn học</param>
        /// <param name="subjectcode">Môn học</param>
        /// <returns></returns>
        public JsonResult UpdateStudentCourse(List <string> listStudentCode, string coursecode, string subjectcode)
        {
            int             ret        = 0;
            MARK_BUS        busMark    = new MARK_BUS();
            List <MARK_OBJ> liMark     = new List <MARK_OBJ>();
            MARK_OBJ        midMarkObj = new MARK_OBJ();
            //gennextcode to define first code to gennextcode for other  n list
            string markCode = busMark.genNextCode(midMarkObj);

            if (listStudentCode == null)
            {
                ret = -1;
            }
            else
            {
                foreach (var studentCode in listStudentCode)
                {
                    MARK_OBJ objMark = new MARK_OBJ {
                        CODE = markCode
                    };
                    markCode               = busMark.GenNextCode(objMark, markCode); //gán giá trị code đầu tiên cho giá trị mặc định sinh được tiến hành gán lại giá trị mặc định mặc gennextcode của đối tượng hiện tại
                    objMark.LOCKDATE       = DateTime.Now;
                    objMark.CODEVIEW       = objMark.CODEVIEW;
                    objMark.COURSECODE     = coursecode;
                    objMark.STUDENTCODE    = studentCode;
                    objMark.SUBJECTCODE    = subjectcode;
                    objMark.LOCK           = 0;
                    objMark.EDITTIME       = DateTime.Now; // thời điểm sửa bản ghi
                    objMark.EDITUSER       = _ses.loginCode;
                    objMark.UNIVERSITYCODE = _ses.gUNIVERSITYCODE;
                    liMark.Add(objMark);
                }
            }
            //Tạo phiên làm việc, thực hiện trong trường hợp có nhiều thao tác với cơ sở dữ liệu,
            //yêu cầu khi thực hiện nhiều hơn một lệnh có thay đổi dữ liệu phải gọi phương thức này.
            busMark.BeginTransaction();
            if (ret >= 0)
            {
                ret = busMark.InsertMultiItems(liMark);
                if (ret < 0)
                {
                    //Trong trường hợp nhiều thao tác, có một thao tác không thành công,
                    //hàm này được gọi để quay lại trạng thái trước khi thực hiện (bắt đầu từ khi gọi BeginTransaction()
                    busMark.RollbackTransaction();
                }
                else
                {
                    //Sau khi thao tác dữ liệu thành công, hàm này được gọi để thực hiện ghi vào cơ sở dữ liệu
                    busMark.CommitTransaction();
                }
            }
            busMark.CloseConnection();
            return(Json(new
            {
                ret
            }, JsonRequestBehavior.AllowGet));
        }