Ejemplo n.º 1
0
        public bool SetFaturado(string id_order, AnyFaturados faturado)
        {
            bool ret = true;
            //foreach (SetStock setStock in lstSetStock)
            //{
            var url            = $"{baseUrl}orders/{id_order}?gumgaToken={token}";
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "PUT";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = JsonConvert.SerializeObject(faturado);

                streamWriter.Write(json);
            }
            try
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                ret = false;
                string msg = ex.Message;
                Log.Set($"Erro Set Faturado: {ex.Message}");
            }
            return(ret);
        }
Ejemplo n.º 2
0
        private void Faturado_Thread()
        {
            Db        db = new Db();
            DataTable dt = db.LoadFaturados();

            foreach (DataRow dr in dt.Rows)
            {
                Invoice invoice = new Invoice();
                //b.id_ANY AS ORDER_ID, 'INVOICED' AS STATUS, a.cd_Serie AS SERIES, a.cd_NF AS NUMBER, cd_Chave AS ACCESSKEY, 1, a.data

                AnyMarket anyMarket = new AnyMarket();
                if (dr["id_psp"].ToString() != "5")
                {
                    AnyFaturados faturado = new AnyFaturados();
                    // faturado.order_id = dr["ORDER_ID"].ToString();

                    faturado.status           = "INVOICED";
                    invoice.number            = dr["NUMBERO"].ToString();
                    invoice.series            = dr["SERIES"].ToString();
                    invoice.date              = dr["data"].ToString();
                    invoice.accessKey         = dr["ACCESSKEY"].ToString();
                    invoice.cfop              = dr["cd_cfop"].ToString();
                    invoice.companyStateTaxId = dr["cd_ie"].ToString();
                    faturado.invoice          = invoice;

                    if (anyMarket.SetFaturado(dr["order_id"].ToString(), faturado))
                    {
                        db.setFaturado(dr["id_nfs01"].ToString(), "200", "sucesso", "1");
                    }
                    else
                    {
                        db.setFaturado(dr["id_nfs01"].ToString(), "400", "erro", "2");
                    }
                }
                else
                {
                    if (dr["ds_xml"].ToString() != "")
                    {
                        anyMarket.PutXML(dr["ds_xml"].ToString(), dr["ds_xml"].ToString());
                    }
                    else
                    {
                        try
                        {
                            String xml = getXmlStr(dr["ACCESSKEY"].ToString() + "-procNFe.xml");
                            if (xml != "")
                            {
                                anyMarket.PutXML(dr["order_id"].ToString(), xml);
                                db.setFaturado(dr["id_nfs01"].ToString(), "200", "sucesso", "1");
                            }
                            else
                            {
                                db.setFaturado(dr["id_nfs01"].ToString(), "400", "erro - xml nao encontrado", "0");
                            }
                        } catch (Exception ex)
                        {
                            Log.Set("Erro no envio do xml " + ex.Message);
                        }
                    }
                }

                /*
                 * AnyMarket anyMarket = new AnyMarket();
                 * if (anyMarket.SetFaturado(dr["order_id"].ToString(), faturado))
                 * {
                 *  if (dr["ds_xml"].ToString() != "")
                 *  {
                 *      anyMarket.PutXML(dr["ds_xml"].ToString(), dr["ds_xml"].ToString());
                 *  }
                 *  else
                 *  {
                 *      String xml = getXmlStr(dr["ACCESSKEY"].ToString() + "-procNFe.xml");
                 *      if (xml != "")
                 *      {
                 *          anyMarket.PutXML(dr["order_id"].ToString(), xml);
                 *      }
                 *  }
                 *  db.setFaturado(dr["id_nfs01"].ToString(), "200", "sucesso", "1");
                 * }
                 * else
                 * {
                 *  db.setFaturado(dr["id_nfs01"].ToString(), "400", "erro", "2");
                 * }
                 */
            }
        }