MultiFusionsSupport.cs 4.8 KB

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