using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using dccdc.Models; using Dapper; namespace dccdc.DAL { public class ChargeProjectMaintainDal { public List GetAllList(string id, string stauts) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (id != "") { param = " and id =@id"; } if (stauts != "") { param += " and status=@stauts"; } return conn.Query("select * from charge_project_maintain where 1=1" + param, new { @id = id, @stauts = stauts }).ToList(); } } public List GetAllList2(string id, string key) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (!string.IsNullOrEmpty(id)) { param = " and id =@id"; } if (!string.IsNullOrEmpty(key)) { param += " and (charge_project_name like @key or pinyin_code like @key)"; } return conn.Query("select * from charge_project_maintain where 1=1 and status='是' and general_status='是' " + param + " order by px", new { @id = id, @key = "%" + key + "%" }).ToList(); } } public List GetAllList4(string id, string key) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (!string.IsNullOrEmpty(id)) { param = " and id =@id"; } if (!string.IsNullOrEmpty(key)) { param += " and charge_project_name like @key"; } return conn.Query("select * from charge_project_maintain where 1=1 and is_vaccine = '是'" + param, new { @id = id, @key = "%" + key + "%" }).ToList(); } } /// /// 根据id查询收费项目 /// /// /// public List GetAllListBytjxm(string id) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query( "select distinct charge.* from charge_project_maintain charge left join exam_project_maintain project on project.charge_project_maintain_id=charge.id where charge.charge_project_name!='无' and project.id in @id", new { @id = id.TrimEnd(',').Split(',').ToArray() }).ToList(); } } /// /// 根据收费项目ID查询收费项目列表 /// /// /// public List GetAllListBysfxmId(string id) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query( "select * from charge_project_maintain where charge_project_name!='无' and id in @id", new { @id = id.TrimEnd(',').Split(',').ToArray() }).ToList(); } } public int getAddCount(string key) { string sql = "select count(1) from dbo.charge_project_maintain where 1=1 and is_add = '是'"; if (!string.IsNullOrEmpty(key)) { sql += " and charge_project_name like @charge_project_name"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { charge_project_name = "%" + key + "%" }); } } public int getVCount(string key) { string sql = "select count(1) from dbo.charge_project_maintain where 1=1 and is_vaccine = '是'"; if (!string.IsNullOrEmpty(key)) { sql += " and charge_project_name like @charge_project_name"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { charge_project_name = "%" + key + "%" }); } } public int getCount(string key) { string sql = "select count(1) from dbo.charge_project_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and charge_project_name like @charge_project_name"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { charge_project_name = "%" + key + "%" }); } } /// /// 根据收费项目名称获取收费项目列表 /// /// /// /// /// public List getList(int page, int pagesize, string key) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id desc) as rownum from charge_project_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and charge_project_name like @charge_project_name"; } sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { charge_project_name = "%" + key + "%" }).ToList(); } } public List getAddList(string key) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from charge_project_maintain where id = " + key; ChargeProjectMaintainModel model = conn.Query(sql).FirstOrDefault(); string ids = ""; if (model != null) { ids = model.add_ids; } if (string.IsNullOrEmpty(ids)) { ids = "-12345"; } //throw new NotImplementedException(); sql = "select * from charge_project_maintain where (id in (" + ids + ") or id = " + key + ")"; return conn.Query(sql).ToList(); } } public List getVList(int page, int pagesize, string key) { string sql = "select *,row_number() over(order by id) as rownum from charge_project_maintain where 1=1 and is_vaccine = '是'"; if (!string.IsNullOrEmpty(key)) { sql += " and charge_project_name like @charge_project_name"; } sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { charge_project_name = "%" + key + "%" }).ToList(); } } public List getAddList(int page, int pagesize, string key) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id) as rownum from charge_project_maintain where 1=1 and is_add = '是'"; if (!string.IsNullOrEmpty(key)) { sql += " and charge_project_name like @charge_project_name"; } sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { charge_project_name = "%" + key + "%" }).ToList(); } } public object save(ChargeProjectMaintainModel cpm, ERPUser user) { //throw new NotImplementedException(); cpm.creator = user.TrueName; cpm.create_time = DateTime.Now.ToString("yyyy-MM-dd"); string sql = ""; if (cpm.id == 0) { sql = @"INSERT INTO [dbo].[charge_project_maintain] ([charge_project_name] ,[occupation_type] ,[fee] ,[pinyin_code] ,[creator] ,[create_time] ,[status] ,[is_vaccine] ,[is_add] ,[add_ids] ,[general_status],px) VALUES (@charge_project_name ,@occupation_type ,@fee ,@pinyin_code ,@creator ,@create_time ,@status ,@is_vaccine ,@is_add ,@add_ids ,@general_status,@px) "; } else { sql = @"UPDATE [dbo].[charge_project_maintain] SET [charge_project_name]=@charge_project_name,[occupation_type] = @occupation_type ,[fee]=@fee,[pinyin_code] = @pinyin_code ,[status] = @status,[is_vaccine] = @is_vaccine,[is_add] = @is_add,[add_ids] = @add_ids,[general_status]=@general_status,px=@px WHERE id=@id "; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int c = conn.Execute(sql, cpm); if (c > 0) { return new { State = 1, Message = "保存成功!" }; } else { return new { State = 0, Message = "操作失败,请联系管理员!" }; } } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public List GetAllTreeList() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query("select * from charge_project_maintain where status=@status", new { @status = "是" }).ToList(); } } /// /// 根据id删除收费项目 /// /// /// public object del(string id) { string sql = @"delete charge_project_maintain where id=@id"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int c = conn.Execute(sql, new { id = id }); if (c > 0) { return new { State = 1, Message = "操作成功!" }; } else { return new { State = 0, Message = "操作失败,请联系管理员!" }; } } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } } }