Example #1
0
        /// <summary>
        /// 新增,返回的是主键
        /// </summary>
        /// <param name="btn"></param>
        /// <returns></returns>
        public static string AddStudent(Students Stu, SYSAccount sys, SYSAccountRole sysR)
        {
            string       ret;
            DBRepository db = new DBRepository(DBKeys.PRX);

            db.BeginTransaction();//事务开始
            try
            {
                ret = db.Insert <Students>(Stu);       //添加学生表
                int max = db.Insert <SYSAccount>(sys); //添加用户表

                sysR.AR_AccountId = max;
                //sysR.AR_AccountId = max.ContainsValue(0);
                db.Insert <SYSAccountRole>(sysR); //添加权限表
                db.Commit();                      //事务提交
                db.Dispose();                     //资源释放
            }
            catch (Exception ex)
            {
                db.Rollback();
                db.Dispose();
                throw new Exception(ex.Message + "。" + ex.InnerException.Message);
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// 添加新的教师
        /// </summary>
        /// <returns></returns>
        public static string AddSYS_SystemRole(SYSAccountRole sys)
        {
            DBRepository db = new DBRepository(DBKeys.PRX);

            db.BeginTransaction();//事务开始
            string ret = "0";

            try
            {
                var number = Getnumber(sys.AR_AccountId);//判断是否存在
                if (number > 0)
                {
                    db.Execute("Delete From SYS_AccountRole where AR_AccountId = " + sys.AR_AccountId);
                }


                for (int i = 0; i < sys.AR_SystemRoleIdS.Length; i++)
                {
                    sys.AR_SystemRoleId = int.Parse(sys.AR_SystemRoleIdS[i]);
                    db.Insert <SYSAccountRole>(sys);
                }

                db.Commit();  //事务提交
                ret = "1";    //新增成功
                db.Dispose(); //资源释放
            }
            catch (Exception ex)
            {
                db.Rollback();
                db.Dispose();
                throw new Exception(ex.Message);
            }
            return(ret);
        }
Example #3
0
        /// <summary>
        ///设置权限
        /// </summary>
        /// <returns></returns>
        public JsonResult AddSYS_SystemRole()
        {
            AjaxStatusModel ajax = new AjaxStatusModel(); //功能操作类的返回类型都是AjaxStatusModel,数据放到AjaxStatusModel.data中,前台获取json后加载

            ajax.status = EnumAjaxStatus.Error;           //默认失败
            ajax.msg    = "新增失败!";                        //前台获取,用于显示提示信息
            var data = Request["data"];                   //获取前台传递的数据,主要序列化

            if (string.IsNullOrEmpty(data))
            {
                return(Json(ajax));
            }
            SYSAccountRole sys = (SYSAccountRole)(JsonConvert.DeserializeObject(data.ToString(), typeof(SYSAccountRole)));

            if (sys.AR_SystemRoleIdS != null)
            {
                if (!string.IsNullOrEmpty(TeacherData.AddSYS_SystemRole(sys)))//注意时间类型,而且需要在前台把所有的值
                {
                    ajax.msg    = "操作成功!";
                    ajax.status = EnumAjaxStatus.Success;
                }
            }
            return(Json(ajax));
        }
Example #4
0
        /// <summary>
        /// 新增学生表
        /// </summary>
        /// <returns></returns>
        public JsonResult AddStudent()
        {
            AjaxStatusModel ajax = new AjaxStatusModel(); //功能操作类的返回类型都是AjaxStatusModel,数据放到AjaxStatusModel.data中,前台获取json后加载

            ajax.status = EnumAjaxStatus.Error;           //默认失败
            ajax.msg    = "新增失败!";                        //前台获取,用于显示提示信息
            var data = Request["data"];                   //获取前台传递的数据,主要序列化

            if (string.IsNullOrEmpty(data))
            {
                return(Json(ajax));
            }

            Students Stu = (Students)(JsonConvert.DeserializeObject(data.ToString(), typeof(Students)));

            //判断手机号码+学员号是否唯一


            string studid = StudentData.BindPhone_insert(Stu.BindPhone, Stu.Name);
            string apid   = Request["apid"];       //预约号

            if (!string.IsNullOrEmpty(apid))       //如果是从预约/市场资源模块进来的,先判断是否存在学员,如果存在就绑定,如果不存在就新增记录
            {
                if (!string.IsNullOrEmpty(studid)) //之前已经存在学员,则做绑定操作
                {
                    StudentData.BindStudentforAP(studid, apid);
                    ajax.status = EnumAjaxStatus.Success;
                    ajax.msg    = "已成功绑定到学员!";
                    return(Json(ajax));
                }
            }
            if (!string.IsNullOrEmpty(studid))
            {
                ajax.status = EnumAjaxStatus.Success;
                ajax.msg    = "手机号码已存在,不能重复使用!";
                return(Json(ajax));
            }
            Stu.StateID    = 1;//新增学员状态默认是未读。
            Stu.CreateTime = DateTime.Now;
            Stu.CreatorId  = UserSession.userid;



            var year  = DateTime.Now.Year.ToString().Substring(2, 2); //获取年份
            var month = DateTime.Now.Month.ToString();                //获取月份

            if (month.ToString().Length == 1)
            {
                month = "0" + month.ToString();
            }
            var Mosaic = year + month;



            Students query = StudentData.GetStudentsOne(Mosaic);//获取创建时间最新的一条数据
            string   MAX_ID;

            if (query != null)
            {
                MAX_ID = query.ID;
            }
            else
            {
                MAX_ID = null;
            }

            if (!string.IsNullOrEmpty(MAX_ID))
            {
                Stu.ID = Mosaic + (Convert.ToInt32(MAX_ID.Substring(4)) + 1).ToString().PadLeft(2, '0');
            }
            else
            {
                Stu.ID = Mosaic + "01";
            }
            SYSAccount     sys     = new SYSAccount();     //用户信息
            SYSAccountRole sysR    = new SYSAccountRole(); //用户角色
            RandomOperate  operate = new RandomOperate();

            //添加默认权限
            Stu.BindAccount   = Stu.ID;//方便登陆
            sys.ACC_Account   = Stu.BindAccount;
            sys.ACC_CreatedBy = UserSession.userid;
            sys.ACC_CreatedOn = DateTime.Now;
            sys.ACC_Password  = operate.CreateMD5Hash("123");


            //添加SYS_AccountRole表数据

            // sysR.AR_AccountId = StudentData.Max_ACC_Id();
            sysR.AR_SystemRoleId = 9;


            string stuid = StudentData.AddStudent(Stu, sys, sysR);

            if (stuid != "")//注意时间类型,而且需要在前台把所有的值
            {
                ajax.msg = "新增成功!";
                if (!string.IsNullOrEmpty(apid))//如果是预约单过来的,重新绑定一下
                {
                    StudentData.BindStudentforAP(stuid, apid);
                    ajax.msg = "绑定成功!";
                }
                vw_Appointment vw_Appointment = StudentData.Getvw_AppointmentList(apid); //查询预约单相应的信息
                ajax.data   = vw_Appointment;                                            //让前台的直报功能能获取到值
                ajax.status = EnumAjaxStatus.Success;
            }
            return(Json(ajax));
        }