/// <summary> /// 根据寻找到的参数,增加实际的值ss /// </summary> /// <param name="myMatch"></param> /// <returns></returns> private string ReplaceSub(Match myMatch) { string Item = myMatch.Value; if (Item[0] != '@') { return(Item); } FieldAttrib myFieldAttrib = this.Fields[Item.TrimStart('@')]; if (myFieldAttrib == null) { throw new ReportException("无法获取参数" + Item); } IDbDataParameter myParameter = myFieldAttrib.GetParameter(); if (this.DbCommand.Parameters.Contains(myParameter)) { this.DbCommand.Parameters.Add(this.CopyParameter(myParameter)); } else { this.DbCommand.Parameters.Add(myParameter); } return("?"); }
/// <summary> /// 增加参数 /// </summary> internal void AppendParameters() { this.DbCommand.Parameters.Clear(); switch (this.DbConType) //根据数据链接类型判断如何增加参数 { case "OdbcConnection": case "OleDbConnection": this.DbCommand.CommandText = FindArgument.Replace(this.DbCommand.CommandText, new MatchEvaluator(this.ReplaceSub)); break; default: foreach (Match myMatch in FindArgument.Matches(this.DbCommand.CommandText)) { string Item = myMatch.Value; if (Item[0] != '@') { continue; } FieldAttrib myFieldAttrib = this.Fields[Item.TrimStart('@')]; if (myFieldAttrib == null) { throw new ReportException("无法获取参数" + Item); } IDbDataParameter myParameter = myFieldAttrib.GetParameter(); if (!this.DbCommand.Parameters.Contains(myParameter)) { this.DbCommand.Parameters.Add(myParameter); } } break; } }
/// <summary> /// 读取新赋予的值 /// </summary> /// <param name="FieldName">字段名</param> /// <returns></returns> public object GetNewValue(string FieldName) { FieldAttrib myFieldAttrib = this.Fields[FieldName]; if (myFieldAttrib == null) { return(null); } else { return(myFieldAttrib.GetParameter().Value); } }
/// <summary> /// 重置所有的值,只在更新状态和删除状态中才有效 /// </summary> public void ResetFieldValues() { if (this.IsPostBack && this.IsUpdateState) { foreach (string Key in this.Fields.GetKeys()) { FieldAttrib myFieldAttrib = this.Fields[Key]; if (!myFieldAttrib.IsKey) { myFieldAttrib.GetParameter().Value = myFieldAttrib.OldValue; } } } }
/// <summary> /// 设置指定字段的值 /// </summary> /// <param name="FieldName"></param> /// <param name="Value"></param> /// <returns></returns> public void SetNewValue(string FieldName, object Value) { FieldAttrib myFieldAttrib = this.Fields[FieldName.ToLower()]; if (myFieldAttrib == null) { throw new ReportException("字段" + FieldName + "在细节屏字段集合中不存在!"); } myFieldAttrib.GetParameter().Value = Value; myFieldAttrib.IsUpdated = true; if (myFieldAttrib.IsKey) { this.RefreshKeyFlag = true; } }
/// <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()); }