301 lines
12 KiB
C#
301 lines
12 KiB
C#
using System;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.Web.UI.WebControls;
|
||
using SuperMap.RealEstate.Web.UI;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using SuperMap.RealEstate.CoreFrameWork;
|
||
using Business = SuperMap.RealEstate.FrameWork.Business;
|
||
using HZQR.Common;
|
||
|
||
namespace Personnel.WebSite.Modules.Users
|
||
{
|
||
public partial class User : UserControl<Business.User>
|
||
{
|
||
//protected string _UserTypeS = ConfigurationManager.AppSettings["UserType"].ToString();
|
||
//protected string _UserTypePID = ConfigurationManager.AppSettings["UserTypePID"].ToString();
|
||
protected string _PROVINCE_CODE = ConfigurationManager.AppSettings["PROVINCE_CODE"].ToString();
|
||
//protected string _ShowPassWordUser = ConfigurationManager.AppSettings["ShowPassWordUser"].ToString();
|
||
|
||
public bool IsExistRelation()
|
||
{
|
||
return this.CurrObject.IsExistRelation(User_ID.Text);
|
||
}
|
||
|
||
public string RelationExplain
|
||
{
|
||
get
|
||
{
|
||
return this.CurrObject.RelationExplain;
|
||
}
|
||
}
|
||
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (IsPostBack) return;
|
||
if (!String.IsNullOrEmpty(User_ID.Text))
|
||
{
|
||
User_Passport.ReadOnly = true;
|
||
ButtonCheckUser.Enabled = false;
|
||
if (User_Indefinit.SelectedValue == "1")
|
||
{
|
||
User_Expiry.AllowEmpty = true;
|
||
}
|
||
}
|
||
if (Page.PassportInfo.UserName == "system" && Page.PassportInfo.UserName == "admin")
|
||
{
|
||
User_PassWordE.Visible = true;
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(User_ID.Text))
|
||
{
|
||
string sql = "SELECT USER_MOBILEPHONE,USER_PROVINCE,PROVINCE_UNIT FROM PLATFORM_FRAMEWORK.T_USER WHERE User_ID = " + User_ID.Text;
|
||
DataTable UserTable = CurrObject.ExecuteDataTable(sql);
|
||
if (UserTable.Rows.Count > 0)
|
||
{
|
||
USER_MOBILEPHONE.Text = UserTable.Rows[0]["USER_MOBILEPHONE"].ToString();
|
||
//USER_PROVINCE.SelectedValue = UserTable.Rows[0]["USER_PROVINCE"].ToString();
|
||
//PROVINCE_UNIT.SelectedValue = UserTable.Rows[0]["PROVINCE_UNIT"].ToString();
|
||
}
|
||
}
|
||
}
|
||
|
||
public override bool LoadData()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public override void OnDataAction_BeforeSave(DataActionEventArgs<Business.User> e)
|
||
{
|
||
if (String.IsNullOrEmpty(e.CurrObject.KeyID))
|
||
{
|
||
if (CheckedExisitUserName())
|
||
{
|
||
LabelCheckUser.Text = "登录账户已存在!";
|
||
LabelCheckUser.ForeColor = System.Drawing.Color.Red;
|
||
e.CancelDataAction = true;
|
||
return;
|
||
}
|
||
LabelCheckUser.Text = "";
|
||
LabelCheckUser.ForeColor = System.Drawing.Color.Empty;
|
||
e.CurrObject.User_PassWord = e.CurrObject.User_Passport.ToEncrypt();
|
||
}
|
||
Business.User _User = new Business.User(this.Transaction);
|
||
if (!string.IsNullOrEmpty(USER_MOBILEPHONE.Text))
|
||
{
|
||
if (e.CurrObject.User_ID != null)
|
||
{
|
||
if (_User.GetCount("WHERE USER_MOBILEPHONE = '" + USER_MOBILEPHONE.Text +
|
||
"' AND USER_STATUS = 1 AND User_ID <> " + e.CurrObject.User_ID) > 0)
|
||
{
|
||
throw new Exception("该手机号已存在,请确认后添加!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (_User.GetCount("WHERE USER_MOBILEPHONE = '" + USER_MOBILEPHONE.Text + "' AND USER_STATUS=1") > 0)
|
||
{
|
||
throw new Exception("该手机号已存在,请确认后添加!");
|
||
}
|
||
}
|
||
}
|
||
e.CurrObject.User_Passport = e.CurrObject.User_Passport.ToLowerInvariant();
|
||
e.CurrObject.User_CityAuthority = SelectTreeView(MyTreeView.Nodes);
|
||
}
|
||
|
||
public override void OnDataAction_AfterSave(DataActionEventArgs<Business.User> e)
|
||
{
|
||
PanelUserName.Enabled = false;
|
||
User_Passport.ReadOnly = true;
|
||
ButtonCheckUser.Enabled = false;
|
||
LabelCheckUser.Text = "";
|
||
|
||
#region 更新省份、业主单位 _PROVINCE_CODE
|
||
e.CurrObject.ExecuteNonQuery("UPDATE PLATFORM_FRAMEWORK.T_USER SET USER_MOBILEPHONE = '" + USER_MOBILEPHONE.Text + "',USER_PROVINCE = '" + _PROVINCE_CODE +
|
||
"' WHERE User_ID = " + e.CurrObject.User_ID, null);
|
||
#endregion
|
||
|
||
if (User_Indefinit.SelectedValue == "1")
|
||
{
|
||
User_Expiry.AllowEmpty = true;
|
||
}
|
||
|
||
#region 同步到第三方平台
|
||
string userPhone = USER_MOBILEPHONE.Text;
|
||
int cmd = 1;//更新用户信息
|
||
if (!string.IsNullOrEmpty(User_ID.Text))
|
||
{
|
||
cmd = 2;//更新用户信息
|
||
}
|
||
int userState = User_Status.SelectedValue.TryParseToInt();//1:有效;0:无效
|
||
string userName = e.CurrObject.User_Name;
|
||
string passPort = e.CurrObject.User_Passport;
|
||
string userPwd = string.IsNullOrEmpty(User_PassWordE.Text) ? (string.IsNullOrEmpty(e.CurrObject.User_PassWord) ?
|
||
e.CurrObject.User_Passport.ToDecrypt() : e.CurrObject.User_PassWord.ToDecrypt()) : User_PassWordE.Text;
|
||
string pageName = "系统用户保存操作";
|
||
Shanxi.ThirdParty.SysncUserToThird(cmd, userName, passPort, userPwd, userPhone, userState, pageName);
|
||
|
||
#region 同步修改远程数据
|
||
if (!String.IsNullOrEmpty(User_ID.Text))
|
||
{
|
||
Shanxi.ThirdParty.SysDataUpdateUser(userName, "1", passPort, userPwd,
|
||
e.CurrObject.User_Status.TryParseToString());
|
||
}
|
||
else
|
||
{
|
||
Shanxi.ThirdParty.SysDataAddUser(userName, "1", passPort, userPwd);
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
}
|
||
|
||
public override void OnDataAction_BeforeDelete(DataActionEventArgs<Business.User> e)
|
||
{
|
||
#region 同步到第三方平台
|
||
string userPhone = USER_MOBILEPHONE.Text;
|
||
int cmd = 2;//更新用户信息
|
||
int userState = 0;//0:无效,删除员工信息
|
||
string userName = e.CurrObject.User_Name;
|
||
string passPort = e.CurrObject.User_Passport;
|
||
string userPwd = string.IsNullOrEmpty(User_PassWordE.Text) ? (string.IsNullOrEmpty(e.CurrObject.User_PassWord) ?
|
||
e.CurrObject.User_Passport.ToDecrypt() : e.CurrObject.User_PassWord.ToDecrypt()) : User_PassWordE.Text;
|
||
string pageName = "系统用户删除操作";
|
||
Shanxi.ThirdParty.SysncUserToThird(cmd, userName, passPort, userPwd, userPhone, userState, pageName);
|
||
|
||
//同步删除OA平台账户数据
|
||
Personnel.WebSite.Shanxi.ThirdParty.SysDataDeleteUser(passPort);
|
||
#endregion
|
||
|
||
base.OnDataAction_BeforeDelete(e);
|
||
}
|
||
|
||
public override void OnDataAction_AfterSelect(DataActionEventArgs<Business.User> e)
|
||
{
|
||
string[] _S = null;
|
||
string _User_CityAuthority = e.CurrObject.User_CityAuthority;
|
||
_User_CityAuthority = _User_CityAuthority == null ? "" : _User_CityAuthority;
|
||
|
||
if (_User_CityAuthority.IndexOf(",") > 0)
|
||
{
|
||
_S = _User_CityAuthority.Split(',');
|
||
}
|
||
else
|
||
{
|
||
_S = _User_CityAuthority.Split(' ');
|
||
}
|
||
|
||
CheckedTreeView(_S, MyTreeView.Nodes);
|
||
if (!e.CurrObject.User_EnabledLicense.HasValue)
|
||
{
|
||
e.CurrObject.User_EnabledLicense = 0; ;
|
||
}
|
||
if (!e.CurrObject.User_EnabledCityAuthority.HasValue)
|
||
{
|
||
e.CurrObject.User_EnabledCityAuthority = 0;
|
||
}
|
||
}
|
||
|
||
//在此加入界面的数据初始化,如DropDownList的数据源绑定等
|
||
public override void InitializeWebControl()
|
||
{
|
||
int ItemLevel = 0;
|
||
UserType_ID.Items.Clear();
|
||
|
||
bool IsShowDefault = true;
|
||
if (!string.IsNullOrEmpty(Request["ShowDefault"]))
|
||
{
|
||
IsShowDefault = false;
|
||
}
|
||
BasePage.BindingDropDownList(Transaction, "-1", UserType_ID.Items, "UserType",
|
||
string.Empty, ItemLevel, "", "", true, false, null, null, true, IsShowDefault);
|
||
User_Expiry.Text = DateTime.Now.Date.AddMonths(3).ToString();
|
||
|
||
MyTreeView.Nodes.Clear();
|
||
TreeNodeCollection _TreeNodeCollection = new TreeNodeCollection();
|
||
DictionaryHelper.BindingTreeView("Division_Code", _TreeNodeCollection, this.Transaction);
|
||
foreach (TreeNode _TreeNode in _TreeNodeCollection)
|
||
{
|
||
if (_TreeNode.Value == _PROVINCE_CODE)
|
||
{
|
||
MyTreeView.Nodes.Add(_TreeNode);
|
||
break;
|
||
}
|
||
}
|
||
SetControlDefaultValue(UserType_ID, User_Index);
|
||
}
|
||
|
||
private string SelectTreeView(TreeNodeCollection treeNodeCollection)
|
||
{
|
||
string _S = "";
|
||
string _temp;
|
||
foreach (TreeNode _TreeNode in treeNodeCollection)
|
||
{
|
||
if (_TreeNode.Checked)
|
||
{
|
||
_S += String.IsNullOrEmpty(_S) ? _TreeNode.Value : " " + _TreeNode.Value;
|
||
}
|
||
_temp = SelectTreeView(_TreeNode.ChildNodes);
|
||
if (!String.IsNullOrEmpty(_temp))
|
||
{
|
||
_S += String.IsNullOrEmpty(_S) ? _temp : " " + _temp;
|
||
}
|
||
}
|
||
return _S;
|
||
}
|
||
|
||
|
||
bool CheckedExisitUserName()
|
||
{
|
||
using (Business.User _User = new Business.User())
|
||
{
|
||
_User.SearchParameters.Clear();
|
||
_User.AddSearchParameter("USER_PASSPORT", User_Passport.Text);
|
||
return _User.Search();
|
||
}
|
||
}
|
||
|
||
void CheckedTreeView(string[] checkedString, TreeNodeCollection treeNodeCollection)
|
||
{
|
||
foreach (TreeNode _TreeNode in treeNodeCollection)
|
||
{
|
||
foreach (string _S in checkedString)
|
||
{
|
||
if (_TreeNode.Value == _S)
|
||
{
|
||
_TreeNode.Checked = true;
|
||
break;
|
||
}
|
||
}
|
||
CheckedTreeView(checkedString, _TreeNode.ChildNodes);
|
||
}
|
||
}
|
||
|
||
protected void ButtonCheckUser_Click(object sender, EventArgs e)
|
||
{
|
||
if (CheckedExisitUserName())
|
||
{
|
||
LabelCheckUser.Text = "登录账户已存在!";
|
||
LabelCheckUser.ForeColor = System.Drawing.Color.Red;
|
||
}
|
||
else
|
||
{
|
||
LabelCheckUser.Text = "可以使用该账户!";
|
||
LabelCheckUser.ForeColor = System.Drawing.Color.Empty;
|
||
}
|
||
}
|
||
|
||
|
||
public void ResetPassWord(Transaction transaction)
|
||
{
|
||
this.CurrObject.ResetProperty();
|
||
this.CurrObject.User_ID = int.Parse(User_ID.Text);
|
||
this.CurrObject.User_PassWord = User_Passport.Text.ToEncrypt();
|
||
if (this.CurrObject.Update())
|
||
{
|
||
this.Page.Alert("密码已重置为“" + User_Passport.Text + "”,请登录系统后自行修改!", 3);
|
||
}
|
||
}
|
||
}
|
||
}
|