You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1015 lines
48 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Web.Script.Serialization;
using System.IO;
using System.Drawing;
using DSWeb.DataAccess;
using System.Data.SqlClient;
using DSWeb.SoftMng.Common;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.Filter;
namespace DSWeb.Users
{
public partial class userinfo : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputText txt_username;
protected System.Web.UI.HtmlControls.HtmlInputText txt_codename;
protected System.Web.UI.HtmlControls.HtmlInputText txt_showname;
//protected System.Web.UI.HtmlControls.HtmlInputText txt_password;
protected System.Web.UI.HtmlControls.HtmlInputText txt_officenum;
protected System.Web.UI.HtmlControls.HtmlInputText txt_homenum;
protected System.Web.UI.HtmlControls.HtmlInputText txt_mobilenum;
protected System.Web.UI.HtmlControls.HtmlInputText txt_faxnum;
protected System.Web.UI.HtmlControls.HtmlInputText txt_email1;
protected System.Web.UI.HtmlControls.HtmlInputText txt_email2;
protected System.Web.UI.HtmlControls.HtmlInputText txt_emergencyuser;
protected System.Web.UI.HtmlControls.HtmlInputText txt_emergencycall;
//protected System.Web.UI.HtmlControls.HtmlInputText txt_emergencyemail;
//protected System.Web.UI.HtmlControls.HtmlInputText txt_postcode;
protected System.Web.UI.HtmlControls.HtmlInputText txt_homeaddr;
//protected System.Web.UI.HtmlControls.HtmlSelect list_company;
protected System.Web.UI.HtmlControls.HtmlSelect list_subcompany;
protected System.Web.UI.HtmlControls.HtmlSelect list_dept;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isdisable;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isoperator;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_iscusservice;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isdocument;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isdriver;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_iscusdeclarer;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isvehiclesdispatch;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isusesystem;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_isfinancialstaff;
protected System.Web.UI.HtmlControls.HtmlInputCheckBox chk_issaleman;
protected System.Web.UI.HtmlControls.HtmlGenericControl dvNotes;
private string strHandleType;
UserDA UserDA = new UserDA();
CompanyDA CompanyDA = new CompanyDA();
public string strUserID;//登录用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
public byte[] imgbytes;//签名图片的数据流
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
this.hdUserID.Value = strUserID;
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
//strUserID = "";
//hdUserID.Value = "";
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
if (!IsPostBack)
{
if (Request.QueryString["handle"] != null)
{
if (Request.QueryString["handle"] != null)
{
strHandleType = Request.QueryString["handle"].Trim().ToString().ToLower();
ViewState["strHandleType"]= Request.QueryString["handle"].Trim().ToString().ToLower();
}
//
if (Request.QueryString["id"] != null)
{
Session["UserGID"] = Request.QueryString["id"].ToString();
this.hid_id.Value = Session["UserGID"].ToString().Trim();
}
//
switch (strHandleType)
{
case "add"://添加新用户
ibAdd.Enabled = false;
ibFullAdd.Enabled = false;
ibEnter.Enabled = true;
ibDel.Enabled = false;
//
this.txt_username.Value = "";
this.txt_codename.Value = "";
this.hdcodename.Value = "";
this.txt_showname.Value = "";
this.hdshowname.Value = "";
//this.txt_password.Value = "";
this.txt_password.Attributes.Add("value", "");
this.txt_officenum.Value = "";
this.txt_homenum.Value = "";
this.txt_mobilenum.Value = "";
this.txt_FINANCESOFTCODE.Value = "";
this.txt_faxnum.Value = "";
this.txt_email1.Value = "";
this.txt_email2.Value = "";
this.txt_emergencyuser.Value = "";
this.txt_emergencycall.Value = "";
this.txt_homeaddr.Value = "";
this.hd_comboSubcompany.Value = "";
this.hd_comboDept.Value = "";
this.chk_isdisable.Checked = false;
this.chk_isoperator.Checked = false;
this.chk_issaleman.Checked = false;
this.chk_iscustomsservice.Checked = false;
this.chk_isdocument.Checked = false;
this.chk_isdriver.Checked = false;
this.chk_iscustomsdeclarer.Checked = false;
this.chk_isfinancialstaff.Checked = false;
this.chk_isusesystem.Checked = false;
this.chk_isvehiclesdispatcher.Checked = false;
//
imgIMAGEURL.ImageUrl = "../images/userpic/noImage.gif";
this.hdIMAGEURL.Value = "../images/userpic/noImage.gif";
//
imgSIGNATUREURL.Src = "../images/userpic/noImage.gif";
this.hdSIGNATUREURL.Value = "../images/userpic/noImage.gif";
//
//Session["UserGID"] = getBSNO();
break;
case "edit"://更新用户信息
ibAdd.Enabled = true;
ibFullAdd.Enabled = true;
ibEnter.Enabled = true;
ibDel.Enabled = true;
//
GetUserInfo();
InitUserAttribute();//初始化用户属性
break;
}
}
}
//加载下拉框
Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>initComboSubcompany();</script>");
}
protected void getLOGO(byte[] photo)
{
//byte[] photo = (byte[])myds.Tables[0].Rows[0]["LOGO"];
//图片路径
string strPath = "../images/userpic/" + Session["UserGID"].ToString().Trim() + ".gif";
string strPhotoPath = Server.MapPath(strPath);
//保存图片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
//显示图片
this.imgSIGNATUREURL.Src = strPath;
ViewState["fuSIGNATUREURL"] = photo;
}
protected void getImage(string strSQL)
{
//设置Image控件显示从数据库中读出的二进制图片
SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DongShengDB"].ConnectionString);
SqlDataAdapter myda = new SqlDataAdapter(strSQL, myConn);
DataSet myds = new DataSet();
myConn.Open();
myda.Fill(myds);
myConn.Close();
//
byte[] photo = (byte[])myds.Tables[0].Rows[0]["LOGO"];
//图片路径
string strPath = "../images/userpic/" + Session["UserGID"].ToString().Trim() + ".gif";
string strPhotoPath = Server.MapPath(strPath);
//保存图片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
//显示图片
this.imgSIGNATUREURL.Src = strPath;
}
#region 初始化用户属性
/// <summary>
/// 初始化用户属性
/// </summary>
private void InitUserAttribute()
{
string strAdminGid = Session["UserGID"].ToString().Trim();
UserAttributeDA userAttrDA = new UserAttributeDA();
//获取用户属性信息
IList<UserAttributeEntity> attributeEntities = userAttrDA.GetUserAttributeValue(strAdminGid);
if (attributeEntities.Count > 0)
{
foreach (Control cl in Form.Controls)
{
foreach (UserAttributeEntity attrEntity in attributeEntities)
{
if (cl.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox") && cl.ID.Trim().Remove(0, 4).Equals(attrEntity.AttributeName.ToLower()))
{
bool bCheckValue = attrEntity.RefEntity.AttributeValue.Trim().ToLower().Equals("true") ? true : false;
HtmlInputCheckBox cb = (HtmlInputCheckBox)cl;
cb.Checked = bCheckValue;
break;
}
}
}
}
}
#endregion
#region 获取用户所有信息
/// <summary>
/// 获取用户所有信息
/// </summary>
private void GetUserInfo()
{
string strGid = Session["UserGID"].ToString().Trim();
UserDA userDA = new UserDA();
UserEntity userEntity = userDA.GetUserAllByID(strGid);
if (!userEntity.Gid.Equals(""))
{
this.txt_username.Value = userEntity.UserName;
this.txt_showname.Value = userEntity.ShowName;
this.hdshowname.Value = userEntity.ShowName;
this.txt_codename.Value = userEntity.CodeName;
this.hdcodename.Value = userEntity.CodeName;
//this.txt_password.Value = userEntity.PassWord;
this.txt_password.Attributes.Add("value", userEntity.PassWord);
Session["BaseGID"] = userEntity.BaseInfo.Gid;
//this.txt_postcode.Value = userEntity.BaseInfo.PostCode;
this.txt_mobilenum.Value = userEntity.BaseInfo.MobilePhone;
this.txt_FINANCESOFTCODE.Value = userEntity.BaseInfo.FINANCESOFTCODE;
this.txt_officenum.Value = userEntity.BaseInfo.OfficePhone;
this.txt_homenum.Value = userEntity.BaseInfo.HomePhone;
this.txt_homeaddr.Value = userEntity.BaseInfo.HomeAddress;
this.txt_faxnum.Value = userEntity.BaseInfo.FaxNum;
this.txt_email1.Value = userEntity.BaseInfo.EmailAddressPrimary;
this.txt_email2.Value = userEntity.BaseInfo.EmailAddressSecond;
this.txt_emergencyuser.Value = userEntity.BaseInfo.EmergencyUser;
this.txt_emergencycall.Value = userEntity.BaseInfo.EmergencyPhone;
//this.txt_emergencyemail.Value = userEntity.BaseInfo.EmergencyEmail;
this.hd_comboSubcompany.Value = userEntity.BaseInfo.COMPANYNAME;
this.hd_comboDept.Value = userEntity.BaseInfo.DEPTNAME;
this.txt_QQ.Value = userEntity.BaseInfo.QQ;
this.txt_MSN.Value = userEntity.BaseInfo.MSN;
if (userEntity.BaseInfo.CONTRACTDATE != "")
{
this.txt_CONTRACTDATE.Text = DateTime.Parse(userEntity.BaseInfo.CONTRACTDATE).Year.ToString().Trim() + "-" + DateTime.Parse(userEntity.BaseInfo.CONTRACTDATE).Month.ToString().Trim() + "-" + DateTime.Parse(userEntity.BaseInfo.CONTRACTDATE).Day.ToString().Trim();
}
else this.txt_CONTRACTDATE.Text = "";
this.txt_TRIALTIME.Value = userEntity.BaseInfo.TRIALTIME;
this.txt_IDNUM.Value = userEntity.BaseInfo.IDNUM;
this.txt_EDURECORD.Value = userEntity.BaseInfo.EDURECORD;
this.txt_ANNUALLEAVE.Value = userEntity.BaseInfo.ANNUALLEAVE;
//
imgIMAGEURL.ImageUrl = userEntity.BaseInfo.IMAGEURL.ToString().Trim();
this.hdIMAGEURL.Value = userEntity.BaseInfo.IMAGEURL.ToString().Trim();
//
//if (userEntity.BaseInfo.SIGNATURE != null)
//{
// getLOGO(userEntity.BaseInfo.SIGNATURE);
//}
imgSIGNATUREURL.Src = userEntity.BaseInfo.SIGNATUREURL.ToString().Trim();
this.hdSIGNATUREURL.Value = userEntity.BaseInfo.SIGNATUREURL.ToString().Trim();
}
}
#endregion
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "Users" + strBSNO;
return strBSNO;
}
protected string setfuIMAGEURL()
{
if (fuIMAGEURL.HasFile == true)//如果用户确实选择了上传控件的浏览按钮,浏览文件成功.
{
string fuName = fuIMAGEURL.FileName.Replace(" ", "_");
string AbsPath = Server.MapPath("../images/userpic/");
string sPath = AbsPath + fuName;
string imgurl = "../images/userpic/" + fuName;
//
Int32 FileLength = 0;//有可能图片的大小会超出INT的范围所以声明为Int32,当然这和下面大小的判断有关系
FileLength = this.fuIMAGEURL.PostedFile.ContentLength;//获取上传文件的字节大小
//取web中的最大限制数FTPMaxRequestLength
string strFTPMaxRequestLength = System.Configuration.ConfigurationSettings.AppSettings["FTPMaxRequestLength"].ToString() as string;
Int32 iFTPMaxRequestLength = 2091151;
if (strFTPMaxRequestLength == null)
{
iFTPMaxRequestLength = Int32.Parse(strFTPMaxRequestLength);
}
//
if (FileLength > iFTPMaxRequestLength)
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key10", "<script>alert('文件最大不能超过4M');</script>");
return "图片1的大小超过最大限制";
}
if (File.Exists(sPath)) //判断文件是否寸在
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key11", "<script>alert('文件上传FTP失败');</script>");
return "当前路径下已经存在同名的图片1文件";
}
this.fuIMAGEURL.SaveAs(sPath); //保存到服务器的目录,需要根据服务器具体情况修改fuIMAGEURL.FileName会自动获取上传文件名.
imgIMAGEURL.ImageUrl = imgurl.Trim();
this.hdIMAGEURL.Value = imgurl.Trim();
}
return "";
}
protected string setfuSIGNATUREURL()
{
try
{
if (fuSIGNATUREURL.HasFile == true)//如果用户确实选择了上传控件的浏览按钮,浏览文件成功.
{
string fuName = fuSIGNATUREURL.FileName.Replace(" ", "_");
string AbsPath = Server.MapPath("../images/userpic/");
string sPath = AbsPath + fuName;
string imgurl = "../images/userpic/" + fuName;
//
Int32 FileLength = 0;//有可能图片的大小会超出INT的范围所以声明为Int32,当然这和下面大小的判断有关系
FileLength = this.fuSIGNATUREURL.PostedFile.ContentLength;//获取上传文件的字节大小
//取web中的最大限制数FTPMaxRequestLength
string strFTPMaxRequestLength = System.Configuration.ConfigurationSettings.AppSettings["FTPMaxRequestLength"].ToString() as string;
Int32 iFTPMaxRequestLength = 2091151;
if (strFTPMaxRequestLength == null)
{
iFTPMaxRequestLength = Int32.Parse(strFTPMaxRequestLength);
}
//
if (FileLength > iFTPMaxRequestLength)
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key10", "<script>alert('文件最大不能超过4M');</script>");
return "图片的大小超过最大限制!";
}
if (File.Exists(sPath)) //判断文件是否寸在
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key11", "<script>alert('文件上传FTP失败');</script>");
return "当前路径下已经存在同名的图片文件!";
}
this.fuSIGNATUREURL.SaveAs(sPath); //保存到服务器的目录,需要根据服务器具体情况修改fuSIGNATUREURL.FileName会自动获取上传文件名.
imgSIGNATUREURL.Src = imgurl.Trim();
this.hdSIGNATUREURL.Value = imgurl.Trim();
//
//签名图片
FileStream fs = new FileStream(sPath, FileMode.Open);
if (fs.Length == 0)
{
imgbytes = (Byte[])ViewState["fuSIGNATUREURL"];
//baseInfoEntity.SIGNATURE = (Byte[])ViewState["fuSIGNATUREURL"];
}
else
{
string exName = fuName.Substring(fuName.LastIndexOf(".") + 1).ToUpper();//截取图片的后缀名
if (exName == "JPG" || exName == "BMP" || exName == "GIF")//判断图片的类型
{
byte[] imagebytes = new byte[fs.Length];//图象文件储存到数组
BinaryReader br = new BinaryReader(fs);//建立数据流对像,获取一个 Stream 对象,该对象指向一个上载文件,以准备读取该文件的内容。
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));//读取图象文件数据
//baseInfoEntity.SIGNATURE = imagebytes;
imgbytes = imagebytes;
}
else
{
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport36", "alert('出错,请选择正确的的图片!');", true);
return "出错,请选择正确的的图片!";
}
}
}
}
catch (Exception)
{
//throw ex;
//System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport37", "alert('出错,请选择正确的的图片!');", true);
return "出错,请选择正确的的图片!";
}
return "";
}
#region 添加新用户
/// <summary>
/// 添加新用户
/// </summary>
private void AddUser()
{
string strAdminGid = strUserID.Trim();
UserEntity userEntity = new UserEntity();
Session["UserGID"] = Guid.NewGuid().ToString();
Session["BaseGID"] = Guid.NewGuid().ToString();
//存储用户登录信息
userEntity.Gid = Session["UserGID"].ToString().Trim();
userEntity.UserName = this.txt_username.Value.Trim().ToLower();
userEntity.PassWord = this.txt_password.Text.Trim();
if (this.txt_showname.Value.Trim() == "")
{
userEntity.ShowName = this.hdshowname.Value.Trim().ToUpper();
}
else
{
userEntity.ShowName = this.txt_showname.Value.Trim().ToUpper();
}
if (this.txt_codename.Value.Trim() == "")
{
userEntity.CodeName = this.hdcodename.Value.Trim().ToUpper();
}
else
{
userEntity.CodeName = this.txt_codename.Value.Trim().ToUpper();
}
userEntity.CreatedUserID = strAdminGid;
userEntity.IsDeleted = false;
userEntity.IsDisable = this.chk_isdisable.Checked;
//录入baseInfoEntity用户基本信息
UserBaseInfoEntity baseInfoEntity = new UserBaseInfoEntity();
baseInfoEntity.Gid = Session["BaseGID"].ToString().Trim();
baseInfoEntity.UserID = Session["UserGID"].ToString().Trim();
baseInfoEntity.OfficePhone = this.txt_officenum.Value.Trim();
baseInfoEntity.HomePhone = this.txt_homenum.Value.Trim();
baseInfoEntity.MobilePhone = this.txt_mobilenum.Value.Trim();
baseInfoEntity.FINANCESOFTCODE = this.txt_FINANCESOFTCODE.Value.Trim();
baseInfoEntity.FaxNum = this.txt_faxnum.Value.Trim();
baseInfoEntity.EmailAddressPrimary = this.txt_email1.Value.Trim();
baseInfoEntity.EmailAddressSecond = this.txt_email2.Value.Trim();
baseInfoEntity.HomeAddress = this.txt_homeaddr.Value.Trim();
baseInfoEntity.CreateUserID = strAdminGid;
baseInfoEntity.EmergencyUser = this.txt_emergencyuser.Value.Trim();
baseInfoEntity.EmergencyPhone = this.txt_emergencycall.Value.Trim();
baseInfoEntity.EmergencyEmail = "";
baseInfoEntity.COMPANYNAME = this.hd_comboSubcompany.Value;
baseInfoEntity.DEPTNAME = this.hd_comboDept.Value;
baseInfoEntity.QQ = this.txt_QQ.Value;
baseInfoEntity.MSN = this.txt_MSN.Value;
baseInfoEntity.IMAGEURL = this.hdIMAGEURL.Value.Trim();
baseInfoEntity.IMAGEURL = baseInfoEntity.IMAGEURL.Replace("../images/userpic/", "");
baseInfoEntity.SIGNATUREURL = this.hdSIGNATUREURL.Value.Trim();
if (imgbytes != null)
{
baseInfoEntity.SIGNATURE = imgbytes;
}
baseInfoEntity.CONTRACTDATE = this.txt_CONTRACTDATE.Text.Trim();
baseInfoEntity.TRIALTIME = this.txt_TRIALTIME.Value.Trim();
baseInfoEntity.IDNUM = this.txt_IDNUM.Value.Trim();
baseInfoEntity.EDURECORD = this.txt_EDURECORD.Value.Trim();
baseInfoEntity.ANNUALLEAVE = this.txt_ANNUALLEAVE.Value.Trim();
//存储用户基本信息
userEntity.BaseInfo = baseInfoEntity;
UserDA userDA = new UserDA();
int result = userDA.InsertUserInfo(userEntity);
if (result == 1)
{
//如果新用户添加成功,则为当前新添加用户默认指定权限范围的查看和操作权限为个人
UserAuthorityDA userAuthorityDA = new UserAuthorityDA();
userAuthorityDA.InsertUserAuthorityRangeForNewUser(userEntity.Gid, strUserID);
ibAdd.Enabled = true;
ibFullAdd.Enabled = true;
ibEnter.Enabled = true;
ibDel.Enabled = true;
//Response.Write("<script>javascript:alert('用户添加成功')</script>");
//System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport1", "alert('用户添加成功!');", true);
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport1", "reloadParent('" + Session["UserGID"].ToString().Trim() + "');", true);
}
else if(result == -2)
{
//Response.Write("<script>javascript:alert('用户添加失败,该用户已经存在!)</script>");
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport1", "alert('用户添加失败,该用户已经存在!');", true);
ibAdd.Enabled = false;
ibFullAdd.Enabled = false;
ibEnter.Enabled = true;
ibDel.Enabled = false;
ViewState["strHandleType"] = "add";
return;
}
else
{
//Response.Write("<script>javascript:alert('用户添加失败 #" + result + "')</script>");
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport1", "alert('用户添加失败!');", true);
//
ibAdd.Enabled = false;
ibFullAdd.Enabled = false;
ibEnter.Enabled = true;
ibDel.Enabled = false;
ViewState["strHandleType"] = "add";
return;
}
baseInfoEntity.IMAGEURL = this.hdIMAGEURL.Value.Trim();
}
#endregion
#region 更新用户
/// <summary>
/// 更新用户
/// </summary>
private void UpdateUser()
{
UserEntity userEntity = new UserEntity();
//存储用户登录信息
userEntity.Gid = Session["UserGID"].ToString().Trim();
userEntity.UserName = this.txt_username.Value.Trim().ToLower();
userEntity.PassWord = this.txt_password.Text.Trim();
if (this.txt_showname.Value.Trim() == "")
{
userEntity.ShowName = this.hdshowname.Value.Trim().ToUpper();
}
else
{
userEntity.ShowName = this.txt_showname.Value.Trim().ToUpper();
}
if (this.txt_codename.Value.Trim() == "")
{
userEntity.CodeName = this.hdcodename.Value.Trim().ToUpper();
}
else
{
userEntity.CodeName = this.txt_codename.Value.Trim().ToUpper();
}
userEntity.ModifiedUserID = strUserID.Trim();
userEntity.IsDeleted = false;
userEntity.IsDisable=this.chk_isdisable.Checked;
//录入baseInfoEntity用户基本信息
UserBaseInfoEntity baseInfoEntity = new UserBaseInfoEntity();
baseInfoEntity.Gid = Session["BaseGID"].ToString().Trim();
baseInfoEntity.UserID = Session["UserGID"].ToString().Trim();
baseInfoEntity.OfficePhone = this.txt_officenum.Value.Trim();
baseInfoEntity.HomePhone = this.txt_homenum.Value.Trim();
baseInfoEntity.MobilePhone = this.txt_mobilenum.Value.Trim();
baseInfoEntity.FINANCESOFTCODE = this.txt_FINANCESOFTCODE.Value.Trim();
baseInfoEntity.FaxNum = this.txt_faxnum.Value.Trim();
baseInfoEntity.EmailAddressPrimary = this.txt_email1.Value.Trim();
baseInfoEntity.EmailAddressSecond = this.txt_email2.Value.Trim();
baseInfoEntity.HomeAddress = this.txt_homeaddr.Value.Trim();
baseInfoEntity.ModifiedUserID = strUserID.Trim();
baseInfoEntity.EmergencyUser = this.txt_emergencyuser.Value.Trim();
baseInfoEntity.EmergencyPhone = this.txt_emergencycall.Value.Trim();
baseInfoEntity.EmergencyEmail = "";
baseInfoEntity.COMPANYNAME = this.hd_comboSubcompany.Value;
baseInfoEntity.DEPTNAME = this.hd_comboDept.Value;
baseInfoEntity.QQ = this.txt_QQ.Value;
baseInfoEntity.MSN = this.txt_MSN.Value;
baseInfoEntity.IMAGEURL = this.hdIMAGEURL.Value.Trim();
baseInfoEntity.IMAGEURL = baseInfoEntity.IMAGEURL.Replace("../images/userpic/", "");
baseInfoEntity.SIGNATUREURL = this.hdSIGNATUREURL.Value.Trim();
if (imgbytes != null)
{
baseInfoEntity.SIGNATURE = imgbytes;
}
baseInfoEntity.CONTRACTDATE = this.txt_CONTRACTDATE.Text.Trim();
baseInfoEntity.TRIALTIME = this.txt_TRIALTIME.Value.Trim();
baseInfoEntity.IDNUM = this.txt_IDNUM.Value.Trim();
baseInfoEntity.EDURECORD = this.txt_EDURECORD.Value.Trim();
baseInfoEntity.ANNUALLEAVE = this.txt_ANNUALLEAVE.Value.Trim();
//
//存储用户基本信息
userEntity.BaseInfo = baseInfoEntity;
UserDA userDA = new UserDA();
int result = userDA.UpdateUserInfo(userEntity);
if (result == 1)
{
//Response.Write("<script>javascript:alert('用户更新成功')</script>");
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport1", "alert('用户更新成功!');", true);
}
else
{
//Response.Write("<script>javascript:alert('用户更新失败 #" + result + "')</script>");
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport2", "alert('用户更新失败 #" + result + "');", true);
}
baseInfoEntity.IMAGEURL = this.hdIMAGEURL.Value.Trim();
}
#endregion
protected void ibEnter_Click(object sender, ImageClickEventArgs e)
{
var state = chk_isusesystem.Checked;
if (state)
{
user_userattributeBLL ubll = new user_userattributeBLL();
var count = ubll.GetRecordCount(
"ATTRIBUTEID='2E5E6066-1C5D-4B04-BF8C-56637C20FC8C' AND VALUE='true' AND USERID IN (select gid from [user])");
sys_secCompanyBLL cbll = new sys_secCompanyBLL();
var model = cbll.GetModelList("").FirstOrDefault();
if (model != null)
{
var smodel = new JavaScriptSerializer().Deserialize<CecrietStr>(DSWeb.SoftMng.Common.Common.string_Decrypt(model.CompanySecretKey, "Dw9pVb9r"));
if (count >= smodel.Times)
{
this.chk_isusesystem.Checked = false;
Response.Write("<script>alert('系统允许使用人数已超过限制!');</script>");
return;
}
}
}
if (this.hd_comboSubcompany.Value.Trim() == "")
{
Response.Write("<script>alert('所属分公司不允许为空!');history.back();</script>");
return;
}
strHandleType = ViewState["strHandleType"].ToString();
if (strHandleType.Equals("add"))//新增
{
string simg1 = setfuIMAGEURL();
if (simg1.Trim() == "")
{
if (this.hdIMAGEURL.Value.Trim() == "")
{
this.hdIMAGEURL.Value = "../images/userpic/noImage.gif";
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('" + simg1 + "');</script>");
return;
}
//
simg1 = setfuSIGNATUREURL();
if (simg1.Trim() == "")
{
if (this.hdSIGNATUREURL.Value.Trim() == "")
{
this.hdSIGNATUREURL.Value = "../images/userpic/noImage.gif";
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('" + simg1 + "');</script>");
return;
}
//
AddUser();
AddUserAttribute();
AddUserCompany();
}
else if (strHandleType.Equals("addfull"))//新增
{
string simg1 = setfuIMAGEURL();
if (simg1.Trim() == "")
{
if (this.hdIMAGEURL.Value.Trim() == "")
{
this.hdIMAGEURL.Value = "../images/userpic/noImage.gif";
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('" + simg1 + "');</script>");
return;
}
//
simg1 = setfuSIGNATUREURL();
if (simg1.Trim() == "")
{
if (this.hdSIGNATUREURL.Value.Trim() == "")
{
this.hdSIGNATUREURL.Value = "../images/userpic/noImage.gif";
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('" + simg1 + "');</script>");
return;
}
//
AddUser();
AddUserAttribute();
AddUserCompany();
}
else if (strHandleType.Equals("edit"))//录入
{
string simg1 = setfuIMAGEURL();
if (simg1.Trim() != "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('" + simg1 + "');</script>");
return;
}
//
simg1 = setfuSIGNATUREURL();
if (simg1.Trim() != "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('" + simg1 + "');</script>");
return;
}
//
UpdateUser();
EditUserAttribute();
AddUserCompany();
}
//
ibAdd.Enabled = false;
ibFullAdd.Enabled = false;
ibEnter.Enabled = true;
ibDel.Enabled = false;
//ViewState["strHandleType"] = "add";
return;
}
private void AddUserAttribute()
{
string strGid = Session["UserGID"].ToString();
UserAttributeDA attrDA = new UserAttributeDA();
//获取所有用户属性表的数据
IList<UserAttributeEntity> attrEntites = attrDA.GetUserAttributeAll();
IList<UserAttributeRefEntity> refEntities = new List<UserAttributeRefEntity>();
foreach (Control cl in Form.Controls)
{
if (cl.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox"))
{
HtmlInputCheckBox cb = (HtmlInputCheckBox)cl;
bool bCheckValue = cb.Checked;
foreach(UserAttributeEntity attrEntity in attrEntites)
{
if(attrEntity.AttributeName.Trim().ToLower().Equals(cb.ID.Trim().Remove(0, 4).ToLower()))
{
UserAttributeRefEntity refEntity = new UserAttributeRefEntity();
refEntity.Gid = Guid.NewGuid().ToString();
refEntity.UserID = strGid;
refEntity.AttributeID = attrEntity.Gid.Trim();
refEntity.AttributeValue = bCheckValue ? "true" : "false";
refEntities.Add(refEntity);
}
}
}
}
if (refEntities.Count > 0)
{
if (attrDA.InsertUserAttribute(strGid, refEntities))
{
//dvNotes.InnerText = "属性加入成功";
ViewState["strHandleType"] = "edit";
}
else
{
//dvNotes.InnerText = "属性加入失败";
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport3", "alert('属性加入失败!');", true);
return;
}
}
}
private void EditUserAttribute()
{
string strGid = Session["UserGID"].ToString();
UserAttributeDA attrDA = new UserAttributeDA();
//获取所有用户属性表的数据
IList<UserAttributeEntity> attrEntites = attrDA.GetUserAttributeValue(strGid);
IList<UserAttributeRefEntity> refEntities = new List<UserAttributeRefEntity>();
foreach (Control cl in Form.Controls)
{
if (cl.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox"))
{
HtmlInputCheckBox cb = (HtmlInputCheckBox)cl;
bool bCheckValue = cb.Checked;
foreach(UserAttributeEntity attrEntity in attrEntites)
{
if(attrEntity.AttributeName.Trim().ToLower().Equals(cb.ID.Trim().Remove(0, 4).ToLower()))
{
UserAttributeRefEntity refEntity = new UserAttributeRefEntity();
refEntity.Gid = attrEntity.RefEntity.Gid.Trim();
refEntity.UserID = strGid.Trim();
refEntity.AttributeID = attrEntity.Gid.Trim();
refEntity.AttributeValue = bCheckValue ? "true" : "false";
refEntities.Add(refEntity);
}
}
}
}
if (refEntities.Count > 0)
{
if (attrDA.UpdateUserAttribute(strGid, refEntities))
{
//dvNotes.InnerText = "属性加入成功";
ViewState["strHandleType"] = "edit";
}
else
{
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport4", "alert('属性更新失败!');", true);
return;
//dvNotes.InnerText = "属性加入失败";
}
}
}
protected void ibDel_Click(object sender, ImageClickEventArgs e)
{
UserDA userDA = new UserDA();
string alt = userDA.GetUserDel(Session["UserGID"].ToString().Trim(), strUserID.Trim());
if (alt != "")
{
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport50", "alert('" + alt + "');", true);
return;
}
System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "unReport50", "alert('删除成功并打开另一票数据!');", true);
//Session["USERID"] = "04eaeac5-f271-45d1-b17b-ad4ccbab63d0";
ViewState["strHandleType"] = "edit";
//
UserEntity userEntity = userDA.GetUserTopOne();
if (!userEntity.Gid.Equals(""))
{
Session["UserGID"] = userEntity.Gid;
this.txt_username.Value = userEntity.UserName;
this.txt_showname.Value = userEntity.ShowName;
this.hdshowname.Value = userEntity.ShowName;
this.txt_codename.Value = userEntity.CodeName;
this.hdcodename.Value = userEntity.CodeName;
//this.txt_password.Value = userEntity.PassWord;
this.txt_password.Attributes.Add("value", userEntity.PassWord);
//this.txt_postcode.Value = userEntity.BaseInfo.PostCode;
this.txt_mobilenum.Value = userEntity.BaseInfo.MobilePhone;
this.txt_FINANCESOFTCODE.Value = userEntity.BaseInfo.FINANCESOFTCODE;
this.txt_officenum.Value = userEntity.BaseInfo.OfficePhone;
this.txt_homenum.Value = userEntity.BaseInfo.HomePhone;
this.txt_homeaddr.Value = userEntity.BaseInfo.HomeAddress;
this.txt_faxnum.Value = userEntity.BaseInfo.FaxNum;
this.txt_email1.Value = userEntity.BaseInfo.EmailAddressPrimary;
this.txt_email2.Value = userEntity.BaseInfo.EmailAddressSecond;
this.txt_emergencyuser.Value = userEntity.BaseInfo.EmergencyUser;
this.txt_emergencycall.Value = userEntity.BaseInfo.EmergencyPhone;
//this.txt_emergencyemail.Value = userEntity.BaseInfo.EmergencyEmail;
this.hd_comboSubcompany.Value = userEntity.BaseInfo.COMPANYNAME;
this.hd_comboDept.Value = userEntity.BaseInfo.DEPTNAME;
this.txt_QQ.Value = userEntity.BaseInfo.QQ;
this.txt_MSN.Value = userEntity.BaseInfo.MSN;
//
imgIMAGEURL.ImageUrl = userEntity.BaseInfo.IMAGEURL.ToString().Trim();
this.hdIMAGEURL.Value = userEntity.BaseInfo.IMAGEURL.ToString().Trim();
//
//if (userEntity.BaseInfo.SIGNATURE != null)
//{
// getLOGO(userEntity.BaseInfo.SIGNATURE);
//}
imgSIGNATUREURL.Src = userEntity.BaseInfo.SIGNATUREURL.ToString().Trim();
this.hdSIGNATUREURL.Value = userEntity.BaseInfo.SIGNATUREURL.ToString().Trim();
//
UserAttributeDA attrDA = new UserAttributeDA();
//获取所有用户属性表的数据
IList<UserAttributeEntity> attrEntites = attrDA.GetUserAttributeValue(userEntity.Gid);
foreach (Control cl in Form.Controls)
{
if (cl.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox"))
{
HtmlInputCheckBox cb = (HtmlInputCheckBox)cl;
bool bCheckValue = cb.Checked;
foreach (UserAttributeEntity attrEntity in attrEntites)
{
if (attrEntity.AttributeName.Trim().ToLower().Equals(cb.ID.Trim().Remove(0, 4).ToLower()))
{
if (attrEntity.RefEntity.AttributeValue.Trim().Equals("true"))
{
cb.Checked = true;
}
else
{
cb.Checked = false;
}
}
}
}
}
}
//
ibAdd.Enabled = true;
ibFullAdd.Enabled = true;
ibEnter.Enabled = true;
ibDel.Enabled = true;
ViewState["strHandleType"] = "edit";
}
protected void AddUserCompany()
{
if (this.hd_comboSubcompany.Value.Trim() != "")
{
string COMPANYID = "";
DataSet ds = CompanyDA.GetCompanySQL(" and [NAME]='" + this.hd_comboSubcompany.Value.Trim() + "'");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
COMPANYID = ds.Tables[0].Rows[0]["GID"].ToString().Trim();
}
else
{
Response.Write("<script>alert('所属分公司出错!');history.back();</script>");
return;
}
}
//
if (COMPANYID.Trim() == "")
{
Response.Write("<script>alert('所属分公司出错!');history.back();</script>");
return;
}
else
{
string alt = UserDA.GetUserCompany(COMPANYID.Trim(), Session["UserGID"].ToString().Trim());
if (alt == "")
{
//Response.Write("<script>alert('删除成功!');history.back();</script>");
return;
}
else
{
Response.Write("<script>alert('" + alt + "');history.back();</script>");
return;
}
}
}
else
{
Response.Write("<script>alert('所属分公司不允许为空!');history.back();</script>");
return;
}
}
protected void ibFullAdd_Click(object sender, ImageClickEventArgs e)
{
ibAdd.Enabled = false;
ibFullAdd.Enabled = false;
ibEnter.Enabled = true;
ibDel.Enabled = false;
//
ViewState["strHandleType"] = "add";
Session["UserGID"] = getBSNO();
}
protected void ibAdd_Click(object sender, ImageClickEventArgs e)
{
ibAdd.Enabled = false;
ibFullAdd.Enabled = false;
ibEnter.Enabled = true;
ibDel.Enabled = false;
//
this.txt_username.Value = "";
this.txt_codename.Value = "";
this.hdcodename.Value = "";
this.txt_showname.Value = "";
this.hdshowname.Value = "";
//this.txt_password.Value = "";
this.txt_password.Attributes.Add("value", "");
this.txt_officenum.Value = "";
this.txt_homenum.Value = "";
this.txt_mobilenum.Value = "";
this.txt_FINANCESOFTCODE.Value = "";
this.txt_faxnum.Value = "";
this.txt_email1.Value = "";
this.txt_email2.Value = "";
this.txt_emergencyuser.Value = "";
this.txt_emergencycall.Value = "";
this.txt_homeaddr.Value = "";
this.hd_comboSubcompany.Value = "";
this.hd_comboDept.Value = "";
this.chk_isdisable.Checked = false;
this.chk_isoperator.Checked = false;
this.chk_issaleman.Checked = false;
this.chk_iscustomsservice.Checked = false;
this.chk_isdocument.Checked = false;
this.chk_isdriver.Checked = false;
this.chk_iscustomsdeclarer.Checked = false;
this.chk_isfinancialstaff.Checked = false;
this.chk_isusesystem.Checked = false;
this.chk_isvehiclesdispatcher.Checked = false;
//
imgIMAGEURL.ImageUrl = "../images/userpic/noImage.gif";
this.hdIMAGEURL.Value = "../images/userpic/noImage.gif";
//
imgSIGNATUREURL.Src = "../images/userpic/noImage.gif";
this.hdSIGNATUREURL.Value = "../images/userpic/noImage.gif";
//
ViewState["strHandleType"] = "add";
Session["UserGID"] = getBSNO();
}
}
}