/* * 仓库名称关联仓库Id */ using System; using System.Collections.Generic; using System.Linq; using System.Data; using MySystem.Models.Main; using Library; using LitJson; namespace MySystem.Service.Main { public class StoreForNameService { static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString(); // public StoreForNameService() // { // _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString(); // } /// /// 通过仓库名称查询一条记录 /// /// 仓库名称 /// public static StoreForName QueryByStoreName(string StoreName) { WebCMSEntities db = new WebCMSEntities(); StoreForName editData = db.StoreForName.FirstOrDefault(m => m.Name == StoreName) ?? new StoreForName(); db.Dispose(); return editData; } /// /// 查询记录数 /// /// 主键Id /// public static int Count(string condition = "") { int result = 0; DataTable dt = CustomerSqlConn.dtable("select count(Id) from StoreForName where 1=1" + condition, _conn); if (dt.Rows.Count > 0) { result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString())); } return result; } /// /// 查询是否存在 /// /// 主键Id /// // public static bool Exist(int Id) // { // WebCMSEntities db = new WebCMSEntities(); // bool check = db.StoreForName.Any(m => m.Id == Id); // db.Dispose(); // return check; // } /// /// 添加数据 /// /// 要设置的字段 /// public static AppResultJson Add(Dictionary fields, bool check = true) { int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("StoreForName", fields, 0); return new AppResultJson() { Status = "1", Data = Id }; } /// /// 逻辑删除 /// /// 主键Id public static void Remove(int Id) { Dictionary fields = new Dictionary(); fields.Add("Status", -1); new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreForName", fields, Id); } /// /// 删除数据 /// /// 主键Id public static void Delete(int Id) { new DbService(AppConfig.Base.mainTables, _conn).Delete("StoreForName", Id); } /// /// 导出excel表格 /// /// 查询条件(单个字段) /// 查询条件(sql语句) /// // public void ExportExcel(List relationData, string condition) // { // } } }