コード例 #1
0
        public Int32 Salvar(TColetorVO tcoletorvo)
        {
            try
            {
                if (tcoletorvo.IDColetor > 0)
                {
                    TColetorBLL.Alterar(tcoletorvo);
                }
                else
                {
                    TColetorBLL.Inserir(tcoletorvo);
                }

                return(tcoletorvo.IDColetor);
            }
            catch (CABTECException)
            {
                throw new CABTECException("Erro ao Salvar Coletor.");
            }
            catch (Exception)
            {
                throw new CABTECException("Erro ao Salvar Coletor.");
            }
        }
コード例 #2
0
        public string AssociarColetorVendedor(string idColetorEscolhido, string idVendedorEscolhido)
        {
            try
            {
                string mensagem = string.Empty;

                //Dois IDs Nulos
                if (string.IsNullOrEmpty(idColetorEscolhido) && string.IsNullOrEmpty(idVendedorEscolhido))
                {
                    mensagem = "Não foi realizado a associação.";
                }


                if (!string.IsNullOrEmpty(idColetorEscolhido))
                {
                    TColetorVO coletorEscolhido = TColetorBLL.Obter(Convert.ToInt32(idColetorEscolhido));

                    //Limpar Associação
                    if (string.IsNullOrEmpty(idVendedorEscolhido))
                    {
                        coletorEscolhido.IDUsuarioResponsavel = 0;
                        TColetorBLL.Alterar(coletorEscolhido);
                        mensagem = "O Coletor: " + coletorEscolhido.NumeroSerie + " não está mais associado a nenhum Vendedor!";
                    }
                    else
                    {
                        //Associar Coletor
                        if (coletorEscolhido != null)
                        {
                            //Limpar Associação Antiga
                            TColetorVO vendedorAntigo = TColetorBLL.ObterPorVendedor(coletorEscolhido.IDUsuarioResponsavel.GetValueOrDefault(0));

                            if (vendedorAntigo != null)
                            {
                                TUsuarioVO usuarioAntigo = TUsuarioBLL.Obter(vendedorAntigo.IDUsuarioResponsavel.Value);
                                vendedorAntigo.IDUsuarioResponsavel = 0;
                                TColetorBLL.Alterar(vendedorAntigo);
                                mensagem = "O Vendedor: " + usuarioAntigo.Nome + " não está mais associado a nenhum Coletor!<br/>";
                            }

                            //Limpar Associação Antiga
                            TColetorVO coletorAntigo = TColetorBLL.ObterPorVendedor(Convert.ToInt32(idVendedorEscolhido));

                            if (coletorAntigo != null)
                            {
                                TUsuarioVO usuarioAntigo = TUsuarioBLL.Obter(coletorAntigo.IDUsuarioResponsavel.Value);
                                coletorAntigo.IDUsuarioResponsavel = 0;
                                TColetorBLL.Alterar(coletorAntigo);
                                mensagem = "O Coletor: " + coletorAntigo.NumeroSerie + " não está mais associado a nenhum Vendedor!<br/>";
                            }

                            coletorEscolhido.IDUsuarioResponsavel = Convert.ToInt32(idVendedorEscolhido);
                            TColetorBLL.Alterar(coletorEscolhido);

                            TUsuarioVO usuarioAtual = TUsuarioBLL.Obter(Convert.ToInt32(idVendedorEscolhido));

                            if (usuarioAtual != null)
                            {
                                mensagem += "O Coletor: " + coletorEscolhido.NumeroSerie + " e o Vendedor: " + usuarioAtual.Nome + " foram associados com sucesso!";
                            }
                        }
                        else
                        {
                            TUsuarioVO usuarioAtual = TUsuarioBLL.Obter(Convert.ToInt32(idVendedorEscolhido));

                            if (usuarioAtual != null)
                            {
                                TColetorVO coletorAntigo = TColetorBLL.ObterPorVendedor(Convert.ToInt32(idVendedorEscolhido));

                                if (coletorAntigo != null)
                                {
                                    coletorAntigo.IDUsuarioResponsavel = 0;
                                    TColetorBLL.Alterar(coletorAntigo);
                                }

                                mensagem = "O Vendedor: " + usuarioAtual.Nome + " não está mais associado a nenhum Coletor!";
                            }
                        }
                    }
                }
                else
                {
                    TColetorVO coletorAntigo = TColetorBLL.ObterPorVendedor(Convert.ToInt32(idVendedorEscolhido));

                    if (coletorAntigo != null)
                    {
                        coletorAntigo.IDUsuarioResponsavel = 0;
                        TColetorBLL.Alterar(coletorAntigo);

                        TUsuarioVO usuarioAtual = TUsuarioBLL.Obter(Convert.ToInt32(idVendedorEscolhido));

                        if (usuarioAtual != null)
                        {
                            mensagem = "O Vendedor: " + usuarioAtual.Nome + " não está mais associado a nenhum Coletor!";
                        }
                    }
                }

                return(mensagem);
            }
            catch (CABTECException)
            {
                throw new CABTECException("Erro ao Associar Coletor e Vendedor.");
            }
            catch (Exception)
            {
                throw new CABTECException("Erro ao Associar Coletor e Vendedor.");
            }
        }