/// <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; } }
/* 获得这个对象集合的一个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; } }
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); } }
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; } }
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; } }