using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using dccdc.Models; using System.Data; using Dapper; namespace dccdc.DAL { public class JfGwjdglDll { public List getJfGwjdgl(JfGwjdgl jfGwjdgl, int page, int pagesize) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { String strsql = "select a.*,row_number() over(order by id) as rownum," + "(select TOP 1 BM.BuMenName FROM OA..ERPBuMen BM WHERE BM.ID = A.KSID) KSMC" + ",(select TOP 1 U.TrueName FROM OA..ERPUser U WHERE U.ID = A.sqrid) SQRMC" + " from jf_gwjdgl a where 1=1 "; if (jfGwjdgl.zt != null) { strsql += " and zt=@zt "; } if (jfGwjdgl.sqrid != 0) { strsql += " and sqrid=@sqrid"; } if (jfGwjdgl.ksid != 0) { strsql += " and ksid = @ksid"; } if (jfGwjdgl.sqsj != null) { strsql += " and sqsj = @sqsj"; } strsql = "select * from (" + strsql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; return conn.Query(strsql, jfGwjdgl).ToList(); } } public List getJfGwjdglOne(JfGwjdgl jfgwjdgl) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { String strsql = "select a.*," + "(select TOP 1 BM.BuMenName FROM OA..ERPBuMen BM WHERE BM.ID = A.KSID) KSMC" + ",(select TOP 1 U.TrueName FROM OA..ERPUser U WHERE U.ID = A.sqrid) SQRMC" + " from jf_gwjdgl a where id=@id"; return conn.Query(strsql, jfgwjdgl).ToList(); } } public int countspJfGwjdgl(string ksidstr, string ztstr) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { String strsql = "select count(1) from jf_gwjdgl where 1 = 1"; if (ztstr != null && ztstr != "") { strsql += ztstr; } else { strsql += "AND 1=2"; } return conn.ExecuteScalar(strsql); } } public List getspJfGwjdgl(string ksidstr, string ztstr, int page, int pagesize) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { String strsql = "select a.*,row_number() over(order by id) as rownum," + "(select TOP 1 BM.BuMenName FROM OA..ERPBuMen BM WHERE BM.ID = A.KSID) KSMC" + ",(select TOP 1 U.TrueName FROM OA..ERPUser U WHERE U.ID = A.sqrid) SQRMC" + " from jf_gwjdgl a where 1=1 "; if (ztstr != null && ztstr != "") { strsql += ztstr; } else { strsql += "AND 1=2"; } strsql = "select * from (" + strsql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; return conn.Query(strsql).ToList(); } } public int countJfGwjdgl(JfGwjdgl jfGwjdgl) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { String strsql = "select count(1) from jf_gwjdgl where ksid = @ksid"; if (jfGwjdgl.zt != null) { strsql += " and zt=@zt "; } if (jfGwjdgl.sqrid != 0) { strsql += " and sqrid=@sqrid"; } return conn.ExecuteScalar(strsql, jfGwjdgl); } } public bool delJfGwjdgl(JfGwjdgl jfgwjdgl) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { String sql = "delete from jf_gwjdgl where id=@id"; return (conn.Execute(sql, jfgwjdgl) != 0 ? true : false); } } public bool addJfGwjdgl(JfGwjdgl jfgwjdgl) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"INSERT INTO [jf_gwjdgl] ([ksid] ,[sqdid] ,[sqrid] ,[sqsj] ,[jdsy] ,[jdsj] ,[sxfy] ,[jfly] ,[bz] ,[zt] ,[ddry] ,[sxrs] ,[lxdh] ,[jdld] ,[pcrs] ,[zrs] ,[ycbz] ,[sfhj] ,[ycqt] ,[gzcbz] ,[gzcrs] ,[zsbz] ,[rs] ,[qt] ,[jdys] ,[jbr] ,[jdbg] ,[jcfjh] ,[zfbg] ,[zsfjh] ,[fydh] ) VALUES (@ksid ,@sqdid ,@sqrid ,@sqsj ,@jdsy ,@jdsj ,@sxfy ,@jfly ,@bz ,@zt ,@ddry ,@sxrs ,@lxdh ,@jdld ,@pcrs ,@zrs ,@ycbz ,@sfhj ,@ycqt ,@gzcbz ,@gzcrs ,@zsbz ,@rs ,@qt ,@jdys ,@jbr ,@jdbg ,@jcfjh ,@zfbg ,@zsfjh,@fydh)"; return (conn.Execute(sql, jfgwjdgl) != 0 ? true : false); } } public bool updJfGwjdgl(JfGwjdgl jfgwjdgl) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"update [jf_gwjdgl] set [jdsy]=@jdsy ,[sxfy]=@sxfy ,[jfly]=@jfly ,[jdsj]=@jdsj ,[bz]=@bz ,[zt]=@zt ,[bgsspyj]=@bgsspyj ,[bgsspsj]=@bgsspsj ,[zxldspyj]=@zxldspyj ,[zxldspsj]=@zxldspsj ,[ddry]=@ddry ,[sxrs]=@sxrs ,[lxdh]=@lxdh ,[jdld]=@jdld ,[pcrs]=@pcrs ,[zrs]=@zrs ,[ycbz]=@ycbz ,[sfhj]=@sfhj ,[ycqt]=@ycqt ,[gzcbz]=@gzcbz ,[gzcrs]=@gzcrs ,[zsbz]=@zsbz ,[rs]=@rs ,[qt]=@qt ,[jdys]=@jdys ,[jbr]=@jbr ,[jdbg]=@jdbg ,[jcfjh]=@jcfjh ,[zfbg]=@zfbg ,[zsfjh]=@zsfjh ,[fydh]=@fydh where id = @id"; return (conn.Execute(sql, jfgwjdgl) != 0 ? true : false); } } //获取申请单号 public string getckkdh(string sqdid,string tablename) { string 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 "+sqdid+" from " + tablename + " where " + sqdid + " >= '" + start + "' and " + sqdid + "<= '" + 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 int getCountLevel(string where) { string sql = "select count(1) from dbo.jf_gwjdgl where 1=1"; if (!string.IsNullOrEmpty(where)) { sql += where; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql); } } public List getPageLevel(int page, int pagesize, string where) { string sql = "select *,row_number() over(order by id desc) as rownum from jf_gwjdgl where 1=1"; if (!string.IsNullOrEmpty(where)) { sql += where; } sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).ToList(); } } } }