Exemplo n.º 1
0
        /// <summary>
        /// 读取数据(从数据库)
        /// </summary>
        private void Select()
        {
            //执行数据读取并赋予相应的参数
            string CommandText = this.CurLayoutState.SelectSql;

            //如果未定义SELECT语句,则不执行数据的读取
            if (CommandText == null)
            {
                return;
            }

            if (CommandText.Length > 0 && CommandText[0] == '@')                //若第一个字符为'@',则代表是存储过程
            {
                this.DbCommand.CommandText = CommandText.Substring(1);
                this.DbCommand.CommandType = CommandType.StoredProcedure;
            }
            else
            {
                this.DbCommand.CommandText = CommandText;
                this.DbCommand.CommandType = CommandType.Text;
            }

            this.DbCommand.CommandText = this.ExplainArgument(this.DbCommand.CommandText);

            try
            {
                this.AppendParameters();
                IDataReader myReader = this.DbCommand.ExecuteReader();
                this.DbCommand.CommandType = CommandType.Text;
                if (myReader.Read())
                {
                    this._Catch = 1;
                    for (int index = 0; index < myReader.FieldCount; index++)
                    {
                        FieldAttrib myFieldAttrib = this.Fields[myReader.GetName(index)];
                        if (myFieldAttrib == null)
                        {
                            myFieldAttrib = new FieldAttrib(myReader.GetName(index), System.Data.DbType.String);
                            this.Fields.Append(myFieldAttrib);
                        }
                        myFieldAttrib.GetParameter().Value = myReader[index];
                    }
                    this.CallEventFunction(this.OnAfterOperate, Operate.Select);
                    if (myReader.Read())
                    {
                        this._Catch   = 2;
                        this.ErrorMsg = "读取数据:错误,查询结果不唯一!";
                    }
                }
                else
                {
                    this._Catch = 0;
                }
                myReader.Close();
            }
            catch (Exception e)
            {
                this.ErrorMsg = "读取数据:" + e.Message;
            }
        }
Exemplo n.º 2
0
        /// <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;
            }
        }
Exemplo n.º 3
0
        /// <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("?");
        }
Exemplo n.º 4
0
 /// <summary>
 /// 增加一个属性
 /// </summary>
 /// <param name="newValue">新属性</param>
 public void Append(FieldAttrib newValue)
 {
     if (newValue.Name != null)
     {
         newValue.Group = this;
         this.myHashtable.Add(newValue.Name.ToLower(), newValue);
     }
 }
Exemplo n.º 5
0
        /// <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);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 读取数据库中先前存在的值
        /// </summary>
        /// <param name="FieldName">字段名</param>
        /// <returns></returns>
        public object GetOldValue(string FieldName)
        {
            FieldAttrib myFieldAttrib = this.Fields[FieldName];

            if (myFieldAttrib == null)
            {
                return(null);
            }
            else
            {
                return(myFieldAttrib.OldValue);
            }
        }
Exemplo n.º 7
0
 /// <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;
             }
         }
     }
 }
Exemplo n.º 8
0
        /// <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;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 在更新、删除记录之前,首先读取数据库中已经存在的值。
        /// </summary>
        private bool GetOldValues()
        {
            //执行数据读取并赋予相应的参数
            string CommandText = this.CurLayoutState.SelectSql;

            //如果未定义SELECT语句,则不执行数据的读取
            if (CommandText == null)
            {
                return(false);
            }

            if (CommandText.Length > 0 && CommandText[0] == '@')                //若第一个字符为'@',则代表是存储过程
            {
                this.DbCommand.CommandText = CommandText.Substring(1);
                this.DbCommand.CommandType = CommandType.StoredProcedure;
            }
            else
            {
                this.DbCommand.CommandText = CommandText;
                this.DbCommand.CommandType = CommandType.Text;
            }

            IDataReader myReader = null;

            try
            {
                this.AppendParameters();
                myReader = this.DbCommand.ExecuteReader();
                if (myReader.Read())
                {
                    for (int index = 0; index < myReader.FieldCount; index++)
                    {
                        string      Key           = myReader.GetName(index);
                        FieldAttrib myFieldAttrib = this.Fields[Key];
                        myFieldAttrib.OldValue = myReader[Key];
                    }
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                myReader.Close();
            }
            return(true);
        }
Exemplo n.º 10
0
        /// <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());
        }