Exemplo n.º 1
0
        /// <summary>
        /// 在原DataTable上插入新数据
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        /// <remarks>2006-11-27, Tony Zhang</remarks>
        public DataTable GetDataTable(DataTable table)
        {
            string SQL;

            System.Data.DataTable dt = null;
            try
            {
                SQL = AssemblyBusinessObject.GetSelectSQL(this.businessobject);
                //this.Businessobject.SqlHelper
                if (this.SessionInstance != null)
                {
                    dt = this.SessionInstance.SqlHelper.ExcuteDataTable(table, SQL, CommandType.Text);
                }
                else
                {
                    dt = this.SqlHelper.ExcuteDataTable(table, SQL, CommandType.Text);
                }

                return(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取分页记录集
        /// </summary>
        /// <param name="pageNumber">页码(1开始)</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="idColumnName">PKID列名</param>
        /// <param name="IsAsc">升序 或 降序</param>
        /// <returns>记录集包括两个DataTable,第一个返回记录总条数,第二个返回分页后的记录(一页)</returns>
        public DataSet GetPagedRecords(int pageNumber, int pageSize, string idColumnName, bool IsAsc, string finalOrder)
        {
            string SQL;

            System.Data.DataSet ds = null;
            try
            {
                SQL = AssemblyBusinessObject.GetPagingSelectSQL(this.businessobject, pageNumber, pageSize, idColumnName, IsAsc, finalOrder);
                //this.Businessobject.SqlHelper
                if (this.SessionInstance != null)
                {
                    ds = this.SessionInstance.SqlHelper.ExecuteDataSet(SQL, CommandType.Text);
                }
                else
                {
                    ds = this.SqlHelper.ExecuteDataSet(SQL, CommandType.Text);
                }
                //				ds.Tables[0].TableName = this.Businessobject.GetType().Name;
                return(ds);               //.Tables[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public static bool HaveRecord(BusinessObject BO)
        {
            string sql;

            sql = AssemblyBusinessObject.GetSelectSQL(BO);

            DataSet   ds;
            DataTable dt;

            ds = null;
            if (BO.SessionInstance != null)
            {
                ds = BO.SessionInstance.SqlHelper.ExecuteDataSet(sql, CommandType.Text);
            }
            else
            {
                ds = BO.SqlHelper.ExecuteDataSet(sql, CommandType.Text);
            }
            dt = ds.Tables[0];
            if (dt.Rows.Count <= 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 4
0
        /* 获得这个对象集合的一个DataTable
         * 使用场合:需要获得一个DataTable绑定到DataGrid中
         *
         * 例程代码
         * BusinessObjectCollection Products = new BusinessObjectCollection("Product");
         * BusinessFilter filter = new BusinessFilter("Product");
         * filter.AddFilterItem();
         * Products.GetDataTable();
         *
         * 支持多种filter
         * */
        public DataTable GetDataTable()
        {
            string SQL;

            System.Data.DataSet ds = null;
            try
            {
                SQL = AssemblyBusinessObject.GetSelectSQL(this.businessobject);
                //this.Businessobject.SqlHelper
                if (this.SessionInstance != null)
                {
                    ds = this.SessionInstance.SqlHelper.ExecuteDataSet(SQL, CommandType.Text);
                }
                else
                {
                    ds = this.SqlHelper.ExecuteDataSet(SQL, CommandType.Text);
                }
                ds.Tables[0].TableName = this.Businessobject.GetType().Name;
                return(ds.Tables[0]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
        public static void Insert(BusinessObject BO)
        {
            string SQL;

            System.Int32 affect;
            bool         haveIdentity = false;
            FieldInfo    fieldinfo    = null;

            //获得插入串
            SQL = AssemblyBusinessObject.GetInsertSQL(BO, out haveIdentity, out fieldinfo);
            try
            {
                //如果该对象有自增字段,将获得自增的值,同时保存到对象中
                //该对象没有自增字段,将按照正常处理方式处理
                if (haveIdentity == false)
                {
                    if (BO.SessionInstance != null)
                    {
                        BO.SessionInstance.SqlHelper.ExecuteNonQuery(SQL, CommandType.Text);
                    }
                    else
                    {
                        BO.SqlHelper.ExecuteNonQuery(SQL, CommandType.Text);
                    }
                }
                else
                {
                    object obj;
                    if (BO.SessionInstance != null)
                    {
                        obj = BO.SessionInstance.SqlHelper.ExecuteScalar(SQL + "; select @@Identity", CommandType.Text).ToString();
                    }
                    else
                    {
                        obj = BO.SqlHelper.ExecuteScalar(SQL + "; select @@Identity", CommandType.Text).ToString();
                    }
                    affect = Convert.ToInt32(obj);
                    Field field = (Field)fieldinfo.GetValue(BO);

                    System.Reflection.PropertyInfo subfieldinfo = field.GetType().GetProperty("Value");
                    subfieldinfo.SetValue(field, affect, BindingFlags.SetProperty, null, null, null);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 6
0
        /*
         * 代码例程
         * BusinessObjectCollection Products = new BusinessObjectCollection("Product");
         * BusinessFilter filter = new BusinessFilter("Product");
         * filter.AddFilterItems();
         * Products.AddFilter(filter);
         * ((Product)Products.BusinessObject).ID = 100;
         * Products.UpdateFilter();
         *
         *
         * */
        public void UpdateFilter()
        {
            string SQL;

            try
            {
                SQL = AssemblyBusinessObject.GetUpdateFilterSQL(this.Businessobject);
                if (this.SessionInstance != null)
                {
                    this.SessionInstance.SqlHelper.ExecuteNonQuery(SQL, CommandType.Text);
                }
                else
                {
                    this.SqlHelper.ExecuteNonQuery(SQL, CommandType.Text);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        public static void Delete(BusinessObject BO)
        {
            string SQL;
            string connectionstring;

            connectionstring = string.Empty;
            SQL = AssemblyBusinessObject.GetDeleteSQL(BO);
            try
            {
                if (BO.SessionInstance != null)
                {
                    BO.SessionInstance.SqlHelper.ExecuteNonQuery(SQL, CommandType.Text);
                }
                else
                {
                    BO.SqlHelper.ExecuteNonQuery(SQL, CommandType.Text);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        public static void Query(BusinessObject BO, BusinessObjectCollection collection)
        {
            try
            {
                string sql;
                string connectionstring;
                sql = AssemblyBusinessObject.GetSelectSQL(BO);
                collection.RemoveAllObject();
                connectionstring = string.Empty;

                DataSet   ds;
                DataTable dt;
                string [] tablename = new string[1];
                string    displayname;

                ds = null;
                if (BO.SessionInstance != null)
                {
                    ds = BO.SessionInstance.SqlHelper.ExecuteDataSet(sql, CommandType.Text);
                }
                else
                {
                    ds = BO.SqlHelper.ExecuteDataSet(sql, CommandType.Text);
                }

                //ds = DBFactory.GetInstance().GetSqlHelper().ExecuteDataSet(sql,CommandType.Text);
                dt = ds.Tables[0];
                if (dt.Rows.Count <= 0)
                {
                    return;
                }
                BusinessObject businessobject;

                for (int rows = 0; rows < dt.Rows.Count; rows++)
                {
                    businessobject = BO.Clone();
                    FieldInfo [] fieldinfo = businessobject.GetType().GetFields();

                    for (int i = 0; i < fieldinfo.Length; i++)
                    {
                        System.Attribute [] attribute = System.Attribute.GetCustomAttributes(fieldinfo[i]);
                        Field field = (Field)fieldinfo[i].GetValue(businessobject);
                        //为外键的Display字段赋值
                        if (attribute.Length > 0)
                        {
                            for (int j = 0; j < attribute.Length; j++)
                            {
                                if (attribute[j].ToString() == "Wicresoft.BusinessObject.ForeignKeyAttribute")
                                {
                                    displayname = ((ForeignKeyAttribute)attribute[0]).MappingName;
                                    if (dt.Rows[rows][fieldinfo[i].Name] == System.DBNull.Value)
                                    {
                                        if (dt.Rows[rows][displayname] != System.DBNull.Value)
                                        {
                                            field.DisplayValue = dt.Rows[rows][displayname].ToString();
                                        }
                                    }
                                    else
                                    {
                                        field.DisplayValue = dt.Rows[rows][displayname].ToString();
                                    }
                                }
                            }
                        }
                        //为每个字段的Value赋值
                        System.Reflection.PropertyInfo subfieldinfo = field.GetType().GetProperty("Value");
                        if (dt.Rows[rows][fieldinfo[i].Name] != System.DBNull.Value)
                        {
                            subfieldinfo.SetValue(field, dt.Rows[rows][fieldinfo[i].Name], BindingFlags.SetProperty, null, null, null);
                        }
                    }
                    businessobject.Rowstatus = RowStatus.Old;
                    collection.Add(businessobject);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 9
0
        public static void Load(BusinessObject BO)
        {
            try
            {
                string sql;
                string connectionstring;
                sql = AssemblyBusinessObject.GetSelectSQL(BO);
                connectionstring = string.Empty;

                DataSet   ds;
                DataTable dt;
                string [] tablename = new string[1];
                string    mappingName;
                ds = null;
                if (BO.SessionInstance != null)
                {
                    ds = BO.SessionInstance.SqlHelper.ExecuteDataSet(sql, CommandType.Text);
                }
                else
                {
                    ds = BO.SqlHelper.ExecuteDataSet(sql, CommandType.Text);
                }
                dt = ds.Tables[0];
                if (dt.Rows.Count <= 0)
                {
                    BO.HaveRecord = false;
                    return;
                }
                else
                {
                    BO.HaveRecord = true;
                }

                FieldInfo [] fieldinfo = BO.GetType().GetFields();
                for (int i = 0; i < fieldinfo.Length; i++)
                {
                    System.Attribute [] attribute = System.Attribute.GetCustomAttributes(fieldinfo[i]);
                    Field field = (Field)fieldinfo[i].GetValue(BO);
                    //为外键的Display字段赋值
                    if (attribute.Length > 0)
                    {
                        for (int j = 0; j < 1; j++)
                        {
                            if (attribute[j].ToString() == "Wicresoft.BusinessObject.ForeignKeyAttribute")
                            {
                                mappingName = ((ForeignKeyAttribute)attribute[0]).MappingName;

                                if (dt.Rows[0][fieldinfo[i].Name] == System.DBNull.Value)
                                {
                                    if (dt.Rows[0][mappingName] != System.DBNull.Value)
                                    {
                                        field.DisplayValue = dt.Rows[0][mappingName].ToString();
                                    }
                                }
                                else
                                {
                                    field.DisplayValue = dt.Rows[0][mappingName].ToString();
                                }
                            }
                        }
                    }
                    //为每个字段的Value赋值
                    System.Reflection.PropertyInfo subfieldinfo = field.GetType().GetProperty("Value");
                    if (dt.Rows[0][fieldinfo[i].Name] != System.DBNull.Value)
                    {
                        subfieldinfo.SetValue(field, dt.Rows[0][fieldinfo[i].Name], BindingFlags.SetProperty, null, null, null);
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }