CeramicProject/newyt/Module_data/UserAccount_Form.aspx.cs

307 lines
9.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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");
}
//获取角色权限
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);
}
}
}
#region
private void binddata()
{
DataSet jueseds = juesebll.GetList(" 1=1");
if (jueseds != null)
{
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);
}
}
}
#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();
}
yhming.Enabled = false;
mima.Enabled = false;
qmima.Enabled = false;
string dz = DBHlper.getfirstcolmn("select touxiang from view_nr_z_yhzh where id=" + did);
txtp.ImageUrl = dz;
}
#endregion
#region model对象
private void getmd()
{
//string password =
zhmodel.zhanghao = yhming.Text;
zhmodel.juese = Convert.ToInt32(juese.SelectedValue);
zhmodel.mima = DBHlper.getmima(qmima.Text);
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");
}
if (DBHlper.GetPermission(juese, "系统用户", "nr_z_yhzh", "添加") == false)
{
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");
}
if (DBHlper.GetPermission(juese, "系统用户", "nr_z_yhzh", "编辑") == false)
{
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;
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
int rtx = 0;
string caozuo = "添加";
if (id.Value != "" && id.Value.Length > 0)
{
//获取初始化原角色值
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;
}
}
}
}
zhmodel = zhbll.GetModel(Convert.ToInt32(id.Value));
zhmodel.juese = Convert.ToInt32(juese.SelectedValue);
zhmodel.yangshi = Convert.ToInt32(zhuangtai.SelectedValue);
if (zhbll.Update(zhmodel))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
}
else
{
//获取角色值是否是管理账号,进行判断
if (Convert.ToInt32(juese.SelectedValue) > 0)
{
if (DBHlper.getyhcount() >= getjs.UserCount)
{
//nelson
//z_error.Text = "请您购买足够的用户!";
//return;
}
}
string cmd = string.Format("select * from nr_z_yhzh where zhanghao='" + yhming.Text.Trim() + "'");
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);
}
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));
DBHlper.excutecmd("update nr_z_yhzh set touxiang='" + path + "' where id='" + bid + "'");
}
}
catch
{
}
}
}