StoreForCodeService.cs 3.3 KB

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