|
【小程序】【在线缴费系统】(五)管理端功能-缴费单位管理-数据库+逻辑处理
导读部分
教程目录:http://www.sufeinet.com/thread-40967-1-1.html
教程部分
数据库设计:
Model层:
[C#] 纯文本查看 复制代码 public class jiaofei_danwei
{
/// <summary>
/// id
/// </summary>
[OrmLiteField(IsPrimaryKey = true, InsertIgnore = true)]
public int id { get; set; }
/// <summary>
/// 父id
/// </summary>
public int parentid { get; set; }
/// <summary>
/// 排序值
/// </summary>
public int sort { get; set; }
/// <summary>
/// 单位名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 是否已删除(0否, 1是)
/// </summary>
public int is_del { get; set; }
/// <summary>
/// 父ids
/// </summary>
public string pids { get; set; }
/// <summary>
/// 单位登记
/// </summary>
public int levelnum { get; set; }
/// <summary>
/// 是否为叶子单位 (0否, 1是)
/// </summary>
public int isyezi { get; set; }
/// <summary>
/// 缴费时间
/// </summary>
public DateTime btime { get; set; }
/// <summary>
/// 缴费时间
/// </summary>
public DateTime etime { get; set; }
/// <summary>
/// 缴费时间规则
/// (0任何时间,1时间段, 2每天固定时间段)
/// </summary>
public int ruletype { get; set; }
/// <summary>
/// 每天固定时间段开始时间
/// </summary>
public int daybtime { get; set; }
/// <summary>
/// 每天固定时间段结束时间
/// </summary>
public int dayetime { get; set; }
/// <summary>
/// 添加时间
/// </summary>
[OrmLiteField(Ignore = true)]
public DateTime addtime { get; set; }
/// <summary>
/// 添加时间
/// </summary>
[OrmLiteField(Ignore = true)]
public string addtimestr { get { return addtime.ToString("yyyy-MM-dd HH:mm"); } }
/// <summary>
///
/// </summary>
[OrmLiteField(Ignore = true)]
public List<jiaofei_danwei> child { get; set; }
/// <summary>
/// 父名称
/// </summary>
[OrmLiteField(Ignore =true)]
public string p_name { get; set; }
[OrmLiteField(Ignore = true)]
public string btimestr { get { if (isyezi == 1) { return btime.ToString("yyyy-MM-dd HH:mm"); } return ""; } }
[OrmLiteField(Ignore = true)]
public string etimestr { get { if (isyezi == 1) { return etime.ToString("yyyy-MM-dd HH:mm"); } return ""; } }
/// <summary>
/// 缴费时间
/// </summary>
[OrmLiteField(Ignore =true)]
public string timerulestr {
get {
if (isyezi == 1) {
if (ruletype == 0) { return "随时可缴费"; }
else if (ruletype == 1) { return $"{btimestr} 至 {etimestr}"; }
else if (ruletype == 2) { return $"每天{daybtime}时 至 {dayetime}时"; }
}
return "";
}
}
BLL逻辑结构层:
[C#] 纯文本查看 复制代码 public class jiaofei_danweiBLL : BaseDAL<jiaofei_danwei>
{
/// <summary>
/// 数据库链接字符串
/// </summary>
protected override string ConnName
{
get { return DALConfig.Zaixianjiaofei; }
}
public bool istojiaofei(jiaofei_danwei danwei, DateTime dt)
{
// 0任何时间
if (danwei.ruletype == 0) { return true; }
// 1时间段
else if (danwei.ruletype == 1) { if ((dt - danwei.btime).TotalMinutes > 0 && (danwei.etime - dt).TotalMinutes > 0) { return true; } return false; }
// 2每天固定时间段
else if (danwei.ruletype == 2) {
DateTime btime = Convert.ToDateTime($"{dt.Date.ToString("yyyy-MM-dd")} {danwei.daybtime}:00");
DateTime etime = DateTime.Now;
if (danwei.dayetime == 24) { etime = Convert.ToDateTime($"{dt.Date.ToString("yyyy-MM-dd")} 23:59"); }
else { etime= Convert.ToDateTime($"{dt.Date.ToString("yyyy-MM-dd")} {danwei.dayetime}:00"); ; }
if ((dt - btime).TotalMinutes > 0 && (etime - dt).TotalMinutes > 0) { return true; }
return false;
}
return false;
}
/// <summary>
/// 获取单位信息
/// </summary>
/// <param name="ids_list"></param>
/// <returns></returns>
public List<jiaofei_danwei> GetList(List<string> ids_list) {
string danwei_ids = string.Join(",", ids_list.Select(l => l.TrimStart(',').TrimEnd(',')));
List<jiaofei_danwei> danwei_list = FindList($"SELECT id,name FROM dbo.jiaofei_danwei WHERE id IN({danwei_ids})") ?? new List<jiaofei_danwei>();
return danwei_list;
}
/// <summary>
/// 获取当前单位ids的单位名称
/// </summary>
/// <param name="danwei_list"></param>
/// <param name="ids"></param>
/// <returns></returns>
public List<string> GetDanwei(List<jiaofei_danwei> danwei_list, string ids)
{
List<string> item_danwei_list = new List<string>();
if (!string.IsNullOrEmpty(ids)) {
foreach (var danwei_id in ids.TrimStart(',').TrimEnd(',').Split(','))
{
jiaofei_danwei danwei = danwei_list.Find(d => d.id == InputHelper.GetInputInt(danwei_id));
if (danwei != null && danwei.id > 0) { item_danwei_list.Add(danwei.name); }
}
}
return item_danwei_list;
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public int Save(jiaofei_danwei info) {
// 获取当前单位是否存在子集
if (info.id > 0)
{
jiaofei_danwei c_info = FindListOne($"parentid={info.id} and is_del=0");
if (c_info != null && c_info.id > 0) { info.isyezi = 0; } else { info.isyezi = 1; }
}
else { info.isyezi = 1; }
int result = 0;
if (info.id > 0) { result = Update(info); }
else { result = (int)insert(info); }
if (result > 0 && info.isyezi == 1) {
// 修改当前叶子节点的所有父节点都为非叶子节点
ExecuteNonQuery(System.Data.CommandType.Text, $"UPDATE dbo.jiaofei_danwei SET isyezi=0 WHERE id={info.parentid}", null);
}
return result;
}
/// <summary>
/// 获取所有的单位
/// </summary>
/// <returns></returns>
public List<jiaofei_danwei> GetAll() {
List<jiaofei_danwei> ret_list = new List<jiaofei_danwei>();
// 获取当前所有
List<jiaofei_danwei> all_list = FindList($"is_del=0 ORDER BY sort DESC");
if (all_list != null && all_list.Any()) {
// 获取最大层级
int max_level = all_list.OrderByDescending(o => o.levelnum).FirstOrDefault().levelnum;
// 获取所有顶级分类
IEnumerable<jiaofei_danwei> p_list = all_list.Where(a => a.parentid == 0);
if (p_list != null && p_list.Any()) {
// 循环顶级,添加子类信息
foreach (var item in p_list)
{
// 循环处理子集信息
LoopToAppendChildren(all_list, item);
ret_list.Add(item);
}
}
}
return ret_list;
}
/// <summary>
/// 获取所有单位
/// </summary>
/// <returns></returns>
public List<dynamic> GetSelectAll() {
List<dynamic> ret_list = new List<dynamic>();
// 获取当前所有
List<jiaofei_danwei> all_list = FindList($"is_del=0 ORDER BY sort DESC");
if (all_list != null && all_list.Any())
{
// 获取最大层级
int max_level = all_list.OrderByDescending(o => o.levelnum).FirstOrDefault().levelnum;
// 获取所有顶级分类
IEnumerable<jiaofei_danwei> p_list = all_list.Where(a => a.parentid == 0);
if (p_list != null && p_list.Any())
{
// 循环顶级,添加子类信息
foreach (var item in p_list)
{
dynamic dy = new ExpandoObject();
dy.value = item.id;
dy.label = item.name;
// 循环处理子集信息
LoopToAppendSelectChildren(all_list, item, dy);
ret_list.Add(dy);
}
}
}
return ret_list;
}
private void LoopToAppendSelectChildren(List<jiaofei_danwei> all, jiaofei_danwei curItem, dynamic ret_dy)
{
List<dynamic> sub_dy_items = new List<dynamic>();
var subItems = all.Where(ee => ee.parentid == curItem.id);
if (subItems != null && subItems.Any())
{
foreach (var subItem in subItems)
{
dynamic sub_dy = new ExpandoObject();
sub_dy.value = subItem.id;
sub_dy.label = subItem.name;
LoopToAppendSelectChildren(all, subItem, sub_dy);//新闻1.1
sub_dy_items.Add(sub_dy);
}
}
else { subItems = new List<jiaofei_danwei>(); }
curItem.child = subItems.ToList();
if (sub_dy_items != null && sub_dy_items.Any()) { ret_dy.children = sub_dy_items; }
}
private void LoopToAppendChildren(List<jiaofei_danwei> all, jiaofei_danwei curItem)
{
var subItems = all.Where(ee => ee.parentid == curItem.id);
if (subItems != null && subItems.Any())
{
foreach (var subItem in subItems)
{
LoopToAppendChildren(all, subItem);//新闻1.1
}
}
curItem.child = subItems.ToList();
}
}
|
|