WarehouseService.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using LeaRun.Application.Entity.WarehouseManage;
  2. using LeaRun.Application.IService.WarehouseManage;
  3. using LeaRun.Data;
  4. using LeaRun.Util;
  5. using LeaRun.Util.WebControl;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace LeaRun.Application.Service.WarehouseManage
  13. {
  14. public class WarehouseService : IWarehouseManageService
  15. {
  16. SqlHelper sqlHelper = new SqlHelper("InstallDB");
  17. public String getWarehouseList(Pagination pagination)
  18. {
  19. String sql = "SELECT WarehouseId,Code,WarehouseName,CreateDt FROM WM_Warehouse";
  20. DataTable dt;
  21. StringBuilder sb = new StringBuilder();
  22. String json = "";
  23. Char c = ',';
  24. int total = pagination.records;
  25. dt = sqlHelper.ExecuteDataTable(sql, "", false, pagination.rows, pagination.page, out total, null);
  26. pagination.records = total;
  27. if (dt.Rows.Count > 0)
  28. {
  29. for (int i = 0; i < dt.Rows.Count; i++)
  30. {
  31. DataRow r = dt.Rows[i];
  32. #region 拼接sql
  33. sb.Append("{");
  34. sb.Append("\"WarehouseId\":\"").Append(r["WarehouseId"].ToString()).Append("\",");
  35. sb.Append("\"Code\":\"").Append(r["Code"].ToString()).Append("\",");
  36. sb.Append("\"WarehouseName\":\"").Append(r["WarehouseName"] != System.DBNull.Value ? r["WarehouseName"].ToString() : "").Append("\",");
  37. sb.Append("\"CreateDt\":\"").Append(r["CreateDt"] != System.DBNull.Value ? Convert.ToDateTime(r["CreateDt"]).ToString("yyyy-MM-dd HH:mm:ss") : "").Append("\"");
  38. sb.Append("},");
  39. #endregion
  40. json = "[" + sb.ToString().TrimEnd(c) + "]";
  41. }
  42. }
  43. return json;
  44. }
  45. public void SaveFrom(String Code, String WarehouseName)
  46. {
  47. String sql = "Insert into WM_Warehouse(Code,WarehouseName,CreateDt,UpdateDt) Values ('" + Code.Trim() + "','" + WarehouseName + "',GETDATE(),GETDATE())";
  48. try
  49. {
  50. sqlHelper.ExecuteNoParams(sql, CommandType.Text);
  51. //sql = "update INS_Budget SET PaymentName = '" + op + "' ,PaymentTime = GETDATE() where Apply_ID =" + applyId;
  52. //sqlHelper.ExecuteNoParams(sql, CommandType.Text);
  53. }
  54. catch (Exception ex)
  55. {
  56. throw;
  57. }
  58. }
  59. #region 获取仓库列表
  60. public IEnumerable<WarehouseEntity> getHouseList() {
  61. try
  62. {
  63. string sql = "select WarehouseId,WarehouseName from WM_Warehouse";
  64. DataTable dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  65. return DataHelper.DataTableToT<WarehouseEntity>(dt);
  66. }
  67. catch (Exception)
  68. {
  69. throw;
  70. }
  71. }
  72. #endregion
  73. }
  74. }