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_CONTROL; using GThinking.N_MISPRO; using System.Text; namespace GThinking.N_XLXSBJ { public partial class TZYZJJ7List : SingleGridBase { TZYZJJ7Entity entity = new TZYZJJ7Entity(); TZYZJJ7_M qryEntity = new TZYZJJ7_M(); DataSet dsTJYS1 = new DataSet(); protected void Page_Load(object sender, EventArgs e) { this.UMID = 100860065; this.UMName = "按报价材料调材料损耗"; this.CurMaster = Master; this.ModuleGV = ContentGrid; this.CurEntity = entity; this.CurQueryEntity = qryEntity; this.sURLTarget = "TZYZJJ7Info.aspx"; this.sQueryURLTarget = "TZYZJJ7Query.aspx"; this.PageHeight = 600; this.PageWidth = 750; Master.EnableCopyBtn = false; //Master.EnableNewBtn = false; //Master.EnableEditBtn = false; //Master.EnableViewBtn = false; //Master.EnableDeleteBtn = false; base.DataKeyNames = new string[] { "XLXSJGBYZZ7_JGBID", "XLXSJGBYZZ7_BJCLID" }; if (!IsPostBack) { if (!PageParam.GetRTrimString("JGBID").Equals("")) CurQueryEntity.FieldByName("JGBID").Value = PageParam.GetRTrimString("JGBID"); else CurQueryEntity.FieldByName("JGBID").Value = GetDefaultJGBID(); CurQueryEntity.FieldByName("PXFS").Value = "0"; } base.InitPage(); if (!IsPostBack) { if (!PageParam.GetRTrimString("JGBID").Equals("")) Master_OnStandardQuery(null, null); else { if (IsDefaultExecute) Master_OnStandardQuery(null, null); else { this.Master.StandardNewButton.OnClientClick = "alert('请先查询调价表!');"; } } } } #region 模板事件继承 protected override void Master_OnStandardQuery(object sender, EventArgs e) { entity.EntityTable.QuerySelSql = GetSQL(); base.Master_OnStandardQuery(sender, e); entity.GridDataBind(ContentGrid, tSession); if (CurQueryEntity.FieldByName("JGBID").Value.Trim().Equals("")) { this.Master.StandardNewButton.OnClientClick = "alert('请先查询调价表!');"; } else { this.Master.StandardNewButton.OnClientClick = "OpenCardForm('INSERT');return false;"; } TPageParams pageParams = new TPageParams(); pageParams.AddString("XLXSJGBYZZ7_JGBID", CurQueryEntity.FieldByName("JGBID").Value.Trim()); pageParams.AddString("TJYZList", txtTJYZList.Value.Trim()); pageParams.AddString("PXFS", CurQueryEntity.FieldByName("PXFS").Value.Trim()); SetNewFormParam(pageParams); } protected override void BeforeDelete(TDatabase db, ref bool ActionIsDone) { entity.Param.Add("XLXSJGBYZZ7_JGBID", this.ContentGrid.SelectedDataKey["XLXSJGBYZZ7_JGBID"].ToString().Trim()); entity.Param.Add("XLXSJGBYZZ7_BJCLID", this.ContentGrid.SelectedDataKey["XLXSJGBYZZ7_BJCLID"].ToString().Trim()); base.BeforeDelete(db, ref ActionIsDone); } protected override bool Master_AfterDeleteAction(object sender, EventArgs e) { if (!base.Master_AfterDeleteAction(sender, e)) return false; entity.EntityTable.QuerySelSql = GetSQL(); entity.GridDataBind(ContentGrid, tSession); ContentGrid.SelectedIndex = -1; return true; } protected override void moduleGV_PageIndexChanging(object sender, GridViewPageEventArgs e) { entity.EntityTable.QuerySelSql = GetSQL(); ContentGrid.SelectedIndex = -1; base.moduleGV_PageIndexChanging(sender, e); } protected override void moduleGV_RowDataBound(object sender, GridViewRowEventArgs e) { base.InitEntityByCondition(); if (e.Row.RowType == DataControlRowType.DataRow) { LinkPageParam.AddString("XLXSJGBYZZ7_JGBID", ContentGrid.DataKeys[e.Row.RowIndex]["XLXSJGBYZZ7_JGBID"].ToString().Trim()); LinkPageParam.AddString("TJYZList", txtTJYZList.Value.Trim()); LinkPageParam.AddString("PXFS", CurQueryEntity.FieldByName("PXFS").Value.Trim()); } base.moduleGV_RowDataBound(sender, e); } #endregion #region 自定义函数 private string GetSQL() { base.InitEntityByCondition(); InitGridView(); StringBuilder sSQL = new StringBuilder(); sSQL.AppendLine("select :pJGBID as XLXSJGBYZZ7_JGBID,XLXSJGBYZZ7_BJCLID,"); sSQL.AppendLine(" rtrim(XLXSJGBYZZ7_BJCLID)|| '|' || XLXSBJCL_BJCLMC as BJCL "); for (int i = 0; i < dsTJYS1.Tables[0].Rows.Count; i++) { sSQL.AppendLine(string.Format(",TZYZ_{0}", dsTJYS1.Tables[0].Rows[i][0].ToString().Trim())); } sSQL.AppendLine(" from "); sSQL.AppendLine(" ( "); sSQL.AppendLine(" select XLXSJGBYZZ7_JGBID,XLXSJGBYZZ7_BJCLID "); for (int i = 0; i < dsTJYS1.Tables[0].Rows.Count; i++) { sSQL.AppendLine(string.Format(",sum(CASE XLXSJGBYZZ7_YZID WHEN '{0}' THEN XLXSJGBYZZ7_YZZ ELSE 0 END) as TZYZ_{0}", dsTJYS1.Tables[0].Rows[i][0].ToString().Trim())); } sSQL.AppendLine(" from XLXSJGBYZZ7 "); if (string.IsNullOrEmpty(CurQueryEntity.FieldByName("JGBID").Value.Trim())) { sSQL.AppendLine(" where 1<>1 "); } else { sSQL.AppendLine(" where XLXSJGBYZZ7_JGBID = :pJGBID "); } sSQL.AppendLine(" group by XLXSJGBYZZ7_JGBID,XLXSJGBYZZ7_BJCLID "); sSQL.AppendLine(" ) a "); sSQL.AppendLine(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSJGBYZZ7_BJCLID"); sSQL.AppendLine(" where 1=1 "); if (CurQueryEntity.FieldByName("PXFS").Value.Trim().Equals("0")) { sSQL.AppendLine(" order by XLXSJGBYZZ7_BJCLID"); } else { sSQL.AppendLine(" order by XLXSBJCL_BJCLMC"); } entity.Param.Add("pJGBID", CurQueryEntity.FieldByName("JGBID").Value.Trim()); return sSQL.ToString(); } private void InitGridView() { TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add("select XLXSTZYZ_YZID, XLXSTZYZ_YZMC, XLXSTZYZ_JJFS "); SQL.Add(" from XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH = 'JZJ' and XLXSTZYZ_TJYS='7' "); SQL.Add(" and XLXSTZYZ_JGBID = :pJGBID"); SQL.Add("order by XLXSTZYZ_XSXH, XLXSTZYZ_YZID "); SQL.ParamByName("pJGBID").Value = CurQueryEntity.FieldByName("JGBID").Value.Trim(); DataSet ds = dberp.OpenDataSet(SQL); dsTJYS1 = ds; txtTJYZList.Value = ""; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string sJJFSMC = ""; int iXSWS = 2; if (ds.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim().Equals("JJ")) { iXSWS = 5; sJJFSMC = "(元)"; } else if (ds.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim().Equals("JD") || ds.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim().Equals("KD")) { sJJFSMC = "(%)"; } AddColumn("TZYZ_" + ds.Tables[0].Rows[i]["XLXSTZYZ_YZID"].ToString().Trim(), ds.Tables[0].Rows[i]["XLXSTZYZ_YZMC"].ToString().Trim() + sJJFSMC, iXSWS, 80); txtTJYZList.Value += ds.Tables[0].Rows[i]["XLXSTZYZ_YZID"].ToString().Trim() + "|" + ds.Tables[0].Rows[i]["XLXSTZYZ_YZMC"].ToString().Trim() + sJJFSMC + ","; } txtTJYZList.Value = txtTJYZList.Value.TrimEnd(','); } private string GetDefaultJGBID() { TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(dberp); SQL.Add("select XLXSJGB_JGBID from XLXSJGB where XLXSJGB_MXBH='JZJ' and XLXSJGB_TJYS='7' order by XLXSJGB_JGBID"); DataSet ds = dberp.OpenDataSet(SQL); if (ds.Tables[0].Rows.Count > 0) { return ds.Tables[0].Rows[0][0].ToString().Trim(); } else return ""; } #endregion #region 控件事件 #endregion #region GridView增加列 /// /// 设置etCheckBox列的属性 /// /// /// /// /// private void AddColumn(string sDataField, string HeadText, int Width, TEditType CheckBox) { BoundField Column = new BoundField(); Column.DataField = sDataField; Column.HeaderText = HeadText; Column.ItemStyle.Width = (Unit)Width; Column.HeaderStyle.Width = (Unit)Width; ContentGrid.Columns.Add(Column); gtGridView_Column ColumnEx = new gtGridView_Column(); ColumnEx.DataField = sDataField; ColumnEx.EditType = TEditType.etCheckBox; ContentGrid.ColumnsEx.Insert(0, ColumnEx); } /// /// 设置etString列的属性 /// /// /// /// private void AddColumn(string sDataField, string HeadText, int Width) { BoundField Column = new BoundField(); Column.DataField = sDataField; Column.HeaderText = HeadText; Column.ItemStyle.Width = (Unit)Width; Column.HeaderStyle.Width = (Unit)Width; ContentGrid.Columns.Add(Column); gtGridView_Column ColumnEx = new gtGridView_Column(); ColumnEx.DataField = sDataField; ColumnEx.EditType = TEditType.etString; ColumnEx.ShowHint = true; ContentGrid.ColumnsEx.Insert(0, ColumnEx); } /// /// 设置etNumber列的属 /// /// /// /// /// 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; ContentGrid.Columns.Add(Column); gtGridView_Column ColumnEx = new gtGridView_Column(); ColumnEx.DataField = sDataField; ColumnEx.EditType = TEditType.etNumber; ColumnEx.ShowHint = true; ColumnEx.NumberDecimalPlace = NumberDecimalPlace; ContentGrid.ColumnsEx.Insert(0, ColumnEx); } /// /// 设置etDateTime列的属性 /// /// /// /// /// private void AddColumn(string sDataField, string HeadText, TDateTimeEditKinds DateTimeKind) { BoundField Column = new BoundField(); Column.DataField = sDataField; Column.HeaderText = HeadText; Column.ItemStyle.Width = (Unit)(DateTimeKind == TDateTimeEditKinds.dtDateTime ? 125 : 72); Column.HeaderStyle.Width = (Unit)(DateTimeKind == TDateTimeEditKinds.dtDateTime ? 125 : 72); ContentGrid.Columns.Add(Column); gtGridView_Column ColumnEx = new gtGridView_Column(); ColumnEx.DataField = sDataField; ColumnEx.EditType = TEditType.etDateTime; ColumnEx.DateTimeEditKins = DateTimeKind; ContentGrid.ColumnsEx.Insert(0, ColumnEx); } #endregion } }