0172fc4e01
Added Nc Option in settlement Merged Vouchers and SaleVoucher table. Need to update the Sql Schema
93 lines
3.7 KiB
C#
93 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Data.DAO;
|
|
|
|
|
|
namespace Tanshu.Accounts.SqlDAO
|
|
{
|
|
public class WaiterDAO : BaseDAO
|
|
{
|
|
public WaiterDAO(IConnectionDAO connection)
|
|
|
|
: base(connection)
|
|
{ }
|
|
public bool Insert(WaiterBO waiter)
|
|
{
|
|
using (SqlCommand cmd = new SqlCommand(@"
|
|
SELECT @WaiterID = NEWID(), @Code = ISNULL(MAX(Code), 0) + 1 FROM Waiters;
|
|
INSERT INTO Waiters (WaiterID, Code, Name) VALUES (@WaiterID, @Code, @Name);
|
|
"))
|
|
{
|
|
cmd.Parameters.Add("@WaiterID", System.Data.SqlDbType.UniqueIdentifier);
|
|
cmd.Parameters["@WaiterID"].Direction = System.Data.ParameterDirection.Output;
|
|
cmd.Parameters.Add("@Code", System.Data.SqlDbType.Int);
|
|
cmd.Parameters["@Code"].Direction = System.Data.ParameterDirection.Output;
|
|
cmd.Parameters.AddWithValue("@Name", waiter.Name);
|
|
connection.ExecuteNonQuery(cmd);
|
|
waiter.WaiterID = (Guid)cmd.Parameters["@WaiterID"].Value;
|
|
waiter.Code = (int)cmd.Parameters["@Code"].Value;
|
|
return true;
|
|
}
|
|
}
|
|
public bool Update(WaiterBO waiter)
|
|
{
|
|
using (SqlCommand cmd = new SqlCommand(@"
|
|
UPDATE Waiters SET Name = @Name, Code = @Code WHERE WaiterID = @WaiterID;
|
|
"))
|
|
{
|
|
cmd.Parameters.AddWithValue("@WaiterID", waiter.WaiterID);
|
|
cmd.Parameters.AddWithValue("@Code", waiter.Code);
|
|
cmd.Parameters.AddWithValue("@Name", waiter.Name);
|
|
connection.ExecuteNonQuery(cmd);
|
|
return true;
|
|
}
|
|
}
|
|
public bool Delete(Guid waiterID)
|
|
{
|
|
bool result;
|
|
using (SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM Voucher WHERE WaiterID = @WaiterID"))
|
|
{
|
|
cmd.Parameters.AddWithValue("@WaiterID", waiterID);
|
|
result = 0 == (int)connection.ExecuteScalar(cmd);
|
|
}
|
|
if (result == false)
|
|
return false;
|
|
using (SqlCommand cmd = new SqlCommand("DELETE FROM Waiters WHERE WaiterID = @WaiterID"))
|
|
{
|
|
cmd.Parameters.AddWithValue("@WaiterID", waiterID);
|
|
connection.ExecuteNonQuery(cmd);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public WaiterBO GetWaiter(Guid waiterID)
|
|
{
|
|
SqlCommand cmd = new SqlCommand("SELECT * FROM Waiters WHERE WaiterID = @WaiterID");
|
|
cmd.Parameters.AddWithValue("@WaiterID", waiterID);
|
|
return BusinessObjectDAO<WaiterBO>.GetBusinessObject(connection.ExecuteReader(cmd));
|
|
}
|
|
public WaiterBO GetWaiter(int code)
|
|
{
|
|
SqlCommand cmd = new SqlCommand("SELECT * FROM Waiters WHERE Code = @Code");
|
|
cmd.Parameters.AddWithValue("@Code", code);
|
|
return BusinessObjectDAO<WaiterBO>.GetBusinessObject(connection.ExecuteReader(cmd));
|
|
}
|
|
|
|
public List<WaiterBO> GetWaiters()
|
|
{
|
|
return BusinessObjectDAO<WaiterBO>.GetBusinessObjects(connection.ExecuteReader("SELECT * FROM Waiters ORDER BY Name"));
|
|
}
|
|
public List<WaiterBO> GetFilteredWaiters(Dictionary<string, string> filter)
|
|
{
|
|
string name = string.Format("%{0}%", filter["Name"].Trim());
|
|
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Waiters WHERE Name LIKE @Name ORDER BY Name"))
|
|
{
|
|
cmd.Parameters.AddWithValue("@Name", name);
|
|
return BusinessObjectDAO<WaiterBO>.GetBusinessObjects(connection.ExecuteReader(cmd));
|
|
}
|
|
}
|
|
}
|
|
}
|