Files
2026-08-21 17:03:02 +08:00

356 lines
14 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GThinking.N_MISPRO;
using GThinking.N_MISPRO.Data;
using GThinking.N_MODEL.Page;
using GThinking.N_MISPRO.Utility;
using GThinking.N_CONTROL;
using GThinking.N_PUBLIC;
using System.Collections.Generic;
using GThinking.N_MISPRO.MISPROAS;
using GThinking.N_MISPRO.Caching;
namespace GThinking.N_XLXSBJ
{
public partial class BJFLJSLM : OperationBase
{
BJFLJS entity = new BJFLJS();
#region 页面初始化
protected void Page_Load(object sender, EventArgs e)
{
this.UMID = 100860023;
this.UMName = "按角色隐藏栏目";
this.CurMaster = Master;
this.Tabs = Tab;
this.PageWidth = 700;
this.PageHeight = 500;
AddListSetMap(new ListSet(pagSHD.ID, null, grdJSLM, entity, UPSHD));
if (!IsPostBack)
{
this.Master.PnlQuery.GroupingText = "按角色隐藏栏目";
this.Master.PnlBill.GroupingText = "按角色隐藏栏目";
this.Master.PnlQuery.Visible = false;
Master.BtnQueryVisible = false;
Master.BtnReportVisible = false;
InsertBeforeQuery(PageParam.GetRTrimString("BJFLID"));
}
base.InitPage();
if (!IsPostBack)
{
Master_OnQuery();
GridDataBind();
}
}
#endregion
#region 模板继承事件
protected override void Master_OnQuery()
{
entity.sBJFLID = PageParam.GetRTrimString("BJFLID");
base.Master_OnQuery();
}
protected override void GridDataBind()
{
base.GridDataBind();
}
protected override bool Master_OnBeforeOK(object sender, EventArgs e)
{
return base.Master_OnBeforeOK(sender, e);
}
protected override bool DataLogicValid()
{
return base.DataLogicValid();
}
protected override bool Master_OnOK()
{
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
dberp.BeginTrans();
try
{
TSQL tmpSQL = new TSQL(dberp);
if (grdJSLM.NewRows.Count > 0)
{
for (int i = 0; i < grdJSLM.NewRows.Count; i++)
{
string XJYJS = grdJSLM.GetValueByFieldName("XJYJS", grdJSLM.NewRows[i]).ToString().Trim();
string SJYJS = grdJSLM.GetValueByFieldName("SJYJS", grdJSLM.NewRows[i]).ToString().Trim();
string HJYJS = grdJSLM.GetValueByFieldName("HJYJS", grdJSLM.NewRows[i]).ToString().Trim();
string QTR = grdJSLM.GetValueByFieldName("QTR", grdJSLM.NewRows[i]).ToString().Trim();
string sLMID = grdJSLM.GetValueByFieldName("XLXSBJFLJSLM_LMID", grdJSLM.NewRows[i]).ToString().Trim();
string sBJFLID = PageParam.GetRTrimString("BJFLID");
UpdateByJSLX(dberp, tmpSQL, sLMID, "X", sBJFLID, XJYJS);
UpdateByJSLX(dberp, tmpSQL, sLMID, "S", sBJFLID, SJYJS);
UpdateByJSLX(dberp, tmpSQL, sLMID, "H", sBJFLID, HJYJS);
UpdateByJSLX(dberp, tmpSQL, sLMID, "Q", sBJFLID, QTR);
}
}
//使用脚本给父页面的隐藏控件赋值,调用父页面的控件事件
DialogOperationScript dos = new DialogOperationScript(this);
////dos.SetOwnerControlValue("ctl00_CPHForm_txtBJCLID", cbxBJCL.SelectedValue.Trim());
//dos.ClickOwnerButton(PageParam.GetRTrimString("RefreshCtrlID"));
ShowMessage("修改成功!");
dos.CloseSelf();
dos.Execute();
CacheNotify.TableIsUpdated("DBERP", "XLXSBJFLJSLM");
dberp.CommitTrans();
}
catch (Exception ex)
{
dberp.RollbackTrans();
ShowMessage(ex.Message);
}
return true;
}
protected override void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[0].Text.Trim().Equals("K") && (e.Row.Cells[2].Text.Trim() != "") && (e.Row.Cells[2].Text.Trim() != "&nbsp;"))
{
e.Row.Cells[2].Text = GetKZXXMC(e.Row.Cells[2].Text.Trim());
}
else if ((e.Row.Cells[2].Text.Trim() != "") && (e.Row.Cells[2].Text.Trim() != "&nbsp;"))
{
e.Row.Cells[2].Text = XLBJDUtils.GetLMMC(e.Row.Cells[2].Text.Trim());
}
if (e.Row.Cells[0].Text.Trim().Equals("B"))
{
e.Row.Cells[0].Text = "按钮";
}
else if (e.Row.Cells[0].Text.Trim().Equals("M"))
{
e.Row.Cells[0].Text = "明细栏目";
}
else if (e.Row.Cells[0].Text.Trim().Equals("K"))
{
e.Row.Cells[0].Text = "附加信息";
}
}
base.Grid_RowDataBound(sender, e);
}
#endregion
#region 自定义函数
//在第一次打开时判断是否需要插入
private void InsertBeforeQuery(string sBJFLID)
{
if (!sBJFLID.Trim().Equals(""))
{
//更新扩展信息栏目
DeleteKZXX(sBJFLID);
InsertKZXX(sBJFLID, "X");
InsertKZXX(sBJFLID, "S");
InsertKZXX(sBJFLID, "H");
InsertKZXX(sBJFLID, "Q");
//获取字典中不在表中的栏目ID
List<string> NotInTableLMID = new List<string>(XLBJDUtils.GetLMID(GetExistedLMID(sBJFLID)));
List<string> NotInTableLMIDOthers = new List<string>(XLBJDUtils.GetLMID(GetExistedLMIDByJSLX(sBJFLID,"Q")));
if (NotInTableLMIDOthers.Count > 0)
{
//将不在表中的栏目ID插入数据表
foreach (string item in NotInTableLMIDOthers)
{
InsertByJSLX(item, "Q", sBJFLID);
}
}
if (NotInTableLMID.Count > 0)
{
//将不在表中的栏目ID插入数据表
foreach (string item in NotInTableLMID)
{
InsertByJSLX(item, "X", sBJFLID);
InsertByJSLX(item, "S", sBJFLID);
InsertByJSLX(item, "H", sBJFLID);
}
}
}
}
//根据角色类别插入
private void InsertByJSLX(string sLMID, string sJSLX, string sBJFLID)
{
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
dberp.BeginTrans();
try
{
TSQL tmpSQL = new TSQL(dberp);
tmpSQL.Clear();
tmpSQL.Add("insert into XLXSBJFLJSLM(XLXSBJFLJSLM_BJFLID,XLXSBJFLJSLM_JSLX,XLXSBJFLJSLM_LMLX,XLXSBJFLJSLM_LMID,XLXSBJFLJSLM_YCBZ)");
tmpSQL.Add("values(");
tmpSQL.Add(string.Format("'{0}',", sBJFLID));
tmpSQL.Add(string.Format("'{0}',", sJSLX));
//tmpSQL.Add("'X',");
tmpSQL.Add(string.Format("'{0}',", XLBJDUtils.GetLMLX(sLMID)));
tmpSQL.Add(string.Format("'{0}',", sLMID));
tmpSQL.Add("'N'");
tmpSQL.Add(")");
dberp.ExecSQL(tmpSQL);
dberp.CommitTrans();
}
catch
{
dberp.RollbackTrans();
ShowMessage("操作数据集出错,请和系统管理员联系!");
}
}
//查询数据表已经存在的栏目ID
private List<string> GetExistedLMID(string sBJFLID)
{
List<string> ExistedLMID = new List<string>();
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL sSQL = new TSQL(dberp);
sSQL.Clear();
sSQL.Add("select XLXSBJFLJSLM_LMID from XLXSBJFLJSLM where XLXSBJFLJSLM_BJFLID=:pFLID");
sSQL.Add("order by XLXSBJFLJSLM_LMID");
sSQL.ParamByName("pFLID").Value = sBJFLID;
DataSet ds = dberp.OpenDataSet(sSQL);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string sLMID = ds.Tables[0].Rows[i]["XLXSBJFLJSLM_LMID"].ToString().Trim();
if (!ExistedLMID.Contains(sLMID))
ExistedLMID.Add(sLMID);
}
}
return ExistedLMID;
}
//查询数据表已经存在的其他人栏目ID
private List<string> GetExistedLMIDByJSLX(string sBJFLID,string sJSLX)
{
List<string> ExistedLMID = new List<string>();
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL sSQL = new TSQL(dberp);
sSQL.Clear();
sSQL.Add("select XLXSBJFLJSLM_LMID from XLXSBJFLJSLM where XLXSBJFLJSLM_BJFLID=:pFLID and XLXSBJFLJSLM_JSLX=:pJSLX");
sSQL.Add("order by XLXSBJFLJSLM_LMID");
sSQL.ParamByName("pFLID").Value = sBJFLID;
sSQL.ParamByName("pJSLX").Value = sJSLX;
DataSet ds = dberp.OpenDataSet(sSQL);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string sLMID = ds.Tables[0].Rows[i]["XLXSBJFLJSLM_LMID"].ToString().Trim();
if (!ExistedLMID.Contains(sLMID))
ExistedLMID.Add(sLMID);
}
}
return ExistedLMID;
}
//按角色类型更新数据表
private void UpdateByJSLX(TDatabase dberp, TSQL tmpSQL, string sLMID, string sJSLX, string sBJFLID, string sYCBZ)
{
tmpSQL.Clear();
tmpSQL.Add(" update XLXSBJFLJSLM set ");
tmpSQL.Add(string.Format("XLXSBJFLJSLM_YCBZ='{0}'", sYCBZ));
tmpSQL.Add(string.Format(" ,XLXSBJFLJSLM_WHR='{0}'", CurSession.UserName.Trim()));
tmpSQL.Add(string.Format(" ,XLXSBJFLJSLM_WHSJ='{0}'", CMISproConvert.ConvertTime(DateTime.Now)));
tmpSQL.Add(string.Format(" ,XLXSBJFLJSLM_WHRID='{0}'", CurSession.UserId.Trim()));
tmpSQL.Add(string.Format(" where XLXSBJFLJSLM_BJFLID='{0}' and XLXSBJFLJSLM_LMID='{1}' and XLXSBJFLJSLM_JSLX='{2}'", sBJFLID, sLMID, sJSLX));
dberp.ExecSQL(tmpSQL);
}
//删除扩展信息
private void DeleteKZXX(string sBJFLID)
{
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
dberp.BeginTrans();
try
{
TSQL tmpSQL = new TSQL(dberp);
tmpSQL.Clear();
tmpSQL.Add("delete from XLXSBJFLJSLM where XLXSBJFLJSLM_BJFLID = :pBJFLID and XLXSBJFLJSLM_LMLX = 'K' ");
tmpSQL.Add(" and not exists (select 1 from XLXSBJKZXXSZ where XLXSBJKZXXSZ_DYZD = XLXSBJFLJSLM_LMID ) ");
tmpSQL.ParamByName("pBJFLID").Value = sBJFLID;
dberp.ExecSQL(tmpSQL);
dberp.CommitTrans();
}
catch
{
dberp.RollbackTrans();
ShowMessage("操作数据集出错,请和系统管理员联系!");
}
}
//插入扩展信息
private void InsertKZXX(string sBJFLID,string sJSLX)
{
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
dberp.BeginTrans();
try
{
TSQL tmpSQL = new TSQL(dberp);
tmpSQL.Clear();
tmpSQL.Add("insert into XLXSBJFLJSLM(XLXSBJFLJSLM_BJFLID,XLXSBJFLJSLM_JSLX,XLXSBJFLJSLM_LMLX,XLXSBJFLJSLM_LMID,XLXSBJFLJSLM_YCBZ) ");
tmpSQL.Add(" select :pBJFLID,:pJSLX,'K',XLXSBJKZXXSZ_DYZD,'N' ");
tmpSQL.Add(" from XLXSBJKZXXSZ ");
tmpSQL.Add(" where XLXSBJKZXXSZ_DYZD not in (select XLXSBJFLJSLM_LMID from XLXSBJFLJSLM where XLXSBJFLJSLM_BJFLID = :pBJFLID and XLXSBJFLJSLM_JSLX = :pJSLX)");
tmpSQL.ParamByName("pBJFLID").Value = sBJFLID;
tmpSQL.ParamByName("pJSLX").Value = sJSLX;
dberp.ExecSQL(tmpSQL);
dberp.CommitTrans();
}
catch
{
dberp.RollbackTrans();
ShowMessage("操作数据集出错,请和系统管理员联系!");
}
}
//获取扩展信息的栏目名称
private string GetKZXXMC(string sDYZD)
{
string sKZXXMC="";
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL tmpSQL = new TSQL(dberp);
tmpSQL.Clear();
tmpSQL.Add("select XLXSBJKZXXSZ_MC from XLXSBJKZXXSZ where XLXSBJKZXXSZ_DYZD = :pDYZD");
tmpSQL.ParamByName("pDYZD").Value = sDYZD;
DataSet ds = dberp.OpenDataSet(tmpSQL);
if (ds.Tables[0].Rows.Count > 0)
sKZXXMC = ds.Tables[0].Rows[0]["XLXSBJKZXXSZ_MC"].ToString().Trim();
return sKZXXMC;
}
#endregion
}
}