Ejemplo n.º 1
0
        public CadastroPN ConsultaUltimoPN()
        {
            WS.ServiceLayer.ServiceLayer Service = new WS.ServiceLayer.ServiceLayer();
            CadastroPN _Retorno = new CadastroPN();

            try
            {
                //var RetLogin = Service.Login();
                //if (!RetLogin.Sucesso)
                //{
                //    Log.Error("Erro do Login SL");
                //}

                using (HanaConnection conn = new HanaConnection(ConfigurationManager.ConnectionStrings["Hana"].ConnectionString))
                {
                    conn.Open();

                    var    Schema = ConfigurationManager.AppSettings["CompanyDB"];
                    string Sql    = string.Format(Properties.Resources.ConsultaUltimoPN, Schema);

                    using (HanaCommand cmd3 = new HanaCommand(Sql, conn))
                    {
                        using (HanaDataReader productInfoReader3 = cmd3.ExecuteReader())
                        {
                            HanaCommand    cmd = new HanaCommand(Sql, conn);
                            HanaDataReader productInfoReader = cmd.ExecuteReader();

                            while (productInfoReader.Read())
                            {
                                var CardCode = productInfoReader.GetString(0);

                                var GetPN = Service.Get($"BusinessPartners('{CardCode}')");
                                _Retorno = JsonConvert.DeserializeObject <CadastroPN>(GetPN.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            finally
            {
                //Service.Logout();
            }

            return(_Retorno);
        }
Ejemplo n.º 2
0
        public Retorno InsereAtualizaPN(CadastroPN PN)
        {
            WS.ServiceLayer.ServiceLayer Service = new WS.ServiceLayer.ServiceLayer();
            Retorno _Retorno = new Retorno();

            try
            {
                //var RetLogin = Service.Login();
                //if (!RetLogin.Sucesso)
                //{
                //    Log.Error("Erro do Login SL");
                //    return RetLogin;
                //}

                var GetPN = Service.Get($"BusinessPartners('{PN.CardCode}')");

                if (!GetPN.Sucesso)
                {
                    #region Insere PN

                    //if (!PN.Series.Equals(73))
                    //{
                    //    PN.CardCode = null;
                    //}

                    var Json = JsonConvert.SerializeObject(PN, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings {
                        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                    });

                    _Retorno = Service.Add("BusinessPartners", Json);

                    #endregion
                }
                else
                {
                    #region Atualiza PN

                    CadastroPN GetObjPN = JsonConvert.DeserializeObject <CadastroPN>(GetPN.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                    });

                    #region Atualiza Endereço PN

                    if (PN.BPAddresses != null)
                    {
                        if (GetObjPN.BPAddresses != null)
                        {
                            foreach (var GetEndereco in GetObjPN.BPAddresses)
                            {
                                foreach (var Endereco in PN.BPAddresses)
                                {
                                    if (GetEndereco.AddressName == Endereco.AddressName && GetEndereco.AddressType == Endereco.AddressType)
                                    {
                                        Endereco.RowNum = GetEndereco.RowNum;
                                        Endereco.BPCode = GetEndereco.BPCode;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                    #region Atualiza Contato PN

                    if (PN.ContactEmployees != null)
                    {
                        if (GetObjPN.ContactEmployees != null)
                        {
                            foreach (var GetContato in GetObjPN.ContactEmployees)
                            {
                                foreach (var Contato in PN.ContactEmployees)
                                {
                                    if (GetContato.Name == Contato.Name)
                                    {
                                        Contato.CardCode     = GetContato.CardCode;
                                        Contato.InternalCode = GetContato.InternalCode;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                    #region Atualiza Fiscal PN

                    if (PN.BPFiscalTaxIDCollection != null)
                    {
                        foreach (var Fiscal in PN.BPFiscalTaxIDCollection)
                        {
                            Fiscal.BPCode = PN.CardCode;
                        }
                    }

                    #endregion

                    var Json = Newtonsoft.Json.JsonConvert.SerializeObject(PN, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings {
                        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                    });

                    _Retorno = Service.Update($"BusinessPartners('{PN.CardCode}')", Json);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            finally
            {
                //Service.Logout();
            }

            return(_Retorno);
        }
Ejemplo n.º 3
0
        public CadastrosPNs ConsultaPN(CadastroPN PN)
        {
            WS.ServiceLayer.ServiceLayer Service = new WS.ServiceLayer.ServiceLayer();
            CadastrosPNs _Retorno = new CadastrosPNs();

            try
            {
                //var RetLogin = Service.Login();
                //if (!RetLogin.Sucesso)
                //{
                //    Log.Error("Erro do Login SL");
                //}

                using (HanaConnection conn = new HanaConnection(ConfigurationManager.ConnectionStrings["Hana"].ConnectionString))
                {
                    conn.Open();

                    var    Schema = ConfigurationManager.AppSettings["CompanyDB"];
                    string CNPJ   = string.Empty;
                    string CPF    = string.Empty;

                    if (PN.BPFiscalTaxIDCollection != null)
                    {
                        CNPJ = PN.BPFiscalTaxIDCollection[0].TaxId0;
                        CPF  = PN.BPFiscalTaxIDCollection[0].TaxId4;
                    }

                    string Sql = string.Format(Properties.Resources.ConsultaPN, Schema, PN.CardCode, PN.CardName, CNPJ, CPF);

                    using (HanaCommand cmd3 = new HanaCommand(Sql, conn))
                    {
                        using (HanaDataReader productInfoReader3 = cmd3.ExecuteReader())
                        {
                            HanaCommand    cmd = new HanaCommand(Sql, conn);
                            HanaDataReader productInfoReader = cmd.ExecuteReader();

                            if (productInfoReader.HasRows)
                            {
                                productInfoReader.Read();

                                var Count    = productInfoReader.GetString(1);
                                var CardCode = productInfoReader.GetString(0);

                                var GetPN      = Service.Get($"BusinessPartners('{CardCode}')");
                                var _RetornoPN = JsonConvert.DeserializeObject <CadastroPN>(GetPN.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                });

                                _Retorno.value    = new CadastroPN[int.Parse(Count)];
                                _Retorno.value[0] = new CadastroPN();
                                _Retorno.value[0] = _RetornoPN;

                                int i = 1;

                                while (productInfoReader.Read())
                                {
                                    _Retorno.value[i] = new CadastroPN();

                                    CardCode = productInfoReader.GetString(0);

                                    GetPN      = Service.Get($"BusinessPartners('{CardCode}')");
                                    _RetornoPN = JsonConvert.DeserializeObject <CadastroPN>(GetPN.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                    });
                                    _Retorno.value[i] = _RetornoPN;

                                    i++;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            finally
            {
                //Service.Logout();
            }

            return(_Retorno);
        }