2011-01-30 07:14:05 +00:00
using System ;
2011-12-05 09:41:02 +00:00
using Tanshu.Accounts.Entities ;
2011-01-30 07:14:05 +00:00
2011-01-31 20:33:22 +00:00
namespace Tanshu.Accounts.Repository
2011-01-30 07:14:05 +00:00
{
public static class DbValues
{
public static DateTime Date
{
get
{
using ( var session = SessionManager . Session )
{
var query = session . CreateSQLQuery ( "SELECT Getdate();" ) ;
return ( DateTime ) query . UniqueResult ( ) ;
}
}
}
public static string KotID
{
get
{
using ( var session = SessionManager . Session )
{
2011-04-11 12:55:45 +00:00
const string query = @"SELECT ISNULL('K-' + CAST(MAX(CAST(SUBSTRING(KotID, 3,8) AS int)) + 1 AS nvarchar(8)), 'K-1') FROM Entities_Vouchers" ;
2011-02-18 16:54:48 +00:00
var sqlQuery = session . CreateSQLQuery ( query ) ;
return ( string ) sqlQuery . UniqueResult ( ) ;
}
}
}
public static string KotCode
{
get
{
using ( var session = SessionManager . Session )
{
2011-04-11 12:55:45 +00:00
const string query = @"SELECT ISNULL('S-' + CAST(MAX(CAST(SUBSTRING(Code, 3,8) AS int)) + 1 AS nvarchar(8)), 'S-1') FROM Entities_Kots" ;
2011-01-30 07:14:05 +00:00
var sqlQuery = session . CreateSQLQuery ( query ) ;
return ( string ) sqlQuery . UniqueResult ( ) ;
}
}
}
2011-12-05 09:41:02 +00:00
public static string BillID ( VoucherType voucherType )
2011-01-30 07:14:05 +00:00
{
using ( var session = SessionManager . Session )
{
2011-12-05 09:41:02 +00:00
var query = "" ;
switch ( voucherType )
{
case VoucherType . Regular :
case VoucherType . TakeAway :
query = @ "
2011-01-30 07:14:05 +00:00
DECLARE @BillID nvarchar ( 10 )
2011-02-18 16:54:48 +00:00
SELECT @BillID = ISNULL ( CAST ( MAX ( CAST ( REPLACE ( BillID , '-' , ' ' ) AS int ) ) + 1 AS nvarchar ( 9 ) ) , ' 010001 ' ) FROM Entities_Vouchers WHERE BillID LIKE ' __ - ____ '
2011-12-05 09:41:02 +00:00
AND BillID NOT LIKE ' NC - % ' AND BillID NOT LIKE ' ST - % '
2011-01-30 07:14:05 +00:00
IF LEN ( @BillID ) = 5
SET @BillID = '0' + @BillID
SET @BillID = SUBSTRING ( @BillID , 1 , 2 ) + '-' + SUBSTRING ( @BillID , 3 , 7 )
IF SUBSTRING ( @BillID , 3 , 7 ) = ' - 0000 '
SET @BillID = SUBSTRING ( @BillID , 1 , 2 ) + ' - 0001 '
SELECT @BillID ";
2011-12-05 09:41:02 +00:00
break ;
case VoucherType . NoCharge :
query = @"SELECT ISNULL('NC-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'NC-1') FROM Entities_Vouchers WHERE BillID LIKE 'NC-%'" ;
break ;
case VoucherType . Staff :
query = @"SELECT ISNULL('ST-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'ST-1') FROM Entities_Vouchers WHERE BillID LIKE 'ST-%'" ;
break ;
default :
throw new ArgumentOutOfRangeException ( "voucherType" ) ;
}
2011-01-30 07:14:05 +00:00
var sqlQuery = session . CreateSQLQuery ( query ) ;
return ( string ) sqlQuery . UniqueResult ( ) ;
}
}
}
}