107 lines
3.6 KiB
C#
107 lines
3.6 KiB
C#
using Dapper;
|
|
using dccdc.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace dccdc.DAL
|
|
{
|
|
public class sqfileDal
|
|
{
|
|
public List<sqfileModel> GetAllList()
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<sqfileModel>("select * from sqfile ").ToList();
|
|
}
|
|
}
|
|
|
|
//sqid=0 要加上用户id 存在sqid就不需要用户id
|
|
public List<sqfileModel> GetListByKey(string type, string sqid, string sqrid)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from sqfile where type=@type and sqid =@sqid";
|
|
if (sqid == "0")
|
|
sql = "select * from sqfile where type=@type and sqid =@sqid and sqrid =@sqrid";
|
|
return conn.Query<sqfileModel>(sql, new { type = type, sqid = sqid, sqrid = sqrid }).ToList();
|
|
}
|
|
}
|
|
|
|
public bool Add(sqfileModel model)
|
|
{
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"INSERT INTO [dbo].[sqfile]
|
|
([type]
|
|
,[sqid]
|
|
,[sqrid]
|
|
,[addtime]
|
|
,[title]
|
|
,[filepath]
|
|
,[downlog])
|
|
VALUES
|
|
(@type
|
|
,@sqid
|
|
,@sqrid
|
|
,@addtime
|
|
,@title
|
|
,@filepath
|
|
,@downlog)";
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
|
|
public object delete(string id)
|
|
{
|
|
string sql = "delete from sqfile where id=@id";
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int result = conn.Execute(sql, new { id = id });
|
|
if (result > 0)
|
|
{
|
|
return new { State = 1, Message = "操作成功!" };
|
|
}
|
|
else
|
|
return new { State = 0, Message = "操作失败!" };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
|
|
public object savelog(string ids, string username)
|
|
{
|
|
string log = username + ":" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "|";
|
|
string sql = "update sqfile set downlog = downlog + '" + log + "' where id in (" + ids + ")";
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int result = conn.Execute(sql, new { ids = ids });
|
|
if (result > 0)
|
|
{
|
|
return new { State = 1, Message = "操作成功!" };
|
|
}
|
|
else
|
|
return new { State = 0, Message = "操作失败!" };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|