MultiFusionsSupport.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Dfs.WayneChina.SinochemEps;
  2. using SinoChemCommonUtilities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Wayne.Lib.Log;
  11. namespace SinochemInternetPlusApp
  12. {
  13. // the sql command should macth the db schema in the target fusion
  14. class MultiFusionsSupport
  15. {
  16. private static SqlCommandUtility sourceSqlCmd;
  17. private static SqlCommandUtility targetSqlCmd;
  18. private static readonly bool supportMultiFusions = ConfigurationValues.SupportMultiFusions;
  19. static MultiFusionsSupport()
  20. {
  21. try
  22. {
  23. if (supportMultiFusions)
  24. {
  25. sourceSqlCmd = new SqlCommandUtility(SinochemEpsApp.AppSettings["AnotherPosDatabaseConnStr"]); // default to the conn string to current machine
  26. string anotherConnStr = SinochemEpsApp.AppSettings["AnotherPosDatabaseConnStr"];
  27. targetSqlCmd = new SqlCommandUtility(anotherConnStr); // conn string to another fusion
  28. }
  29. }
  30. catch (Exception ex)
  31. {
  32. }
  33. }
  34. public static bool CopyXiaofei2ToTargetFusion(int jihao, string liushuihao, DebugLogger debugLogger)
  35. {
  36. if (!supportMultiFusions)
  37. {
  38. return false;
  39. }
  40. try
  41. {
  42. string querySql = string.Format(" select * from xiaofei2 " +
  43. " where jihao={0} and liushuino='{1}' ",
  44. jihao, liushuihao);
  45. Xiaofei2Model xiaofei2Model = sourceSqlCmd.ReadData<Xiaofei2Model>(querySql, DbModelConstructors.ConstructXiaofei2Model);
  46. if (xiaofei2Model != null)
  47. {
  48. string insertSql = string.Format(" insert into xiaofei2 (jihao, youpin, qty, danjia, amount, xf_date, xf_time, liushuino, fzqty, fzamount) " +
  49. " values({0}, '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}', {8}, {9}) ",
  50. xiaofei2Model.jihao, xiaofei2Model.youpin, xiaofei2Model.qty, xiaofei2Model.danjia, xiaofei2Model.amount, xiaofei2Model.xf_date, xiaofei2Model.xf_time,
  51. xiaofei2Model.liushuino, xiaofei2Model.fzqty, xiaofei2Model.fzamount);
  52. targetSqlCmd.Insertdata(insertSql, false);
  53. return true;
  54. }
  55. else
  56. {
  57. return false;
  58. }
  59. }
  60. catch (Exception ex)
  61. {
  62. debugLogger.Add(ex);
  63. return false;
  64. }
  65. }
  66. public static bool UpdateJyInfoToTargetFusionWhenFuelingStarted(int jihao, DebugLogger debugLogger)
  67. {
  68. if (!supportMultiFusions)
  69. {
  70. return false;
  71. }
  72. try
  73. {
  74. string updateSql = string.Format(" update jy_info set [status]='{0}', qty=0, amount=0 " +
  75. " where jihao='{1}' ",
  76. 'B', jihao);
  77. targetSqlCmd.UpdateData(updateSql);
  78. return true;
  79. }
  80. catch (Exception ex)
  81. {
  82. debugLogger.Add(ex);
  83. return false;
  84. }
  85. }
  86. public static bool CopyJyInfoToTargetFusion(int jihao, DebugLogger debugLogger)
  87. {
  88. if (!supportMultiFusions)
  89. {
  90. return false;
  91. }
  92. try
  93. {
  94. string querySql = string.Format(" select * from jy_info " +
  95. " where jihao={0} ",
  96. jihao);
  97. JyInfoModel jyInfoModel = sourceSqlCmd.ReadData<JyInfoModel>(querySql, DbModelConstructors.ConstructJyInfoModel);
  98. if (jyInfoModel != null)
  99. {
  100. string updateSql = string.Format(" update jy_info set [status]='{0}', youpin=N'{1}', qty={2}, amount={3}, fzqty={4}, fzamount={5} " +
  101. " where jihao='{6}' ",
  102. jyInfoModel.status, jyInfoModel.youpin, jyInfoModel.qty, jyInfoModel.amount, jyInfoModel.fzqty, jyInfoModel.fzamount,
  103. jyInfoModel.jihao);
  104. targetSqlCmd.UpdateData(updateSql);
  105. return true;
  106. }
  107. else
  108. {
  109. return false;
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. debugLogger.Add(ex);
  115. return false;
  116. }
  117. }
  118. }
  119. }