<?xml version="1.0"?>
<Entity>
	<Name>Station</Name>
	<Type>Single</Type>
	<Table>
		<Name>Station</Name>
		<Column>
			<Name>StationCode</Name>
			<DataType>System.String</DataType>
			<IsKey>true</IsKey>
			<IsAllowNull>false</IsAllowNull>
			<ColumnSize>50</ColumnSize>
		</Column>
		<Column>
			<Name>StationName</Name>
			<DataType>System.String</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>50</ColumnSize>
		</Column>
		<Column>
			<Name>UnitCode</Name>
			<DataType>System.String</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>50</ColumnSize>
		</Column>
		<Column>
			<Name>RoleCode</Name>
			<DataType>System.String</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>2000</ColumnSize>
		</Column>
		<Column>
			<Name>Description</Name>
			<DataType>System.String</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>400</ColumnSize>
		</Column>
		<Column>
			<Name>RoleLevel</Name>
			<DataType>System.Int32</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>4</ColumnSize>
		</Column>
		<Column>
			<Name>AccessRangeUnitCode</Name>
			<DataType>System.String</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>50</ColumnSize>
		</Column>
		<Column>
			<Name>AccessRangeUnitFullCode</Name>
			<DataType>System.String</DataType>
			<IsKey>false</IsKey>
			<IsAllowNull>true</IsAllowNull>
			<ColumnSize>50</ColumnSize>
		</Column>
		<Sql>
			<Name>Select</Name>
			<String>select * from Station where  StationCode=@StationCode</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@StationCode</Name>
				<Column>StationCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>SelectAll</Name>
			<String>select * from Station</String>
			<CommandType>Text</CommandType>
		</Sql>
		<Sql>
			<Name>Insert</Name>
			<String> Insert into Station (  StationCode, StationName, UnitCode, RoleCode, Description, RoleLevel, AccessRangeUnitCode, AccessRangeUnitFullCode ) values (  @StationCode, @StationName, @UnitCode, @RoleCode, @Description, @RoleLevel, @AccessRangeUnitCode, @AccessRangeUnitFullCode )</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@StationCode</Name>
				<Column>StationCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@StationName</Name>
				<Column>StationName</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@UnitCode</Name>
				<Column>UnitCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@RoleCode</Name>
				<Column>RoleCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@Description</Name>
				<Column>Description</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@RoleLevel</Name>
				<Column>RoleLevel</Column>
				<SqlDbType>Int</SqlDbType>
			</Param>
			<Param>
				<Name>@AccessRangeUnitCode</Name>
				<Column>AccessRangeUnitCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@AccessRangeUnitFullCode</Name>
				<Column>AccessRangeUnitFullCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>Update</Name>
			<String> Update Station set StationName=@StationName,UnitCode=@UnitCode,RoleCode=@RoleCode,Description=@Description,RoleLevel=@RoleLevel,AccessRangeUnitCode=@AccessRangeUnitCode,AccessRangeUnitFullCode=@AccessRangeUnitFullCode where  StationCode=@StationCode</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@StationCode</Name>
				<Column>StationCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@StationName</Name>
				<Column>StationName</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@UnitCode</Name>
				<Column>UnitCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@RoleCode</Name>
				<Column>RoleCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@Description</Name>
				<Column>Description</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@RoleLevel</Name>
				<Column>RoleLevel</Column>
				<SqlDbType>Int</SqlDbType>
			</Param>
			<Param>
				<Name>@AccessRangeUnitCode</Name>
				<Column>AccessRangeUnitCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
			<Param>
				<Name>@AccessRangeUnitFullCode</Name>
				<Column>AccessRangeUnitFullCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>Delete</Name>
			<String> Delete from Station  where  StationCode=@StationCode</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@StationCode</Name>
				<Column>StationCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>SelectByUnitCode</Name>
			<String>select * , dbo.GetStationUserCount(StationCode) as UserCount from Station where UnitCode=@UnitCode</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@UnitCode</Name>
				<Column>UnitCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>SelectByRoleCode</Name>
			<String>select * , dbo.GetStationUserCount(StationCode) as UserCount from Station where  ',' + RoleCode + ',' like '%,' + @RoleCode + ',%'</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@RoleCode</Name>
				<Column>RoleCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>SelectByUserCode</Name>
			<String>select * , dbo.GetStationUserCount(StationCode) as UserCount from Station where exists ( select 1 from UserRole where UserRole.StationCode = Station.StationCode and UserCode=@UserCode )</String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@UserCode</Name>
				<Column>UserCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
		<Sql>
			<Name>SelectByUnitAccess</Name>
			<String> select * from station where (( rolelevel=0 ) or ( rolelevel=3 and substring(@fullCode,1,len(accessRangeUnitFullCode)) = accessRangeUnitFullCode )) </String>
			<CommandType>Text</CommandType>
			<Param>
				<Name>@fullCode</Name>
				<Column>fullCode</Column>
				<SqlDbType>VarChar</SqlDbType>
			</Param>
		</Sql>
	</Table>
</Entity>