public static ContestDll.User GetUserByUserID(long userID) { using (ContestEntities db = new ContestEntities()) { ContestDll.User atList = db.User.SingleOrDefault(at => at.UserID == userID); return(atList); } }
void btnSave_Click(object sender, EventArgs e) { try { if (editState == 1) { EditSave(); DAL.ADHelper.EditUser(txtAccount.Text, txtName.Text, txtEmail.Text, txtTelephone.Text); //Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script defer>alert('保存成功');if (window.opener.document.getElementById('btnSearch')!=null) window.opener.document.getElementById('btnSearch').click();window.close()</script>"); Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script defer>alert('保存成功');window.close()</script>"); return; } string account = txtAccount.Text.Trim().Replace(" ", ""); List <ContestDll.User> ds = DAL.User.GetUserByAccount(account); if (ds.Count > 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script defer>alert('用户已存在');document.forms(0).txtAccount.select()</script>"); return; } else { bool succeed = SaveAD(account, txtName.Text.Trim(), txtEmail.Text.Trim(), txtTelephone.Text.Trim(), txtPwd.Text.Trim(), ddlCareer.SelectedItem.Text, ddlSchool.SelectedItem == null ? "其它" : ddlSchool.SelectedItem.Text, true); if (succeed) { ContestDll.User dr = new ContestDll.User(); dr.Account = account; if (ddlSchool.SelectedItem != null) { dr.SchoolID = int.Parse(ddlSchool.SelectedValue); } dr.Name = txtName.Text.Trim(); dr.IDCard = txtId.Text.Trim(); dr.Sex = rblSex.SelectedValue == "1" ? true : false; dr.Telephone = txtTelephone.Text.Trim(); dr.Email = txtEmail.Text.Trim(); dr.Flag = 1; dr.RoleID = int.Parse(ddlCareer.SelectedValue); DAL.User.InsertUser(dr); Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script defer>alert('注册成功');top.location.href='" + SPContext.Current.Site.Url + "'</script>"); //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>LoginSys('" + ADHelper.Domain + "','" + account + "','" + txtPwd.Text.Trim() + "');</script>"); } else { Common.ShowMessage(Page, this.GetType(), "用户已经存在!"); } } } catch (Exception ex) { Common.ShowMessage(Page, this.GetType(), "注册失败!" + ex.ToString()); } }
/// <summary> /// 编辑用户信息 /// </summary> private void UpdateSave() { ContestDll.User dr = DAL.User.GetUserByUserID((long)ViewState["editDsUserID"]); dr.SchoolID = int.Parse(ddlSchollNew.SelectedValue); dr.Sex = rblSex.SelectedValue == "1"?true:false; dr.IDCard = txtId.Text; dr.Telephone = txtTelephone.Text; dr.Email = txtEmail.Text; dr.ModifiedBy = DAL.Common.LoginID; dr.Modified = DateTime.Now; DAL.User.UpdateUser(dr); ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "message", "alert('保存成功');document.getElementById('divManageUser').style.display='none'", true); ViewState.Remove("ShowInfo"); btnSearch_Click(null, null); }
public static long GetUserID(SPUser user) { string name = user.LoginName; //检查用户 List <ContestDll.User> dt = DAL.User.GetUserByAccount(name.Substring(name.LastIndexOf("\\") + 1)); if (dt.Count == 0) { ContestDll.User dr = new ContestDll.User(); dr.Account = user.LoginName.Split('\\')[1]; dr.Name = user.Name; dr.Flag = 1; return(DAL.User.InsertUser(dr)); } else { return(dt[0].UserID); } }
public static long InsertUser(ContestEntities db, ContestDll.User dr) { ContestDll.User at = new ContestDll.User(); at.Account = dr.Account; at.Department = dr.Department; at.Duty = dr.Duty; at.Email = dr.Email; at.Department = dr.Department; at.Telephone = dr.Telephone; at.IDCard = dr.IDCard; at.Name = dr.Name; at.SchoolID = dr.SchoolID; at.Major = dr.Major; at.RoleID = dr.RoleID; at.Sex = dr.Sex; at.StateID = dr.StateID; at.Created = DateTime.Now; db.User.Add(at); db.SaveChanges(); return(at.UserID); }
public static int UpdateUser(ContestDll.User dr) { using (ContestEntities db = new ContestEntities()) { ContestDll.User at = db.User.SingleOrDefault(p => p.UserID == dr.UserID); at.Account = dr.Account; at.Department = dr.Department; at.Duty = dr.Duty; at.Email = dr.Email; at.Department = dr.Department; at.Telephone = dr.Telephone; at.IDCard = dr.IDCard; at.Name = dr.Name; at.SchoolID = dr.SchoolID; at.Major = dr.Major; at.RoleID = dr.RoleID; at.Sex = dr.Sex; at.StateID = dr.StateID; at.Created = DateTime.Now; db.SaveChanges(); return(1); } }
public static bool InsertUser(ContestDll.User drUser, UserRole drUserRole) { List <WorksExpert> dsType = DAL.Works.GetWorksExpertByID(0); ContestEntities db = new ContestEntities(); using (TransactionScope scope = new TransactionScope()) { try { long userID = DAL.User.InsertUser(db, drUser); drUserRole.UserID = userID; DAL.User.InsertUserRole(db, drUserRole); scope.Complete(); return(true); } catch (Exception ex) { scope.Dispose(); return(false); } } }
//保存 void btnSave_Click(object sender, EventArgs e) { if (txtAccountNew.ReadOnly == true) { UpdateSave(); return; } List <User> ds = DAL.User.GetUserByAccount(txtAccountNew.Text); if (ds.Count > 0) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "message", "alert('用户已存在');document.forms(0).txtAccountNew.select()", true); return; } ds = DAL.User.GetUserByIDCard(txtId.Text); if (ds.Count > 0) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "message", "alert('身份证号码已存在');document.forms(0).txtId.select()", true); return; } ContestDll.User dr = new ContestDll.User(); dr.Account = txtAccountNew.Text; dr.Name = txtNameNew.Text; dr.IDCard = txtId.Text; dr.Sex = rblSex.SelectedValue == "1"?true :false; dr.Telephone = txtTelephone.Text; dr.Email = txtEmail.Text; dr.Flag = 1; dr.SchoolID = int.Parse(ddlSchollNew.SelectedValue); UserRole drRole = new UserRole(); drRole.CreatedBy = DAL.Common.LoginID; drRole.Created = DateTime.Now; drRole.RoleID = int.Parse(rblRole.SelectedValue); drRole.StateID = 1; drRole.Flag = 1; drRole.ContestID = DAL.Common.GetContestID(Page); //这里加的专家和管理员无需审批 try { bool enableUser = true;// ViewState["ShowInfo"] != null; bool succeed = SaveAD(enableUser); if (succeed) { BLL.User.InsertUser(dr, drRole);; ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "message", "alert('保存成功');document.getElementById('divManageUser').style.display='none'", true); Clear(); ViewState.Remove("ShowInfo"); } else { DAL.Common.ShowMessage(Page, this.GetType(), "帐号已经存在!"); } } catch { DAL.Common.ShowMessage(Page, this.GetType(), "保存失败!"); } }