/// <summary> /// 摘要:更新一条记录 /// </summary> /// <param name="T">实体类对象</param> public ReturnMessage Update() { ReturnMessage rm = new ReturnMessage(true); string stTableName = string.Empty; try { T obj = (T)this.MemberwiseClone(); stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName; IDBCore iDB = DBFactory.CreateDB(); /*if (DATABASE_TYPE == "XML") * { * iDB = new XMLCore(_TagData); * } * else * { * iDB = DBFactory.CreateDB(); * }*/ iDB.Update(obj); } catch (Exception ex) { rm.IsSucessed = false; rm.Message = "表【" + stTableName + "】更新数据失败,原因:" + ex.Message; } return(rm); }
/// <summary> /// 摘要:根据条件查询数据集记录条数 /// </summary> /// <param name="dataSetSql">查询语句(包括列名、表等信息,支持表关联)</param> /// <param name="where">条件组,二维数据【0】为包括字段名的语句段模板,【1】为取值</param> /// <returns></returns> public int GetDataSetCount(string dataSetSql, List <string[]> where) { int iCount = -1; string stTableName = string.Empty; try { T obj = (T)this.MemberwiseClone(); stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName; IDBCore iDB = DBFactory.CreateDB(); /*if (DATABASE_TYPE == "XML") * { * iDB = new XMLCore(_TagData); * } * else * { * iDB = DBFactory.CreateDB(); * }*/ iCount = iDB.GetDataSetCount(dataSetSql, where); } catch (Exception ex) { throw ex; } return(iCount); }
public MainWindow() { InitializeComponent(); DBFactory.CreateDB(); string result = ProductController.HTMLParser(); ProductController.HTMLWriter(result); }
/// <summary> /// 摘要:删除记录 /// </summary> /// <param name="value">要删除的主键值数组</param> public ReturnMessage Delete(List <string> value) { ReturnMessage rm = new ReturnMessage(true); string stTableName = string.Empty; try { T obj = (T)this.MemberwiseClone(); stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName; string stPK = string.Empty; PropertyInfo[] propertyInfos = obj.GetType().GetProperties(); for (int i = 0; i < propertyInfos.Length; i++) { if (propertyInfos[i].GetCustomAttributes(true).Length != 0) { if (propertyInfos[i].GetCustomAttributes(true)[0].GetType().Name == "PrimaryKeyAttribute") { stPK = propertyInfos[i].Name; } } } IDBCore iDB = DBFactory.CreateDB(); /*if (DATABASE_TYPE == "XML") * { * iDB = new XMLCore(_TagData); * } * else * { * iDB = DBFactory.CreateDB(); * }*/ iDB.Delete(stPK, stTableName, value); } catch (Exception ex) { rm.IsSucessed = false; rm.Message = "表【" + stTableName + "】删除数据失败,原因:" + ex.Message; } return(rm); }
/// <summary> /// 摘要:对数据进行分页 /// </summary> /// <param name="dataSetSql">查询语句(包括列名、表等信息,支持表关联)</param> /// <param name="where">条件组,二维数据【0】为包括字段名的语句段模板,【1】为取值</param> /// <param name="orderByColumn">排序列,二维数据【0】为字段名,【1】为ASC(升序)或DESC(降序)</param> /// <param name="rowBegin">排序后数据集的行开始索引</param> /// <param name="rowEnd">排序后数据集的行结束索引</param> /// <returns></returns> public DataTable GetDataSet(string dataSetSql, List <string[]> where, List <string[]> orderByColumn, int rowBegin, int rowEnd) { DataTable dt = new DataTable(); string stTableName = string.Empty; try { T obj = (T)this.MemberwiseClone(); stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName; IDBCore iDB = DBFactory.CreateDB(); /*if (DATABASE_TYPE == "XML") * { * iDB = new XMLCore(_TagData); * } * else * { * iDB = DBFactory.CreateDB(); * }*/ if ((rowBegin == -1 || rowEnd == -1) && orderByColumn != null) { dt = iDB.GetDataSet(dataSetSql, where, orderByColumn); } else if ((rowBegin == -1 || rowEnd == -1) && orderByColumn == null) { dt = iDB.GetDataSet(dataSetSql, where); } else { dt = iDB.GetDataSet(dataSetSql, where, orderByColumn, rowBegin, rowEnd); } } catch (Exception ex) { dt = null; throw ex; } return(dt); }