InitSiteCommunicator.cs 2.3 KB

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