using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using Dapper; using dccdc.Models; namespace dccdc.DAL { public class AreaInfoMaintainDal { public int getCount(string key) { string sql = "select count(1) from dbo.area_info_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and (area_name like @area_name or pinyin_code like @area_name)"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { area_name = "%" + key + "%" }); } } public List GetAllList(string id) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (id != "") { param += " and id=@id"; } string sql = "select * from dbo.area_info_maintain where 1=1 "; return conn.Query(sql + param, new { id = id }).ToList(); } } public List GetAllList() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from dbo.area_info_maintain where status='是' "; return conn.Query(sql).ToList(); } } /// /// 根据地区名称获取地区列表 /// /// /// /// /// public List getList(int page, int pagesize, string key) { string sql = "select *,row_number() over(order by id desc) as rownum from area_info_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and (area_name like @area_name or pinyin_code like @area_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 { area_name = "%" + key + "%" }).ToList(); } } public object save(AreaInfoMaintainModel ct, ERPUser user) { ct.creator = user.TrueName; ct.create_time = DateTime.Now.ToString("yyyy-MM-dd"); string sql = ""; if (ct.id == 0) { sql = @"INSERT INTO [dbo].[area_info_maintain] ([area_code] ,[area_name] ,[status] ,[pinyin_code] ,[creator] ,[create_time]) VALUES (@area_code ,@area_name ,@status ,@pinyin_code ,@creator ,@create_time) "; } else { sql = @"UPDATE [dbo].[area_info_maintain] SET [area_code] = @area_code ,[area_name] = @area_name ,[status] = @status ,[pinyin_code] = @pinyin_code WHERE id=@id "; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int c = conn.Execute(sql, ct); if (c > 0) { return new { State = 1, Message = "保存成功!" }; } else { return new { State = 0, Message = "操作失败,请联系管理员!" }; } } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } /// /// 根据id删除地区维护 /// /// /// public object del(string id) { string sql = @"delete area_info_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 }; } } } } }