using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using WeiSha.Common;
using Song.Entities;
using WeiSha.Data;
using Song.ServiceInterfaces;
using System.Data.Common;
namespace Song.ServiceImpls
{
public class PayInterfaceCom :IPayInterface
{
///
/// 添加
///
/// 业务实体
public void PayAdd(PayInterface entity)
{
if (entity.Org_ID < 1)
{
Song.Entities.Organization org = Business.Do().OrganCurrent();
if (org != null)
{
entity.Org_ID = org.Org_ID;
}
}
//添加对象,并设置排序号
object obj = Gateway.Default.Max(PayInterface._.Pai_Tax, PayInterface._.Pai_Tax > -1 && PayInterface._.Org_ID == entity.Org_ID);
entity.Pai_Tax = obj is int ? (int)obj + 1 : 1;
Gateway.Default.Save(entity);
}
///
/// 修改
///
/// 业务实体
public void PaySave(PayInterface entity)
{
Gateway.Default.Save(entity);
}
///
/// 删除
///
/// 业务实体
public void PayDelete(PayInterface entity)
{
Gateway.Default.Delete(entity);
}
///
/// 删除,按主键ID;
///
/// 实体的主键
public void PayDelete(int identify)
{
Gateway.Default.Delete(PayInterface._.Pai_ID == identify);
}
///
/// 获取单一实体对象,按主键ID;
///
/// 实体的主键
///
public PayInterface PaySingle(int identify)
{
return Gateway.Default.From().Where(PayInterface._.Pai_ID == identify).ToFirst();
}
///
/// 获取所有;
///
/// 机构id
/// 接口平台,电脑为web,手机为mobi
/// 是否允许
///
public PayInterface[] PayAll(int orgid, string platform, bool? isEnable)
{
WhereClip wc = new WhereClip();
if (orgid > -1) wc.And(PayInterface._.Org_ID == orgid);
if (!string.IsNullOrWhiteSpace(platform)) wc &= PayInterface._.Pai_Platform == platform.ToLower();
if (isEnable != null) wc.And(PayInterface._.Pai_IsEnable == (bool)isEnable);
return Gateway.Default.From().Where(wc).OrderBy(PayInterface._.Pai_Tax.Asc).ToArray();
}
///
/// 当前对象名称是否重名
///
/// 业务实体
///
public PayInterface PayIsExist(int orgid, PayInterface entity)
{
PayInterface mm = null;
WhereClip wc = new WhereClip();
if (orgid > -1) wc.And(PayInterface._.Org_ID == orgid);
mm = Gateway.Default.From()
.Where(PayInterface._.Org_ID == orgid && PayInterface._.Pai_Name == entity.Pai_Name && PayInterface._.Pai_ID != entity.Pai_ID)
.ToFirst();
return mm;
}
///
/// 将当前项目向上移动;仅在当前对象的同层移动,即同一父节点下的对象这前移动;
///
///
/// 如果已经处于顶端,则返回false;移动成功,返回true
public bool PayRemoveUp(int id)
{
//当前对象
PayInterface current = Gateway.Default.From().Where(PayInterface._.Pai_ID == id).ToFirst();
//当前对象排序号
int orderValue = (int)current.Pai_Tax; ;
//上一个对象,即兄长对象;
PayInterface up = Gateway.Default.From().Where(PayInterface._.Pai_Tax < orderValue)
.OrderBy(PayInterface._.Pai_Tax.Desc).ToFirst();
if (up == null) return false;
//交换排序号
current.Pai_Tax = up.Pai_Tax;
up.Pai_Tax = orderValue;
using (DbTrans tran = Gateway.Default.BeginTrans())
{
try
{
tran.Save(current);
tran.Save(up);
tran.Commit();
}
catch
{
tran.Rollback();
throw;
}
finally
{
tran.Close();
}
}
return true;
}
///
/// 将当前项目向下移动;仅在当前对象的同层移动,即同一父节点下的对象这前移动;
///
///
/// 如果已经处于顶端,则返回false;移动成功,返回true
public bool PayRemoveDown(int id)
{
//当前对象
PayInterface current = Gateway.Default.From().Where(PayInterface._.Pai_ID == id).ToFirst();
//当前对象排序号
int orderValue = (int)current.Pai_Tax;
//下一个对象,即弟弟对象;
PayInterface down = Gateway.Default.From().Where(PayInterface._.Pai_Tax > orderValue)
.OrderBy(PayInterface._.Pai_Tax.Asc).ToFirst();
if (down == null) return false;
//交换排序号
current.Pai_Tax = down.Pai_Tax;
down.Pai_Tax = orderValue;
using (DbTrans tran = Gateway.Default.BeginTrans())
{
try
{
tran.Save(current);
tran.Save(down);
tran.Commit();
}
catch
{
tran.Rollback();
throw;
}
finally
{
tran.Close();
}
}
return true;
}
}
}