Files
N_XLXSBJ----MX/CLWLList.aspx.cs
T
2026-08-21 17:03:02 +08:00

493 lines
21 KiB
C#

#region 功能说明
/*
* 参数说明:
* 注意事项:
* 更新记录:
*/
#endregion
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_PUBLIC;
using System.Text;
using GThinking.N_MISPRO.Utility;
using System.Collections.Generic;
namespace GThinking.N_XLXSBJ
{
public partial class CLWLList : SingleGridBase
{
CLWL entity = new CLWL();
CLWL_M qryEntity = new CLWL_M();
#region Page类事件继承
protected void Page_Load(object sender, EventArgs e)
{
this.UMID = 100860013;
this.UMName = "线缆销售报价材料物料";
this.CurMaster = Master;
this.ModuleGV = grdContentGrid;
this.CurEntity = entity;
this.CurQueryEntity = qryEntity;
this.sURLTarget = "CLWLInfo.aspx";
this.sQueryURLTarget = "CLWLQuery.aspx";
this.PageHeight = 600;
this.PageWidth = 750;
base.DataKeyNames = new string[] { "XLXSBJCLWL_WLID" };
CanDeleteCheckedRows = true;
base.InitPage();
if (!IsPostBack)
{
Master_OnStandardQuery(null, null);
}
}
#endregion
#region 模板事件继承
protected override void Master_OnStandardQuery(object sender, EventArgs e)
{
base.InitEntityByCondition();
entity.EntityTable.QuerySelSql = GetSQL();
base.Master_OnStandardQuery(sender, e);
entity.GridDataBind(grdContentGrid, tSession);
}
protected override void BeforeDelete(TDatabase db, ref bool ActionIsDone)
{
entity.Param.Add("OLD_XLXSBJCLWL_WLID", this.grdContentGrid.SelectedDataKey["XLXSBJCLWL_WLID"].ToString());
base.BeforeDelete(db, ref ActionIsDone);
}
protected override bool Master_BeforeDeleteAction(object sender, EventArgs e)
{
bool bReturn = base.Master_BeforeDeleteAction(sender, e);
return bReturn;
}
protected override bool Master_AfterDeleteAction(object sender, EventArgs e)
{
if (!base.Master_AfterDeleteAction(sender, e)) return false;
base.InitEntityByCondition();
entity.EntityTable.QuerySelSql = GetSQL();
entity.GridDataBind(grdContentGrid, tSession);
grdContentGrid.SelectedIndex = -1;
return true;
}
protected override void moduleGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkPageParam.AddString("XLXSBJCLWL_WLID", grdContentGrid.DataKeys[e.Row.RowIndex]["XLXSBJCLWL_WLID"].ToString().Trim());
}
base.moduleGV_RowDataBound(sender, e);
}
protected override void moduleGV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
base.InitEntityByCondition();
entity.EntityTable.QuerySelSql = GetSQL();
grdContentGrid.SelectedIndex = -1;
base.moduleGV_PageIndexChanging(sender, e);
}
protected override void AfterDelete(TDatabase db, ref bool ActionIsDone)
{
base.AfterDelete(db, ref ActionIsDone);
string sWLID = this.grdContentGrid.SelectedDataKey["XLXSBJCLWL_WLID"].ToString();
db.ExecSQL(string.Format("delete from XLXSWLHQ where 1 = 1 and XLXSWLHQ_JGBID=' ' and XLXSWLHQ_WLID='{0}'", sWLID));
}
#endregion
#region 自定义函数
private string GetSQL()
{
StringBuilder sSQL = new StringBuilder();
sSQL.AppendLine(" select XLXSBJCLWL_WLID,WL_MC,WL_GG,WL_TZ,WL_CL,WL_JLDW, ");
sSQL.AppendLine(" (case when isnull(XLXSBJCLWL_BJCLID,' ')= ' ' then ' ' ");
sSQL.AppendLine(" else ( case when isnull(XLXSBJCL_BJCLMC,' ')=' 'then rtrim(XLXSBJCL_BJCLID)||'|'||'(尚未使用)' else rtrim(XLXSBJCL_BJCLID)||'|'||rtrim(XLXSBJCL_BJCLMC)||'|'||'Kg' end ) ");
sSQL.AppendLine(" end ) as XLXSBJCLWL_BJCLID, XLXSBJCL_BJCLMC,");
sSQL.AppendLine(" XLXSBJCLWL_BZ,XLXSBJCLWL_WHRID,XLXSBJCLWL_WHR,XLXSBJCLWL_WHSJ ");
sSQL.AppendLine(" from XLXSBJCLWL ");
sSQL.AppendLine(" left join WL on WL_WLID=XLXSBJCLWL_WLID ");
sSQL.AppendLine(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID ");
sSQL.AppendLine(" where 1=1 ");
if (!CurQueryEntity.FieldByName("BJCL").Value.Equals(""))
{
sSQL.AppendLine(" and XLXSBJCLWL_BJCLID = :pBJCL ");
entity.Param.Add("pBJCL", CurQueryEntity.FieldByName("BJCL").Value);
}
if (!CurQueryEntity.FieldByName("WLID").Value.Trim().Equals(""))
{
sSQL.AppendLine(" and XLXSBJCLWL_WLID like :pWLID ");
entity.Param.Add("pWLID", "%" + CurQueryEntity.FieldByName("WLID").Value.Trim() + "%");
}
if (!CurQueryEntity.FieldByName("WLMC").Value.Trim().Equals(""))
{
sSQL.AppendLine(" and WL_MC like :pWLMC ");
entity.Param.Add("pWLMC", "%" + CurQueryEntity.FieldByName("WLMC").Value.Trim() + "%");
}
if (!CurQueryEntity.FieldByName("GGXH").Value.Trim().Equals(""))
{
sSQL.AppendLine(" and WL_GG like :pGGXH ");
entity.Param.Add("pGGXH", "%" + CurQueryEntity.FieldByName("GGXH").Value.Trim() + "%");
}
if (!CurQueryEntity.FieldByName("TH").Value.Trim().Equals(""))
{
sSQL.AppendLine(" and WL_TZ like :pTH ");
entity.Param.Add("pTH", "%" + CurQueryEntity.FieldByName("TH").Value.Trim() + "%");
}
if (!CurQueryEntity.FieldByName("CZ").Value.Trim().Equals(""))
{
sSQL.AppendLine(" and WL_CL like :pCZ ");
entity.Param.Add("pCZ", "%" + CurQueryEntity.FieldByName("CZ").Value.Trim() + "%");
}
if (!CurQueryEntity.FieldByName("PSQK").Value.ToString().Trim().Equals(""))
{
string sWLIDList = "";
getPSCLWL(ref sWLIDList);
if (CurQueryEntity.FieldByName("PSQK").Value.ToString().Trim().Equals("已派生材料物料"))
{
sSQL.AppendLine(" and " + GetWhereEqual("XLXSBJCLWL_WLID", sWLIDList));
}
else if (CurQueryEntity.FieldByName("PSQK").Value.ToString().Trim().Equals("未派生材料物料"))
{
sSQL.AppendLine(" and " + GetWhereNotEqual("XLXSBJCLWL_WLID", sWLIDList));
}
}
sSQL.AppendLine(" order by XLXSBJCLWL_WLID ");
return sSQL.ToString();
}
private void getPSCLWL(ref string sWLIDList)
{
base.InitEntityByCondition();
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL SQL = new TSQL(dberp);
SQL.Clear();
if (!CurQueryEntity.FieldByName("PSQK").Value.ToString().Trim().Equals(""))
{
SQL.Add(" select WLID00 from ( ");
for (int i = 1; i <= 80; i++)
{
if (i != 1)
{
SQL.Add(" union all ");
}
SQL.Add(" select distinct ISNULL(XLXSCLQDWL_WLID" + i.ToString().PadLeft(2, '0') + ",' ') as WLID00 from XLXSCLQDWL where 1 = 1 ");
}
SQL.Add(" ) c where 1=1 and c.WLID00 <> ' ' ");
DataSet ds = dberp.OpenDataSet(SQL);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!ds.Tables[0].Rows[i][0].ToString().Trim().Equals(""))
{
sWLIDList = sWLIDList + ds.Tables[0].Rows[i][0].ToString().Trim() + ",";
}
}
sWLIDList = sWLIDList.TrimStart(',').TrimEnd(',');
}
}
}
public string GetWhereEqual(string p_FieldName, string p_Values)
{
p_Values = p_Values.Replace(",", "' or " + p_FieldName + "='");
p_Values = p_FieldName + "='" + p_Values + "'";
p_Values = "(" + p_Values + ")";
return p_Values;
}
public string GetWhereNotEqual(string p_FieldName, string p_Values)
{
p_Values = p_Values.Replace(",", "' and " + p_FieldName + "<>'");
p_Values = p_FieldName + "<>'" + p_Values + "'";
p_Values = "(" + p_Values + ")";
return p_Values;
}
#endregion
# region 控件事件
//从产品结构导入
protected void btnDR_Click(object sender, EventArgs e)
{
TPageParams param = new TPageParams();
param.UrlPath = "CLWL_DRInfo.aspx";
OpenDialogClickBtn(param, btnRefreshDR.ClientID.ToString());
}
//从结构尺重表导入----检索XLXSCQLDWL
//需要保证报价材料是物料行情,需要保证XLJGCZBLM表材料清单列,报价材料列不为空,需要保证XLXSCQLDWL有物料
protected void btnJGCZBDR_Click(object sender, EventArgs e)
{
string sMsg = "将按照派生材料用量时,报价材料匹配的物料导入至材料物料,是否继续?";
Confirm.Register("IsQD", sMsg);
Confirm.ShowBtnText = TConfirm.cBtnText.Yes_No;
if (Confirm.GetValue("IsQD").Trim().Equals(""))
{
Confirm.Ask("IsQD");
return;
}
else if (Confirm.GetValue("IsQD").Trim().Equals("N"))
{
//表示进行了提示并选择了取消,直接返回或其他处理
Confirm.Clear();
return;
}
else if (Confirm.GetValue("IsQD").Trim().Equals("Y"))
{
//表示进行了提示并选择了确认
Confirm.Clear();
}
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL SQL = new TSQL(dberp);
SQL.Clear();
string sJGCZBID = "";
string sJGCZBBBID = "";
string sJGCZBMC = "";
string sDRHH = "";
string sJGCZBXH = "";
string sWLID = "";
string sCLIDQDL = "";
string sBJCLID = "";
List<string> lstWLID = new List<string>();
int iMaxCZBLM = 0;
iMaxCZBLM = XLBJDUtils.GetMaxCLQDL("", "", "");
if (iMaxCZBLM > 80)
{
iMaxCZBLM = 80;
}
try
{
//①数据初始化----存所有数据(可能对应报价材料为空,如果要更新,需要增加lst)
SQL.Clear();
SQL.Add(" select XLXSBJCLWL_WLID from XLXSBJCLWL ");
DataSet dsCLWL = dberp.OpenDataSet(SQL);
for (int i = 0; i < dsCLWL.Tables[0].Rows.Count; i++)
{
lstWLID.Add(dsCLWL.Tables[0].Rows[i][0].ToString().Trim());
}
//②构建XLJGCZBLM用于循环获取报价材料ID
SQL.Clear();
SQL.Add(" select XLJGCZBLM_BJCLID,XLJGCZBLM_CLQDL,");
SQL.Add(" replace(replace(XLJGCZBLM_CLQDL,'第',''),'列','') as CLQDL,");
SQL.Add(" XLJGCZBLM_JGCZBID,XLJGCZBLM_JGCZBBBID,XLJGCZBML_JGCZBMC ");
SQL.Add(" from XLJGCZBLM");
SQL.Add(" left join XLJGCZBML on XLJGCZBML_JGCZBID = XLJGCZBLM_JGCZBID ");
SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID = XLJGCZBLM_BJCLID ");
SQL.Add(" where 1 = 1 ");
//限定材料用量列
SQL.Add(" and XLJGCZBLM_HLMLX = 'Z' ");
SQL.Add(" and XLJGCZBLM_ZDLMLX = '4' ");
SQL.Add(" and ISNULL(XLJGCZBLM_BJCLID, ' ') <> ' ' ");
//限定物料
SQL.Add(" and XLXSBJCL_BJHQ = '2' ");
//SQL.Add(" and XLJGCZBLM_JGCZBID = '2020100001' ");
SQL.Add(" order by XLJGCZBLM_JGCZBID,XLJGCZBLM_JGCZBBBID,XLJGCZBLM_CZBLMBH ");
DataSet dsCZBLM = dberp.OpenDataSet(SQL);
//③根据最大列进行XLXSCLQDWL的主列大循环
SQL.Clear();
SQL.Add(" select XLXSCLQDWL_JGCZBID as JGCZBID,XLXSCLQDWL_JGCZBBBID as JGCZBBBID,XLXSCLQDWL_DRHH as DRHH,XLXSCLQDWL_JGCZBXH as JGCZBXH, ");
for (int t = 1; t <= iMaxCZBLM; t++)
{
SQL.Add(" XLXSCLQDWL_WLID" + t.ToString().PadLeft(2, '0') + ", ");
}
SQL.Add(" 1 FROM XLXSCLQDWL ");
SQL.Add(" where 1 =1 ");
//此处增加查询条件
//SQL.Add(" and XLXSCLQDWL_JGCZBID = '2020100001' ");
SQL.Add(" order by JGCZBID, JGCZBBBID, JGCZBXH, DRHH ");
DataSet dsWLID00 = dberp.OpenDataSet(SQL);
if (dsWLID00 != null && dsWLID00.Tables.Count > 0 && dsWLID00.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsWLID00.Tables[0].Rows.Count; i++)
{
sJGCZBID = dsWLID00.Tables[0].Rows[i]["JGCZBID"].ToString().Trim();
sJGCZBBBID = dsWLID00.Tables[0].Rows[i]["JGCZBBBID"].ToString().Trim();
sDRHH = dsWLID00.Tables[0].Rows[i]["DRHH"].ToString().Trim();
sJGCZBXH = dsWLID00.Tables[0].Rows[i]["JGCZBXH"].ToString().Trim();
for (int j = 4; j < dsWLID00.Tables[0].Columns.Count - 1; j++)
{
sWLID = dsWLID00.Tables[0].Rows[i][j].ToString().Trim();
sCLIDQDL = (j - 3).ToString().Trim().PadLeft(2, '0');
if (!lstWLID.Contains(sWLID) && !sWLID.Equals(""))
{
//④逐个单元格进行匹配
for (int k = 0; k < dsCZBLM.Tables[0].Rows.Count; k++)
{
//XLJGCZBLM比较
if (dsCZBLM.Tables[0].Rows[k]["XLJGCZBLM_JGCZBID"].ToString().Trim().Equals(sJGCZBID)
&& dsCZBLM.Tables[0].Rows[k]["XLJGCZBLM_JGCZBBBID"].ToString().Trim().Equals(sJGCZBBBID)
&& dsCZBLM.Tables[0].Rows[k]["CLQDL"].ToString().Trim().Equals(sCLIDQDL))
{
sBJCLID = dsCZBLM.Tables[0].Rows[k]["XLJGCZBLM_BJCLID"].ToString().Trim();
sJGCZBMC = dsCZBLM.Tables[0].Rows[k]["XLJGCZBML_JGCZBMC"].ToString().Trim();
SQL.Clear();
SQL.Add(" insert into XLXSBJCLWL(XLXSBJCLWL_WLID,XLXSBJCLWL_BZ,XLXSBJCLWL_WHR,XLXSBJCLWL_WHRID,XLXSBJCLWL_WHSJ,XLXSBJCLWL_BJCLID) ");
SQL.Add("values(:pWLID,:pBZ,:pWHR,:pWHRID,:pWHSJ,:pBJCLID) ");
SQL.ParamByName("pWLID").Value = sWLID;
SQL.ParamByName("pBZ").Value = "产生自:" + sJGCZBID + "|" + sJGCZBMC;
SQL.ParamByName("pWHR").Value = tSession.UserName;
SQL.ParamByName("pWHRID").Value = tSession.UserId;
SQL.ParamByName("pWHSJ").Value = DateTime.Now.ToString();
SQL.ParamByName("pBJCLID").Value = sBJCLID;
dberp.ExecSQL(SQL);
lstWLID.Add(sWLID);
break;
}
}
}
else
{
//更新
}
}
}
}
}
catch(Exception ex)
{
ShowMessage("导入出现错误,错误信息:" + ex.ToString().Trim());
return;
}
ShowMessage("导入完成!");
btnRefreshDR_Click(null,null);
}
protected void btnRefreshDR_Click(object sender, EventArgs e)
{
moduleGV_PageIndexChanging(null, null);
}
protected void btnPLSZ_Click(object sender, EventArgs e)
{
txtBJCLID.Value = "";
if (!((grdContentGrid.CheckBox && !String.IsNullOrEmpty(grdContentGrid.CheckedRowIndexs)) || (grdContentGrid.SelectedIndex >= 0)))
{
ShowMessage("请勾选处理记录!");
return;
}
TPageParams param = new TPageParams();
param.UrlPath = "CLWL_PLSZInfo.aspx";
param.AddString("RefreshCtrlID", btnRefresh1.ClientID.Trim());
OpenDialog(param);
}
protected void btnRefresh1_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(txtBJCLID.Value.Trim()))
{
string[] RowsArry;
if (grdContentGrid.CheckBox && !String.IsNullOrEmpty(grdContentGrid.CheckedRowIndexs))
{
RowsArry = grdContentGrid.CheckedRowIndexs.Split(new char[] { ',' });
}
else
{
RowsArry = new string[1];
RowsArry[0] = grdContentGrid.SelectedIndex.ToString();
}
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
dberp.BeginTrans();
try
{
string sWLIDList = "";
for (int j = 0; j < RowsArry.Length; j++)
{
sWLIDList += grdContentGrid.DataKeys[CMISproConvert.StrToInt(RowsArry[j])]["XLXSBJCLWL_WLID"].ToString().Trim() + ",";
}
sWLIDList = sWLIDList.TrimEnd(',');
if (GetOption("XTF010").Equals("Y"))
dberp.ExecSQL(string.Format("update XLXSBJCLWL set XLXSBJCLWL_BJCLID='{0}' where XLXSBJCLWL_WHRID='{1}' and " + CMISproDataBase.GetWhereEqual("XLXSBJCLWL_WLID", sWLIDList), txtBJCLID.Value.Trim(), tSession.UserId));
else
dberp.ExecSQL(string.Format("update XLXSBJCLWL set XLXSBJCLWL_BJCLID='{0}' where " + CMISproDataBase.GetWhereEqual("XLXSBJCLWL_WLID", sWLIDList), txtBJCLID.Value.Trim()));
dberp.CommitTrans();
}
catch (Exception ex)
{
txtBJCLID.Value = "";
dberp.RollbackTrans();
ShowMessage(ex.Message);
return;
}
}
//更新完成后清空隐藏控件的值
txtBJCLID.Value = "";
moduleGV_PageIndexChanging(null, null);
FormAreaUpdate();
}
protected void btnXLJGCZB_Click(object sender, EventArgs e)
{
if (!((grdContentGrid.CheckBox && !String.IsNullOrEmpty(grdContentGrid.CheckedRowIndexs)) || (grdContentGrid.SelectedIndex >= 0)))
{
ShowMessage("请选择需要查看记录!");
return;
}
string sWLID = "";
string[] sTempArr = grdContentGrid.CheckedRowIndexs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (sTempArr.Length >= 2)
{
ShowMessage("最多只允许勾选一条物料查看对应的结构尺重表信息!");
return;
}
else if (grdContentGrid.SelectedIndex >= 0)
{
sWLID = grdContentGrid.DataKeys[grdContentGrid.SelectedIndex]["XLXSBJCLWL_WLID"].ToString().Trim();
}
else
{
sWLID = grdContentGrid.DataKeys[CMISproConvert.StrToInt(sTempArr[0])]["XLXSBJCLWL_WLID"].ToString().Trim();
}
TPageParams param = new TPageParams();
param.UrlPath = "CLWL_XLJGCZBList.aspx";
param.AddString("WLID", sWLID);
OpenDialog(param);
}
#endregion
}
}