using Model.ModelDto.SysDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IDAL;
using WMS.IDAL.ISysInterface;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
namespace WMS.DAL.SysInfrastructure
{
///
/// 功能设定仓储实践
///
public class FunSettingRepository : BaseRepository, IFunSettingRepository
{
private static readonly SqlSugarScope Db = DataContext.Db;
public FunSettingRepository() : base(Db)
{
}
///
/// 获取功能设定信息列表
///
/// 功能名称
/// 开启状态
/// 组号
///
public List GetFunSettingList(string FunSetName, string IsEnable, string GroupNo)
{
string str = "select setting.*,user1.RealName CreateName from SysFunSetting setting left join SysUserInfor user1 on setting.CreateUser = user1.Id where setting.IsDel = @isdel";
//判断功能名称是否为空
if (!string.IsNullOrEmpty(FunSetName))
{
str += " and setting.FunSetName like @funsetname";
}
//判断开启状态
if (!string.IsNullOrEmpty(IsEnable))
{
str += " and setting.IsEnable = @isenable";
}
//判断组号
if (!string.IsNullOrEmpty(GroupNo))
{
str += " and setting.GroupNo like @groupno";
}
//排序
str += " order by setting.GroupNo,setting.Ord,setting.Id";
List settinglist = Db.Ado.SqlQuery(str, new
{
isdel = "0", //是否删除
funsetname = "%" + FunSetName + "%", //功能名称
isenable = IsEnable, //开启状态
groupno = "%" + GroupNo + "%" //组号
});
return settinglist;
}
///
/// 根据id查询功能设定信息
///
/// 功能id
///
public SysFunSetting GetFunSettingById(int id)
{
string str = "select * from SysFunSetting where IsDel = @isdel and Id = @id";
SysFunSetting settinglist = Db.Ado.SqlQuery(str, new
{
isdel = "0",
id
}).First();
return settinglist;
}
/////
///// 根据编号查询功能设定信息
/////
///// 功能编号
/////
//public List GetFunSettingByNo(string FunSetNo)
//{
// string str = "select * from SysFunSetting where FunSetNo = @funsetno";
// List settinglist = Db.Ado.SqlQuery(str, new
// {
// funsetno = FunSetNo //功能编号
// });
// return settinglist;
//}
///
/// 新增功能信息
///
/// 功能设定实体
///
public async Task AddFunSettings(SysFunSetting setting)
{
if (setting.FunSetNo == "Fun013")
{
if (int.Parse(setting.SetValue) < 5 || int.Parse(setting.SetValue) > 200)
{
throw new Exception("该功能必须为5到200之间");
}
}
string str = "insert into sysfunsetting values(@funsetno, @funsetname, @setvalue, @funtext, @isenable, @ord, @groupno, @isdel, @createtime, @createuser, null, null)";
string sql = "select * from SysFunSetting where FunSetNo = @funsetno and Ord = @ord and IsDel = @isdel";
SysFunSetting sett = new SysFunSetting();
if (!string.IsNullOrEmpty(setting.GroupNo))
{
sett = Db.Ado.SqlQuerySingle(sql, new
{
funsetno = setting.GroupNo, //组号
ord = "1", //显示顺序
isdel = "0" //是否删除
});
}
int i;
//获取当前组显示顺序
//string sql = "select max(ord) Ord from SysFunSetting where GroupNo = @groupno and IsDel = @isdel";
//判断显示顺序数量是否符合
if (Convert.ToInt32(setting.Ord) <= 5 && Convert.ToInt32(setting.Ord) >= 1)
{
if (sett != null || !string.IsNullOrEmpty(setting.GroupNo))
{
string sql1 = "select Count(IsEnable) IsEnable from SysFunSetting where GroupNo = @group and IsDel = @isdel and IsEnable = @isenable";
SysFunSetting count = Db.Ado.SqlQuerySingle(sql1, new
{
group = setting.GroupNo, //组号
isdel = "0", //是否删除
isenable = "No" //是否开启 每一组只能有一个开启
});
if (count.IsEnable == "0" || setting.IsEnable == "OFF")
{
i = await Db.Ado.ExecuteCommandAsync(str, new
{
funsetno = setting.FunSetNo, //功能编号
funsetname = setting.FunSetName, //功能名称
setvalue = setting.SetValue, //设定值
funtext = setting.FunText, //功能描述
isenable = setting.IsEnable, //是否开启
ord = setting.GroupNo == "" ? "1" : setting.Ord,
groupno = setting.GroupNo == "" ? setting.FunSetNo : setting.GroupNo, //组号 判断表单组号是否为空 是 当前编号 否 输入组号
isdel = "0", //是否删除
createtime = Db.GetDate(), //创建时间
createuser = setting.CreateUser //创建人
});
}
else
{
i = 6;
}
}
else
{
i = 5;
}
}
else
{
i = 4;
}
return i;
}
///
/// 删除功能信息
///
/// 功能设定实体
///
public async Task DelFunSettings(SysFunSetting setting)
{
string str = "update SysFunSetting set IsDel = @isdel,UpdateTime = @updatetime,UpdateUser = @updateuser where id = @id";
int i = await Db.Ado.ExecuteCommandAsync(str, new
{
isdel = "1", //是否删除
updatetime = Db.GetDate(), //更改时间
updateuser = setting.CreateUser, //更改人
id = setting.Id //id
});
return i;
}
///
/// 编辑功能信息
///
/// 功能设定实体
///
public async Task ExitFunSettings(SysFunSetting setting)
{
if (setting.FunSetNo == "Fun013")
{
if (int.Parse(setting.SetValue) < 5 || int.Parse(setting.SetValue) > 200)
{
throw new Exception("该功能必须为5到200之间");
}
}
string str = "update SysFunSetting set FunSetName = @funsetname, SetValue = @setvalue, FunText = @funtext, IsEnable = @isenable, Ord = @ord, GroupNo = @groupno, UpdateTime = @updatetime,UpdateUser = @updateuser where id = @id";
int i;
string sql1 = "select Count(IsEnable) IsEnable from SysFunSetting where GroupNo = @group and IsDel = @isdel and IsEnable = @isenable and Id!= @id ";
SysFunSetting count = Db.Ado.SqlQuerySingle(sql1, new
{
group = setting.GroupNo, //组号
isdel = "0", //是否删除
isenable = "No", //是否开启 每一组只能有一个开启
id = setting.Id
});
if (count.IsEnable == "0" || setting.IsEnable == "OFF")
{
i = await Db.Ado.ExecuteCommandAsync(str, new
{
funsetname = setting.FunSetName, //功能名称
setvalue = setting.SetValue, //设定值
funtext = setting.FunText, //功能描述
isenable = setting.IsEnable, //是否开启
ord = setting.Ord, //显示顺序
groupno = setting.GroupNo, //组号
updatetime = Db.GetDate(), //更改时间
updateuser = setting.CreateUser, //更改人
id = setting.Id //id
});
}
else
{
i = 6;
}
return i;
}
}
}