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.Utility; using GThinking.N_MISPRO; using GThinking.N_PUBLIC; using GThinking.N_MISPRO.Data; using System.Collections.Generic; namespace GThinking.N_XLJC { public partial class XLDZBZInfo : SingleBillBase { XLDZBZ entity = new XLDZBZ(); XLDZBZYQ hypotaxisEntity = new XLDZBZYQ(); #region Page类事件继承 protected void Page_Load(object sender, EventArgs e) { this.UMID = 101421011; this.UMName = "线缆定制标准"; this.CurMaster = Master; this.ModuleGV = grdXLDZBZLX; this.CurEntity = entity; this.CurHypotaxisEntity = hypotaxisEntity; this.PageHeight = 500; this.PageWidth = 700; this.sURLTarget = "XLDZBZYQInfo.aspx"; this.sRefreshClientID = "default"; //设置标准按钮是否隐藏 this.Master.EnableAttachBtn = false; this.Master.EnableHCopyBtn = false; base.DataKeyNames = new string[] { "XLDZBZ_XH" }; base.InitPage(); if (!this.IsPostBack) { //页面第一次加载需要的操作在此实现,只能处理与记录值无关的初始化操作; hypotaxisEntity.GridDataBind(grdXLDZBZLX, tSession); } } #endregion #region 模板事件继承 protected override void OnNewRecorder() { base.OnNewRecorder(); //必须调用基类方法;在数据表属性中配置缺省值的,由基类方法实现 txtWHR.Text = tSession.UserName; txtWHRID.Value = tSession.UserId; datWHSJ.Text = CMISproConvert.ConvertTime(System.DateTime.Now); } protected override void LoadRecord() { if (!IsPostBack) { entity.Param.Add("XLBZ_XLBZID", PageParam.GetRTrimString("XLBZ_XLBZID")); this.CurHypotaxisEntity.Param.Add("XLDZBZ_XLBZID", PageParam.GetRTrimString("XLBZ_XLBZID")); } else { entity.Param.Add("XLBZ_XLBZID", txtXLBZID_OLD.Value.Trim()); this.CurHypotaxisEntity.Param.Add("XLDZBZ_XLBZID", txtXLBZID_OLD.Value.Trim()); } base.LoadRecord(); txtXLBZID_OLD.Value = txtXLBZID.Text.Trim(); } public override void NewInit() { this.CurHypotaxisEntity.Param.Add("XLDZBZ_XLBZID", ""); base.NewInit(); } protected override void SetControlState() { base.SetControlState(); txtXLBZID.Enabled = false; txtWHR.Enabled = false; datWHSJ.Enabled = false; } protected override void RefreshForm() { base.RefreshForm(); TPageParams tpp = new TPageParams(); tpp.AddString("XLDZBZ_XLBZID", txtXLBZID.Text.Trim()); SetNewFormParam(tpp); } protected override void RefreshGrid() { if (IsPostBack) { this.CurHypotaxisEntity.Param.Clear(); this.CurHypotaxisEntity.Param.Add("XLDZBZ_XLBZID", txtXLBZID.Text.ToString().Trim()); hypotaxisEntity.GridDataBind(grdXLDZBZLX, tSession); grdXLDZBZLX.SelectedIndex = -1; base.RefreshGrid(); } } protected override bool DataLogicValid() { if (txtXLBZMC.Text.Trim().Equals("")) { ShowMessage("定制标准名称不允许为空!"); return false; } string sSQL = string.Format("select TOP 1 XLBZ_XLBZLXMC from XLBZ where 1=1 and XLBZ_XLBZLXMC = '{0}' and XLBZ_XLBZID <> '{1}' ", txtXLBZMC.Text.ToString().Trim(), txtXLBZID_OLD.Value.ToString().Trim()); if (CMISproDataBase.ExistsRecord("DBERP", sSQL)) { ShowMessage("已存在定制标准名称相同的记录,不允许保存!"); return false; } //bool bReturn = base.DataLogicValid(); //string sSQL = ""; //if ((ControlState == TControlState.ctsInsert) || (ControlState == TControlState.ctsCopy)) //{ // sSQL = string.Format("select XLBZ_XLBZID from XLBZ where XLBZ_XLBZID='{0}'", txtXLBZID.Text); // if (CMISproDataBase.ExistsRecord("DBERP", sSQL)) // { // ShowMessage("已存在相同的记录!"); // bReturn = false; // } //} //if ((ControlState == TControlState.ctsEdit) && (txtXLBZID_OLD.Value.Trim() != txtXLBZID.Text.Trim())) //{ // sSQL = string.Format("select XLBZ_XLBZID from XLBZ where XLBZ_XLBZID='{0}'", txtXLBZID.Text.ToString().Trim()); // if (CMISproDataBase.ExistsRecord("DBERP", sSQL)) // { // ShowMessage("已存在相同的记录!"); // bReturn = false; // } //} return base.DataLogicValid(); } protected override void AfterSave(TDatabase db, ref bool ActionIsDone) { base.AfterSave(db, ref ActionIsDone); txtXLBZID_OLD.Value = txtXLBZID.Text.ToString().Trim(); if (ControlState == TControlState.ctsInsert || ControlState == TControlState.ctsCopy) { TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL sSQL = new TSQL(dberp); sSQL.Add(" update XLBZ set XLBZ_PX=9999,XLBZ_DZSC='Y' where XLBZ_XLBZID=:pXLBZID "); sSQL.ParamByName("pXLBZID").Value = txtXLBZID.Text.Trim(); dberp.ExecSQL(sSQL); } } protected override bool Master_BeforeSaveAction(object sender, EventArgs e) { txtWHR.Text = tSession.UserName.Trim(); txtWHRID.Value = tSession.UserId.Trim(); datWHSJ.Value = CMISproConvert.ConvertTime(System.DateTime.Now.ToString()); return base.Master_BeforeSaveAction(sender, e); } protected override void BeforeSave(TDatabase db, ref bool ActionIsDone) { base.BeforeSave(db, ref ActionIsDone); if (ControlState == TControlState.ctsInsert || ControlState == TControlState.ctsCopy) { string sXLBZID = ""; sXLBZID = GetMaxBH(); if (sXLBZID.Equals("") || sXLBZID.Equals("000000000")) { TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add(" select XLBZ_XLBZID from XLBZ where XLBZ_DZSC ='Y' and len(XLBZ_XLBZID) <10 "); DataSet ds = dberp.OpenDataSet(SQL); if (ds.Tables[0].Rows.Count > 0) { string sDZXLBZID = ""; sDZXLBZID = ds.Tables[0].Rows[0][0].ToString().Trim(); if (sDZXLBZID.Trim().Length == 2) { sXLBZID = ds.Tables[0].Rows[0][0].ToString().Trim() + "00000001"; } else { sXLBZID = ds.Tables[0].Rows[0][0].ToString().Trim() + "000000001"; } } } txtXLBZID.Text = sXLBZID; } if (ControlState == TControlState.ctsEdit) { string sSQL = "update XLDZBZ set XLDZBZ_XLBZID=:XLDZBZ_XLBZID where XLDZBZ_XLBZID = :XLDZBZ_OLDXLBZID"; TSQL sql = new TSQL(db); sql.Clear(); sql.Text = sSQL; sql.ParamByName("XLDZBZ_XLBZID").Value = txtXLBZID.Text.Trim(); sql.ParamByName("XLDZBZ_OLDXLBZID").Value = txtXLBZID_OLD.Value.Trim(); db.ExecSQL(sql); } } protected override bool Master_BeforeHypotaxisDeleteAction(object sender, EventArgs e) { return base.Master_BeforeHypotaxisDeleteAction(sender, e); } protected override void BeforeHypotaxisDelete(TDatabase db, ref bool ActionIsDone) { string sXH = grdXLDZBZLX.SelectedDataKey["XLDZBZ_XH"].ToString().Trim(); hypotaxisEntity.Param.Add("XLDZBZ_XLBZID", txtXLBZID.Text.ToString().Trim()); hypotaxisEntity.Param.Add("XLDZBZ_XH", sXH); base.BeforeHypotaxisDelete(db, ref ActionIsDone); } protected override void BeforeDelete(TDatabase db, ref bool ActionIsDone) { if (!IsUsedXLBZID(txtXLBZID_OLD.Value))//是否被引用 { TSQL sql = new TSQL(db); string sSQLText = "delete from XLDZBZ where XLDZBZ_XLBZID =:XLDZBZ_XLBZID"; sql.Clear(); sql.Text = sSQLText; sql.ParamByName("XLDZBZ_XLBZID").Value = txtXLBZID_OLD.Value; db.ExecSQL(sql); base.BeforeDelete(db, ref ActionIsDone); } else { AjaxResponseWrite(grdXLDZBZLX, "alert('该定制标准已被使用,不允许删除!');"); ActionIsDone = false; } } protected override bool Master_AfterHypotaxisDeleteAction(object sender, EventArgs e) { RefreshGrid(); this.ModuleGV.SelectedIndex = -1; return base.Master_AfterHypotaxisDeleteAction(sender, e); } protected override void AfterDelete(TDatabase db, ref bool ActionIsDone) { string sXLBZID = txtXLBZID.Text.Trim(); string sSQL = string.Format("delete from XLDZBZ where XLDZBZ_XLBZID='{0}'", sXLBZID); db.ExecSQL(sSQL); base.AfterDelete(db, ref ActionIsDone); //对其他数据表进行更新操作 } protected override void moduleGV_PageIndexChanging(object sender, GridViewPageEventArgs e) { this.CurHypotaxisEntity.Param.Clear(); this.CurHypotaxisEntity.Param.Add("XLDZBZ_XLBZID", txtXLBZID_OLD.Value.Trim()); base.moduleGV_PageIndexChanging(sender, e); grdXLDZBZLX.SelectedIndex = -1; } protected override void moduleGV_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Dictionary dicXLCPZLID = new Dictionary(); int Index_XLCPZLID = grdXLDZBZLX.Columns.IndexOf(grdXLDZBZLX.FindColumnByFieldName("XLDZBZ_XLCPZLID")); int Index_DZSCXM = grdXLDZBZLX.Columns.IndexOf(grdXLDZBZLX.FindColumnByFieldName("XLDZBZ_DZSCXM")); int Index_DZSCYQ = grdXLDZBZLX.Columns.IndexOf(grdXLDZBZLX.FindColumnByFieldName("XLDZBZ_DZSCYQ")); XLDZBZYQ.GetXLCPZLID(ref dicXLCPZLID); if (dicXLCPZLID.ContainsKey(e.Row.Cells[Index_XLCPZLID].Text.Trim())) { e.Row.Cells[Index_XLCPZLID].Text = e.Row.Cells[Index_XLCPZLID].Text.Trim() + "|" + dicXLCPZLID[e.Row.Cells[Index_XLCPZLID].Text.Trim()]; } if (e.Row.Cells[Index_DZSCXM].Text.Trim().Equals("导体材料")) { e.Row.Cells[Index_DZSCYQ].Text = GetDTCLMC(e.Row.Cells[Index_DZSCYQ].Text.Trim()); } LinkPageParam.AddString("XLDZBZ_XLBZID", txtXLBZID.Text.Trim()); LinkPageParam.AddString("XLDZBZ_XH", grdXLDZBZLX.DataKeys[e.Row.RowIndex]["XLDZBZ_XH"].ToString().Trim()); } base.moduleGV_RowDataBound(sender, e); } protected override void moduleGV_Sorting(object sender, GridViewSortEventArgs e) { string sSQL = " select XLDZBZ_XH, XLDZBZ_XLCPZLID, XLDZBZ_DZSCXM, XLDZBZ_DZSCYQ, XLDZBZ_WHR, XLDZBZ_WHRID, XLDZBZ_WHSJ " + " from XLDZBZ " + " where XLDZBZ_XLBZID=:XLDZBZ_XLBZID" + " order by XLDZBZ_XH "; hypotaxisEntity.EntityTable.QuerySelSql = sSQL; hypotaxisEntity.Param.Clear(); hypotaxisEntity.Param.Add("XLDZBZ_XLBZID", txtXLBZID.Text.Trim()); base.moduleGV_Sorting(sender, e); } protected override bool Master_AfterSaveAction(object sender, EventArgs e) { RefreshGrid(); FormAreaUpdate(); BillFormAreaUpdate(); return base.Master_AfterSaveAction(sender, e); } protected override void SetComboxItems() { base.SetComboxItems(); } #endregion #region 自定义函数 public string GetMaxBH() { string sValue = "000000000"; TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add(" select max(XLBZ_XLBZID) as MAXXH from XLBZ where len(XLBZ_XLBZID)=10 "); DataSet ds = dberp.OpenDataSet(SQL); if (ds.Tables[0].Rows.Count > 0) { string sTmp = ds.Tables[0].Rows[0][0].ToString().Trim(); if (!sTmp.Equals("")) { string sDZXLBZID = ""; TDatabase dberpDZBZ = TContextDatabases.GetDatabase("DBERP"); TSQL sSQL = new TSQL(dberpDZBZ); sSQL.Clear(); sSQL.Add(" select XLBZ_XLBZID from XLBZ where XLBZ_DZSC ='Y' and len(XLBZ_XLBZID) <10 "); DataSet dsDZBZ = dberpDZBZ.OpenDataSet(sSQL); if (dsDZBZ.Tables[0].Rows.Count > 0) { sDZXLBZID = dsDZBZ.Tables[0].Rows[0][0].ToString().Trim(); } if (sDZXLBZID.Trim().Length == 2) { double fTmp = CMISproConvert.StrToFloat(sTmp.Substring(2, sTmp.Length - 2)) + 1; sValue = sTmp.Substring(0, 2) + fTmp.ToString().Trim().PadLeft(8, '0'); } else { double fTmp = CMISproConvert.StrToFloat(sTmp.Substring(1, sTmp.Length - 1)) + 1; sValue = sTmp.Substring(0, 1) + fTmp.ToString().Trim().PadLeft(9, '0'); } } } return sValue; } public string GetDTCLMC(string sDTCLID) { string sDtclMC = ""; TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL sql = new TSQL(dberp); sql.Clear(); sql.Add("select XLDTCLB_DTCLID,XLDTCLB_WLMC from XLDTCLB where XLDTCLB_WLID=' ' and XLDTCLB_DTCLID=:pDTCLID"); sql.ParamByName("pDTCLID").Value = sDTCLID; DataSet ds = dberp.OpenDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { sDtclMC = ds.Tables[0].Rows[0]["XLDTCLB_DTCLID"].ToString().Trim() + "|" + ds.Tables[0].Rows[0]["XLDTCLB_WLMC"].ToString().Trim(); } return sDtclMC; } private bool IsUsedXLBZID(string sXLBZID) { string sSQL = string.Format("select top 1 XLXSCLQD_XLBZID from XLXSCLQD where XLXSCLQD_XLBZID ='{0}' ", sXLBZID.Trim()); return CMISproDataBase.ExistsRecord("DBERP", sSQL); } #endregion } }