Facebook
From ola, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 223
  1. using BapPress.BapService.ServiceMessages;
  2. using BapFramework.Data.Generic;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Data.Common;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace BapPress.BapService.Services.SPL
  11. {
  12.     [Guid("622735FF-F92A-441A-988E-68A185FF819C")]
  13.     public class CBPO : ScheduleBase
  14.     {
  15.         //private Dictionary<int, string> DcTypes;
  16.  
  17.         public CBPO(string constr) : base(constr)
  18.         {
  19.             System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  20.             //DcTypes = new Dictionary<int, string>();
  21.             //DcTypes.Add(11, "SALONY EMPIK");
  22.             //DcTypes.Add(3, "PACZKOMATY");
  23.             //DcTypes.Add(15, "POCZTA ODBIORY");
  24.             //DcTypes.Add(16, "POCZTA ORLEN");
  25.             //DcTypes.Add(18, "POCZTA ŻABKI");
  26.             //DcTypes.Add(17, "PUNKTY ODBIORU LIVRO");
  27.             //DcTypes.Add(9, "PUNKTY ODBIORU MOLE MOLE ");
  28.         }
  29.  
  30.         protected override bool Job()
  31.         {
  32.             ConnectionBase SPLConn = ConnectionBase.GetConnection(ConnectionString, true);
  33.  
  34.             Recpoints.Recpoints_pttClient client = new Recpoints.Recpoints_pttClient("Recpoints_bindingQSPort", Properties.Settings.Default.CBPO_WebService.Value);
  35.  
  36.             //client.ClientCredentials.UserName.UserName = Properties.Settings.Default.CBPO_User.Value;
  37.             //client.ClientCredentials.UserName.Password = Properties.Settings.Default.CBPO_Pass.Value;
  38.  
  39.             client.ClientCredentials.UserName.UserName = Properties.Settings.Default.CBPO_User.Value;
  40.             client.ClientCredentials.UserName.Password = Properties.Settings.Default.CBPO_Pass.Value;
  41.  
  42. #if DEBUG
  43.             //dodane w celu podglądu zapytanie i odpowiedzi SOAP (klasa SimpleMessageInspector)
  44.             client.Endpoint.Behaviors.Add(new SimpleEndpointBehavior());
  45. #endif
  46.             DataTable ClientKinds = SPLConn.GetTable("select CBPO_DCTYPE, \"Name\", \"Description\" from dba.clientkinds where CBPO_DCTYPE is not null;");
  47.  
  48.             foreach (DataRow kind in ClientKinds.Rows)
  49.             {
  50.                 Recpoints.RecpointsRequest_msg msg = new Recpoints.RecpointsRequest_msg();
  51.                 msg.RECPOINTSREQUEST = new Recpoints.RECPOINTSREQUEST()
  52.                 {
  53.                     QUERY = new Recpoints.RECPOINTSREQUESTFIELD[] {
  54.                     new Recpoints.RECPOINTSREQUESTFIELD(){ NAME="DCTYPE", VALUE=kind["CBPO_DCTYPE"].ToString()}
  55.                 }
  56.                 };
  57.                 //msg.RECPOINTSREQUEST = "";
  58.                 //msg.RECPOINTSREQUEST = new Recpoints.RECPOINTSREQUEST();
  59.                 SendMessage(MessageType.Info, $"Wczytuję {kind["Description"]}");
  60.                 Recpoints.RecpointsResponse_msg resp = client.getRecpoints(msg);
  61.  
  62.                 //MD - zapisanie xml-a do pliku
  63.                 if (Properties.Settings.Default.CBPO_ToXML.Value == "1")
  64.                 {
  65.                     SendMessage(MessageType.Info, "Zapisuję do pliku");
  66.                     System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Recpoints.RecpointsResponse_msg));
  67.                     System.IO.StreamWriter file = new System.IO.StreamWriter(Properties.Settings.Default.CBPO_ToXMLFile.Value + "_" + kind["CBPO_DCTYPE"].ToString());
  68.                     writer.Serialize(file, resp);
  69.                     file.Close();
  70.                     SendMessage(MessageType.Info, "Zapisane do pliku " + Properties.Settings.Default.CBPO_ToXMLFile.Value);
  71.                     return true;
  72.                 }
  73.                 else
  74.                 {
  75.  
  76.                     // koniec
  77.                     Recpoints.RECPOINTSRECPOINT[] points = resp.RECPOINTS;
  78.  
  79.                     if (points != null)
  80.                     {
  81.                         DbCommand cmd = null;
  82.                         DbParameter param = null;
  83.  
  84.                         //Dictionary<int, int> dc_cnt = new Dictionary<int, int>();
  85.                         //dc_cnt.Add(0, 0);
  86.                         //dc_cnt.Add(11, 0);
  87.                         //dc_cnt.Add(3, 0);
  88.                         //dc_cnt.Add(15, 0);
  89.                         //dc_cnt.Add(16, 0);
  90.                         //dc_cnt.Add(17, 0);
  91.                         //dc_cnt.Add(18, 0);
  92.                         //dc_cnt.Add(9, 0);
  93.  
  94.                         int cnt = 1;
  95.                         int max = points.Length;
  96.                         //int o = 0;
  97.  
  98.                         SendMessage(MessageType.Info, string.Format("Przetwarzam {0} punktów", max));
  99.  
  100.                         foreach (Recpoints.RECPOINTSRECPOINT point in points)
  101.                         {
  102.                             if (StopPending)
  103.                                 break;
  104.  
  105.                             //if (DcTypes.ContainsKey(point.RECPOINTSHEADER.DCTYPE))
  106.                             //{
  107.                             try
  108.                             {
  109.                                 cmd = SPLConn.Connection.CreateCommand();
  110.                                 cmd.CommandText = "DBA.IP_UpdateSalonInfo";
  111.                                 cmd.CommandType = CommandType.StoredProcedure;
  112.  
  113.                                 param = cmd.CreateParameter();
  114.                                 param.ParameterName = "@RefCBPO";
  115.                                 param.Value = point.RECPOINTSHEADER.DCID;
  116.                                 cmd.Parameters.Add(param);
  117.  
  118.                                 param = cmd.CreateParameter();
  119.                                 param.ParameterName = "@RefNumber";
  120.                                 //if (point.RECPOINTSHEADER.DCTYPE == 12)
  121.                                 //    param.Value = "S" + point.RECPOINTSHEADER.EXTID1.PadLeft(4, '0');
  122.                                 //else
  123.                                 param.Value = point.RECPOINTSHEADER.EXTID1;//.PadLeft(5, '0'); //;
  124.                                 cmd.Parameters.Add(param);
  125.  
  126.                                 param = cmd.CreateParameter();
  127.                                 param.ParameterName = "@SalonType";
  128.                                 param.Value = point.RECPOINTSHEADER.DCTYPE;
  129.                                 cmd.Parameters.Add(param);
  130.                                 /*
  131.                                 Typ Punktu Odbioru:
  132.                                     1 - Kurier (UPS)
  133.                                     2 - POCZTA
  134.                                     3 - PACZKOMAT
  135.                                     11 - SALON EMPIK
  136.                                     12 - SALON SMYK - już nie używany
  137.                                     15 - siecPlacowek="POCZTAPOLSKA"
  138.                                     16 - siecPlacowek="ORLEN"
  139.                                     18 – siecPlacowek=’ZABKA’
  140.                                     17 - PUNKT ODBIORU livro
  141.                                     9 - Punkt Odbioru Mole Mole
  142.                                 */
  143.  
  144.                                 param = cmd.CreateParameter();
  145.                                 param.ParameterName = "@Name";
  146.                                 //if (point.RECPOINTSHEADER.DCTYPE == 11)
  147.                                 param.Value = point.ADDRESS.NAME;
  148.                                 //else
  149.                                 //param.Value = point.RECPOINTSHEADER.EXTID1;
  150.                                 cmd.Parameters.Add(param);
  151.  
  152.                                 param = cmd.CreateParameter();
  153.                                 param.ParameterName = "@Email";
  154.                                 if (point.COMMUNICATION.COMMITEMS.Length > 0)
  155.                                     param.Value = point.COMMUNICATION.COMMITEMS[0].COMMADD;
  156.                                 else
  157.                                 {
  158.                                     param.DbType = DbType.String;
  159.                                     param.Value = DBNull.Value;
  160.                                 }
  161.                                 cmd.Parameters.Add(param);
  162.  
  163.                                 param = cmd.CreateParameter();
  164.                                 param.ParameterName = "@StreetName";
  165.                                 param.Value = point.ADDRESS.ADDR;
  166.                                 cmd.Parameters.Add(param);
  167.  
  168.                                 param = cmd.CreateParameter();
  169.                                 param.ParameterName = "@ZIP";
  170.                                 param.Value = point.ADDRESS.POSTCODE;
  171.                                 cmd.Parameters.Add(param);
  172.  
  173.                                 param = cmd.CreateParameter();
  174.                                 param.ParameterName = "@TownName";
  175.                                 param.Value = point.ADDRESS.CITY;
  176.                                 cmd.Parameters.Add(param);
  177.  
  178.                                 //Log("DBA.SPL_UpdateSalonInfo("
  179.                                 //    + row["RefNumber"].ToString() + ","
  180.                                 //    + row["ShortName"].ToString() + ","
  181.                                 //    + row["Name"].ToString() + ","
  182.                                 //    + row["E_mail"].ToString() + ","
  183.                                 //    + row["StreetName"].ToString() + ","
  184.                                 //    + row["ZIP"].ToString() + ","
  185.                                 //    + row["TownName"].ToString() + ")");
  186.  
  187.                                 cmd.ExecuteNonQuery();
  188.                                 cmd.Dispose();
  189.  
  190.                             }
  191.                             catch (Exception ex)
  192.                             {
  193.                                 Log(MessageType.Error, "CBPO", ex.Message, ex.StackTrace);
  194.                             }
  195.  
  196.                             SendMessage(MessageType.Count, "Punkt(" + point.RECPOINTSHEADER.DCID.ToString() + ") - " + cnt.ToString() + " z " + max.ToString());
  197.                             //    dc_cnt[point.RECPOINTSHEADER.DCTYPE]++;
  198.                             //}
  199.                             //else
  200.                             //    dc_cnt[0]++;
  201.                             cnt++;
  202.  
  203.                         }
  204.                         //SendMessage(MessageType.Info, string.Format("Wczytano {0} salonów", dc_cnt[11]));
  205.                         //SendMessage(MessageType.Info, string.Format("Wczytano {0} paczkomatów", dc_cnt[3]));
  206.                         //SendMessage(MessageType.Info, string.Format("Wczytano {0} placówek pocztowych", dc_cnt[15]));
  207.                         //SendMessage(MessageType.Info, string.Format("Wczytano {0} stacji orlen", dc_cnt[16]));
  208.                         //SendMessage(MessageType.Info, string.Format("Wczytano {0} punktów odbioru Livro", dc_cnt[17]));
  209.                         //SendMessage(MessageType.Info, string.Format("Wczytano {0} Żabek", dc_cnt[18]));
  210.                         ////SendMessage(MessageType.Info, string.Format("Wczytano {0} punktów odbioru Mole Mole", dc_cnt[9]));
  211.                         //SendMessage(MessageType.Info, string.Format("Pominięto {0} punktów", dc_cnt[0]));
  212.                     }
  213.                     else
  214.                         SendMessage(MessageType.Info, "Brak punktów odbioru :(");
  215.                 }
  216.             }
  217.             return true;
  218.         }
  219.  
  220.         protected override void ConfigValueChanged(string key)
  221.         {
  222.             Properties.Settings.Default.Reload();
  223.  
  224.             base.ConfigValueChanged(key);
  225.         }
  226.     }
  227. }
  228.