Пример #1
0
        public JsonResult Update(SKILL_OBJ obj, string educationlevelcode)
        {
            SKILL_BUS bus      = new SKILL_BUS();
            int       ret      = 0;
            int       add      = 0;
            SKILL_OBJ obj_temp = null;

            //kiểm tra tồn tại cho trường hợp sửa
            if (!string.IsNullOrEmpty(obj.CODE))//edit
            {
                obj_temp = bus.GetByID(new SKILL_OBJ.BusinessObjectID(obj.CODE));
                if (obj_temp == null || obj_temp.UNIVERSITYCODE != ses.gUNIVERSITYCODE)
                {
                    ret = -4;
                }
            }
            else
            {
                obj_temp = new SKILL_OBJ();
            }
            if (ret < 0)
            {
                //đóng kết nối trước khi trả về
                bus.CloseConnection();
                //ban ghi sửa đã bị xóa
                return(Json(new { sussess = ret }, JsonRequestBehavior.AllowGet));
            }
            //hết kiểm tra tồn tại bản ghi
            obj_temp.EDITTIME       = DateTime.Now;  //Thời điểm sủa bản ghi
            obj_temp.EDITUSER       = ses.loginCode; //Người sửa bản ghi
            obj_temp.CODEVIEW       = obj.CODEVIEW;
            obj_temp.NAME           = obj.NAME;
            obj_temp.UNIVERSITYCODE = ses.gUNIVERSITYCODE;
            obj_temp.NOTE           = obj.NOTE;
            obj_temp.LOCK           = obj.LOCK;
            obj_temp.THEORDER       = obj.THEORDER;
            //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ã
                obj_temp.CODE     = bus.genNextCode(obj);
                obj_temp.LOCKDATE = DateTime.Now;
            }
            if (add == 1)
            {
                ret = bus.insert(obj_temp);
            }
            else
            {
                //gán _ID để xác định bản ghi sẽ được cập nhật
                obj_temp._ID.CODE = obj.CODE;
                ret = bus.update(obj_temp);
            }
            int pagecount   = 0;
            int currentpage = 0;

            if (ret >= 0)
            {
                List <fieldpara> lipa = new List <fieldpara>();
                //Lọc đơn vị cấp trên; '' sẽ là không co đơn vị cấp trên
                if (!string.IsNullOrEmpty(educationlevelcode))
                {
                    lipa.Add(new fieldpara("EDUCATIONLEVELCODE", educationlevelcode, 0));
                }
                lipa.Add(new fieldpara("UNIVERSITYCODE", ses.gUNIVERSITYCODE, 0));
                obj_temp._ID.CODE = obj_temp.CODE;
                ret = bus.checkPage(obj_temp._ID, "CODE", AppConfig.item4page(), out pagecount, out currentpage, lipa);
            }
            bus.CloseConnection();
            //some thing like that
            return(Json(new { ret = ret, pagecount = pagecount, currentpage = currentpage }, JsonRequestBehavior.AllowGet));
        }