282 lines
12 KiB
C#
282 lines
12 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 JiezhongmianyitiaomaDal
|
|
{
|
|
public int getCount(string key)
|
|
{
|
|
string sql = "select count(1) from dbo.jiezhongmianyi_tiaomadayin where 1=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and (barcode like @barcode)";
|
|
}
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.ExecuteScalar<int>(sql, new { barcode = "%" + key + "%" });
|
|
}
|
|
}
|
|
|
|
public List<JiezhongmianyitiaomaModel> GetAllList(string id)
|
|
{
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from jiezhongmianyi_tiaomadayin where 1=1 ";
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
if (id.Length > 8)
|
|
{
|
|
param += " and barcode=@id";
|
|
}
|
|
else
|
|
{
|
|
param += " and id=@id";
|
|
}
|
|
|
|
}
|
|
|
|
return conn.Query<JiezhongmianyitiaomaModel>(sql + param, new { id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
public List<BDXX> getListByopenid(string session)
|
|
{
|
|
//throw new NotImplementedException();
|
|
string sql = "select * from bdxx where openid=@openid";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<BDXX>(sql, new { openid = session }).ToList();
|
|
}
|
|
}
|
|
|
|
public List<JiezhongmianyitiaomaModel> getetlistbybdxx(string session)
|
|
{
|
|
//throw new NotImplementedException();
|
|
string sql = "select a.* from jiezhongmianyi_tiaomadayin a join bdxx b on a.id=b.etid where b.openid=@openid";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<JiezhongmianyitiaomaModel>(sql, new { openid = session }).ToList();
|
|
}
|
|
}
|
|
|
|
public JiezhongmianyitiaomaModel getetxx(string etid, string v)
|
|
{
|
|
//throw new NotImplementedException();
|
|
string sql = "select a.id,a.sfz,a.barcode,b.jzxm,b.sfzh,b.lxdh from jiezhongmianyi_tiaomadayin a join bdxx b on a.id=b.etid where a.id=@etid and b.openid=@openid";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<JiezhongmianyitiaomaModel>(sql, new { etid = etid, openid = v }).FirstOrDefault();
|
|
}
|
|
|
|
}
|
|
|
|
public wdpd getpdxx(string session)
|
|
{
|
|
//throw new NotImplementedException();
|
|
string sql = "";
|
|
using (var conn = CommHelper.GetSqlConnection())
|
|
{
|
|
sql = "select top 1 * from pd_xx where rq>@rq and jhbz=1 order by hm desc";
|
|
var dq = conn.Query<Models.PD_XX>(sql, new { rq = DateTime.Now.Date }).FirstOrDefault();
|
|
sql = "select a.* from pd_xx a join bdxx b on a.etid=b.etid and b.openid=@openid where a.rq>@rq and a.jhbz=0";
|
|
var m = conn.Query<Models.PD_XX>(sql, new { openid = session, rq = DateTime.Now.Date }).FirstOrDefault();
|
|
if (m == null)
|
|
return new wdpd { ddrs = 0, wdhm = 0, dqhm = dq.hm };
|
|
sql = "select count(1) from pd_xx where hm<@hm and rq>@rq and jhbz=0";
|
|
var c = conn.ExecuteScalar<int>(sql, new { m.hm, rq=DateTime.Now.Date });
|
|
|
|
if (dq == null)
|
|
{
|
|
return new wdpd { ddrs = c, wdhm = m.hm, dqhm = 0 };
|
|
}
|
|
return new wdpd { ddrs = c, wdhm = m.hm, dqhm = dq.hm };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断儿童信息是否可以绑定
|
|
/// </summary>
|
|
/// <param name="username">儿童姓名</param>
|
|
/// <param name="barcode">接种条码</param>
|
|
/// <param name="yetgx">家长与儿童关系</param>
|
|
/// <param name="openid">微信opendi</param>
|
|
/// <returns></returns>
|
|
public OperationResult checkBarcode(string username, string barcode, string yetgx, string openid)
|
|
{
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from jiezhongmianyi_tiaomadayin where 1=1 and barcode=@barcode and username=@username";
|
|
//int c= conn.ExecuteScalar<int>(sql, new { username=username,barcode=barcode });
|
|
var m = conn.Query<Models.jingfeilbModel>(sql, new { barcode, username }).FirstOrDefault();
|
|
if (m == null)
|
|
{
|
|
return new OperationResult { State = 0, Message = "没有查到您要绑定的儿童信息!" };
|
|
}
|
|
else
|
|
{
|
|
sql = "select count(1) from bdxx where etid=@etid and (yetgx=@yetgx or openid=@openid)";
|
|
int c = conn.ExecuteScalar<int>(sql, new { etid = m.id, yetgx = yetgx, openid = openid });
|
|
if (c > 0)
|
|
{
|
|
return new OperationResult { State = 0, Message = "已经有与此儿童绑定的家长信息,不能重复绑定!" };
|
|
}
|
|
else
|
|
{
|
|
return new OperationResult { State = 1, Message = "" };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<JiezhongmianyitiaomaModel> getList(int page, int pagesize, string key)
|
|
{
|
|
string sql = "select *,row_number() over(order by id) as rownum from jiezhongmianyi_tiaomadayin where 1=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and (barcode like @barcode)";
|
|
}
|
|
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<Models.JiezhongmianyitiaomaModel>(sql, new { barcode = "%" + key + "%" }).ToList();
|
|
}
|
|
}
|
|
|
|
public OperationResult bd(JiezhongmianyitiaomaModel model)
|
|
{
|
|
//string czsql= "select count(1) from jiezhongmianyi_tiaomadayin"
|
|
|
|
string sql = "update [dbo].[jiezhongmianyi_tiaomadayin] set [sjh]=@sjh,[sfz]=@sfz,[jzxm]=@jzxm,[jzsfz]=@jzsfz,[openid]=@openid where username = @username and barcode=@barcode";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int c = conn.Execute(sql, model);
|
|
sql = "select * from jiezhongmianyi_tiaomadayin where username = @username and barcode=@barcode";
|
|
var m = conn.Query<Models.JiezhongmianyitiaomaModel>(sql, model).FirstOrDefault();
|
|
if (m == null)
|
|
{
|
|
return new OperationResult { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
sql = @"insert into bdxx(etid,jzxm,yetgx,lxdh,sfzh,openid,bdsj) values(@etid,@jzxm,@yetgx,@lxdh,@sfzh,@openid,@bdsj)";
|
|
c = conn.Execute(sql, new { etid = m.id, jzxm = model.jzxm, yetgx = model.yetgx, lxdh = model.sjh, sfzh = model.jzsfz, openid = model.openid, bdsj = DateTime.Now });
|
|
if (c > 0)
|
|
{
|
|
return new OperationResult { State = 1, Message = "操作成功" };
|
|
}
|
|
else
|
|
{
|
|
return new OperationResult { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new OperationResult { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
|
|
public OperationResult jb(string id, string openid)
|
|
{
|
|
string sql = "";// "update [dbo].[jiezhongmianyi_tiaomadayin] set openid='' where id = @id";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
//int c = conn.Execute(sql, new { id = id });
|
|
sql = "delete from bdxx where openid=@openid and etid=@etid";
|
|
int c = conn.Execute(sql, new { etid = id, openid });
|
|
if (c > 0)
|
|
{
|
|
return new OperationResult { State = 1, Message = "操作成功" };
|
|
}
|
|
else
|
|
{
|
|
return new OperationResult { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new OperationResult { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public object save(JiezhongmianyitiaomaModel jzmytm)
|
|
{
|
|
List<JiezhongmianyitiaomaModel> list = this.GetAllList(jzmytm.id.ToString());
|
|
string sql = "";
|
|
string mess = "";
|
|
if (list != null && list.Count > 0)
|
|
{
|
|
sql = "update [dbo].[jiezhongmianyi_tiaomadayin] set [barcode]=@barcode,[username]=@username,[sjh]=@sjh,[csrq]=@csrq,[jdid]=@jdid where id = " + jzmytm.id;
|
|
mess = "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
sql = "INSERT INTO [dbo].[jiezhongmianyi_tiaomadayin]([barcode],[username],[sjh],[csrq],[jdid])VALUES(@barcode,@username,@sjh,@csrq,@jdid)";
|
|
mess = "添加成功!";
|
|
}
|
|
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int c = conn.Execute(sql, jzmytm);
|
|
if (c > 0)
|
|
{
|
|
return new { State = 1, Message = mess };
|
|
}
|
|
else
|
|
{
|
|
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
|
|
public object del(JiezhongmianyitiaomaModel jzmytm)
|
|
{
|
|
List<JiezhongmianyitiaomaModel> list = this.GetAllList(jzmytm.id.ToString());
|
|
string sql = "DELETE FROM jiezhongmianyi_tiaomadayin WHERE ID = @id";
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int c = conn.Execute(sql, jzmytm);
|
|
if (c > 0)
|
|
{
|
|
return new { State = 1, Message = "删除成功!" };
|
|
}
|
|
else
|
|
{
|
|
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|