279 lines
11 KiB
C#
279 lines
11 KiB
C#
using BLL;
|
||
using FineUIPro.Web.DataShow;
|
||
using System;
|
||
using System.Data;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.SysManage
|
||
{
|
||
public partial class UnitEdit : PageBase
|
||
{
|
||
#region 单位主键
|
||
/// <summary>
|
||
/// 单位主键
|
||
/// </summary>
|
||
public string UnitId
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["UnitId"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["UnitId"] = value;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
||
////权限按钮方法
|
||
this.GetButtonPower();
|
||
//主数据组织
|
||
BindGrid();
|
||
UnitTypeService.InitUnitTypeDropDownList(this.ddlUnitTypeId, true);
|
||
BasicDataService.InitBasicDataProjectUnitDropDownList(this.drpIdcardType, "ZHENGJIAN_TYPE", true);
|
||
this.UnitId = Request.Params["UnitId"];
|
||
if (!string.IsNullOrEmpty(this.UnitId))
|
||
{
|
||
Model.Base_Unit unit = BLL.UnitService.GetUnitByUnitId(this.UnitId);
|
||
if (unit != null)
|
||
{
|
||
if (!string.IsNullOrEmpty(unit.MasterAdOrgCode))
|
||
{
|
||
this.drpMasterBox1.Value = unit.MasterAdOrgCode;
|
||
}
|
||
|
||
this.txtUnitCode.Text = unit.UnitCode;
|
||
this.txtUnitName.Text = unit.UnitName;
|
||
this.txtUnitEnName.Text = unit.UnitEnName;
|
||
if (!string.IsNullOrEmpty(unit.UnitTypeId))
|
||
{
|
||
this.ddlUnitTypeId.SelectedValue = unit.UnitTypeId;
|
||
}
|
||
this.txtCorporate.Text = unit.Corporate;
|
||
this.txtAddress.Text = unit.Address;
|
||
this.txtTelephone.Text = unit.Telephone;
|
||
this.txtShortUnitName.Text = unit.ShortUnitName;
|
||
this.txtFax.Text = unit.Fax;
|
||
this.txtEMail.Text = unit.EMail;
|
||
this.txtProjectRange.Text = unit.ProjectRange;
|
||
if (unit.IsBranch == true)
|
||
{
|
||
this.rblIsBranch.SelectedValue = "true";
|
||
}
|
||
if (!string.IsNullOrEmpty(unit.IsChina))
|
||
{
|
||
this.rblIsChina.SelectedValue = unit.IsChina;
|
||
}
|
||
this.txtCollCropCode.Text = unit.CollCropCode;
|
||
this.txtLinkName.Text = unit.LinkName;
|
||
if (!string.IsNullOrEmpty(unit.IdcardType))
|
||
{
|
||
this.drpIdcardType.SelectedValue = unit.IdcardType;
|
||
}
|
||
this.txtIdcardNumber.Text = unit.IdcardNumber;
|
||
this.txtLinkMobile.Text = unit.LinkMobile;
|
||
if (!string.IsNullOrEmpty(unit.CollCropStatus))
|
||
{
|
||
this.rblCollCropStatus.SelectedValue = unit.CollCropStatus;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#region 集团主数据项目
|
||
|
||
/// <summary>
|
||
/// 集团主数据项目
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
var list = MasterOrgService.GetMasterOrgUnits();
|
||
string code = ttbCodeSearch.Text.Trim();
|
||
string name = ttbNameSearch.Text.Trim();
|
||
if (!string.IsNullOrWhiteSpace(code))
|
||
{
|
||
list = list.Where(x => x.AdOrgCode.Contains(code)).ToList();
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(name))
|
||
{
|
||
list = list.Where(x => x.AdOrgName.Contains(name) || x.Shortname.Contains(name)).ToList();
|
||
}
|
||
// 1.设置总项数(特别注意:数据库分页一定要设置总记录数RecordCount)
|
||
Grid1.RecordCount = list.Count();
|
||
// 2.获取当前分页数据
|
||
DataTable table = Funs.LINQToDataTable(list);
|
||
|
||
// 3.绑定到Grid
|
||
Grid1.DataSource = table;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
protected void ttbCodeSearch_Trigger1Click(object sender, EventArgs e)
|
||
{
|
||
ttbCodeSearch.Text = string.Empty;
|
||
ttbCodeSearch.ShowTrigger1 = false;
|
||
BindGrid();
|
||
}
|
||
protected void ttbCodeSearch_Trigger2Click(object sender, EventArgs e)
|
||
{
|
||
ttbCodeSearch.ShowTrigger1 = true;
|
||
BindGrid();
|
||
}
|
||
protected void ttbNameSearch_Trigger1Click(object sender, EventArgs e)
|
||
{
|
||
ttbNameSearch.Text = string.Empty;
|
||
ttbNameSearch.ShowTrigger1 = false;
|
||
BindGrid();
|
||
}
|
||
protected void ttbNameSearch_Trigger2Click(object sender, EventArgs e)
|
||
{
|
||
ttbNameSearch.ShowTrigger1 = true;
|
||
BindGrid();
|
||
}
|
||
|
||
#region 集团主数据组织信息选择触发事件
|
||
|
||
/// <summary>
|
||
/// 集团主数据组织信息选择触发事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void MasterData_Changed(object sender, EventArgs e)
|
||
{
|
||
string proName = this.drpMasterBox1.Text.Trim();
|
||
string adOrgCode = Grid1.SelectedRowID;
|
||
if (!string.IsNullOrWhiteSpace(adOrgCode))
|
||
{
|
||
var org = MasterOrgService.GetMasterOrg(adOrgCode);
|
||
var relate = Funs.DB.Base_Unit.FirstOrDefault(x => x.MasterAdOrgCode == adOrgCode && (x.UnitId != this.UnitId || (this.UnitId == null && x.UnitId != null)));
|
||
if (relate != null)
|
||
{
|
||
ShowNotify($"已存在关联此主数据的单位:({relate.UnitCode}){relate.UnitName}!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 保存按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (BLL.UnitService.IsExitUnitByUnitName(this.UnitId, this.txtUnitName.Text.Trim()))
|
||
{
|
||
Alert.ShowInTop("单位中文名称已存在!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (BLL.UnitService.IsExitUnitByUnitEnName(this.UnitId, this.txtUnitEnName.Text.Trim()))
|
||
{
|
||
Alert.ShowInTop("单位英文名称已存在!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (BLL.UnitService.IsExitUnitByUnitName(this.UnitId, this.txtUnitCode.Text.Trim()))
|
||
{
|
||
Alert.ShowInTop("单位代码已存在!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
//单位类型下拉框
|
||
string unitTypeId = this.ddlUnitTypeId.SelectedValue;
|
||
if (unitTypeId == null || this.ddlUnitTypeId.SelectedValue == BLL.Const._Null)
|
||
{
|
||
Alert.ShowInTop("请选择单位类型!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
Model.Base_Unit unit = new Model.Base_Unit
|
||
{
|
||
UnitCode = this.txtUnitCode.Text.Trim(),
|
||
UnitName = this.txtUnitName.Text.Trim(),
|
||
UnitEnName = this.txtUnitEnName.Text.TrimStart().TrimEnd()
|
||
};
|
||
|
||
string adOrgCode = this.drpMasterBox1.Value;
|
||
string adOrgName = this.drpMasterBox1.Text;
|
||
if (!string.IsNullOrWhiteSpace(adOrgCode))
|
||
{
|
||
var relate = Funs.DB.Base_Unit.FirstOrDefault(x => x.MasterAdOrgCode == adOrgCode && (x.UnitId != this.UnitId || (this.UnitId == null && x.UnitId != null)));
|
||
if (relate != null)
|
||
{
|
||
Alert.ShowInTop($"已存在关联此主数据的单位:({relate.UnitCode}){relate.UnitName}!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
unit.MasterAdOrgCode = adOrgCode;
|
||
unit.MasterAdOrgName = adOrgName;
|
||
}
|
||
unit.IsBranch = Convert.ToBoolean(this.rblIsBranch.SelectedValue);
|
||
unit.UnitTypeId = this.ddlUnitTypeId.SelectedValue;
|
||
unit.Corporate = this.txtCorporate.Text.Trim();
|
||
unit.Address = this.txtAddress.Text.Trim();
|
||
unit.Telephone = this.txtTelephone.Text.Trim();
|
||
unit.ShortUnitName = this.txtShortUnitName.Text.Trim();
|
||
unit.Fax = this.txtFax.Text.Trim();
|
||
unit.EMail = this.txtEMail.Text.Trim();
|
||
unit.ProjectRange = this.txtProjectRange.Text.Trim();
|
||
unit.IsChina = this.rblIsChina.SelectedValue;
|
||
unit.CollCropCode = this.txtCollCropCode.Text.Trim();
|
||
unit.LinkName = this.txtLinkName.Text.Trim();
|
||
if (this.drpIdcardType.SelectedValue != BLL.Const._Null)
|
||
{
|
||
unit.IdcardType = this.drpIdcardType.SelectedValue;
|
||
}
|
||
unit.IdcardNumber = this.txtIdcardNumber.Text.Trim();
|
||
unit.LinkMobile = this.txtLinkMobile.Text.Trim();
|
||
unit.CollCropStatus = this.rblCollCropStatus.SelectedValue;
|
||
if (string.IsNullOrEmpty(this.UnitId))
|
||
{
|
||
unit.UnitId = SQLHelper.GetNewID(typeof(Model.Base_Unit));
|
||
unit.DataSources = this.CurrUser.LoginProjectId;
|
||
BLL.UnitService.AddUnit(unit);
|
||
BLL.LogService.AddSys_Log(this.CurrUser, unit.UnitCode, unit.UnitId, BLL.Const.UnitMenuId, Const.BtnAdd);
|
||
|
||
}
|
||
else
|
||
{
|
||
unit.UnitId = this.UnitId;
|
||
BLL.UnitService.UpdateUnit(unit);
|
||
BLL.LogService.AddSys_Log(this.CurrUser, unit.UnitCode, unit.UnitId, BLL.Const.UnitMenuId, Const.BtnModify);
|
||
}
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
|
||
}
|
||
|
||
#region 获取按钮权限
|
||
/// <summary>
|
||
/// 获取按钮权限
|
||
/// </summary>
|
||
/// <param name="button"></param>
|
||
/// <returns></returns>
|
||
private void GetButtonPower()
|
||
{
|
||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.UnitMenuId);
|
||
if (buttonList.Count() > 0)
|
||
{
|
||
if (buttonList.Contains(BLL.Const.BtnSave))
|
||
{
|
||
this.btnSave.Hidden = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
} |