CeramicProject/newyt/Module_data/UserAccount_Form.aspx.cs

307 lines
9.2 KiB
C#
Raw Normal View History

2024-05-18 15:28:29 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.BLL;
using System.Data;
using System.Data.SqlClient;
using Ajax;
using System.IO;
public partial class UserAccount_Form : CommonPage
{
//创建一个共用的角色模板
Maticsoft.BLL.nr_z_yhjs juesebll = new Maticsoft.BLL.nr_z_yhjs();
//创建一个共用的账号模板
Maticsoft.Model.nr_z_yhzh zhmodel = new Maticsoft.Model.nr_z_yhzh();
//创建一个共用的账号bll
Maticsoft.BLL.nr_z_yhzh zhbll = new Maticsoft.BLL.nr_z_yhzh();
//创建一个操作记录模板
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(UserAccount_Form));
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
2024-05-21 15:05:24 +08:00
//获取角色权限
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
binddata();
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
pdquanxianbj(user.juese);
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(uid);
}
else
{
pdquanxian(user.juese);
2024-05-18 15:28:29 +08:00
}
}
2024-05-21 15:05:24 +08:00
2024-05-18 15:28:29 +08:00
}
#region
private void binddata()
{
2024-05-21 15:05:24 +08:00
DataSet jueseds = juesebll.GetList(" 1=1");
if (jueseds != null)
{
2024-05-18 15:28:29 +08:00
2024-05-21 15:05:24 +08:00
juese.DataSource = jueseds.Tables[0].DefaultView;
juese.DataValueField = "id";
juese.DataTextField = "mingcheng";
juese.DataBind();
//if (juese.Items.FindByText("客户账号") == null)
//{
// ListItem lm = new ListItem("客户账号", "0");
// juese.Items.Insert(jueseds.Tables[0].Rows.Count, lm);
//}
if (juese.Items.Count <= 0)
{
ListItem lm = new ListItem("----请先创建角色----", "-1");
juese.Items.Insert(0, lm);
}
}
2024-05-18 15:28:29 +08:00
}
#endregion
#region
private void initdata(string did)
{
int idz = Convert.ToInt32(did);
zhmodel = zhbll.GetModel(idz);
if (zhmodel != null)
{
yhming.Text = zhmodel.zhanghao;
juese.SelectedValue = zhmodel.juese.ToString();
js.Value = zhmodel.juese.ToString();
zt.Value = zhmodel.yangshi.ToString();
mima.Text = zhmodel.mima;
qmima.Text = zhmodel.mima;
zhuangtai.SelectedValue = zhmodel.yangshi.ToString();
2024-05-21 15:05:24 +08:00
2024-05-18 15:28:29 +08:00
}
yhming.Enabled = false;
mima.Enabled = false;
qmima.Enabled = false;
2024-05-21 15:05:24 +08:00
string dz = DBHlper.getfirstcolmn("select touxiang from view_nr_z_yhzh where id=" + did);
2024-05-18 15:28:29 +08:00
2024-05-21 15:05:24 +08:00
txtp.ImageUrl = dz;
2024-05-18 15:28:29 +08:00
}
#endregion
#region model对象
private void getmd()
{
//string password =
zhmodel.zhanghao = yhming.Text;
zhmodel.juese = Convert.ToInt32(juese.SelectedValue);
2024-05-21 15:05:24 +08:00
zhmodel.mima = DBHlper.getmima(qmima.Text);
2024-05-18 15:28:29 +08:00
zhmodel.yangshi = 1;
}
#endregion
#region
void pdquanxian(int juese)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (DBHlper.getzt(user.id) == 0)
{
Response.Redirect("../index.aspx");
}
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(juese, "系统用户", "nr_z_yhzh", "添加") == false)
2024-05-18 15:28:29 +08:00
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region
void pdquanxianbj(int juese)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (DBHlper.getzt(user.id) == 0)
{
Response.Redirect("../index.aspx");
}
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(juese, "系统用户", "nr_z_yhzh", "编辑") == false)
2024-05-18 15:28:29 +08:00
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region
[Ajax.AjaxMethod]
public int serchmingcheng(string str)
{
string cmd = string.Format("select * from nr_z_yhzh where zhanghao='{0}'", str.Replace(" ", ""));
int count = DBHlper.getcount(cmd);
return count;
}
2024-05-21 15:05:24 +08:00
#endregion
2024-05-18 15:28:29 +08:00
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
2024-05-21 15:05:24 +08:00
int rtx = 0;
2024-05-18 15:28:29 +08:00
string caozuo = "添加";
2024-05-21 15:05:24 +08:00
if (id.Value != "" && id.Value.Length > 0)
2024-05-18 15:28:29 +08:00
{
//获取初始化原角色值
if (Convert.ToInt32(js.Value) == 0 || Convert.ToInt32(zt.Value) == 0)
{
if (getjs.PanDing)
{
//获取修改角色值是否是管理账号,进行判断
if (Convert.ToInt32(juese.SelectedValue) > 0)
{
if (DBHlper.getyhcount() >= getjs.UserCount)
{
//nelson
//z_error.Text = "请您购买足够的用户!";
//return;
}
}
}
}
2024-05-21 15:05:24 +08:00
zhmodel = zhbll.GetModel(Convert.ToInt32(id.Value));
2024-05-18 15:28:29 +08:00
zhmodel.juese = Convert.ToInt32(juese.SelectedValue);
2024-05-21 15:05:24 +08:00
zhmodel.yangshi = Convert.ToInt32(zhuangtai.SelectedValue);
2024-05-18 15:28:29 +08:00
if (zhbll.Update(zhmodel))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
2024-05-21 15:05:24 +08:00
2024-05-18 15:28:29 +08:00
}
else
{
//获取角色值是否是管理账号,进行判断
if (Convert.ToInt32(juese.SelectedValue) > 0)
{
if (DBHlper.getyhcount() >= getjs.UserCount)
{
//nelson
//z_error.Text = "请您购买足够的用户!";
//return;
}
}
2024-05-21 15:05:24 +08:00
string cmd = string.Format("select * from nr_z_yhzh where zhanghao='" + yhming.Text.Trim() + "'");
2024-05-18 15:28:29 +08:00
int count = DBHlper.getcount(cmd);
if (count > 0)
{
z_error.Text = "用户密码已存在!";
return;
}
if (mima.Text != qmima.Text)
{
z_error.Text = "两次密码不一致!";
return;
}
getmd();
rtx = zhbll.Add(zhmodel);
2024-05-21 15:05:24 +08:00
2024-05-18 15:28:29 +08:00
}
if (rtx > 0)
{
tpsc(rtx);
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
rizhi.yonghuming = zh.zhanghao;
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "系统用户";
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "用户,用户名为:" + yhming.Text.Trim();
rizhibll.Add(rizhi);
Response.Redirect("UserAccount.aspx", false);
}
else
{
Response.Redirect("../Common/error.aspx");
}
}
catch (Exception)
{
Response.Redirect("../Common/error.aspx");
}
}
public void tpsc(int bid)
{
string fileName = "";
try
{
if (!textFoo.HasFile)
{
return;
}
else
{
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("../Images_Folder/Yh_tx/");
if (!System.IO.Directory.Exists(directoyPath))
{
System.IO.Directory.CreateDirectory(directoyPath);
}
fileName = textFoo.PostedFile.FileName.Substring(textFoo.PostedFile.FileName.LastIndexOf("\\") + 1);
string path = "../Images_Folder/Yh_tx/" + DateTime.Now.ToString("yyyy-MM-dd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + fileName;
if (File.Exists(path))
{
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + fileName + "');</script>");
return;
}
textFoo.PostedFile.SaveAs(Server.MapPath(path));
2024-05-21 15:05:24 +08:00
DBHlper.excutecmd("update nr_z_yhzh set touxiang='" + path + "' where id='" + bid + "'");
2024-05-18 15:28:29 +08:00
}
}
catch
{
}
}
}