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

508 lines
19 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 sqxxxdDal
{
public List<sqxxxdModel> GetAllList(string id)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from sqxxxd where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
return conn.Query<sqxxxdModel>(sql, new { @id = id }).ToList();
}
}
public List<sqxxxdModel> GetAllListbycc(string ccsqd)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from sqxxxd where 1=1";
if (!string.IsNullOrEmpty(ccsqd))
{
sql += " and ccsqd=@ccsqd";
}
return conn.Query<sqxxxdModel>(sql, new { @ccsqd = ccsqd }).ToList();
}
}
public List<sqxxxdModel> GetAllList(string id, string zt)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from sqxxxd where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
if (!string.IsNullOrEmpty(zt))
{
sql += " and zt=@zt";
}
return conn.Query<sqxxxdModel>(sql, new { @id = id, @zt = zt }).ToList();
}
}
public string getCcsqds()
{
string sql = " select stuff((select distinct ','+CONVERT(varchar(20), ccsqd) from sqxxxd for xml path ('')),1,1,'') as ccsqds";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<string>(sql);
}
}
public object save(sqxxxdModel model)
{
string sql = "";
if (model.id == 0)
{
sql = @"INSERT INTO [dbo].[sqxxxd]
([sqdh]
,[sqsj]
,[sqrid]
,[sqr]
,[ksid]
,[ksmc]
,[xxsj]
,[xxdd]
,[cyry]
,[cyryids]
,[bz]
,[bz2]
,[bz3]
,[ccsqd]
,[zt]
,[sprid1]
,[spr1]
,[sprtime1]
,[spnr1]
,[sprid2]
,[spr2]
,[sprtime2]
,[spnr2]
,[sprid3]
,[spr3]
,[sprtime3]
,[spnr3]
,[sprid4]
,[spr4]
,[sprtime4]
,[spnr4])
VALUES
(@sqdh
,@sqsj
,@sqrid
,@sqr
,@ksid
,@ksmc
,@xxsj
,@xxdd
,@cyry
,@cyryids
,@bz
,@bz2
,@bz3
,@ccsqd
,@zt
,@sprid1
,@spr1
,@sprtime1
,@spnr1
,@sprid2
,@spr2
,@sprtime2
,@spnr2
,@sprid3
,@spr3
,@sprtime3
,@spnr3
,@sprid4
,@spr4
,@sprtime4
,@spnr4)";
}
else
{
sql = @"UPDATE [dbo].[sqxxxd]
SET [sqdh] = @sqdh
,[sqsj] = @sqsj
,[sqrid] = @sqrid
,[sqr] = @sqr
,[ksid] = @ksid
,[ksmc] = @ksmc
,[xxsj] = @xxsj
,[xxdd] = @xxdd
,[cyry] = @cyry
,[cyryids] = @cyryids
,[bz] = @bz
,[bz2] = @bz2
,[bz3] = @bz3
,[ccsqd] = @ccsqd
,[zt] = @zt
,[sprid1] = @sprid1
,[spr1] = @spr1
,[sprtime1] = @sprtime1
,[spnr1] = @spnr1
,[sprid2] = @sprid2
,[spr2] = @spr2
,[sprtime2] = @sprtime2
,[spnr2] = @spnr2
,[sprid3] = @sprid3
,[spr3] = @spr3
,[sprtime3] = @sprtime3
,[spnr3] = @spnr3
,[sprid4] = @sprid4
,[spr4] = @spr4
,[sprtime4] = @sprtime4
,[spnr4] = @spnr4
WHERE id=@id";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, model);
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 List<sqxxxdModel> getListBydh(string dh)
{
string sql = "select * from sqxxxd where sqdh in (@dh)";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<sqxxxdModel>(sql, new { dh = dh }).ToList();
}
}
public object opSave(string id, int ksid, string ksmc, string items, int sqrid, string sqr, string xxsj, string ccsj1, string ccsj2, string xxdd, string cyry, string cyryids, string bz, string bz2, string bz3, string isdb, string ccsqd, int zt)
{
string errmsg = "";
string sqdh = getckkdh(out errmsg);
if (errmsg != "")
return new { State = 0, Message = errmsg };
sqxxxdModel model = new sqxxxdModel();
model.sqdh = sqdh;
model.sqrid = sqrid;
model.sqr = sqr;
model.sqsj = DateTime.Now;
model.ksid = ksid;
model.ksmc = ksmc;
model.xxsj = Convert.ToDateTime(xxsj);
model.ccsj1 = Convert.ToDateTime(ccsj1);
model.ccsj2 = Convert.ToDateTime(ccsj2);
model.xxdd = xxdd;
model.cyry = cyry;
model.cyryids = cyryids;
model.bz = bz;
model.bz2 = bz2;
model.bz3 = bz3;
model.isdb = Convert.ToBoolean(isdb);
model.ccsqd = Convert.ToInt32(ccsqd);
model.zt = zt;
string sql = @"INSERT INTO [dbo].[sqxxxd]
([sqdh],[sqsj],[sqrid],[sqr],[ksid],[ksmc],[xxsj],[ccsj1],[ccsj2],[xxdd],[cyry],[cyryids],[bz],[bz2],[bz3],[isdb],[ccsqd],[zt])
VALUES
(@sqdh,@sqsj,@sqrid,@sqr,@ksid,@ksmc,@xxsj,@ccsj1,@ccsj2,@xxdd,@cyry,@cyryids,@bz,@bz2,@bz3,@isdb,@ccsqd,@zt)select SCOPE_IDENTITY()";
int sqdid = 0;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
sqdid = conn.Query<int>(sql, model).FirstOrDefault();
return new { State = 1, Message = "操作成功", id = sqdid };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public object opSave2(string id, int ksid, string ksmc, string items, int sqrid, string sqr, string xxsj, string ccsj1, string ccsj2, string xxdd, string cyry, string cyryids, string bz, string bz2, string bz3, string isdb, string ccsqd, int zt)
{
sqxxxdModel model = new sqxxxdModel();
model.id = Convert.ToInt32(id);
model.xxsj = Convert.ToDateTime(xxsj);
model.ccsj1 = Convert.ToDateTime(ccsj1);
model.ccsj2 = Convert.ToDateTime(ccsj2);
model.xxdd = xxdd;
model.cyry = cyry;
model.cyryids = cyryids;
model.bz = bz;
model.bz2 = bz2;
model.bz3 = bz3;
model.isdb = Convert.ToBoolean(isdb);
model.ccsqd = Convert.ToInt32(ccsqd);
model.zt = zt;
string sql = @"UPDATE [dbo].[sqxxxd]
SET [xxsj] = @xxsj,[xxsj1] = @xxsj1,[xxsj2] = @xxsj2,[xxdd] = @xxdd,[cyry] = @cyry,[cyryids] = @cyryids,[bz] = @bz,[bz2] = @bz2,[bz3] = @bz3,[isdb] = @isdb,[ccsqd] = @ccsqd,[zt] = @zt
WHERE id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
conn.Execute(sql, model);
return new { State = 1, Message = "操作成功" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public object opSp(string id, int sprid, string spr, string yj, bool ty)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql2 = "select * from sqxxxd where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql2 += " and id=@id";
}
sqxxxdModel model = conn.Query<sqxxxdModel>(sql2, new { @id = id }).FirstOrDefault();
if (model == null)
return new { State = 0, Message = "不存在记录" };
else
{
string sql = "";
int zt = 0;
switch (model.zt)
{
case 1:
sql = "update sqxxxd set sprid1=@sprid, spr1=@spr,sptime1=@sptime,spnr1=@spnr,zt=@zt where id=@id";
if (ty) { zt = 2; } else { zt = -1; }
break;
case 2:
sql = "update sqxxxd set sprid2=@sprid, spr2=@spr,sptime2=@sptime,spnr2=@spnr,zt=@zt where id=@id";
if (ty) { zt = 7; } else { zt = -2; }
break;
case 7:
sql = "update sqxxxd set sprid3=@sprid, spr3=@spr,sptime3=@sptime,spnr3=@spnr,zt=@zt where id=@id";
if (ty) { zt = 8; } else { zt = -7; }
break;
}
try
{
int result = conn.Execute(sql, new { @id = id, @sprid = sprid, @spr = spr, @sptime = DateTime.Now, @spnr = yj, @zt = zt });
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 opSpOneself(string id, int sprid, string spr, string yj, bool ty, string zw)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql2 = "select * from sqxxxd where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql2 += " and id=@id";
}
sqxxxdModel model = conn.Query<sqxxxdModel>(sql2, new { @id = id }).FirstOrDefault();
if (model == null)
return new { State = 0, Message = "不存在记录" };
else
{
string sql = "";
switch (zw)
{
case "科室领导":
sql = "update sqxxxd set sprid1=@sprid, spr1=@spr,sptime1=@sptime,spnr1=@spnr where id=@id";
break;
case "分管领导":
sql = "update sqxxxd set sprid2=@sprid, spr2=@spr,sptime2=@sptime,spnr2=@spnr where id=@id";
break;
}
try
{
int result = conn.Execute(sql, new { @id = id, @sprid = sprid, @spr = spr, @sptime = DateTime.Now, @spnr = yj });
if (result > 0)
{
return new { State = 1, Message = "修改成功" };
}
else
return new { State = 0, Message = "修改失败" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
}
//获取申请单号
private string getckkdh(out string errmsg)
{
errmsg = "";
string result = "";
string start = DateTime.Now.ToString("yyyyMM") + "0001";
string end = DateTime.Now.ToString("yyyyMM") + "9999";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select top 1 sqdh from sqxxxd where sqdh >= '" + start + "' and sqdh<= '" + end + "' order by id desc";
try
{
var result2 = conn.ExecuteScalar(sql);
if (result2 == null)
result = start;
else
{
result = (Convert.ToInt32(result2) + 1).ToString();
if (result == end)
errmsg = "单号不足!";
}
}
catch (Exception ex)
{
errmsg = ex.Message;
}
}
return result;
}
public object delete(string id)
{
string sql = "delete from sqxxxd 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 int getCount(string key)
{
string sql = "select count(1) from dbo.sqxxxd where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and ksid = @key";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { key = key });
}
}
public List<sqxxxdModel> getPage(int page, int pagesize, string key)
{
string sql = "select *,row_number() over(order by id desc) as rownum from sqxxxd where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and ksid = @key";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.sqxxxdModel>(sql, new { key = key }).ToList();
}
}
public int getCountLevel(string where)
{
string sql = "select count(1) from dbo.sqxxxd";
if (!string.IsNullOrEmpty(where))
{
sql += " where " + where;
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql);
}
}
public List<sqxxxdModel> getPageLevel(int page, int pagesize, string where)
{
string sql = "select *,row_number() over(order by id desc) as rownum from sqxxxd";
if (!string.IsNullOrEmpty(where))
{
sql += " where " + where;
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.sqxxxdModel>(sql).ToList();
}
}
public object insertXxxsSite(string title, string content)
{
string sql = @"INSERT INTO [dbo].[siteserver_Content_1]
([ChannelId],[SiteId],[AddUserName],[LastEditUserName],[LastEditDate],[AdminId],[UserId],[Taxis],[GroupNameCollection]
,[Tags],[SourceId],[ReferenceId],[IsChecked],[CheckedLevel],[Hits],[HitsByDay],[HitsByWeek],[HitsByMonth],[LastHitsDate]
,[Downloads],[SettingsXml],[Title],[IsTop],[IsRecommend],[IsHot],[IsColor],[LinkUrl],[AddDate]
,[SubTitle],[ImageUrl],[VideoUrl],[FileUrl],[Content],[Summary],[Author],[Source])
VALUES
(166, 1, 'admin', 'admin', @now, 0, 0, 1, '', '', 0, 0, 'True', 0, 0, 0, 0, 0, @now, 0, '', @title, 'False', 'False'
, 'False', 'False', '', @now, '', '', '', '', @content, '', '', '')";
using (IDbConnection conn = CommHelper.GetSqlConnection("SiteDB"))
{
try
{
int result = conn.Execute(sql, new { title = title, content = content, now = DateTime.Now });
return new { State = 1, Message = "操作成功!" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
}
}