StoreForNameService.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * 仓库名称关联仓库Id
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class StoreForNameService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. // public StoreForNameService()
  17. // {
  18. // _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. // }
  20. /// <summary>
  21. /// 通过仓库名称查询一条记录
  22. /// </summary>
  23. /// <param name="StoreName">仓库名称</param>
  24. /// <returns></returns>
  25. public static StoreForName QueryByStoreName(string StoreName)
  26. {
  27. WebCMSEntities db = new WebCMSEntities();
  28. StoreForName editData = db.StoreForName.FirstOrDefault(m => m.Name == StoreName) ?? new StoreForName();
  29. db.Dispose();
  30. return editData;
  31. }
  32. /// <summary>
  33. /// 查询记录数
  34. /// </summary>
  35. /// <param name="Id">主键Id</param>
  36. /// <returns></returns>
  37. public static int Count(string condition = "")
  38. {
  39. int result = 0;
  40. DataTable dt = CustomerSqlConn.dtable("select count(Id) from StoreForName where 1=1" + condition, _conn);
  41. if (dt.Rows.Count > 0)
  42. {
  43. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  44. }
  45. return result;
  46. }
  47. /// <summary>
  48. /// 查询是否存在
  49. /// </summary>
  50. /// <param name="Id">主键Id</param>
  51. /// <returns></returns>
  52. // public static bool Exist(int Id)
  53. // {
  54. // WebCMSEntities db = new WebCMSEntities();
  55. // bool check = db.StoreForName.Any(m => m.Id == Id);
  56. // db.Dispose();
  57. // return check;
  58. // }
  59. /// <summary>
  60. /// 添加数据
  61. /// </summary>
  62. /// <param name="Fields">要设置的字段</param>
  63. /// <returns></returns>
  64. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  65. {
  66. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("StoreForName", fields, 0);
  67. return new AppResultJson() { Status = "1", Data = Id };
  68. }
  69. /// <summary>
  70. /// 逻辑删除
  71. /// </summary>
  72. /// <param name="Id">主键Id</param>
  73. public static void Remove(int Id)
  74. {
  75. Dictionary<string, object> fields = new Dictionary<string, object>();
  76. fields.Add("Status", -1);
  77. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreForName", fields, Id);
  78. }
  79. /// <summary>
  80. /// 删除数据
  81. /// </summary>
  82. /// <param name="Id">主键Id</param>
  83. public static void Delete(int Id)
  84. {
  85. new DbService(AppConfig.Base.mainTables, _conn).Delete("StoreForName", Id);
  86. }
  87. /// <summary>
  88. /// 导出excel表格
  89. /// </summary>
  90. /// <param name="fields">查询条件(单个字段)</param>
  91. /// <param name="condition">查询条件(sql语句)</param>
  92. /// <returns></returns>
  93. // public void ExportExcel(List<RelationData> relationData, string condition)
  94. // {
  95. // }
  96. }
  97. }