public CConstants.State.Existed Exist(UserInfo info) { if (info == null) return CConstants.State.Existed.None; try { CConstants.State.Existed vlreturn = CConstants.State.Existed.None; using (iSqlConnection iConn = HELPER.getConnect(HELPER.SQL_SYSTEM)) { if (HELPER.isExist(iConn, TABLENAME, "username", info.Username, info.Id)) { vlreturn = CConstants.State.Existed.Name; goto closeConn; } if (HELPER.isExist(iConn, TABLENAME, "email", info.Email, info.Id)) { vlreturn = CConstants.State.Existed.Mail; goto closeConn; } closeConn: iConn.Close(); } return vlreturn; } catch (Exception ex) { throw ex; } }
public UserInfo Login(UserInfo info) { try { UserInfo _info = null; using (iSqlConnection iConn = HELPER.getConnect(HELPER.SQL_SYSTEM)) { string SQL = SQL_GETIFO; SQL += " AND A.status<>" + (int)CConstants.State.Status.Waitactive; SQL += " AND A.status<>" + (int)CConstants.State.Status.Disabled; SQL += " AND A.pis=0"; SQL += " AND (A.username=@USERNAME) AND (A.password=@PASSWORD)"; iSqlParameter[] parms = new iSqlParameter[]{ new iSqlParameter(PARM_USERNAME, iSqlType.Field_tString), new iSqlParameter(PARM_PASSWORD, iSqlType.Field_tString) }; parms[0].Value = info.Username; parms[1].Value = info.Password; using (iSqlDataReader dar = HELPER.executeReader(iConn, iCommandType.Text, SQL, parms)) { if (dar.Read()) { _info = this.getDataReader(dar); } } iConn.Close(); } return _info; } catch (Exception ex) { throw ex; } }
private UserInfo Take() { try { int iid = 0; int.TryParse(txtId.Value, out iid); UserInfo info = (new CUser()).Wcmm_Getinfo(iid); if (info == null) info = new UserInfo(); info.Id = iid; info.Name = txtName.Text.Trim(); info.Username = txtUsername.Text.Trim(); info.Password = CFunctions.MBEncrypt(txtPassword.Text); info.Email = txtEmail.Text.Trim(); info.Pis = 0; info.Pid = int.Parse(ddlGroup.SelectedValue); info.Depth = PARENT == null ? 1 : PARENT.Depth + 1; info.Status = Displaysetting.Get_Status(); info.Timeupdate = DateTime.Now; UserrightInfo rinfo = (new CUserright()).Getinfo(info.Pid); info.iRight = rinfo; return info; } catch { return null; } }
public bool ChangePwd(UserInfo info) { try { if (info == null) return false; using (iSqlConnection iConn = HELPER.getConnect(HELPER.SQL_SYSTEM)) { iSqlParameter[] parms = new iSqlParameter[]{ new iSqlParameter(PARM_PASSWORD, iSqlType.Field_tString), new iSqlParameter(PARM_ID, iSqlType.Field_tInterger) }; parms[0].Value = info.Password; parms[1].Value = info.Id; HELPER.executeNonQuery(iConn, iCommandType.Text, SQL_CHANGE_PWD, parms); iConn.Close(); } return true; } catch (Exception ex) { throw ex; } }
private bool Save(UserInfo info) { try { if (info == null) return false; return (new CUser()).Save(info); } catch { return false; } }
private bool Save(UserInfo info) { try { if (info == null) return false; int iid = info.Id; if ((new CUser()).Save(info)) if (PARENT != null && iid == 0) (new CUser()).Updatenum(PARENT.Id.ToString(), Queryparam.Sqlcolumn.Pis, CConstants.NUM_INCREASE); return true; } catch { return false; } }
protected void Page_Load(object sender, EventArgs e) { PARENT = this.Get_Parent(); if (!Page.IsPostBack) { this.Init_State(); this.Bind_grdView(); } }
private bool Saveitem(iSqlTransaction trans, UserInfo info) { try { if (trans == null || info == null) return false; string SQL = string.Empty; if (info.Id == 0) { SQL = SQL_INSERT; info.Id = (int)HELPER.getNewID(trans, TABLENAME); iSqlParameter[] parms = this.getParameter(SQL); this.setParameter(parms, info); HELPER.executeNonQuery(trans, iCommandType.Text, SQL, parms); } else if (HELPER.isExist(trans, TABLENAME, info.Id)) { SQL = SQL_UPDATE; iSqlParameter[] parms = this.getParameter(SQL); this.setParameter(parms, info); HELPER.executeNonQuery(trans, iCommandType.Text, SQL, parms); } else { SQL = SQL_INSERT; info.Id = (int)HELPER.getNewID(trans, TABLENAME); iSqlParameter[] parms = this.getParameter(SQL); this.setParameter(parms, info); HELPER.executeNonQuery(trans, iCommandType.Text, SQL, parms); } return true; } catch (Exception ex) { throw ex; } }
private void Write_Cookies(UserInfo logger) { if (chkRememberlogin.Checked) { Response.Cookies[CConstants.WEBSITE][":cmm:username"] = Server.HtmlDecode(logger.Username); Response.Cookies[CConstants.WEBSITE][":cmm:password"] = Server.HtmlDecode(logger.Password); Response.Cookies[CConstants.WEBSITE][":cmm:remember"] = "1"; Response.Cookies[CConstants.WEBSITE][":cmm:lang"] = Server.HtmlDecode(ddlLang.SelectedValue); Response.Cookies[CConstants.WEBSITE].Expires.AddDays(7); } else { Response.Cookies.Remove(CConstants.WEBSITE); } }
protected void cmdLogin_Click(object sender, EventArgs e) { try { UserInfo info = new UserInfo(); info.Username = txtUsername.Text.Trim(); info.Password = CFunctions.MBEncrypt(txtPassword.Text); UserInfo logger = (new CUser()).Login(info); if (logger == null) { lblError.Text = CCommon.Get_Definephrase(Definephrase.Interface_login_invalid); } else { if (logger.iRight == null) logger.iRight = (new CUserright()).Getinfo(logger.Id); CCommon.Session_Set(Sessionparam.USERLOGIN, logger); this.Write_Cookies(logger); if (Session[Sessionparam.PREVIOUSURL] != null) Response.Redirect(Session[Sessionparam.PREVIOUSURL].ToString()); else Response.Redirect(CCommon.LANG + "/" + "dashboard.aspx"); } } catch (Exception ex) { throw ex; } }
private UserInfo Read_Cookies() { if (Request.Cookies[CConstants.WEBSITE] == null) return null; UserInfo logger = new UserInfo(); logger.Username = Server.HtmlEncode(Request.Cookies[CConstants.WEBSITE][":cmm:username"]); logger.Password = Server.HtmlEncode(Request.Cookies[CConstants.WEBSITE][":cmm:password"]); if (Request.Cookies[CConstants.WEBSITE][":cmm:remember"] != null) logger.Logincache = int.Parse(Server.HtmlEncode(Request.Cookies[CConstants.WEBSITE][":cmm:remember"])); CCommon.LANG = Server.HtmlEncode(Request.Cookies[CConstants.WEBSITE][":cmm:lang"]); return logger; }
private bool Createuser_MailToUser(UserInfo user) { try { string content = this.Gettemplate("MailToUser.Createuser"); if (content == null) return false; string subject = "Tài khoản quản trị web " + CConstants.WEBSITE; content = content.Replace("$VAR_NAME$", user.Name); content = content.Replace("$VAR_USERNAME$", user.Username); content = content.Replace("$VAR_PASSWORD$", user.Password); content = content.Replace("$VAR_EMAIL$", user.Email); content = content.Replace("$VAR_WEBSITE$", CConstants.WEBSITE); this.SendMailToUser(user.Email, subject, content); return true; } catch { return false; } }
private UserInfo Take() { try { int iid = 0; int.TryParse(txtId.Value, out iid); UserInfo info = (new CUser()).Wcmm_Getinfo(iid); if (info == null) info = new UserInfo(); info.Id = iid; info.Name = txtName.Text.Trim(); if (iid == 0) info.Username = CFunctions.remove_blank(info.Name); info.Password = CFunctions.MBEncrypt("DFTY$FDSSDYE$#%"); info.Email = info.Username + "@dangdong.vn"; info.Pis = info.Pis == 0 ? 1 : info.Pis; if (PARENT != null) { info.Pid = PARENT.Id; info.Depth = PARENT.Depth + 1; } else { info.Depth = info.Pid != 0 ? info.Depth : 1; } info.Status = CCommon.GetStatus_upt(); info.Timeupdate = DateTime.Now; UserrightInfo rinfo = new UserrightInfo(); rinfo.Id = info.Id; string RPages = ""; if (dtlListRPages.Items.Count > 0) { foreach (DataListItem row in dtlListRPages.Items) { string Navigateurl = dtlListRPages.DataKeys[row.ItemIndex].ToString(); CheckBox RPages_typeof = (CheckBox)row.FindControl("RPages_typeof"); ListBox RPages_cid = (ListBox)row.FindControl("RPages_cid"); if (RPages_typeof.Checked) { string page = Navigateurl.Replace("l.aspx", ""); RPages += page + "#"; foreach (ListItem item in RPages_cid.Items) { if (item.Selected) RPages += page + item.Value + "#"; } } } } rinfo.R_new = rinfo.R_upt = rinfo.R_del = "#" + RPages; rinfo.R_sys = ""; info.iRight = rinfo; return info; } catch { return null; } }
public bool Save(UserInfo info) { try { using (iSqlConnection iConn = HELPER.getConnect(HELPER.SQL_SYSTEM)) { using (iSqlTransaction trans = iConn.BeginTransaction()) { try { if (this.Saveitem(trans, info)) { UserrightInfo rinfo = info.iRight; rinfo.Id = info.Id; (new CUserright()).Saveitem(trans, rinfo); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ex; } } iConn.Close(); } return true; } catch (Exception ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { PARENT = this.Get_Parent(); if (!Page.IsPostBack) { this.Init_State(); this.Load_Info(CCommon.Get_QueryNumber(Queryparam.Iid)); } }
private UserInfo getDataReader(iSqlDataReader dar) { try { int i = -1; UserInfo info = new UserInfo(); info.Username = dar.IsDBNull(++i) ? string.Empty : dar.GetString(i); info.Password = dar.IsDBNull(++i) ? string.Empty : dar.GetString(i); info.Name = dar.IsDBNull(++i) ? string.Empty : dar.GetString(i); info.Email = dar.IsDBNull(++i) ? string.Empty : dar.GetString(i); info.Status = dar.IsDBNull(++i) ? (int)CConstants.State.Status.Waitactive : dar.GetInt32(i); info.Markas = dar.IsDBNull(++i) ? (int)CConstants.State.MarkAs.None : dar.GetInt32(i); info.Timeupdate = dar.IsDBNull(++i) ? new DateTime(0) : dar.GetDateTime(i); info.Pis = dar.IsDBNull(++i) ? 0 : dar.GetInt32(i); info.Pid = dar.IsDBNull(++i) ? 0 : dar.GetInt32(i); info.Depth = dar.IsDBNull(++i) ? 1 : dar.GetInt32(i); info.Logincache = dar.IsDBNull(++i) ? 0 : dar.GetInt32(i); info.Loginfirst = dar.IsDBNull(++i) ? 0 : dar.GetInt32(i); info.Id = dar.IsDBNull(++i) ? 0 : dar.GetInt32(i); info.Rownumber = dar.IsDBNull(++i) ? 0 : dar.GetInt64(i); if (info.iRight == null) info.iRight = (new CUserright()).Getinfo(info.Id); return info; } catch (Exception ex) { throw ex; } }
private bool Load_Info(int iid) { try { UserInfo info = null; if (iid != 0) { info = (new CUser()).Wcmm_Getinfo(iid); if (info != null) { lstError = new List<Errorobject>(); lstError = Form_GetError(lstError, Errortype.Notice, Definephrase.Save_notice, "[" + info.Id + "] " + info.Name, null); Master.Form_ShowError(lstError); } } if (info == null) info = new UserInfo(); chkSaveoption_golist.Checked = info.Id != 0; txtId.Value = info.Id.ToString(); txtName.Text = info.Name; txtUsername.Text = info.Username; txtPassword.Text = CFunctions.MBDecrypt(info.Password); txtEmail.Text = info.Email; ddlGroup.SelectedValue = info.Id == 0 ? (PARENT == null ? "0" : PARENT.Id.ToString()) : info.Pid.ToString(); if (info.Id == 2) { txtUsername.Enabled = false; ddlGroup.Enabled = false; } Displaysetting.Set("", info.Status, 0); return true; } catch { return false; } }
private void setParameter(iSqlParameter[] parms, UserInfo info) { try { int i = -1; parms[++i].Value = CFunctions.SetDBString(info.Username); parms[++i].Value = CFunctions.SetDBString(info.Password); parms[++i].Value = CFunctions.SetDBString(info.Name); parms[++i].Value = CFunctions.SetDBString(info.Email); parms[++i].Value = info.Status; parms[++i].Value = info.Markas; parms[++i].Value = CFunctions.SetDBDatetime(info.Timeupdate); parms[++i].Value = info.Pis; parms[++i].Value = info.Pid; parms[++i].Value = info.Depth; parms[++i].Value = info.Logincache; parms[++i].Value = info.Loginfirst; parms[++i].Value = CFunctions.install_keyword(info.Name) + " " + CFunctions.install_keyword(info.Username) + " " + CFunctions.install_keyword(info.Email); parms[++i].Value = info.Id; return; } catch (Exception ex) { throw ex; } }
private bool Load_Info(int iid) { try { UserInfo info = null; if (iid != 0) { info = (new CUser()).Wcmm_Getinfo(iid); if (info != null) { lstError = new List<Errorobject>(); lstError = Form_GetError(lstError, Errortype.Notice, Definephrase.Save_notice, "[" + info.Id + "] " + info.Name, null); Master.Form_ShowError(lstError); } } if (info == null) info = new UserInfo(); chkSaveoption_golist.Checked = info.Id != 0; txtId.Value = info.Id.ToString(); txtName.Text = info.Name; if (info.iRight == null) info.iRight = (new CUserright()).Getinfo(info.Id); if (info.iRight != null) { UserrightInfo rinfo = info.iRight; chkr_sys.Checked = rinfo.R_sys == "" ? false : true; foreach (DataListItem row in dtlListRPages.Items) { string Navigateurl = dtlListRPages.DataKeys[row.ItemIndex].ToString(); CheckBox RPages_typeof = (CheckBox)row.FindControl("RPages_typeof"); ListBox RPages_cid = (ListBox)row.FindControl("RPages_cid"); Panel divRPages = (Panel)row.FindControl("divRPages"); string page = Navigateurl.Replace("l.aspx", ""); RPages_typeof.Checked = rinfo.R_new.IndexOf(page + "#") != -1; foreach (ListItem item in RPages_cid.Items) item.Selected = rinfo.R_new.IndexOf(page + item.Value + "#") != -1; divRPages.Attributes.Add("style", RPages_typeof.Checked ? "" : "display:none"); } } else { chkr_sys.Checked = false; foreach (DataListItem row in dtlListRPages.Items) { CheckBox RPages_typeof = (CheckBox)row.FindControl("RPages_typeof"); ListBox RPages_cid = (ListBox)row.FindControl("RPages_cid"); Panel divRPages = (Panel)row.FindControl("divRPages"); RPages_typeof.Checked = false; foreach (ListItem item in RPages_cid.Items) item.Selected = false; divRPages.Attributes.Add("style", "display:none"); } } pnlForm.Enabled = info.Id != 1; chkr_sys.Visible = info.Id == 1; return true; } catch { return false; } }