using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; namespace Mtxfw.VipSite { public partial class Admin_Member_GLY_Add : Mtxfw.Utility.MemberBase { public Mtxfw.DAL.queue_window daoQuque = new DAL.queue_window(); Mtxfw.DAL.user_info daoUser = new Mtxfw.DAL.user_info(); Mtxfw.DAL.user_Results daoResults = new Mtxfw.DAL.user_Results(); private static Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(""); protected Mtxfw.DAL.Adminjs Adminjs = new Mtxfw.DAL.Adminjs(); protected string strTitle="添加管理员"; public int gtype = 0; #region 判断页面是否刷新 private bool _refreshState; private bool _isRefresh; /// /// 判断页面是否刷新 /// public bool IsRefresh { get { return _isRefresh; } } protected override void LoadViewState(object savedState) { object[] allStates = (object[])savedState; base.LoadViewState(allStates[0]); _refreshState = (bool)allStates[1]; _isRefresh = _refreshState == (bool)Session["__ISREFRESH"]; } protected override object SaveViewState() { Session["__ISREFRESH"] = _refreshState; object[] allStates = new object[2]; allStates[0] = base.SaveViewState(); allStates[1] = !_refreshState; return allStates; } #endregion protected override void OnLoad(EventArgs e) { base.OnLoad(e); string hostname = Request.Url.Host; if (!IsPostBack) { if (Session["IFPassword"] == null) { Response.Redirect("/Member_IFPassword.aspx?Url=/Admin_Member_GLY.aspx"); } if (IFStores != 1) { Mtxfw.Utility.Tools.Message("您没有权限!", "/gl.aspx"); } if (MemberJS.IndexOf("管理员列表") == -1) { Mtxfw.Utility.Tools.Message("您没有权限!", "/gl.aspx"); } Drop_type.Attributes.Add("onchange", "typechang()"); txtUserId.Attributes.Add("placeholder", "请输入会员账号"); Drop_Role.Attributes.Add("onchange", "Rolechang()"); //Btn_Insert.Attributes.Add("onclick", "return abutton()"); Drop_Role.DataSource = Adminjs.GetList("gtype=" + gtype + ""); Drop_Role.DataBind(); if (Request.QueryString["id"] != null) { strTitle = "编辑管理员"; Btn_Insert.Text = "保存"; Mtxfw.Model.user_info umodel = daoUser.GetModel(int.Parse(Request.QueryString["id"])); if (umodel != null) { Text_Name.Text = umodel.UserName; Text_User.Text = umodel.RealName; for (int i = 0; i < Drop_type.Items.Count; i++) { if (umodel.uLevel29.ToString() == Drop_type.Items[i].Value) { Drop_type.Items[i].Selected = true; } else { Drop_type.Items[i].Selected = false; } } SqlDataReader dr = daoUser.GetUserName(gtype, umodel.ShippingID); if (dr.HasRows) { if (dr.Read()) { txtUserId.Text = dr["UserName"].ToString(); } } dr.Close(); for (int i = 0; i < Drop_Role.Items.Count; i++) { if (umodel.SJRememberID.ToString() == Drop_Role.Items[i].Value) { Drop_Role.Items[i].Selected = true; } else { Drop_Role.Items[i].Selected = false; } } hiddenlbs.Value = umodel.SJRememberIDS; } } Page.Title = "角色管理 - " + GetWebName; } //添加管理员 Btn_Insert.Click += delegate(object s, EventArgs ex) { if (Request.QueryString["id"] != null) { if (!String.IsNullOrEmpty(Text_Name.Text)) { Mtxfw.Model.user_info umodel = daoUser.GetModel(int.Parse(Request.QueryString["id"])); if (umodel != null) { bool b = true; if (umodel.UserName != Text_Name.Text) { if (daoUser.IsExists(Text_Name.Text, gtype)) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } int type = Convert.ToInt32(Drop_type.SelectedItem.Value); int userid = 0; if (b) { if (type > 0) { txtUserId.Text = txtUserId.Text.Trim(); string bindtitle = "门店"; if (txtUserId.Text != "") { int uLevel16 = 0; int uLevel30 = 0; int uLevel41 = 0; SqlDataReader dr = daoUser.GetUserId(gtype, txtUserId.Text); if (dr.HasRows) { if (dr.Read()) { userid = Convert.ToInt32(dr["id"].ToString()); uLevel16 = Convert.ToInt32(dr["uLevel16"].ToString()); uLevel30 = Convert.ToInt32(dr["uLevel30"].ToString()); uLevel41 = Convert.ToInt32(dr["uLevel41"].ToString()); } } else { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } dr.Close(); if (b) { if (type == 1) { if (uLevel16 < 2 && uLevel41 < 1) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } else if (type == 2) { if (uLevel30 < 2) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (type > 0) { if (daoUser.GetCount("IFStores=1 and uLevel29=" + type + " and ShippingID=" + userid + " and id<>" + umodel.Id) > 0) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } } else { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (Text_Password.Text != "") { if (Text_Password.Text != Text_Password0.Text) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (Text_Password1.Text != "") { if (Text_Password1.Text != Text_Password2.Text) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (Text_Password.Text != "") { umodel.Password = Mtxfw.Utility.Security.EncryptString(Text_Password.Text); daoUser.UpdatePassword("Password", umodel.Password, umodel.Id); } if (Text_Password1.Text != "") { umodel.Password2 = Mtxfw.Utility.Security.EncryptString(Text_Password1.Text); daoUser.UpdatePassword("Password2", umodel.Password2, umodel.Id); } if (umodel.UserName != Text_Name.Text) { daoUser.UpdatePassword("UserName", Text_Name.Text, umodel.Id); } if (umodel.RealName != Text_User.Text) { daoUser.UpdatePassword("RealName", Text_User.Text, umodel.Id); } if (umodel.SJRememberID != int.Parse(Drop_Role.SelectedItem.Value)) { daoUser.UpdateuLevel("SJRememberID", (type == 2 ? 42 : (type == 1 ? 40 : int.Parse(Drop_Role.SelectedItem.Value))), umodel.Id); } if (type == 2 || type == 3) { daoUser.UpdatePassword("SJRememberIDS", hiddenlbs.Value, umodel.Id); } daoUser.UpdateuLevel("uLevel29", type, umodel.Id); if (type > 0) { if (umodel.ShippingID != userid) { new DAL.P_Product().UpdateP_UserID(userid, type, umodel.ShippingID); daoUser.UpdateuLevel("ShippingID", userid, umodel.Id); } } Model.User_CZ_log logmodel = new Model.User_CZ_log(); logmodel.MemberId = Card; logmodel.AddTime = DateTime.Now; logmodel.IP = Mtxfw.Utility.Common.GetIP; logmodel.Body = "银花优选" + "修改管理员" + Text_Name.Text; logmodel.UType = 0; logmodel.gtype = gtype; new DAL.User_CZ_log().Add(logmodel); Response.Redirect("Admin_Member_GLY.aspx"); } } } else ClientScript.RegisterStartupScript(this.GetType(), "", ""); } else { if (!String.IsNullOrEmpty(Text_Name.Text) && !String.IsNullOrEmpty(Text_Password.Text) && !String.IsNullOrEmpty(Text_Password0.Text) && !String.IsNullOrEmpty(Text_Password1.Text) && !String.IsNullOrEmpty(Text_Password2.Text)) { var b = true; if (b) { if (!daoUser.IsExists(Text_Name.Text, gtype)) { ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } int type = Convert.ToInt32(Drop_type.SelectedItem.Value); int userid = 0; if (b) { if (type > 0) { txtUserId.Text = txtUserId.Text.Trim(); string bindtitle = "门店"; if (txtUserId.Text != "") { int uLevel16 = 0; int uLevel30 = 0; SqlDataReader dr = daoUser.GetUserId(gtype, txtUserId.Text); if (dr.HasRows) { if (dr.Read()) { userid = Convert.ToInt32(dr["id"].ToString()); uLevel16 = Convert.ToInt32(dr["uLevel16"].ToString()); uLevel30 = Convert.ToInt32(dr["uLevel30"].ToString()); } } else { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } dr.Close(); if (b) { if (type == 1) { if (uLevel16 < 2) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } else if (type == 2) { if (uLevel30 < 2) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (type > 0) { if (daoUser.GetCount("IFStores=1 and uLevel29=" + type + " and ShippingID=" + userid) > 0) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } } else { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (Text_Password.Text != "") { if (Text_Password.Text != Text_Password0.Text) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { if (Text_Password1.Text != "") { if (Text_Password1.Text != Text_Password2.Text) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } Mtxfw.Model.user_info model = new Mtxfw.Model.user_info(); model.MemberCard = "hz" + (daoUser.GetMaxMemberCard(gtype) + 1).ToString(); model.UserName = Text_Name.Text; model.Password = Mtxfw.Utility.Security.EncryptString(Text_Password.Text); model.Password2 = Mtxfw.Utility.Security.EncryptString(Text_Password1.Text); model.RealName = Text_User.Text; model.NCName = ""; model.UserPic = ""; model.Sex = ""; model.SFZ = ""; model.Mobile = ""; model.Phone = ""; model.Email = ""; model.Province = ""; model.City = ""; model.County = ""; model.MailingAddress = ""; model.PostalCode = ""; model.QQ = ""; model.ProductName = ""; model.CompanyName = ""; model.CompanyTel = ""; model.CompanyNumber = ""; model.CompanyCert = ""; model.CompanyPic = ""; model.CompanyProvince = ""; model.CompanyCity = ""; model.CompanyCounty = ""; model.Companyaddress = ""; model.Companylatitude = 0; model.Companylongitude = 0; model.Companycontent = ""; model.UserState = "正常"; model.RegTime = DateTime.Now; model.RegTime2 = DateTime.Now; model.RememberID = 0; model.RememberIDS = ""; model.SuperiorsID = 0; model.SuperiorsIDS = ""; model.ContactID = 0; model.ContactIDS = ""; model.DLRememberID = 0; model.DLRememberIDS = ""; model.SJRememberID = (type == 2 ? 42 : (type == 1 ? 40 : int.Parse(Drop_Role.SelectedItem.Value))); model.SJRememberIDS = ((type == 2 || type == 3) ? hiddenlbs.Value : ""); model.umoney20 = 0; model.umoney21 = 0; model.uLevel = 0; model.uLevel0 = 0; model.uLevel1 = 0; model.uLevel3 = 0; model.uLevel5 = 0; model.utype = "0"; model.uutype = "0"; model.openid = ""; model.openid0 = ""; model.openid1 = ""; model.opentype = 0; model.opentype2 = 0; model.refresh_token = ""; model.refresh_token_time = ""; model.IFUpUserName = 0; string IP = Mtxfw.Utility.Common.GetIP; model.IP = IP; model.gtype = gtype; model.session_key = ""; model.unionid = ""; model.refresh_token = ""; model.refresh_token_time = ""; int returnid = daoUser.Add(model); daoUser.UpdateuLevel("IFStores", 1, returnid); daoUser.UpdateuLevel("uLevel29", type, returnid); daoUser.UpdateuLevel("ShippingID", (type > 0 ? userid : 0), returnid); Model.User_CZ_log logmodel = new Model.User_CZ_log(); logmodel.MemberId = Card; logmodel.AddTime = DateTime.Now; logmodel.IP = IP; logmodel.Body = "银花优选" + "添加管理员" + Text_Name.Text; logmodel.UType = 0; logmodel.gtype = gtype; new DAL.User_CZ_log().Add(logmodel); Response.Redirect("Admin_Member_GLY.aspx"); } else ClientScript.RegisterStartupScript(this.GetType(), "", ""); } }; } } }