tijian_tieying/web/dccdc.DAL/ExamGroupLocalMaintainDal.cs
2025-02-20 12:14:39 +08:00

135 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using dccdc.Models;
namespace dccdc.DAL
{
public class ExamGroupLocalMaintainDal
{
/// <summary>
/// 根据id删除小组位置
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public object del(string id)
{
string sql = @"delete exam_group_local_maintain where id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int c = conn.Execute(sql, new { id = id });
if (c > 0)
{
return new { State = 1, Message = "操作成功!" };
}
else
{
return new { State = 0, Message = "操作失败,请联系管理员!" };
}
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public int getCount(string key)
{
string sql = "select count(1) from dbo.exam_group_local_maintain where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and (team_name like @team_name)";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { team_name = "%" + key + "%" });
}
}
/// <summary>
/// 根据小组名称查询小组位置列表
/// </summary>
/// <param name="page"></param>
/// <param name="pagesize"></param>
/// <param name="key"></param>
/// <returns></returns>
public List<ExamGroupLocalMaintain> getList(int page, int pagesize, string key)
{
string sql = "select *,row_number() over(order by id desc) as rownum from exam_group_local_maintain where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and (team_name like @team_name)";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.ExamGroupLocalMaintain>(sql, new { team_name = "%" + key + "%" }).ToList();
}
}
public object save(ExamGroupLocalMaintain ct, ERPUser user)
{
ct.creator = user.TrueName;
ct.create_time = DateTime.Now.ToString("yyyy-MM-dd");
string sql = "";
if (ct.id == 0)
{
sql = @"INSERT INTO [dbo].[exam_group_local_maintain]
([team_name]
,[exam_group_maintain_id]
,[check_room]
,[status]
,[creator]
,[create_time])
VALUES
(@team_name
,@exam_group_maintain_id
,@check_room
,@status
,@creator
,@create_time )
";
}
else
{
sql = @"UPDATE [dbo].[exam_group_local_maintain]
SET [team_name] = @team_name
,[exam_group_maintain_id] = @exam_group_maintain_id
,[check_room] = @check_room
,[status] = @status
WHERE id=@id
";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int c = conn.Execute(sql, ct);
if (c > 0)
{
return new { State = 1, Message = "保存成功!" };
}
else
{
return new { State = 0, Message = "操作失败,请联系管理员!" };
}
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
}
}