Files
N_XLXSBJ----MX/BJYF_TLJQJList.aspx.cs
T
2026-09-19 14:12:58 +08:00

238 lines
9.3 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_MODEL.Page;
using GThinking.N_MISPRO.Data;
using GThinking.N_MISPRO.Utility;
using System.Text;
using GThinking.N_CONTROL;
namespace GThinking.N_XLXSBJ
{
public partial class BJYF_TLJQJList : SingleGridBase
{
BJYF_TLJQJ entity = new BJYF_TLJQJ();
BJYF_TLJQJ_M qryEntity = new BJYF_TLJQJ_M();
protected void Page_Load(object sender, EventArgs e)
{
this.UMID = 100860173;
this.UMName = "按运距铜铝价区间维护运费比例";
this.CurMaster = Master;
this.ModuleGV = grdContentGrid;
this.CurEntity = entity;
this.CurQueryEntity = qryEntity;
this.sURLTarget = "BJYF_TLJQJInfo.aspx";
this.sQueryURLTarget = "BJYF_TLJQJQuery.aspx";
this.PageHeight = 600;
this.PageWidth = 750;
base.DataKeyNames = new string[] { "XLXSBJDQYFB_XZQHID" };
Master.EnableCopyBtn = false;
base.InitPage();
if (!IsPostBack)
{
Master_OnStandardQuery(null, null);
}
}
#region 模板事件
protected override void Master_OnStandardQuery(object sender, EventArgs e)
{
base.InitEntityByCondition();
InitGridView();
entity.EntityTable.QuerySelSql = GetSql();
base.Master_OnStandardQuery(sender, e);
entity.GridDataBind(grdContentGrid, tSession);
}
protected override void moduleGV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
base.InitEntityByCondition();
InitGridView();
entity.EntityTable.QuerySelSql = GetSql();
base.moduleGV_PageIndexChanging(sender, e);
grdContentGrid.SelectedIndex = -1;
}
protected override void moduleGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkPageParam.AddString("XLXSBJDQYFB_XZQHID", grdContentGrid.DataKeys[e.Row.RowIndex]["XLXSBJDQYFB_XZQHID"].ToString().Trim());
LinkPageParam.AddString("YFJZQHList", txtYFJZQHList.Value.Trim());
}
base.moduleGV_RowDataBound(sender, e);
}
protected override bool Master_BeforeDeleteAction(object sender, EventArgs e)
{
entity.Param.Add("XLXSBJDQYFB_XZQHID", grdContentGrid.SelectedDataKey["XLXSBJDQYFB_XZQHID"].ToString().Trim());
return base.Master_BeforeDeleteAction(sender, e);
}
protected override void AfterDelete(TDatabase db, ref bool ActionIsDone)
{
string sXZQHID = grdContentGrid.SelectedDataKey["XLXSBJDQYFB_XZQHID"].ToString().Trim();
string[] sYFJZQHs = txtYFJZQHList.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (sYFJZQHs.Length > 0)
{
string sIn = "'" + string.Join("','", sYFJZQHs) + "'";
db.ExecSQL(string.Format("delete from XLXSBJDQYFB where XLXSBJDQYFB_XZQHID='{0}' and XLXSBJDQYFB_YFJZQH in ({1})", sXZQHID, sIn));
}
ActionIsDone = true;
base.AfterDelete(db, ref ActionIsDone);
}
protected override bool Master_AfterDeleteAction(object sender, EventArgs e)
{
if (!base.Master_AfterDeleteAction(sender, e))
{ return false; }
base.InitEntityByCondition();
InitGridView();
entity.EntityTable.QuerySelSql = GetSql();
entity.GridDataBind(grdContentGrid, tSession);
grdContentGrid.SelectedIndex = -1;
return true;
}
#endregion
protected void btnYFJZQJ_Click(object sender, EventArgs e)
{
TPageParams tpp = new TPageParams();
tpp.UrlPath = "BJYFJZQJList.aspx";
tpp.AddString("YFJSFS", "6");
OpenModuleDialog(100860071, tpp, btnRefresh.ClientID);
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
moduleGV_PageIndexChanging(null, null);
}
protected void btnDR_Click(object sender, EventArgs e)
{
TPageParams tpp = new TPageParams();
tpp.UrlPath = "BJYFDRInfo.aspx";
tpp.AddString("YFJSFS", "6");
OpenDialog(tpp);
}
#region 自定义函数
private string GetSql()
{
base.InitEntityByCondition();
string[] sYFJZQHs = txtYFJZQHList.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder strSQL = new StringBuilder();
strSQL.AppendLine(" select A.XZQH_XZQHID as XLXSBJDQYFB_XZQHID,");
strSQL.AppendLine(" isnull(A.XZQH_PROVINCE,'') as XZQH_PROVINCE,");
strSQL.AppendLine(" isnull(A.XZQH_CITY,'') as XZQH_CITY,");
for (int i = 0; i < sYFJZQHs.Length; i++)
{
strSQL.AppendLine(string.Format(" isnull(sum(case when B.XLXSBJDQYFB_YFJZQH='{0}' then B.XLXSBJDQYFB_YSFL else 0 end),0) as YL_{0},", sYFJZQHs[i].Trim()));
}
strSQL.AppendLine(" max(B.XLXSBJDQYFB_WHR) as XLXSBJDQYFB_WHR,");
strSQL.AppendLine(" max(B.XLXSBJDQYFB_WHSJ) as XLXSBJDQYFB_WHSJ");
strSQL.AppendLine(" from XZQH A");
strSQL.AppendLine(" left join XLXSBJDQYFB B on B.XLXSBJDQYFB_XZQHID = A.XZQH_XZQHID");
if (sYFJZQHs.Length > 0)
{
string sIn = "'" + string.Join("','", sYFJZQHs) + "'";
strSQL.AppendLine(" and B.XLXSBJDQYFB_YFJZQH in (" + sIn + ")");
strSQL.AppendLine(" where exists(select 1 from XLXSBJDQYFB where XLXSBJDQYFB_XZQHID = A.XZQH_XZQHID and XLXSBJDQYFB_YFJZQH in (" + sIn + "))");
}
else
{
strSQL.AppendLine(" where 1<>1");
}
string sSF = CurQueryEntity.FieldByName("SF").Value.Trim();
if (!string.IsNullOrEmpty(sSF))
{
strSQL.AppendLine(string.Format(" and XZQH_PROVINCE like '%{0}%' ",sSF));
}
string sCS = CurQueryEntity.FieldByName("CS").Value.Trim();
if (!string.IsNullOrEmpty(sCS))
{
strSQL.AppendLine(string.Format(" and XZQH_CITY like '%{0}%' ", sCS));
}
strSQL.AppendLine(" group by A.XZQH_XZQHID, A.XZQH_PROVINCE, A.XZQH_CITY");
strSQL.AppendLine(" order by A.XZQH_PROVINCE, A.XZQH_CITY");
return strSQL.ToString();
}
private void InitGridView()
{
// 移除已存在的动态列,避免重复添加
for (int i = grdContentGrid.Columns.Count - 1; i >= 0; i--)
{
BoundField bf = grdContentGrid.Columns[i] as BoundField;
if (bf != null && bf.DataField.StartsWith("YL_"))
{
grdContentGrid.Columns.RemoveAt(i);
}
}
for (int i = grdContentGrid.ColumnsEx.Count - 1; i >= 0; i--)
{
if (grdContentGrid.ColumnsEx[i].DataField.StartsWith("YL_"))
{
grdContentGrid.ColumnsEx.RemoveAt(i);
}
}
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL SQL = new TSQL(dberp);
SQL.Clear();
SQL.Add("select XLXSBJYFJZQJ_YFJZQH, XLXSBJYFJZQJ_YFJZQJMC ");
SQL.Add(" from XLXSBJYFJZQJ");
SQL.Add(" where XLXSBJYFJZQJ_YFJSGS = '6'");
SQL.Add(" order by XLXSBJYFJZQJ_YFJZQH");
DataSet ds = dberp.OpenDataSet(SQL);
StringBuilder sbYFJZQH = new StringBuilder();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string sYFJZQH = ds.Tables[0].Rows[i]["XLXSBJYFJZQJ_YFJZQH"].ToString().Trim();
string sYFJZQJMC = ds.Tables[0].Rows[i]["XLXSBJYFJZQJ_YFJZQJMC"].ToString().Trim();
if (sbYFJZQH.Length > 0)
sbYFJZQH.Append(",");
sbYFJZQH.Append(sYFJZQH);
AddColumn("YL_" + sYFJZQH, sYFJZQJMC, 2, 120);
}
txtYFJZQHList.Value = sbYFJZQH.ToString();
}
private void AddColumn(string sDataField, string HeadText, int NumberDecimalPlace, int Width)
{
BoundField Column = new BoundField();
Column.DataField = sDataField;
Column.HeaderText = HeadText;
Column.ItemStyle.Width = (Unit)Width;
Column.HeaderStyle.Width = (Unit)Width;
Column.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
grdContentGrid.Columns.Add(Column);
gtGridView_Column ColumnEx = new gtGridView_Column();
ColumnEx.DataField = sDataField;
ColumnEx.EditType = TEditType.etNumber;
ColumnEx.ShowHint = true;
ColumnEx.NumberDecimalPlace = NumberDecimalPlace;
grdContentGrid.ColumnsEx.Add(ColumnEx);
}
#endregion
}
}