Files
CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/SysManage/UnitEdit.aspx.cs
T

279 lines
11 KiB
C#
Raw Normal View History

2026-09-10 18:51:12 +08:00
using BLL;
using FineUIPro.Web.DataShow;
using System;
using System.Data;
2021-04-30 10:28:37 +08:00
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();
2026-09-10 18:51:12 +08:00
//主数据组织
BindGrid();
2021-04-30 10:28:37 +08:00
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)
{
2026-09-10 18:51:12 +08:00
if (!string.IsNullOrEmpty(unit.MasterAdOrgCode))
{
this.drpMasterBox1.Value = unit.MasterAdOrgCode;
}
2021-04-30 10:28:37 +08:00
this.txtUnitCode.Text = unit.UnitCode;
this.txtUnitName.Text = unit.UnitName;
2025-09-02 10:48:28 +08:00
this.txtUnitEnName.Text = unit.UnitEnName;
2021-04-30 10:28:37 +08:00
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;
}
}
}
}
}
2026-09-10 18:51:12 +08:00
#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
2021-04-30 10:28:37 +08:00
/// <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()))
{
2025-09-02 10:48:28 +08:00
Alert.ShowInTop("单位中文名称已存在!", MessageBoxIcon.Warning);
return;
}
if (BLL.UnitService.IsExitUnitByUnitEnName(this.UnitId, this.txtUnitEnName.Text.Trim()))
{
Alert.ShowInTop("单位英文名称已存在!", MessageBoxIcon.Warning);
2021-04-30 10:28:37 +08:00
return;
}
if (BLL.UnitService.IsExitUnitByUnitName(this.UnitId, this.txtUnitCode.Text.Trim()))
{
Alert.ShowInTop("单位代码已存在!", MessageBoxIcon.Warning);
return;
}
2025-09-02 10:48:28 +08:00
//单位类型下拉框
string unitTypeId = this.ddlUnitTypeId.SelectedValue;
if (unitTypeId == null || this.ddlUnitTypeId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择单位类型!", MessageBoxIcon.Warning);
return;
}
2021-04-30 10:28:37 +08:00
Model.Base_Unit unit = new Model.Base_Unit
{
UnitCode = this.txtUnitCode.Text.Trim(),
2025-09-02 10:48:28 +08:00
UnitName = this.txtUnitName.Text.Trim(),
UnitEnName = this.txtUnitEnName.Text.TrimStart().TrimEnd()
2021-04-30 10:28:37 +08:00
};
2026-09-10 18:51:12 +08:00
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;
}
2021-04-30 10:28:37 +08:00
unit.IsBranch = Convert.ToBoolean(this.rblIsBranch.SelectedValue);
2025-09-02 10:48:28 +08:00
unit.UnitTypeId = this.ddlUnitTypeId.SelectedValue;
2021-04-30 10:28:37 +08:00
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
}
}