StatStoreDataService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class StatStoreDataService
  12. {
  13. public readonly static StatStoreDataService Instance = new StatStoreDataService();
  14. private StatStoreDataService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. // bool op = true;
  25. // while (op)
  26. // {
  27. try
  28. {
  29. WebCMSEntities db = new WebCMSEntities();
  30. DataTable dt = dbconn.dtable("select * from TmpStoreHouse where Status='正常' order by Id");
  31. foreach (DataRow dr in dt.Rows)
  32. {
  33. string Id = dr["Id"].ToString();
  34. string StoreCode = dr["StoreCode"].ToString();
  35. string StoreName = dr["StoreName"].ToString();
  36. string StoreAddress = dr["StoreAddress"].ToString();
  37. string ManageMakerCode = dr["ManageMakerCode"].ToString();
  38. string Manager = dr["Manager"].ToString();
  39. string ManageMobile = dr["ManageMobile"].ToString();
  40. string ManageEmail = dr["ManageEmail"].ToString();
  41. string MakerCode = dr["MakerCode"].ToString();
  42. string LimitMakerCode = dr["LimitMakerCode"].ToString();
  43. string StoreKind = dr["StoreKind"].ToString();
  44. string Status = dr["Status"].ToString();
  45. string CreateMan = dr["CreateMan"].ToString();
  46. string CreateDate = dr["CreateDate"].ToString();
  47. UserForMakerCode manageUser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode) ?? new UserForMakerCode();
  48. UserForMakerCode userFor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  49. UserForMakerCode limitFor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LimitMakerCode) ?? new UserForMakerCode();
  50. StoreHouse store = db.StoreHouse.Add(new StoreHouse()
  51. {
  52. StoreNo = StoreCode,
  53. StoreName = StoreName,
  54. Address = StoreAddress,
  55. ManageMobile = ManageMobile,
  56. ManagerEmail = ManageEmail,
  57. StoreKind = StoreKind == "灵动总部" ? 1 : 0,
  58. Status = 1,
  59. CreateMan = CreateMan,
  60. CreateDate = DateTime.Parse(CreateDate),
  61. ManageUserId = manageUser.UserId,
  62. UserId = userFor.UserId,
  63. LimitTopUserId = limitFor.UserId.ToString(),
  64. }).Entity;
  65. db.SaveChanges();
  66. StoreForCode storeFor = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode);
  67. if (storeFor == null)
  68. {
  69. storeFor = db.StoreForCode.Add(new StoreForCode()
  70. {
  71. Code = StoreCode,
  72. }).Entity;
  73. db.SaveChanges();
  74. }
  75. storeFor.StoreId = store.Id;
  76. StoreForName storeForName = db.StoreForName.FirstOrDefault(m => m.Name == StoreName);
  77. if (storeForName == null)
  78. {
  79. storeForName = db.StoreForName.Add(new StoreForName()
  80. {
  81. Name = StoreName,
  82. }).Entity;
  83. db.SaveChanges();
  84. }
  85. storeForName.StoreId = store.Id;
  86. db.SaveChanges();
  87. function.WritePage("/stat/", "StoreIdFlag.txt", Id);
  88. }
  89. }
  90. catch (Exception ex)
  91. {
  92. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "导仓库数据异常");
  93. }
  94. Thread.Sleep(200);
  95. // }
  96. }
  97. }
  98. }