InitSiteCommunicator.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Data.SqlClient;
  3. namespace SinochemInternetPlusApp.Communicator
  4. {
  5. class InitSiteCommunicator : ICommunicator
  6. {
  7. static NLog.Logger debugLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("PumpHandler");
  8. public bool IsStarted
  9. {
  10. get { throw new NotImplementedException(); }
  11. }
  12. public bool Start()
  13. {
  14. debugLogger.Info("InitSiteCommunicator start");
  15. foreach (var siteLevelNozzleId in SiteConfigUtility.Default.GetAllSiteLevelNozzleIds())
  16. {
  17. using (
  18. var posSqlConnection =
  19. new SqlConnection(GenericSinochemEpsApp.PosDatabaseConnString))
  20. {
  21. try
  22. {
  23. var gradeFriendlyName = Translator.GetFriendlyGradeName(SiteConfigUtility.Default.GetGradeName(siteLevelNozzleId));
  24. var totalizer = SiteConfigUtility.Default.GetTotalizer(siteLevelNozzleId);
  25. var setPumpOnStartingCommand =
  26. new SqlCommand(string.Format("if not exists(select * from jy_info where jihao={0})" +
  27. " BEGIN" +
  28. " insert jy_info (jihao, [status], youpin, qty, amount, fzqty, fzamount) values({0}, '{1}', N'{2}', 0, 0, '{3}', {4})" +
  29. " END", siteLevelNozzleId, 'F', gradeFriendlyName,
  30. totalizer.Item1, totalizer.Item2), posSqlConnection);
  31. debugLogger.Debug("initTable_jy_info_Command: " + setPumpOnStartingCommand.CommandText);
  32. posSqlConnection.Open();
  33. setPumpOnStartingCommand.ExecuteNonQuery();
  34. }
  35. catch (Exception ex)
  36. {
  37. debugLogger.Error("executing initTable_jy_info_Command failed for siteLevelNozzleId: " + siteLevelNozzleId + ", exception detail: " + ex);
  38. throw;
  39. }
  40. }
  41. }
  42. return true;
  43. }
  44. }
  45. }