2011-01-30 07:14:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Tanshu.Accounts.Contracts;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using Tanshu.Data.DAO;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using Tanshu.Accounts.SqlDAO;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
using NHibernate;
|
2011-02-18 16:54:48 +00:00
|
|
|
|
using NHibernate.Criterion;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public class FoodTableBI : IDisposable
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
ISession session;
|
2011-02-18 16:54:48 +00:00
|
|
|
|
bool disposeSession;
|
|
|
|
|
bool useTransaction;
|
|
|
|
|
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public FoodTableBI()
|
|
|
|
|
{
|
|
|
|
|
this.session = SessionManager.Session;
|
2011-02-18 16:54:48 +00:00
|
|
|
|
disposeSession = true;
|
|
|
|
|
this.useTransaction = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FoodTableBI(ISession session)
|
|
|
|
|
{
|
|
|
|
|
this.session = session;
|
|
|
|
|
disposeSession = false;
|
|
|
|
|
this.useTransaction = false;
|
|
|
|
|
}
|
|
|
|
|
public FoodTableBI(ISession session, bool useTransaction)
|
|
|
|
|
{
|
|
|
|
|
this.session = session;
|
|
|
|
|
disposeSession = false;
|
|
|
|
|
this.useTransaction = useTransaction;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public void Insert(FoodTable foodTable)
|
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
session.Save(foodTable);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
public void Update(FoodTable foodTable)
|
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
session.Update(foodTable);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
public void Delete(int foodTableID)
|
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
session.Delete(new FoodTable() { FoodTableID = foodTableID });
|
|
|
|
|
}
|
|
|
|
|
public FoodTable Get(int foodTableID)
|
|
|
|
|
{
|
|
|
|
|
return session.Get<FoodTable>(foodTableID);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public FoodTable GetByName(string name)
|
|
|
|
|
{
|
|
|
|
|
return session.CreateCriteria<FoodTable>()
|
|
|
|
|
.Add(Restrictions.Eq("Name", name))
|
|
|
|
|
.UniqueResult<FoodTable>();
|
|
|
|
|
}
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public IList<FoodTable> List()
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return session.CreateCriteria<FoodTable>().List<FoodTable>();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public void UpdateStatus(string name, int voucherID, string status)
|
|
|
|
|
{
|
|
|
|
|
if (!useTransaction)
|
|
|
|
|
using (var trans = session.BeginTransaction())
|
|
|
|
|
{
|
|
|
|
|
var table = session.CreateCriteria<FoodTable>()
|
|
|
|
|
.Add(Restrictions.Eq("Name", name))
|
|
|
|
|
.UniqueResult<FoodTable>();
|
|
|
|
|
if (table == null)
|
|
|
|
|
return;
|
|
|
|
|
if (status == null || status == string.Empty)
|
|
|
|
|
table.VoucherID = 0;
|
|
|
|
|
else
|
|
|
|
|
table.VoucherID = voucherID;
|
|
|
|
|
table.Status = status;
|
|
|
|
|
session.Update(table);
|
|
|
|
|
trans.Commit();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var table = session.CreateCriteria<FoodTable>()
|
|
|
|
|
.Add(Restrictions.Eq("Name", name))
|
|
|
|
|
.UniqueResult<FoodTable>();
|
|
|
|
|
if (status == null || status == string.Empty)
|
|
|
|
|
table.VoucherID = 0;
|
|
|
|
|
else
|
|
|
|
|
table.VoucherID = voucherID;
|
|
|
|
|
table.Status = status;
|
|
|
|
|
session.Update(table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public void Dispose()
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
if (disposeSession)
|
|
|
|
|
session.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Move(string name, FoodTable foodTable)
|
|
|
|
|
{
|
|
|
|
|
using (var trans = session.BeginTransaction())
|
|
|
|
|
{
|
|
|
|
|
var oldTable = session.CreateCriteria<FoodTable>()
|
|
|
|
|
.Add(Restrictions.Eq("Name", name))
|
|
|
|
|
.UniqueResult<FoodTable>();
|
|
|
|
|
foodTable.Status = oldTable.Status;
|
|
|
|
|
foodTable.VoucherID = oldTable.VoucherID;
|
|
|
|
|
oldTable.Status = null;
|
|
|
|
|
oldTable.VoucherID = 0;
|
|
|
|
|
session.Merge(foodTable);
|
|
|
|
|
session.Update(oldTable);
|
|
|
|
|
|
|
|
|
|
var voucher = session.Get<Voucher>(foodTable.VoucherID);
|
|
|
|
|
voucher.TableID = foodTable.Name;
|
|
|
|
|
session.Update(voucher);
|
|
|
|
|
trans.Commit();
|
|
|
|
|
return voucher.VoucherID;
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|