using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PMS.EntityModels.SysManager;
using QWPlatform.IService;
namespace PMS.DBService.SysManager
{
///
/// 按钮的数据层操作
///
public class ButtonDBService : DataServiceBase
{
///
/// 增加数据记录
///
///
///
public int Add(ButtonModel model)
{
model.SetDataFactory(this.DataFactoryObject);
return model.Insert();
}
///
/// 更新数据库记录
///
///
///
public int Update(ButtonModel model)
{
model.SetDataFactory(this.DataFactoryObject);
model.Where("ID");
return model.Update("名称", "标识", "图标", "序号", "颜色", "备注", "启用");
}
///
/// 删除数据记录
///
///
///
public int Delete(ButtonModel model)
{
model.SetDataFactory(this.DataFactoryObject);
return model.Delete("ID");
}
///
/// 查询数据对象并进行赋值
///
///
public ButtonModel Select(ButtonModel model)
{
model.SetDataFactory(this.DataFactoryObject);
model.Select();
return model;
}
///
/// 检查是否存在重复的tag
///
/// tag
/// id
///
public bool CheckNameExists(string tag, int id)
{
if (id > 0)
{//修改时查询
return this.SqlBuilder
.SqlText("select 1 from 系统按钮 where id <> :id and 标识=:标识")
.Exists();
}
else
{//新增时查询
return this.SqlBuilder
.SqlText("select 1 from 系统按钮 where 标识=:标识")
.Exists();
}
}
///
/// 读取所有按钮
///
///
///
public DataTable GetAllButtons(bool includeActive)
{
var selectBuilder = this.SelectBuilder
.Columns("*")
.From("系统按钮")
.OrderBy("序号 asc");
if (includeActive)
{//启用
return selectBuilder.Where("启用", 1)
.Select();
}
else
{//所有按钮
return selectBuilder.Select();
}
}
}
}