Files
N_XLJC--MX/CPML_PLDRList.aspx.cs
T
2026-08-21 17:02:49 +08:00

326 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_MODEL.Page;
using GThinking.N_MISPRO.Data;
using GThinking.N_MISPRO.Utility;
using System.Text;
using GThinking.N_CONTROL;
using GThinking.N_MISPRO;
using GThinking.N_MISPRO.TableCache;
namespace GThinking.N_XLJC
{
public partial class CPML_PLDRList : SingleGridBase
{
CPML_PLDR entity = new CPML_PLDR();
CPML_PLDR_M queryEntity = new CPML_PLDR_M();
#region 页面初始化
protected void Page_Load(object sender, EventArgs e)
{
this.UMID = 101421007;
this.UMName = "线缆产品目录";
this.CurMaster = Master;
this.ModuleGV = ContentGrid;
this.CurEntity = entity;
this.CurQueryEntity = queryEntity;
sQueryURLTarget = "CPML_PLDRQuery.aspx";
this.PageHeight = 400;
this.PageWidth = 500;
base.DataKeyNames = new string[] { "XLXSCLQD_XLXHID", "XLXSCLQD_DYDJID" };
this.Master.EnableNewBtn = false;
this.Master.EnableCopyBtn = false;
this.Master.EnableEditBtn = false;
this.Master.EnableDeleteBtn = false;
this.Master.EnableViewBtn = false;
//this.Master.EnablePrintBtn = false;
base.InitPage();
this.ModuleGV.OnClientDblClick = "return false;";
if (!IsPostBack)
{
Master_OnStandardQuery(null, null);
}
}
#endregion
#region 模板继承事件
protected override void Master_OnStandardQuery(object sender, EventArgs e)
{
base.InitEntityByCondition();
entity.EntityTable.QuerySelSql = GetQuerySql();
base.Master_OnStandardQuery(sender, e);
entity.GridDataBind(ContentGrid, tSession);
}
protected override void moduleGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
}
base.moduleGV_RowDataBound(sender, e);
}
protected override void moduleGV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
base.InitEntityByCondition();
entity.EntityTable.QuerySelSql = GetQuerySql();
ContentGrid.SelectedIndex = -1;
base.moduleGV_PageIndexChanging(sender, e);
}
#endregion
#region 私有函数
private string GetQuerySql()
{
string sSQL = "select distinct XLXSCLQD_XLXHID, XLXSCLQD_DYDJID from XLXSCLQD ";
sSQL += " left join XLXHB on XLXHB_XLXHID = XLXSCLQD_XLXHID ";
sSQL += " where 1=1 and XLXSCLQD_WPID ='ZZZZ' and isnull(XLXHB_TYBZ,'N') <> 'Y' ";
if (PageParam.GetRTrimString("XHMLLB") == "TJ")
{
sSQL += " and not exists (select 1 from XLXSBJTJXHML where XLXSBJTJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJTJXHML_DYDJID=XLXSCLQD_DYDJID)";
sSQL += " and not exists (select 1 from XLXSBJTJXHML where XLXSBJTJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJTJXHML_DYDJID=' ')";
}
else if (PageParam.GetRTrimString("XHMLLB") == "BJ")
{
sSQL += " and not exists (select 1 from XLXSBJXHML where XLXSBJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJXHML_DYDJID=XLXSCLQD_DYDJID)";
sSQL += " and not exists (select 1 from XLXSBJXHML where XLXSBJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJXHML_DYDJID=' ')";
}
//型号模糊
if (!CurQueryEntity.FieldByName("XLXHIDJQPP").Value.ToString().Trim().ToUpper().Equals("TRUE"))
{
if (!string.IsNullOrEmpty(CurQueryEntity.FieldByName("XLXHID").Value.Trim()))
{
sSQL += "\r\n and XLXSCLQD_XLXHID like :pXLXHID ";
entity.Param.Add("pXLXHID", "%" + CurQueryEntity.FieldByName("XLXHID").Value.Trim() + "%");
}
}
else
{
if (!string.IsNullOrEmpty(CurQueryEntity.FieldByName("XLXHID").Value.Trim()))
{
sSQL += "\r\n and XLXSCLQD_XLXHID = :pXLXHID ";
entity.Param.Add("pXLXHID", CurQueryEntity.FieldByName("XLXHID").Value.Trim());
}
}
if (!string.IsNullOrEmpty(CurQueryEntity.FieldByName("DYDJ").Value.Trim()))
{
sSQL += "\r\n and XLXSCLQD_DYDJID = :pDYDJ ";
entity.Param.Add("pDYDJ", CurQueryEntity.FieldByName("DYDJ").Value.Trim());
}
sSQL += " order by XLXSCLQD_XLXHID,XLXSCLQD_DYDJID";
return sSQL;
}
#endregion
#region 控件事件
protected void btnQR_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(ContentGrid.CheckedRowIndexs))
{
ShowMessage("请勾选要导入的记录!");
return;
}
string[] sRowIndexs = ContentGrid.CheckedRowIndexs.Split(',');
if (!string.IsNullOrEmpty(PageParam.GetRTrimString("CPMLID")))
{
int maxXH = CMISproDataBase.GetMaxXH("DBERP", "XLXSBJXHML", "XLXSBJXHML_ZSXH", " XLXSBJXHML_CPMLID='" + PageParam.GetRTrimString("CPMLID")+"'" );
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL sSQL = new TSQL(dberp);
try
{
dberp.BeginTrans();
for (int i = 0; i < sRowIndexs.Length; i++)
{
string sCPMLID = PageParam.GetRTrimString("CPMLID");
string sXLXHID = ContentGrid.DataKeys[int.Parse(sRowIndexs[i])]["XLXSCLQD_XLXHID"].ToString().Trim();
string sDYDJID=ContentGrid.DataKeys[int.Parse(sRowIndexs[i])]["XLXSCLQD_DYDJID"].ToString().Trim();
sSQL.Clear();
if (PageParam.GetRTrimString("XHMLLB") == "BJ")
{
//批量插入XLXSBJXHML
sSQL.Add("insert into XLXSBJXHML( ");
sSQL.Add("XLXSBJXHML_CPMLID,XLXSBJXHML_XLXHID,XLXSBJXHML_DYDJID, ");
sSQL.Add("XLXSBJXHML_WHR,XLXSBJXHML_WHRID,XLXSBJXHML_WHSJ,XLXSBJXHML_ZSXH) ");
}
else if (PageParam.GetRTrimString("XHMLLB") == "TJ")
{
//批量插入XLXSBJTJXHML
sSQL.Add("insert into XLXSBJTJXHML( ");
sSQL.Add("XLXSBJTJXHML_CPMLID,XLXSBJTJXHML_XLXHID,XLXSBJTJXHML_DYDJID, ");
sSQL.Add("XLXSBJTJXHML_WHR,XLXSBJTJXHML_WHRID,XLXSBJTJXHML_WHSJ) ");
}
sSQL.Add("select :pCPMLID,:pXLXHID,:pDYDJID,");
sSQL.Add(":pWHR,:pWHRID,:pWHSJ ");
if (PageParam.GetRTrimString("XHMLLB") == "BJ")
{
sSQL.Add(" ,:pXH ");
sSQL.ParamByName("pXH").Value = ++maxXH;
}
sSQL.ParamByName("pCPMLID").Value = sCPMLID;
sSQL.ParamByName("pXLXHID").Value = sXLXHID;
sSQL.ParamByName("pDYDJID").Value = sDYDJID;
sSQL.ParamByName("pWHRID").Value = tSession.UserId;
sSQL.ParamByName("pWHR").Value = tSession.UserName;
sSQL.ParamByName("pWHSJ").Value = DateTime.Now;
dberp.ExecSQL(sSQL);
}
dberp.CommitTrans();
}
catch (Exception ex)
{
ShowMessage(ex.Message);
dberp.RollbackTrans();
return;
}
ShowMessage("导入完成!");
}
moduleGV_PageIndexChanging(null, null);
}
protected void btnALL_Click(object sender, EventArgs e)
{
Confirm.Register("IsQD", "当前查询记录即将进行全部导入,是否继续?");
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();
}
if (!string.IsNullOrEmpty(PageParam.GetRTrimString("CPMLID")))
{
base.InitEntityByCondition();
int maxXH = CMISproDataBase.GetMaxXH("DBERP", "XLXSBJXHML", "XLXSBJXHML_ZSXH", " XLXSBJXHML_CPMLID='" + PageParam.GetRTrimString("CPMLID") + "'");
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL sSQL = new TSQL(dberp);
try
{
dberp.BeginTrans();
//查询结果全部插入
sSQL.Clear();
if (PageParam.GetRTrimString("XHMLLB") == "BJ")
{
//批量插入XLXSBJXHML
sSQL.Add("insert into XLXSBJXHML( ");
sSQL.Add("XLXSBJXHML_CPMLID,XLXSBJXHML_XLXHID,XLXSBJXHML_DYDJID, ");
sSQL.Add("XLXSBJXHML_WHR,XLXSBJXHML_WHRID,XLXSBJXHML_WHSJ,XLXSBJXHML_ZSXH) ");
}
else if (PageParam.GetRTrimString("XHMLLB") == "TJ")
{
//批量插入XLXSBJTJXHML
sSQL.Add("insert into XLXSBJTJXHML( ");
sSQL.Add("XLXSBJTJXHML_CPMLID,XLXSBJTJXHML_XLXHID,XLXSBJTJXHML_DYDJID, ");
sSQL.Add("XLXSBJTJXHML_WHR,XLXSBJTJXHML_WHRID,XLXSBJTJXHML_WHSJ) ");
}
if (PageParam.GetRTrimString("XHMLLB") == "BJ")
{
sSQL.Add(" select CPMLID,XLXHID,DYDJID,WHR,WHRID,WHSJ,:pMaXH+ row_number() over(order by XLXHID,DYDJID) from ( ");
sSQL.ParamByName("pMaXH").Value = maxXH;
}
sSQL.Add("select distinct :pCPMLID as CPMLID,XLXSCLQD_XLXHID as XLXHID,XLXSCLQD_DYDJID as DYDJID,");
sSQL.Add(":pWHR as WHR,:pWHRID as WHRID,:pWHSJ as WHSJ");
sSQL.Add("from XLXSCLQD");
sSQL.Add(" left join XLXHB on XLXHB_XLXHID = XLXSCLQD_XLXHID ");
sSQL.Add( " where 1=1 and XLXSCLQD_WPID ='ZZZZ' and isnull(XLXHB_TYBZ,'N') <> 'Y'");
if (PageParam.GetRTrimString("XHMLLB") == "TJ")
{
sSQL.Add(" and not exists (select 1 from XLXSBJTJXHML where XLXSBJTJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJTJXHML_DYDJID=XLXSCLQD_DYDJID)");
sSQL.Add(" and not exists (select 1 from XLXSBJTJXHML where XLXSBJTJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJTJXHML_DYDJID=' ')");
}
else if (PageParam.GetRTrimString("XHMLLB") == "BJ")
{
sSQL.Add(" and not exists (select 1 from XLXSBJXHML where XLXSBJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJXHML_DYDJID=XLXSCLQD_DYDJID)");
sSQL.Add(" and not exists (select 1 from XLXSBJXHML where XLXSBJXHML_XLXHID=XLXSCLQD_XLXHID and XLXSBJXHML_DYDJID=' ')");
}
//型号模糊
if (!CurQueryEntity.FieldByName("XLXHIDJQPP").Value.ToString().Trim().ToUpper().Equals("TRUE"))
{
if (!string.IsNullOrEmpty(CurQueryEntity.FieldByName("XLXHID").Value.Trim()))
{
sSQL.Add(" and XLXSCLQD_XLXHID like :pXLXHID ");
sSQL.ParamByName("pXLXHID").Value = string.Format("%{0}%", CurQueryEntity.FieldByName("XLXHID").Value.Trim());
}
}
else
{
if (!string.IsNullOrEmpty(CurQueryEntity.FieldByName("XLXHID").Value.Trim()))
{
sSQL.Add(" and XLXSCLQD_XLXHID = :pXLXHID ");
sSQL.ParamByName("pXLXHID").Value = CurQueryEntity.FieldByName("XLXHID").Value.Trim();
}
}
if (!string.IsNullOrEmpty(CurQueryEntity.FieldByName("DYDJ").Value.Trim()))
{
sSQL.Add(" and XLXSCLQD_DYDJID = :pDYDJ ");
sSQL.ParamByName("pDYDJ").Value = CurQueryEntity.FieldByName("DYDJ").Value.Trim();
}
if (PageParam.GetRTrimString("XHMLLB") == "BJ")
sSQL.Add(" )a ");
sSQL.ParamByName("pCPMLID").Value = PageParam.GetRTrimString("CPMLID");
sSQL.ParamByName("pWHRID").Value = tSession.UserId;
sSQL.ParamByName("pWHR").Value = tSession.UserName;
sSQL.ParamByName("pWHSJ").Value = DateTime.Now;
dberp.ExecSQL(sSQL);
dberp.CommitTrans();
}
catch (Exception ex)
{
ShowMessage(ex.Message);
dberp.RollbackTrans();
return;
}
ShowMessage("全部导入完成!");
DialogOperationScript dos = new DialogOperationScript(this);
dos.CloseSelf();
dos.Execute();
}
}
#endregion
}
}