/// <summary> /// 增加一项布局 /// </summary> /// <param name="NewLayoutState">新布局</param> public void Append(LayoutState NewLayoutState) { if (NewLayoutState.Name == null) { do { NewLayoutState.Name = "layout" + unchecked (TempIndex++).ToString(); }while(this.myHashtable.ContainsKey(NewLayoutState.Name)); } this.myHashtable.Add(NewLayoutState.Name.ToLower(), NewLayoutState); NewLayoutState.Group = this; if (this._DefaultLayout == null) { this._DefaultLayout = NewLayoutState.Name; } }
/// <summary> /// 获取向客户端输出的内容 /// </summary> /// <returns></returns> protected virtual string GetContent() { LayoutState myLayout = this.CurLayoutState; string Content = null; //替换一些用户自定义参数 Content = this.ExplainHtml(myLayout.InnerHtml.Trim()); //增加对自定义HTC的支持 Content = this.AddUserDefineComponent(Content); if (this.OnBeforeOutput != null) { this.DbCommand.CommandText = ""; this.DbCommand.CommandType = CommandType.Text; this.OnBeforeOutput(this, ref Content); } return(Content); }
/// <summary> /// 向客户端输出信息 /// </summary> /// <param name="writer"></param> protected override void Render(System.Web.UI.HtmlTextWriter writer) { LayoutState myLayout = null; if (this.ErrorMsg == null) { //检测布局 if (this.Layouts == null) { this.ErrorMsg = "输出页面布局:尚未定义页面布局!"; } myLayout = this.Layouts[this.Layout]; if (myLayout == null) { if (this.Layout == null) { this.ErrorMsg = "输出页面布局:尚未定义页面布局,或未给页面布局赋予名字!"; } else { this.ErrorMsg = "输出页面布局:不存在指定的页面布局" + this.Layout; } } } if (this.ErrorMsg != null) { if (this.Request.UserHostAddress == "127.0.0.1" || this.Request.UserHostName == System.Net.Dns.Resolve(System.Net.Dns.GetHostName()).AddressList[0].ToString()) { writer.Write(this.CreateErrorButton(this.ErrorMsg)); } else { writer.Write(this.CreateErrorButton("")); } return; } //输出样式表 writer.Write(this.GetStyle()); //向客户端输出代码 writer.Write("<span id=ReportDetail_"); writer.Write(this.ClientID); writer.Write(">"); if (this.Content == null) { this.Content = this.GetContent(); } writer.Write(this.Content); writer.Write("</span>"); //构造一段Javascript脚本,并发送到客户端,用于给各字段赋值 System.Text.StringBuilder myScript = new System.Text.StringBuilder(); myScript.Append("<script language = javascript>\n"); myScript.Append("var ?clientId?_arrValues = new Array(\n".Replace("?clientId?", this.ClientID)); bool IsExist = false; foreach (object Key in this.Fields.GetKeys()) { FieldAttrib myFieldAttrib = this.Fields[Key.ToString()]; IDbDataParameter myParameter = myFieldAttrib.GetParameter(); //获取字段值 object Value = myFieldAttrib.TrueValue; if (Tools.IsNull(Value)) { Value = null; } else if (Value is string) //支持UBB代码的转换 { if (myFieldAttrib.IsSupportUBB && myLayout.IsSupportUBB) { Value = this.UBB.GetHtmlCode(Value as string); } } myScript.Append("new Array('"); myScript.Append(Key); //字段名 myScript.Append("', '"); myScript.Append(Value == null?null:Value.ToString().Replace("'", @"\'").Replace("\r\n", @"\n")); //值 myScript.Append("', '"); myScript.Append(myFieldAttrib.IsKey); //是否为主键 myScript.Append("', '"); myScript.Append(myFieldAttrib.DbType); //字段类型 myScript.Append("', '"); myScript.Append(myFieldAttrib.Size); //字段长度 myScript.Append("', '"); myScript.Append(myFieldAttrib.IsNullable); //是否允许为空 myScript.Append("', '"); myScript.Append(myFieldAttrib.Verification == null?null:myFieldAttrib.Verification.Replace("'", @"\'").Replace("\r\n", @"\n").Replace(@"\", @"\\")); //验证码 myScript.Append("', '"); myScript.Append(myFieldAttrib.ErrorMsg == null?null:myFieldAttrib.ErrorMsg.Replace("'", @"\'").Replace("\r\n", @"\n")); //错误信息 myScript.Append("', '"); myScript.Append(myFieldAttrib.Title.Replace("'", @"\'").Replace("\r\n", @"\n")); //别名 myScript.Append("', '"); myScript.Append(myFieldAttrib.IsSupportUBB); //是否支持UBB代码 myScript.Append("', '"); myScript.Append(myFieldAttrib.FormatString == null?null:myFieldAttrib.TrueFormatString.Replace("'", @"\'")); //格式化字符串 myScript.Append("', '"); myScript.Append(myFieldAttrib.IsUpdateable); //是否允许更改 myScript.Append("'),\n"); IsExist = true; } if (IsExist == true) { myScript[myScript.Length - 2] = '\n'; } myScript.Append(");\n"); myScript.Append("try{var ?clientId? = new ReportDetailOperate('?clientId?', ?clientId?_arrValues);\n".Replace("?clientId?", this.ClientID)); myScript.Append("ReportDetailSetValue('?clientId?', ?clientId?_arrValues);\n".Replace("?clientId?", this.ClientID)); myScript.Append("}catch(e){}</script>\n"); writer.Write(myScript.ToString()); }