xinjiang/SGGL/FineUIPro.Web/JDGL/WBS/WBSSetEdit.aspx.cs

285 lines
11 KiB
C#
Raw Normal View History

2024-11-19 09:45:27 +08:00
using BLL;
using Model;
using System;
using System.Linq;
namespace FineUIPro.Web.JDGL.WBS
{
public partial class WBSSetEdit : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
string id = Request.Params["Id"];
string type = Request.Params["Type"];
string operating = Request.Params["operating"];
if (operating == "add")
{
int i = 0;
if (type.Equals("cnProfession") || type.Equals("unitProject"))
{
txtCode.Text = GetNewCode(id, i, "cnProfession");
}
else
{
txtCode.Text = GetNewCode(id, i, "wbsSet");
Model.WBS_WbsSetInit wbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(id);
if (wbsSet != null)
{
if (BLL.WbsSetInitService.GetItemCount(id) == 0) //末级节点
{
this.trWbsSet2.Hidden = false;
this.trWeight.Hidden = false;
if (wbsSet.Weights != null)
{
this.nbWeights.Text = wbsSet.Weights.ToString();
}
}
}
}
}
else
{
if (type.Equals("unitProject"))
{
Model.Wbs_UnitProjectInit unitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(id);
if (unitProject != null)
{
txtCode.Text = unitProject.UnitProjectCode;
txtName.Text = unitProject.UnitProjectName;
txtRemark.Text = unitProject.Remark;
}
}
else
{
Model.WBS_WbsSetInit wbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(id);
if (wbsSet != null)
{
if (BLL.WbsSetInitService.GetItemCount(id) == 0) //末级节点
{
this.trWbsSet2.Hidden = false;
this.trWeight.Hidden = false;
if (wbsSet.Weights != null)
{
this.nbWeights.Text = wbsSet.Weights.ToString();
}
txtControlItemDef.Text = wbsSet.ControlItemDef;
}
txtCode.Text = wbsSet.WbsSetCode;
txtName.Text = wbsSet.WbsSetName;
txtRemark.Text = wbsSet.Remark;
}
}
}
}
}
private void LoadData()
{
btnClose.OnClientClick = ActiveWindow.GetHideReference();
}
#endregion
#region
/// <summary>
/// 获取编号
/// </summary>
/// <param name="code"></param>
/// <param name="i"></param>
/// <param name="type"></param>
/// <returns></returns>
private string GetNewCode(string code, int i, string type)
{
string newCode = string.Empty;
string testCode = string.Empty;
string istr = string.Empty;
i++;
if (i < 10)
{
istr = "0" + i.ToString();
}
else
{
istr = i.ToString();
}
testCode = string.Empty;
if (type == "cnProfession" && !code.Contains('-'))
{
var cnProfess = CnProfessionInitService.GetCnProfessionInitByCnProfessionId(code);
var count = 0;
if (cnProfess != null)
{
count = BLL.UnitProjectInitService.GetUnitProcountByCnProfessionId(System.Convert.ToInt32(code));
testCode = cnProfess.CnProfessionCode + "-" + istr;
}
else
{
count = BLL.UnitProjectInitService.GetUnitProjectInitcountByUnitProjectCode(code);
testCode = code + "-" + istr;
}
if (count == 0)
{
newCode = testCode;
}
else
{
do
{
i++;
if (i < 10)
{
istr = "0" + i.ToString();
}
else
{
istr = i.ToString();
}
if (cnProfess != null)
{
testCode = cnProfess.CnProfessionCode + "-" + istr;
}
else
{
testCode = code + "-" + istr;
}
} while (BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(testCode) != null);
newCode = testCode;
}
}
else
{
testCode = code + "-" + istr;
if (BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(testCode) == null)
{
newCode = testCode;
}
else
{
do
{
i++;
if (i < 10)
{
istr = "0" + i.ToString();
}
else
{
istr = i.ToString();
}
testCode = code + "-" + istr;
} while (BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(testCode) != null);
newCode = testCode;
}
}
return newCode;
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
string id = Request.Params["Id"];
string type = Request.Params["Type"];
string operating = Request.Params["operating"];
if (operating == "add")
{
if (type == "cnProfession")
{
Model.WBS_CnProfessionInit cnProfession = CnProfessionInitService.GetCnProfessionInitByCnProfessionId(id);
Model.Wbs_UnitProjectInit unitProject = new Wbs_UnitProjectInit();
unitProject.UnitProjectCode = txtCode.Text.Trim();
unitProject.UnitProjectName = txtName.Text.Trim();
unitProject.CnProfessionId = cnProfession.CnProfessionId;
unitProject.IsIn = false;
unitProject.Remark = txtRemark.Text.Trim();
BLL.UnitProjectInitService.AddUnitProjectInit(unitProject);
}
else
{
Model.WBS_WbsSetInit oldWbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(id);
Model.Wbs_UnitProjectInit oldUnitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(id);
Model.WBS_WbsSetInit wbsSet = new WBS_WbsSetInit();
wbsSet.WbsSetCode = txtCode.Text.Trim();
wbsSet.WbsSetName = txtName.Text.Trim();
if (!string.IsNullOrEmpty(this.nbWeights.Text.Trim()))
{
wbsSet.Weights = Funs.GetNewIntOrZero(this.nbWeights.Text.Trim());
}
if (oldWbsSet == null)
{
wbsSet.Flag = 1;
wbsSet.CnProfessionId = oldUnitProject.CnProfessionId;
wbsSet.UnitProjectCode = oldUnitProject.UnitProjectCode;
wbsSet.SuperWbsSetCode = oldUnitProject.UnitProjectCode;
}
else
{
wbsSet.Flag++;
wbsSet.CnProfessionId = oldWbsSet.CnProfessionId;
wbsSet.UnitProjectCode = oldWbsSet.UnitProjectCode;
wbsSet.SuperWbsSetCode = oldWbsSet.WbsSetCode;
}
wbsSet.ControlItemDef = this.txtControlItemDef.Text.Trim();
wbsSet.IsIn = false;
wbsSet.Remark = txtRemark.Text.Trim();
BLL.WbsSetInitService.AddWbsSetInit(wbsSet);
}
BLL.LogService.AddSys_Log(this.CurrUser, id, id, BLL.Const.WBSSetMenuId, "增加WBS库单位、分部、分项工程");
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(txtCode.Text.Trim()) + ActiveWindow.GetHidePostBackReference());
}
else
{
if (type == "unitProject")
{
Model.Wbs_UnitProjectInit unitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(id);
if (unitProject != null)
{
unitProject.UnitProjectCode = id;
unitProject.UnitProjectName = txtName.Text.Trim();
unitProject.Remark = txtRemark.Text.Trim();
BLL.UnitProjectInitService.UpdateUnitProjectInit(unitProject);
}
}
else
{
Model.WBS_WbsSetInit wbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(id);
if (wbsSet != null)
{
wbsSet.WbsSetCode = txtCode.Text.Trim();
wbsSet.WbsSetName = txtName.Text.Trim();
if (!string.IsNullOrEmpty(this.nbWeights.Text.Trim()))
{
wbsSet.Weights = Funs.GetNewIntOrZero(this.nbWeights.Text.Trim());
}
wbsSet.ControlItemDef = this.txtControlItemDef.Text.Trim();
wbsSet.Remark = txtRemark.Text.Trim();
BLL.WbsSetInitService.UpdateWbsSetInit(wbsSet);
}
}
BLL.LogService.AddSys_Log(this.CurrUser, id, id, BLL.Const.WBSSetMenuId, "修改WBS库单位、分部、分项工程");
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
}
#endregion
}
}