public TicketOpenRes ApriTicket(ContrattoConto conto)
 {
     try {
         ParametriConto par = new ParametriConto(conto);
         if (!String.IsNullOrEmpty(par.idBuonoChiaro))
         {
             log.InfoFormat("Apri Ticket - Ticket giĆ  aperto - idBuonoChiaro: {0} - idConto {1} idUtente: {2}", par.idBuonoChiaro, par.IdConto, conto.CassiereLogin);
             return(new TicketOpenRes()
             {
                 COMRES = enumCOMRES.OK.ToString(), ERRMSG = String.Empty, IDTR = par.idBuonoChiaro
             });
         }
         else
         {
             TicketOpenReq apriTicket = new TicketOpenReq();
             apriTicket.Init(conto);
             string request     = apriTicket.ToXML();
             string logFileName = System.IO.Path.Combine(config.AppSettings.Settings["LogPath"].Value
                                                         , conto.DataGestione.Value.ToString("yyMMdd") + "_" + conto.IdGestionale + "_" + apriTicket.TipoOperazione + "_{0}_{1}.xml");
             System.IO.File.WriteAllText(String.Format(logFileName, "request", DateTime.Now.ToString("hhmmss")), request);
             string response = InviaSocket(request);
             System.IO.File.WriteAllText(String.Format(logFileName, "response", DateTime.Now.ToString("hhmmss")), request);
             TicketOpenRes res = (TicketOpenRes) new System.Xml.Serialization.XmlSerializer(typeof(TicketOpenRes)).Deserialize(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(response)));
             return(res);
         }
     }
     catch (Exception ex)
     {
         log.ErrorFormat("Errore Apri Ticket - Origine: {0} - Riga {1} Errore: {2}", System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString().Substring(ex.ToString().LastIndexOf(" ") + 1), ex.Message);
         return(new TicketOpenRes()
         {
             COMRES = enumCOMRES.KO.ToString(), ERRMSG = ex.Message
         });
     }
 }
        public TicketVoidRes AnnullaTicketChiuso(ContrattoConto conto, string numeroConto, string buono)
        {
            try
            {
                TicketOpenReq apriTicket = new TicketOpenReq();
                apriTicket.Init(conto);
                apriTicket.NumeroScontrino = numeroConto;
                apriTicket.Progressivo     = apriTicket.Progressivo.Replace(conto.IdGestionale.ToString(), numeroConto);
                string openrequest = apriTicket.ToXML();
                string logFileName = System.IO.Path.Combine(config.AppSettings.Settings["LogPath"].Value
                                                            , conto.DataGestione.Value.ToString("yyMMdd") + "_" + numeroConto + "_" + apriTicket.TipoOperazione + "_{0}_{1}.xml");
                System.IO.File.WriteAllText(String.Format(logFileName, "request", DateTime.Now.ToString("hhmmss")), openrequest);
                string openresponse = InviaSocket(openrequest);
                System.IO.File.WriteAllText(String.Format(logFileName, "response", DateTime.Now.ToString("hhmmss")), openresponse);


                TicketVoidAdminModeReq validaTicket = new TicketVoidAdminModeReq();
                validaTicket.Init(conto);
                validaTicket.CaricaBuono(buono);
                validaTicket.NumeroScontrino = numeroConto;
                validaTicket.Progressivo     = apriTicket.Progressivo.Replace(conto.IdGestionale.ToString(), numeroConto);
                string request = validaTicket.ToXML();
                logFileName = System.IO.Path.Combine(config.AppSettings.Settings["LogPath"].Value
                                                     , conto.DataGestione.Value.ToString("yyMMdd") + "_" + conto.IdGestionale + "_" + validaTicket.TipoOperazione + "_{0}_{1}.xml");
                System.IO.File.WriteAllText(String.Format(logFileName, "request", DateTime.Now.ToString("hhmmss")), request);
                string response = InviaSocket(request);
                System.IO.File.WriteAllText(String.Format(logFileName, "response", DateTime.Now.ToString("hhmmss")), response);
                TicketVoidRes res = (TicketVoidRes) new System.Xml.Serialization.XmlSerializer(typeof(TicketVoidRes)).Deserialize(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(response)));
                return(res);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Errore Valida Ticket - Origine: {0} - Riga {1} Errore: {2}", System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString().Substring(ex.ToString().LastIndexOf(" ") + 1), ex.Message);
                return(new TicketVoidRes()
                {
                    COMRES = enumCOMRES.KO.ToString(), ERRMSG = ex.Message
                });
            }
        }