/// <summary> /// 登录,如果没有账号,则创建 /// </summary> /// <param name="accout"></param> /// <param name="user"></param> private void loginUser(string accout, JObject user) { //判断是否存在 Song.Entities.Accounts acc = Business.Do <IAccounts>().IsAccountsExist(accout); if (acc == null) { acc = new Entities.Accounts(); acc.Ac_AccName = accout; //账号 acc.Ac_Name = user["username"] != null ? user["username"].ToString() : string.Empty; //姓名 acc.Ac_IsPass = acc.Ac_IsUse = true; Business.Do <IAccounts>().AccountsAdd(acc); } //用户头像,如果没有上传,或图片不存在 if (string.IsNullOrEmpty(acc.Ac_Photo) || acc.Ac_Photo.Trim() == "" || !System.IO.File.Exists(Upload.Get["Accounts"].Physics + acc.Ac_Photo)) { acc = Business.Do <IAccounts>().AccountsSingle(acc.Ac_ID); //头像 string photo = user["photoUrl"].ToString(); string photoPath = Upload.Get["Accounts"].Physics + accout + ".jpg"; WeiSha.Common.Request.LoadFile(photo, photoPath); acc.Ac_Photo = accout + ".jpg"; //名称 if (string.IsNullOrWhiteSpace(acc.Ac_Name)) { acc.Ac_Name = user["username"] != null ? user["username"].ToString() : string.Empty; //姓名 } Business.Do <IAccounts>().AccountsSave(acc); } LoginState.Accounts.Write(acc); //登录成功 Business.Do <IAccounts>().PointAdd4Login(acc, "手机网页", "云之家登录", ""); //增加登录积分 Business.Do <IStudent>().LogForLoginAdd(acc); }
/// <summary> /// 获取当前登录QQ的详细信息 /// </summary> /// <param name="access_token"></param> /// <param name="openid"></param> /// <returns>xml对象</returns> private Song.Entities.Accounts getUserInfo(string access_token, string openid) { string userUrl = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}"; userUrl = string.Format(userUrl, access_token, openid); string retjson = WeiSha.Common.Request.WebResult(userUrl); //解析QQ账户信息 Song.Entities.Accounts acc = null; JObject jo = (JObject)JsonConvert.DeserializeObject(retjson); string errcode = jo["errcode"] != null ? jo["errcode"].ToString() : string.Empty; //错误代码 if (!string.IsNullOrEmpty(errcode)) { return(acc); } if (string.IsNullOrEmpty(errcode)) { acc = new Entities.Accounts(); acc.Ac_Name = jo["nickname"] != null ? jo["nickname"].ToString() : string.Empty; //昵称 acc.Ac_Sex = jo["sex"] != null?Convert.ToInt16(jo["sex"].ToString()) : 0; //性别,1为男,2为女 acc.Ac_Photo = jo["headimgurl"] != null ? jo["headimgurl"].ToString() : string.Empty; //用户头像 //取132的头像 if (acc.Ac_Photo.IndexOf("/") > -1) { acc.Ac_Photo = acc.Ac_Photo.Substring(0, acc.Ac_Photo.LastIndexOf("/") + 1) + "132"; } acc.Ac_WeixinOpenID = openid; } return(acc); }
/// <summary> /// 注册,但不验证手机号 /// </summary> private void register1() { string access_token = WeiSha.Common.Request.QueryString["token"].String; string openid = WeiSha.Common.Request.QueryString["openid"].String; string mobi = WeiSha.Common.Request.Form["mobi"].String; //手机号 int sex = WeiSha.Common.Request.Form["sex"].Int16 ?? 0; string name = WeiSha.Common.Request.Form["name"].String; string photo = WeiSha.Common.Request.Form["photo"].String; //验证手机号是否存在 if (!string.IsNullOrWhiteSpace(mobi)) { Song.Entities.Accounts acc = Business.Do <IAccounts>().IsAccountsExist(-1, mobi, 1); if (acc != null) { Response.Write("{\"success\":\"-1\",\"state\":\"2\"}"); //手机号已经存在 return; } } Song.Entities.Organization org = getOrgan(); //创建新账户 Song.Entities.Accounts tmp = new Entities.Accounts(); tmp.Ac_AccName = string.IsNullOrWhiteSpace(mobi) ? openid : mobi; tmp.Ac_MobiTel1 = tmp.Ac_MobiTel2 = mobi; //手机号 tmp.Ac_WeixinOpenID = openid; tmp.Ac_Name = name; tmp.Ac_Sex = sex; tmp.Org_ID = org.Org_ID; //头像图片 string photoPath = Upload.Get["Accounts"].Physics + openid + ".jpg"; WeiSha.Common.Request.LoadFile(photo, photoPath); tmp.Ac_Photo = openid + ".jpg"; //获取推荐人 int recid = WeiSha.Common.Request.Cookies["sharekeyid"].Int32 ?? 0; Song.Entities.Accounts accRec = null; if (accRec == null && recid > 0) { accRec = Business.Do <IAccounts>().AccountsSingle(recid); } if (accRec != null && accRec.Ac_ID != tmp.Ac_ID) { tmp.Ac_PID = accRec.Ac_ID; //设置推荐人,即:当前注册账号为推荐人的下线 Business.Do <IAccounts>().PointAdd4Register(accRec); //增加推荐人积分 } //如果需要审核通过 tmp.Ac_IsPass = tmp.Ac_IsUse = true; int id = Business.Do <IAccounts>().AccountsAdd(tmp); LoginState.Accounts.Write(tmp); string domain = getOrganDomain(org); Response.Write("{\"success\":\"1\",\"name\":\"" + tmp.Ac_Name + "\",\"domain\":\"" + domain + "\",\"acid\":\"" + tmp.Ac_ID + "\",\"state\":\"1\"}"); }
private AccountsModel EntityToModelMapper(Entities.Accounts Account) { AccountsModel account = new AccountsModel() { AccountID = Account.AccountID, Name = Account.Name, ManagerID = Account.ManagerID }; return(account); }
private Entities.Accounts ModelToEntityMapper(Models.AccountsModel Account) { Entities.Accounts AccountEntity = new Entities.Accounts { AccountID = Account.AccountID, Name = Account.Name, ManagerID = Account.ManagerID }; return(AccountEntity); }
/// <summary> /// 验证账号是否已经存在 /// </summary> /// <param name="source"></param> /// <param name="args"></param> protected void cusv_ServerValidate(object source, ServerValidateEventArgs args) { Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); Song.Entities.Accounts th = Business.Do <IAccounts>().AccountsSingle(this.tbStudentAcc.Text.Trim(), org.Org_ID); if (th == null) { th = new Entities.Accounts(); } th.Org_ID = org.Org_ID; th.Ac_AccName = this.tbStudentAcc.Text.Trim(); //判断是否通过验证 Song.Entities.Accounts t = Business.Do <IAccounts>().IsAccountsExist(org.Org_ID, th); args.IsValid = t == null; }
/// <summary> /// 没有注册,直接通过微信注册并登录 /// </summary> private void _directLogin() { string openid = WeiSha.Common.Request.QueryString["openid"].String; string token = WeiSha.Common.Request.QueryString["token"].String; int sex = WeiSha.Common.Request.Form["sex"].Int16 ?? 0; string name = WeiSha.Common.Request.Form["name"].String; string photo = WeiSha.Common.Request.Form["photo"].String; Song.Entities.Organization org = getOrgan(-1); //创建新账户 //获取微信登录账户的信息 string unionid = string.Empty; Song.Entities.Accounts tmp = getUserInfo(token, openid, out unionid); if (tmp == null) { tmp = new Entities.Accounts(); } tmp.Ac_AccName = unionid; tmp.Org_ID = org.Org_ID; //头像图片 string photoPath = Upload.Get["Accounts"].Physics + unionid + ".jpg"; WeiSha.Common.Request.LoadFile(photo, photoPath); tmp.Ac_Photo = unionid + ".jpg"; //获取推荐人 int recid = WeiSha.Common.Request.Cookies["sharekeyid"].Int32 ?? 0; Song.Entities.Accounts accRec = null; if (accRec == null && recid > 0) { accRec = Business.Do <IAccounts>().AccountsSingle(recid); } if (accRec != null && accRec.Ac_ID != tmp.Ac_ID) { tmp.Ac_PID = accRec.Ac_ID; //设置推荐人,即:当前注册账号为推荐人的下线 Business.Do <IAccounts>().PointAdd4Register(accRec); //增加推荐人积分 } //如果需要审核通过 tmp.Ac_IsPass = tmp.Ac_IsUse = true; int id = Business.Do <IAccounts>().AccountsAdd(tmp); LoginState.Accounts.Write(tmp); string domain = getOrganDomain(org); Response.Write("{\"success\":\"1\",\"name\":\"" + tmp.Ac_Name + "\",\"domain\":\"" + domain + "\",\"acid\":\"" + tmp.Ac_ID + "\",\"state\":\"1\"}"); }
/// <summary> /// 获取当前登录微信账号的详细信息 /// </summary> /// <param name="access_token"></param> /// <param name="openid"></param> /// <returns>xml对象</returns> private Song.Entities.Accounts getUserInfo(string access_token, string openid, out string unionid) { string userUrl = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN"; //string userUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN"; userUrl = string.Format(userUrl, access_token, openid); string retjson = WeiSha.Common.Request.HttpGet(userUrl); unionid = string.Empty; //解析微信账户信息 Song.Entities.Accounts acc = null; JObject jo = (JObject)JsonConvert.DeserializeObject(retjson); string errcode = jo["errcode"] != null ? jo["errcode"].ToString() : string.Empty; //错误代码 string errmsg = jo["errmsg"] != null ? jo["errmsg"].ToString() : string.Empty; if (!string.IsNullOrWhiteSpace(errcode)) { this.Document.Variables.SetValue("errcode", errcode); this.Document.Variables.SetValue("errmsg", errmsg); return(acc); } if (string.IsNullOrEmpty(errcode)) { acc = new Entities.Accounts(); acc.Ac_Name = jo["nickname"] != null ? jo["nickname"].ToString() : string.Empty; //昵称 acc.Ac_Sex = jo["sex"] != null?Convert.ToInt16(jo["sex"].ToString()) : 0; //性别,1为男,2为女 acc.Ac_Photo = jo["headimgurl"] != null ? jo["headimgurl"].ToString() : string.Empty; //用户头像 //取132的头像 if (acc.Ac_Photo.IndexOf("/") > -1) { acc.Ac_Photo = acc.Ac_Photo.Substring(0, acc.Ac_Photo.LastIndexOf("/") + 1) + "132"; } unionid = jo["unionid"] != null ? jo["unionid"].ToString() : string.Empty; //unionid acc.Ac_WeixinOpenID = unionid; } return(acc); }
public bool AddAccount(AccountsModel Account) { try { Entities.Accounts AccountEntity = this.ModelToEntityMapper(Account); if (AccountRepository.AddAccount(AccountEntity)) { return(true); } else { return(false); } } catch (Exception ex) { logger.Info("Error in AddAccount"); logger.Error(ex.InnerException); logger.Error(ex.Message); logger.Error(ex.Source); return(false); } }
/// <summary> /// 获取当前登录QQ的详细信息 /// </summary> /// <param name="access_token"></param> /// <param name="openid"></param> /// <returns>xml对象</returns> private Song.Entities.Accounts getUserInfo(string access_token, string openid) { string userUrl = "https://graph.qq.com/user/get_user_info?access_token={0}&oauth_consumer_key={1}&openid={2}"; string appid = Business.Do <ISystemPara>()["QQAPPID"].String; userUrl = string.Format(userUrl, access_token, appid, openid); //解析QQ账户信息 Song.Entities.Accounts acc = new Entities.Accounts(); try { string infoJson = WeiSha.Common.Request.WebResult(userUrl); JObject jo = (JObject)JsonConvert.DeserializeObject(infoJson); string ret = jo["ret"] != null ? jo["ret"].ToString() : string.Empty; //返回码 string msg = jo["msg"] != null ? jo["msg"].ToString() : string.Empty; //返回的提示信息 if (ret == "0") { acc.Ac_AccName = acc.Ac_QqOpenID = openid; acc.Ac_Name = jo["nickname"] != null ? jo["nickname"].ToString() : string.Empty; //姓名 string gender = jo["gender"] != null ? jo["gender"].ToString() : string.Empty; acc.Ac_Sex = gender == "男" ? 1 : 2; acc.Ac_Age = jo["year"] != null?Convert.ToInt32(jo["year"].ToString()) : 0; //年龄 acc.Ac_Photo = jo["figureurl_qq_2"] != null ? jo["figureurl_qq_2"].ToString() : string.Empty; //头像 acc.Org_ID = WeiSha.Common.Request.QueryString["orgid"].Int32 ?? 0; //所属机构 } else { this.Document.Variables.SetValue("errcode", ret); this.Document.Variables.SetValue("errmsg", msg); } } catch (Exception ex) { throw ex; } return(acc); }
string goto_url = WeiSha.Common.Request.QueryString["goto"].UrlDecode; //成功后的跳转地址 public void ProcessRequest(HttpContext context) { SSO_State state = null; try { if (string.IsNullOrWhiteSpace(user)) { throw new Exception("1.账号不得为空"); } if (string.IsNullOrWhiteSpace(appid)) { throw new Exception("2.APPID不得为空"); } if (string.IsNullOrWhiteSpace(domain)) { throw new Exception("3.请求域不得为空"); } //接口是否存在或正确 Song.Entities.SingleSignOn entity = Business.Do <ISSO>().GetSingle(appid); if (entity == null) { throw new Exception("2.接口对象不存在"); } if (!entity.SSO_Domain.Equals(domain, StringComparison.CurrentCultureIgnoreCase)) { throw new Exception("3.该请求来自的域不合法"); } //通过验证,进入登录状态 Song.Entities.Accounts emp = Business.Do <IAccounts>().IsAccountsExist(user); if (emp == null) { if (!"add".Equals(action, StringComparison.CurrentCultureIgnoreCase)) { throw new Exception(string.Format("4.当前账号({0})不存在", user)); } Song.Entities.Accounts tmp = new Entities.Accounts(); tmp.Ac_AccName = user; tmp.Ac_Name = name; tmp.Ac_IsPass = tmp.Ac_IsUse = true; Business.Do <IAccounts>().AccountsAdd(tmp); LoginState.Accounts.Write(tmp); state = new SSO_State(true, 10, string.Format("新建账号({0})", user)); } else { if (!emp.Ac_IsPass || !emp.Ac_IsUse) { throw new Exception(string.Format("5.当前账号({0})被禁用或未通过审核", user)); } switch (action) { //退出登录 case "logout": LoginState.Accounts.Logout(); state = new SSO_State(true, 7, string.Format("当前账号({0})退出登录", user)); break; //验证密码 case "verify": Song.Entities.Accounts acc = Business.Do <IAccounts>().AccountsLogin(emp.Ac_ID, pw, true); if (acc == null) { throw new Exception(string.Format("8.当前账号({0})与密码不匹配", user)); } state = new SSO_State(true, 9, string.Format("当前账号({0})与密码校验成功", user)); break; //登录 case "login": default: LoginState.Accounts.Write(emp); //登录成功 Business.Do <IAccounts>().PointAdd4Login(emp, "协同站点登录", domain, ""); //增加登录积分 Business.Do <IStudent>().LogForLoginAdd(emp); state = new SSO_State(true, 6, string.Format("当前账号({0})登录成功", user)); break; } } } catch (Exception ex) { int s = 0; string msg = string.Empty; if (ex.Message.IndexOf(".") > 0) { string str = ex.Message.Substring(0, ex.Message.IndexOf(".")); int.TryParse(str, out s); msg = ex.Message.Substring(ex.Message.IndexOf(".") + 1); } state = new SSO_State(false, s, msg); } //如果成功,且转向地址不为空,则跳转 if (state != null && state.success && !string.IsNullOrWhiteSpace(goto_url)) { context.Response.Redirect(goto_url); } else { string reslut = state.ToReturn(ret); context.Response.Write(reslut); context.Response.End(); } }
/// <summary> /// 手机注册的验证 /// </summary> private void mobiregister_verify() { string vname = WeiSha.Common.Request.Form["vname"].String; string imgCode = WeiSha.Common.Request.Cookies[vname].ParaValue; //取图片验证码 string userCode = WeiSha.Common.Request.Form["vcode"].MD5; //取输入的验证码 string phone = WeiSha.Common.Request.Form["phone"].String; //输入的手机号 string sms = WeiSha.Common.Request.Form["sms"].MD5; //输入的短信验证码 string pw = WeiSha.Common.Request.Form["pw"].MD5; //密码 string name = WeiSha.Common.Request.Form["name"].String; //姓名 string email = WeiSha.Common.Request.Form["email"].String; //邮箱 string rec = WeiSha.Common.Request.Form["rec"].String; //推荐人的电话 int recid = WeiSha.Common.Request.Form["recid"].Int32 ?? 0; //推荐人的账户id //验证图片验证码 if (imgCode != userCode) { Response.Write("{\"success\":\"-1\",\"state\":\"1\"}"); //图片验证码不正确 return; } //验证手机号是否存在 Song.Entities.Accounts acc = Business.Do <IAccounts>().IsAccountsExist(-1, phone, 1); if (acc != null) { Response.Write("{\"success\":\"-1\",\"state\":\"2\"}"); //手机号已经存在 return; } //验证短信验证码 bool isSmsCode = true; //是否短信验证; WeiSha.Common.CustomConfig config = CustomConfig.Load(this.Organ.Org_Config); isSmsCode = config["IsRegSms"].Value.Boolean ?? true; string smsCode = WeiSha.Common.Request.Cookies["reg_mobi_" + vname].ParaValue; if (isSmsCode && sms != smsCode) { Response.Write("{\"success\":\"-1\",\"state\":\"3\"}"); //短信验证失败 return; } else { //创建新账户 Song.Entities.Accounts tmp = new Entities.Accounts(); tmp.Ac_AccName = phone; tmp.Ac_Pw = pw; tmp.Ac_Name = name; tmp.Ac_MobiTel1 = phone; tmp.Ac_Email = email; //获取推荐人 Song.Entities.Accounts accRec = null; if (!string.IsNullOrWhiteSpace(rec)) { accRec = Business.Do <IAccounts>().AccountsSingle(rec, true, true); } if (accRec == null && recid > 0) { accRec = Business.Do <IAccounts>().AccountsSingle(recid); } if (accRec != null && accRec.Ac_ID != tmp.Ac_ID) { tmp.Ac_PID = accRec.Ac_ID; //设置推荐人,即:当前注册账号为推荐人的下线 Business.Do <IAccounts>().PointAdd4Register(accRec); //增加推荐人积分 } //如果需要审核通过 tmp.Ac_IsPass = !(bool)(config["IsVerifyStudent"].Value.Boolean ?? true); tmp.Ac_IsUse = tmp.Ac_IsPass; int id = Business.Do <IAccounts>().AccountsAdd(tmp); //以下为判断是否审核通过 if (tmp.Ac_IsPass) { LoginState.Accounts.Write(tmp); Response.Write("{\"success\":\"1\",\"name\":\"" + tmp.Ac_Name + "\",\"state\":\"1\"}"); } else { //注册成功,但待审核 Response.Write("{\"success\":\"1\",\"name\":\"" + tmp.Ac_Name + "\",\"state\":\"0\"}"); } } }
/// <summary> /// 将某一行数据加入到数据库 /// </summary> /// <param name="dr"></param> /// <param name="dl"></param> private void _inputData(DataRow dr) { //取所有分类 if (this.sorts == null) { this.sorts = Business.Do <IStudent>().SortCount(org.Org_ID, null, 0); } Song.Entities.Accounts obj = null; bool isExist = false; foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Ac_AccName") { obj = Business.Do <IAccounts>().AccountsSingle(column, -1); isExist = obj != null; continue; } } if (obj == null) { obj = new Entities.Accounts(); } foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Ac_Sex") { obj.Ac_Sex = (short)(column == "男" ? 1 : (column == "女" ? 2 : 0)); continue; } PropertyInfo[] properties = obj.GetType().GetProperties(); for (int j = 0; j < properties.Length; j++) { PropertyInfo pi = properties[j]; if (field == pi.Name && !string.IsNullOrEmpty(column)) { pi.SetValue(obj, Convert.ChangeType(column, pi.PropertyType), null); } } } //设置分组 if (!string.IsNullOrWhiteSpace(obj.Sts_Name)) { obj.Sts_ID = _getSortsId(sorts, obj.Sts_Name); } if (!string.IsNullOrWhiteSpace(obj.Ac_Pw)) { obj.Ac_Pw = new WeiSha.Common.Param.Method.ConvertToAnyValue(obj.Ac_Pw).MD5; } obj.Org_ID = org.Org_ID; obj.Ac_IsPass = true; obj.Ac_IsUse = true; if (isExist) { Business.Do <IAccounts>().AccountsSave(obj); } else { Business.Do <IAccounts>().AccountsAdd(obj); } }
/// <summary> /// 手机号注册,需短信验证 /// </summary> private void register2() { string vname = WeiSha.Common.Request.Form["vname"].String; string imgCode = WeiSha.Common.Request.Cookies[vname].ParaValue; //取图片验证码 string userCode = WeiSha.Common.Request.Form["vcode"].MD5; //取输入的验证码 string access_token = WeiSha.Common.Request.QueryString["access_token"].String; string openid = WeiSha.Common.Request.Form["openid"].String; string mobi = WeiSha.Common.Request.Form["mobi"].String; //手机号 string sms = WeiSha.Common.Request.Form["sms"].MD5; //输入的短信验证码 int sex = WeiSha.Common.Request.Form["sex"].Int16 ?? 0; string name = WeiSha.Common.Request.Form["name"].String; string photo = WeiSha.Common.Request.Form["photo"].String; //短信验证码Cookie名称 string smsName = WeiSha.Common.Request.Form["smsname"].String; string btnName = WeiSha.Common.Request.Form["smsbtn"].String; //验证图片验证码 if (imgCode != userCode) { Response.Write("{\"success\":\"-1\",\"state\":\"1\",\"btn\":\"" + btnName + "\"}"); //图片验证码不正确 return; } //验证手机号是否存在 Song.Entities.Accounts acc = Business.Do <IAccounts>().IsAccountsExist(-1, mobi, 1); if (acc != null) { Response.Write("{\"success\":\"-1\",\"state\":\"2\",\"btn\":\"" + btnName + "\"}"); //手机号已经存在 return; } //验证短信验证码 bool isSmsCode = true; //是否短信验证; string smsCode = WeiSha.Common.Request.Cookies[smsName].ParaValue; if (isSmsCode && sms != smsCode) { Response.Write("{\"success\":\"-1\",\"state\":\"3\",\"btn\":\"" + btnName + "\"}"); //短信验证失败 return; } else { //创建新账户 Song.Entities.Accounts tmp = new Entities.Accounts(); Song.Entities.Organization org = getOrgan(); tmp.Ac_AccName = string.IsNullOrWhiteSpace(mobi) ? openid : mobi; tmp.Ac_MobiTel1 = tmp.Ac_MobiTel2 = mobi; //手机号 tmp.Ac_WeixinOpenID = openid; tmp.Ac_Name = name; tmp.Ac_Sex = sex; tmp.Org_ID = org.Org_ID; //头像图片 string photoPath = Upload.Get["Accounts"].Physics + openid + ".jpg"; WeiSha.Common.Request.LoadFile(photo, photoPath); tmp.Ac_Photo = openid + ".jpg"; //获取推荐人 int recid = WeiSha.Common.Request.Cookies["sharekeyid"].Int32 ?? 0; Song.Entities.Accounts accRec = null; if (accRec == null && recid > 0) { accRec = Business.Do <IAccounts>().AccountsSingle(recid); } if (accRec != null && accRec.Ac_ID != tmp.Ac_ID) { tmp.Ac_PID = accRec.Ac_ID; //设置推荐人,即:当前注册账号为推荐人的下线 Business.Do <IAccounts>().PointAdd4Register(accRec); //增加推荐人积分 } //如果需要审核通过 tmp.Ac_IsPass = tmp.Ac_IsUse = true; int id = Business.Do <IAccounts>().AccountsAdd(tmp); LoginState.Accounts.Write(tmp); string domain = getOrganDomain(org); Response.Write("{\"success\":\"1\",\"name\":\"" + tmp.Ac_Name + "\",\"domain\":\"" + domain + "\",\"acid\":\"" + tmp.Ac_ID + "\",\"state\":\"1\",\"btn\":\"" + btnName + "\"}"); } }
/// <summary> /// 将某一行数据加入到数据库 /// </summary> /// <param name="dr"></param> /// <param name="dl"></param> private void _inputData(DataRow dr) { //取所有分类 if (org == null) { org = Business.Do <IOrganization>().OrganCurrent(); } if (this.sorts == null) { this.sorts = Business.Do <ITeacher>().SortCount(org.Org_ID, null, 0); } Song.Entities.Accounts acc = null; Song.Entities.Teacher teacher = null; bool isExistAcc = false; //是否存在该账号 bool isExistTh = false; //是否存在该教师 foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Th_PhoneMobi") { acc = Business.Do <IAccounts>().AccountsSingle(column, -1); if (acc != null) { teacher = Business.Do <IAccounts>().GetTeacher(acc.Ac_ID, null); } isExistAcc = acc != null; isExistTh = teacher != null; continue; } } if (acc == null) { acc = new Entities.Accounts(); } if (teacher == null) { teacher = new Entities.Teacher(); } foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Th_Sex") { teacher.Th_Sex = (short)(column == "男" ? 1 : 2); continue; } PropertyInfo[] properties = teacher.GetType().GetProperties(); for (int j = 0; j < properties.Length; j++) { PropertyInfo pi = properties[j]; if (field == pi.Name && !string.IsNullOrEmpty(column)) { pi.SetValue(teacher, Convert.ChangeType(column, pi.PropertyType), null); } } } //设置分组 if (!string.IsNullOrWhiteSpace(teacher.Ths_Name)) { teacher.Ths_ID = _getDepartId(sorts, teacher.Ths_Name); } if (!string.IsNullOrWhiteSpace(teacher.Th_Pw)) { teacher.Th_Pw = teacher.Th_Pw.Trim(); } acc.Org_ID = teacher.Org_ID = org.Org_ID; acc.Ac_Name = teacher.Th_Name; teacher.Org_Name = org.Org_Name; teacher.Th_AccName = teacher.Th_PhoneMobi; acc.Ac_IsPass = teacher.Th_IsPass = true; teacher.Th_IsShow = true; acc.Ac_IsUse = teacher.Th_IsUse = true; //如果账号不存在 if (!isExistAcc) { acc.Ac_AccName = acc.Ac_MobiTel1 = acc.Ac_MobiTel2 = teacher.Th_PhoneMobi; //账号手机号 acc.Ac_Pw = new WeiSha.Common.Param.Method.ConvertToAnyValue(teacher.Th_Pw).MD5; //密码 acc.Ac_Sex = teacher.Th_Sex; //性别 acc.Ac_Birthday = teacher.Th_Birthday; acc.Ac_Qq = teacher.Th_Qq; acc.Ac_Email = teacher.Th_Email; acc.Ac_IDCardNumber = teacher.Th_IDCardNumber; //身份证 acc.Ac_IsTeacher = true; //该账号有教师身份 //保存 teacher.Ac_ID = Business.Do <IAccounts>().AccountsAdd(acc); Business.Do <ITeacher>().TeacherSave(teacher); } else { acc.Ac_IsTeacher = true; teacher.Ac_ID = acc.Ac_ID; //如果账号存在,但教师不存在 if (!isExistTh) { Business.Do <ITeacher>().TeacherAdd(teacher); } else { teacher.Th_Pw = new WeiSha.Common.Param.Method.ConvertToAnyValue(teacher.Th_Pw).MD5; //密码 Business.Do <ITeacher>().TeacherSave(teacher); } } }