233 lines
8.4 KiB
C#
233 lines
8.4 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 jbyc_sqDal
|
|
{
|
|
public int getCountLevel(string where)
|
|
{
|
|
string sql = "select count(1) from dbo.jbyc_sq";
|
|
if (!string.IsNullOrEmpty(where))
|
|
{
|
|
sql += " where " + where;
|
|
}
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.ExecuteScalar<int>(sql);
|
|
}
|
|
}
|
|
|
|
public List<jbyc_sqModel> getPageLevel(int page, int pagesize, string where)
|
|
{
|
|
string sql = "select *,row_number() over(order by id desc) as rownum from jbyc_sq";
|
|
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.jbyc_sqModel>(sql).ToList();
|
|
}
|
|
}
|
|
|
|
private string getjbycsqdh(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 jbyc_sq 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 List<jbyc_sqModel> GetAllList(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from jbyc_sq where 1=1";
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
sql += " and id=@id";
|
|
}
|
|
return conn.Query<jbyc_sqModel>(sql, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
public object jbyc_sqSave(string id, int ksid, string ksmc, int sqrid, string sqr, string jbsy, string jbrq, string jbsj, string rs, string bz,string ycbz)
|
|
{
|
|
string errmsg = "";
|
|
string sqdh = getjbycsqdh(out errmsg);
|
|
if (errmsg != "")
|
|
return new { State = 0, Message = "false" };
|
|
jbyc_sqModel model = new jbyc_sqModel();
|
|
model.sqdh = sqdh;
|
|
model.sqrid = sqrid;
|
|
model.sqr = sqr;
|
|
model.sqsj = DateTime.Now;
|
|
model.ksid = ksid;
|
|
model.ksmc = ksmc;
|
|
model.jbsy = jbsy;
|
|
model.jbrq = Convert.ToDateTime(jbrq);
|
|
model.jbsj = jbsj;
|
|
model.rs = Convert.ToInt32(rs);
|
|
model.bz = bz;
|
|
model.zt = 1;
|
|
model.ycbz = ycbz;
|
|
|
|
string sql = @"INSERT INTO [dbo].[jbyc_sq]
|
|
([sqdh],[sqsj],[sqrid],[sqr],[ksid],[ksmc],[jbsy],[jbrq],[jbsj],[rs],[bz],[zt],[ycbz])
|
|
VALUES
|
|
(@sqdh,@sqsj,@sqrid,@sqr,@ksid,@ksmc,@jbsy,@jbrq,@jbsj,@rs,@bz,@zt,@ycbz)select SCOPE_IDENTITY()";
|
|
|
|
int sqdid = 0;
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
sqdid = conn.Query<int>(sql, model).FirstOrDefault();
|
|
return new { State = 1, Message = sqdid };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = "false" };
|
|
}
|
|
}
|
|
}
|
|
|
|
public object delete(string id)
|
|
{
|
|
string sql = "delete from jbyc_sq 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 opjbycSp(string id, string spr, string yj, bool ty)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql2 = "select * from jbyc_sq where 1=1";
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
sql2 += " and id=@id";
|
|
}
|
|
jbyc_sqModel model = conn.Query<jbyc_sqModel>(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 jbyc_sq set spr1=@spr,sptime1=@sptime,spnr1=@spnr,zt=@zt where id=@id";
|
|
if (ty) { zt = 2; } else { zt = -1; }
|
|
break;
|
|
case 2:
|
|
sql = "";
|
|
sql = "update jbyc_sq set spr2=@spr,sptime2=@sptime,spnr2=@spnr,zt=@zt where id=@id";
|
|
if (ty) { zt = 3; } else { zt = -2; }
|
|
break;
|
|
case 3:
|
|
sql = "";
|
|
sql = "update jbyc_sq set spr3=@spr,sptime3=@sptime,spnr3=@spnr,zt=@zt where id=@id";
|
|
if (ty) { zt = 4; } else { zt = -3; }
|
|
break;
|
|
}
|
|
|
|
try
|
|
{
|
|
int result = conn.Execute(sql, new { @id = id, @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 jbycSave2(string id, int ksid, string ksmc, int sqrid, string sqr, string jbsy, string jbrq, string jbsj, string rs, string bz,string ycbz)
|
|
{
|
|
jbyc_sqModel model = new jbyc_sqModel();
|
|
model.id = Convert.ToInt32(id);
|
|
model.jbsy = jbsy;
|
|
model.jbrq = Convert.ToDateTime(jbrq);
|
|
model.jbsj = jbsj;
|
|
model.rs = Convert.ToInt32(rs);
|
|
model.bz = bz;
|
|
model.zt = 1;
|
|
model.ycbz = ycbz;
|
|
|
|
string sql = @"UPDATE [dbo].[jbyc_sq]
|
|
SET [jbsy] = @jbsy,[jbrq] = @jbrq,[jbsj] = @jbsj,[rs] = @rs,[bz] = @bz,[zt] = @zt,[ycbz]=@ycbz
|
|
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 = "false" };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|