Exemplo n.º 1
0
        public CadastroPedido ConsultaUltimoPedido()
        {
            WS.ServiceLayer.ServiceLayer Service = new WS.ServiceLayer.ServiceLayer();
            CadastroPedido _Retorno = new CadastroPedido();

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

                    var    Schema = ConfigurationManager.AppSettings["CompanyDB"];
                    string Sql    = string.Format(Properties.Resources.ConsultaUltimoPedido, 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 DocEntry = productInfoReader.GetString(0);

                                var GetPedido = Service.Get($"Orders({DocEntry})");
                                _Retorno = JsonConvert.DeserializeObject <CadastroPedido>(GetPedido.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                });

                                //var GetJob = Service.Get($"JOB?$select=*&$filter=U_NEO_DocEntry eq '{DocEntry}'");
                                //var RetObjJob = Newtonsoft.Json.JsonConvert.DeserializeObject<CadastroJobs>(GetJob.Documento, new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore });

                                //if (RetObjJob.value.ToList().Count > 0)
                                //{
                                //    _Retorno.CadastroJob = new CadastroJob[RetObjJob.value.ToList().Count];
                                //    _Retorno.CadastroJob = RetObjJob.value;
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            finally
            {
                //Service.Logout();
            }

            return(_Retorno);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public CadastroAtividade ConsultaUltimoAtividade()
        {
            WS.ServiceLayer.ServiceLayer Service  = new WS.ServiceLayer.ServiceLayer();
            CadastroAtividade            _Retorno = new CadastroAtividade();

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

                    var    Schema = ConfigurationManager.AppSettings["CompanyDB"];
                    string Sql    = string.Format(Properties.Resources.ConsultaUltimoAtividade, 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 DocEntry = productInfoReader.GetString(0);
                                var CardName = productInfoReader.GetString(1);

                                var GetAtividade = Service.Get($"Activities({DocEntry})");
                                _Retorno = JsonConvert.DeserializeObject <CadastroAtividade>(GetAtividade.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                });
                                _Retorno.CardName = CardName;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            finally
            {
                //Service.Logout();
            }

            return(_Retorno);
        }
Exemplo n.º 4
0
        public CadastroAtividades ConsultaAtividade(CadastroAtividade atividade)
        {
            WS.ServiceLayer.ServiceLayer Service  = new WS.ServiceLayer.ServiceLayer();
            CadastroAtividades           _Retorno = new CadastroAtividades();

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

                    var Schema = ConfigurationManager.AppSettings["CompanyDB"];

                    string Sql = string.Format(Properties.Resources.ConsultaAtividade, Schema, atividade.CardCode, atividade.CardName, atividade.ActivityCode);

                    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 DocEntry = productInfoReader.GetString(0);
                                var CardName = productInfoReader.GetString(1);
                                var Count    = productInfoReader.GetString(2);

                                var GetPN             = Service.Get($"Activities({DocEntry})");
                                var _RetornoAtividade = JsonConvert.DeserializeObject <CadastroAtividade>(GetPN.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                });
                                _RetornoAtividade.CardName = CardName;

                                _Retorno.value    = new CadastroAtividade[int.Parse(Count)];
                                _Retorno.value[0] = new CadastroAtividade();
                                _Retorno.value[0] = _RetornoAtividade;

                                int i = 1;

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

                                    DocEntry = productInfoReader.GetString(0);
                                    CardName = productInfoReader.GetString(1);

                                    GetPN             = Service.Get($"Activities({DocEntry})");
                                    _RetornoAtividade = JsonConvert.DeserializeObject <CadastroAtividade>(GetPN.Documento, new Newtonsoft.Json.JsonSerializerSettings {
                                        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                                    });
                                    _RetornoAtividade.CardName = CardName;

                                    _Retorno.value[i] = _RetornoAtividade;

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

            return(_Retorno);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }