示例#1
0
        public ActionResult UserMenu()
        {
            string menuJson = ProfilesBLL.GetValue(ProfilesInfo.Wechat.MenuJson, true);

            ViewBag.menuJson = menuJson;
            return(View());
        }
        public ActionResult Join(UserInfo info)
        {
            string log = string.Empty;

            try
            {
                int PlanID = Function.GetRequestInt("PlanID");
                log += "\n PlanID=" + PlanID;
                string infoWechatUserReturnOpenID = Function.GetRequestString("infoWechatUserReturnOpenID");
                log += "\n infoWechatUserReturnOpenID=" + infoWechatUserReturnOpenID;
                ResearchPlanInfo infoPlan = ResearchPlanBLL.GetList(p => p.ID == PlanID).FirstOrDefault();
                log += "\n infoPlan=" + infoPlan;
                UserInfo infoUser = null;
                if (info.ID > 0)
                {
                    log     += "\n info.ID > 0=";
                    infoUser = UserBLL.GetList(a => a.ID == info.ID).FirstOrDefault();
                }
                if (null == infoUser)
                {
                    log     += "\n info.ID < 0=";
                    infoUser = UserBLL.GetList(a => a.WechatOpenID == infoWechatUserReturnOpenID).FirstOrDefault();
                }
                log += "\n infoUser="******"\n infoUser is null";
                    WechatUserReturnInfo infoWechatUserReturn = WeiXin.APIClient.WechatService.WechatUser.GetWechatUserReturnInfo(infoWechatUserReturnOpenID);
                    if (null == infoWechatUserReturn)
                    {
                        return(Json(new APIJson(-1, "无法获取用户信息")));
                    }
                    log     += "\n infoWechatUserReturn=" + infoWechatUserReturn;
                    infoUser = new UserInfo();
                    //infoUser.DepartmentID 从config中读到表单hiden了里
                    //infoUser.Name
                    if (string.IsNullOrEmpty(info.Name) || info.Name.Length > 50)
                    {
                        return(Json(new APIJson(-1, "请输入您的姓名")));
                    }
                    if (UserBLL.GetList(a => true).Any(a => a.Name == infoUser.Name))
                    {
                        return(Json(new APIJson(-1, "系统里居然有人跟你同名了,你换一个或加个数字后缀吧")));
                    }
                    var infoUserExistName = UserBLL.GetList(a => a.Name == info.Name).FirstOrDefault();
                    if (null != infoUserExistName)
                    {
                        return(Json(new APIJson(-1, "系统已存在当前用户名,请更换")));
                    }
                    infoUser.DepartmentID = info.DepartmentID;
                    infoUser.Name         = info.Name;
                    infoUser.Code         = infoUser.Name;
                    infoUser.PassWord     = string.Empty;
                    //infoUser.Email
                    if (null == infoUser.Email)
                    {
                        infoUser.Email = string.Empty;
                    }
                    infoUser.Email            = info.Email;
                    infoUser.Tel              = string.Empty;
                    infoUser.CreateDate       = DateTime.Now;
                    infoUser.LastDate         = DateTime.Now;
                    infoUser.Enable           = true;
                    infoUser.LocationX        = infoUser.LocationY = 0;
                    infoUser.WechatOpenID     = infoWechatUserReturn.openid;
                    infoUser.WechatNameNick   = infoWechatUserReturn.nickname;
                    infoUser.WechatHeadImg    = infoWechatUserReturn.headimgurl;
                    infoUser.Sex              = infoWechatUserReturn.sex.ToString();
                    infoUser.IDCard           = string.Empty;
                    infoUser.TypeID           = -1;
                    infoUser.DefaultSubjectID = 0;

                    log += "\n 准备完后infoUser="******"\n 创建完了";
                }

                ResearchPlanUserInfo infoPlanUser = new ResearchPlanUserInfo();
                infoPlanUser.ResearchPlanID = info.ID;
                infoPlanUser.UserID         = infoUser.ID;
                infoPlanUser.DateCreate     = DateTime.Now;
                infoPlanUser.DateConfirm    = DicInfo.DateZone;
                infoPlanUser.IsConfirmed    = true;
                infoPlanUser.Memo           = "二维码邀请";
                infoPlanUser.SumRemark      = string.Empty;
                infoPlan.ResearchPlanUserInfo.Add(infoPlanUser);
                var result = ResearchPlanBLL.Edit(infoPlan);
                if (result)
                {
                    return(Json(new APIJson(0, "恭喜您,成功加入本次听评课计划")));
                }
                else
                {
                    return(Json(new APIJson(-1, "加入失败了,请重试")));
                }
            }
            catch (Exception ex)
            {
                var ex2 = (System.Data.Entity.Infrastructure.DbUpdateException)ex;

                var ErrorMsg = log
                               + "Ex========" + ex.Message
                               + "\n ex2.InnerException.ObjectToJSON();" + ex2.InnerException.ObjectToJSON();
                return(Json(new APIJson(-1, ErrorMsg)));

                throw;
            }
        }
示例#3
0
        public ActionResult InportLightPost2()
        {
            bool   HidenIsInport = Function.GetRequestString("HidenIsInport").ToLower() == "true";
            string DdlWorkSheet  = Function.GetRequestString("DdlWorkSheet");
            string HidenFileURL  = Function.GetRequestString("HidenFileURL");

            HidenFileURL = Server.MapPath(HidenFileURL);
            DataTable dt = new DataTable();

            try
            {
                dt = Tool.ExcelHelper.ExcelToDatatable(HidenFileURL, DdlWorkSheet);
            }
            catch (Exception ex)
            {
                return(Json(new APIJson(-1, "系统出错:" + ex.Message)));
            }
            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                if (string.IsNullOrEmpty(dt.Rows[i][0].ToString().Trim()))
                {
                    dt.Rows.RemoveAt(i);
                }
            }


            var ErrorMsg = CheckDataTableHeadLight(dt);

            if (!string.IsNullOrEmpty(ErrorMsg))
            {
                return(Json(new APIJson(-1, ErrorMsg)));
            }
            if (!HidenIsInport)
            {
                return(Json(new APIJson(0, "解析成功", dt.DataTableToList())));
            }
            var      ListSubject             = SubjectBLL.GetList(a => true).ToList();
            int      DefaultRuleIDWhenInport = Function.ConverToInt(ProfilesBLL.GetValue(ProfilesInfo.InportSetting.DefaultRuleIDWhenInport));
            RuleInfo infoRule = RuleBLL.GetList(a => a.ID == DefaultRuleIDWhenInport).FirstOrDefault();


            List <string>   listInportResult = new List <string>();
            List <UserInfo> listUserInport   = new List <UserInfo>();

            foreach (DataRow item in dt.Rows)
            {
                UserInfo infoUser = new UserInfo();
                infoUser.DepartmentID     = CurrentUser.DepartmentID;
                infoUser.Name             = item["真实姓名"].ToString().Trim();
                infoUser.Code             = item["登录名"].ToString().Trim();
                infoUser.PassWord         = item["初始密码"].ToString().Trim();
                infoUser.Email            = string.Empty;
                infoUser.Tel              = string.Empty;
                infoUser.CreateDate       = DateTime.Now;
                infoUser.LastDate         = DicInfo.DateZone;
                infoUser.Enable           = true;
                infoUser.LocationX        = 0;
                infoUser.LocationY        = 0;
                infoUser.WechatOpenID     = string.Empty;
                infoUser.WechatNameNick   = string.Empty;
                infoUser.WechatHeadImg    = string.Empty;
                infoUser.Sex              = string.Empty;
                infoUser.IDCard           = string.Empty;
                infoUser.TypeID           = -3;
                infoUser.DefaultSubjectID = 0;
                infoUser.Email            = string.Empty;
                var HelpText1 = item["学科"].ToString().Trim();

                var UserSubjectinfo = ListSubject.Where(a => HelpText1.Split('|').Contains(a.Name));
                if (UserSubjectinfo.Count() > 0)
                {
                    infoUser.DefaultSubjectID = UserSubjectinfo.FirstOrDefault().ID;
                    infoUser.SubjectInfo      = new List <SubjectInfo>();
                    foreach (var itemSubject in UserSubjectinfo)
                    {
                        infoUser.SubjectInfo.Add(itemSubject);
                    }
                }
                else
                {
                    return(Json(new APIJson(-1, string.Format("提交失败,序号:{0}所在行中,对应学科数据无法识别", item["序号"].ToString()))));
                }
                infoUser.RuleInfo.Add(infoRule);

                if (string.IsNullOrEmpty(infoUser.Name) || string.IsNullOrEmpty(infoUser.Code))
                {
                    return(Json(new APIJson(-1, string.Format("提交失败,序号:{0}所在行中,用户名或登录名为空白,请先补填完整", item["序号"].ToString()))));
                }
                UserInfo infoDb = UserBLL.GetList(a => a.Code == infoUser.Code || a.Name == infoUser.Name).FirstOrDefault();
                if (null != infoDb)
                {
                    return(Json(new APIJson(-1, string.Format("提交失败,序号:{0}所在行中,用户名或登录名被占用,请为更改【可以登录名后加上数字或字母】", item["序号"].ToString()))));
                }
                if (infoUser.PassWord.Length < 6 || !ValidatePassWord(infoUser))
                {
                    return(Json(new APIJson(-1, string.Format("提交失败,序号:{0}所在行中,密码不符合要求,必需包括数字和字母,并且长度在6位数以上", item["序号"].ToString()))));
                }
                listUserInport.Add(infoUser);
            }
            foreach (var item in listUserInport)
            {
                UserBLL.Create(item);
            }
            listInportResult.Add("导入完成!");
            return(Json(new APIJson(2, "提交成功," + listUserInport.Count() + "个帐户成功导入")));
        }