public bool Delete(AccountCatalogEntity item) { if (item == null) { throw new System.ArgumentNullException("参数 item 不能为空。"); } return(this.Delete(item.CatalogId)); }
public bool Create(AccountCatalogEntity entity) { if (entity == null) { throw new System.ArgumentNullException("参数 entity 不能为空。"); } bool tmpExecuteResult = false; using (var tmpDataConnection = ((IDataBase)this).CreateConnection(this.ConnectionString)) { var tmpInsertCommand = ((IDataBase)this).CreateCommand(); tmpInsertCommand.Connection = tmpDataConnection; tmpInsertCommand.CommandType = System.Data.CommandType.Text; tmpInsertCommand.CommandText = Statement_Insert; tmpInsertCommand.Parameters.Add(new SQLiteParameter("@Name", System.Data.DbType.String, 30)); tmpInsertCommand.Parameters.Add(new SQLiteParameter("@ParentId", System.Data.DbType.Int32)); tmpInsertCommand.Parameters.Add(new SQLiteParameter("@OrderNo", System.Data.DbType.Int32)); tmpInsertCommand.Parameters.Add(new SQLiteParameter("@Depth", System.Data.DbType.Int32)); tmpInsertCommand.Parameters.Add(new SQLiteParameter("@Description", System.Data.DbType.String, 255)); try { tmpDataConnection.Open(); tmpInsertCommand.Parameters["@Name"].Value = entity.Name; tmpInsertCommand.Parameters["@ParentId"].Value = entity.ParentId; tmpInsertCommand.Parameters["@OrderNo"].Value = entity.Order; tmpInsertCommand.Parameters["@Depth"].Value = entity.Depth; tmpInsertCommand.Parameters["@Description"].Value = entity.Description; var tmpInsertResult = tmpInsertCommand.ExecuteScalar(); if (tmpInsertResult != null && tmpInsertResult != System.DBNull.Value) { tmpExecuteResult = true; entity.CatalogId = System.Convert.ToInt32(tmpInsertResult); } } catch (System.SystemException exception) { loger.Error(exception); throw exception; } finally { if (tmpDataConnection.State == System.Data.ConnectionState.Open) { tmpDataConnection.Close(); } tmpDataConnection.Dispose(); } } return(tmpExecuteResult); }
public bool Update(AccountCatalogEntity entity) { if (entity == null) { throw new System.ArgumentNullException("参数 entity 不能为空。"); } bool tmpUpdateResult = false; using (var tmpDataConnection = ((IDataBase)this).CreateConnection(this.ConnectionString)) { var tmpUpdateCommand = ((IDataBase)this).CreateCommand(); tmpUpdateCommand.Connection = tmpDataConnection; tmpUpdateCommand.CommandType = System.Data.CommandType.Text; tmpUpdateCommand.CommandText = Statement_UpdateOnPK; tmpUpdateCommand.Parameters.Add(new SQLiteParameter("@Name", System.Data.DbType.String, 30)); tmpUpdateCommand.Parameters.Add(new SQLiteParameter("@OrderNo", System.Data.DbType.Int32)); tmpUpdateCommand.Parameters.Add(new SQLiteParameter("@Depth", System.Data.DbType.Int32)); tmpUpdateCommand.Parameters.Add(new SQLiteParameter("@Description", System.Data.DbType.String, 255)); tmpUpdateCommand.Parameters.Add(new SQLiteParameter("@CatalogId", System.Data.DbType.Int32)); tmpUpdateCommand.Parameters.Add(new SQLiteParameter("@VersionNo", System.Data.DbType.Int32)); try { tmpDataConnection.Open(); tmpUpdateCommand.Parameters["@Name"].Value = entity.Name; tmpUpdateCommand.Parameters["@OrderNo"].Value = entity.Order; tmpUpdateCommand.Parameters["@Depth"].Value = entity.Depth; tmpUpdateCommand.Parameters["@Description"].Value = entity.Description; tmpUpdateCommand.Parameters["@CatalogId"].Value = entity.CatalogId; tmpUpdateCommand.Parameters["@VersionNo"].Value = entity.VersionNo; int tmpRowsAffected = tmpUpdateCommand.ExecuteNonQuery(); tmpUpdateResult = tmpRowsAffected > 0; } catch (System.SystemException exception) { loger.Error(exception); throw exception; } finally { if (tmpDataConnection.State == System.Data.ConnectionState.Open) { tmpDataConnection.Close(); } tmpDataConnection.Dispose(); } } return(tmpUpdateResult); }
public AccountCatalogEntity GetCatalogEntity(int catalogId) { AccountCatalogEntity tmpCatalogEntity = null; using (var tmpDataConnection = ((IDataBase)this).CreateConnection(this.ConnectionString)) { var tmpSelectCommand = ((IDataBase)this).CreateCommand(); tmpSelectCommand.Connection = tmpDataConnection; tmpSelectCommand.CommandType = System.Data.CommandType.Text; tmpSelectCommand.CommandText = Statement_SelectOnPK; tmpSelectCommand.Parameters.Add(new SQLiteParameter("@CatalogId", System.Data.DbType.Int32)); tmpSelectCommand.Parameters["@CatalogId"].Value = catalogId; try { tmpDataConnection.Open(); var tempDataReader = this.ExecuteReader(tmpSelectCommand); var tmpCatalogEntities = this.ReadCatalogEntities(tempDataReader); tempDataReader.Close(); if (tmpCatalogEntities != null && tmpCatalogEntities.Count > 0) { tmpCatalogEntity = tmpCatalogEntities[0]; } } catch (System.SystemException exception) { loger.Error(exception); throw exception; } finally { if (tmpDataConnection.State == System.Data.ConnectionState.Open) { tmpDataConnection.Close(); } tmpDataConnection.Dispose(); } } return(tmpCatalogEntity); }
public static AccountCatalogEntity Convert(AccountCatalog catalog) { AccountCatalogEntity tmpCatalogEntity = null; if (catalog != null) { tmpCatalogEntity = new AccountCatalogEntity(); tmpCatalogEntity.CatalogId = catalog.CatalogId; tmpCatalogEntity.Name = catalog.Name; tmpCatalogEntity.Depth = catalog.Depth; tmpCatalogEntity.Order = catalog.Order; tmpCatalogEntity.ParentId = catalog.ParentId; tmpCatalogEntity.VersionNo = catalog.VersionNo; tmpCatalogEntity.CreateTime = catalog.CreateTime; tmpCatalogEntity.UpdateTime = catalog.UpdateTime; tmpCatalogEntity.Description = catalog.Description; } return(tmpCatalogEntity); }
public static AccountCatalog Convert(AccountCatalogEntity entity) { AccountCatalog tmpCatalogModel = null; if (entity != null) { tmpCatalogModel = new AccountCatalog(); tmpCatalogModel.CatalogId = entity.CatalogId; tmpCatalogModel.Name = entity.Name; tmpCatalogModel.Depth = entity.Depth; tmpCatalogModel.Order = entity.Order; tmpCatalogModel.ParentId = entity.ParentId; tmpCatalogModel.VersionNo = entity.VersionNo; tmpCatalogModel.CreateTime = entity.CreateTime; tmpCatalogModel.UpdateTime = entity.UpdateTime; tmpCatalogModel.Description = entity.Description; } return(tmpCatalogModel); }
private IList <AccountCatalogEntity> ReadCatalogEntities(System.Data.IDataReader dataReader) { IList <AccountCatalogEntity> tmpCatalogEntities = null; if (dataReader != null) { tmpCatalogEntities = new List <AccountCatalogEntity>(); while (dataReader.Read()) { var tmpCatalogEntity = new AccountCatalogEntity(); string tmpColumnName; for (int index = 0; index < dataReader.FieldCount; index++) { if (dataReader.IsDBNull(index)) { continue; } tmpColumnName = dataReader.GetName(index); switch (tmpColumnName.ToLower()) { case "catalogid": tmpCatalogEntity.CatalogId = dataReader.GetInt32(index); break; case "name": tmpCatalogEntity.Name = dataReader.GetString(index); break; case "parentid": tmpCatalogEntity.ParentId = dataReader.GetInt32(index); break; case "depth": tmpCatalogEntity.Depth = dataReader.GetInt32(index); break; case "orderno": tmpCatalogEntity.Order = dataReader.GetInt32(index); break; case "versionno": tmpCatalogEntity.VersionNo = dataReader.GetInt32(index); break; case "createtime": tmpCatalogEntity.CreateTime = dataReader.GetDateTime(index); break; case "updatetime": tmpCatalogEntity.UpdateTime = dataReader.GetDateTime(index); break; case "description": tmpCatalogEntity.Description = dataReader.GetString(index); break; default: break; } } tmpCatalogEntities.Add(tmpCatalogEntity); } } return(tmpCatalogEntities); }