示例#1
0
        private void Save_Historico(GTI_Models.Models.Cidadao regNew)
        {
            List <string> aLog = new List <string>();

            if (regNew.Nomecidadao != regHist.Nome)
            {
                aLog.Add("Alterado o nome de " + regHist.Nome + " para " + regNew.Nomecidadao);
            }
            if (gtiCore.SubNull(regNew.Rg) != gtiCore.SubNull(regHist.Rg))
            {
                aLog.Add("Alterado o Rg de " + regHist.Rg + " para " + regNew.Rg);
            }
            if (gtiCore.SubNull(regNew.Cpf) != gtiCore.SubNull(regHist.Cpf))
            {
                aLog.Add("Alterado o Cpf de " + regHist.Cpf + " para " + regNew.Cpf);
            }
            if (gtiCore.SubNull(regNew.Cnpj) != gtiCore.SubNull(regHist.Cnpj))
            {
                aLog.Add("Alterado o Cnpj de " + regHist.Cnpj + " para " + regNew.Cnpj);
            }
            if (gtiCore.SubNull(regNew.Cnh) != gtiCore.SubNull(regHist.Cnh))
            {
                aLog.Add("Alterado a Cnh de " + regHist.Cnh + " para " + regNew.Cnh);
            }
            if (regNew.Data_nascimento != regHist.DataNascto)
            {
                aLog.Add("Alterado a data de nascto. de " + regHist.DataNascto + " para " + regNew.Data_nascimento);
            }
            if (gtiCore.SubNull(LogradouroRText.Text) != gtiCore.SubNull(regHist.EnderecoR))
            {
                aLog.Add("Alterado o logradouro res. de " + regHist.EnderecoR + " para " + regNew.Nomelogradouro);
            }
            if (gtiCore.SubNull(LogradouroCText.Text) != gtiCore.SubNull(regHist.EnderecoC))
            {
                aLog.Add("Alterado o logradouro com. de " + regHist.EnderecoC + " para " + regNew.Nomelogradouro2);
            }
            if (gtiCore.SubNull(regNew.Numimovel) != gtiCore.SubNull(regHist.NumeroR))
            {
                aLog.Add("Alterado o nº res. de " + regHist.NumeroR + " para " + regNew.Numimovel);
            }
            if (gtiCore.SubNull(regNew.Numimovel2) != gtiCore.SubNull(regHist.NumeroC))
            {
                aLog.Add("Alterado o nº com. de " + regHist.NumeroC + " para " + regNew.Numimovel2);
            }
            if (gtiCore.SubNull(regNew.Profissao) != gtiCore.SubNull(regHist.Profissao))
            {
                aLog.Add("Alterado a profissão de " + regHist.Profissao + " para " + regNew.Profissao);
            }

            if (aLog.Count > 0)
            {
                Cidadao_bll cidadaoRepository = new Cidadao_bll(_connection);
                foreach (string item in aLog)
                {
                    historicocidadao _hist = new historicocidadao {
                        Codigo = regNew.Codcidadao,
                        Obs    = item,
                        Userid = Properties.Settings.Default.UserId,
                        Data   = DateTime.Now
                    };
                    Exception ex = cidadaoRepository.Incluir_Historico_Cidadao(_hist);
                }
            }
        }
示例#2
0
        private void SaveReg()
        {
            if (MessageBox.Show("Gravar os dados?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                GTI_Models.Models.Cidadao reg = new GTI_Models.Models.Cidadao {
                    Nomecidadao = NomeText.Text,
                    Rg          = string.IsNullOrWhiteSpace(RGText.Text) ? null : RGText.Text,
                    Orgao       = string.IsNullOrWhiteSpace(OrgaoText.Text) ? null : OrgaoText.Text,
                    Cnh         = string.IsNullOrWhiteSpace(CnhText.Text) ? null : CnhText.Text,
                    Orgaocnh    = string.IsNullOrWhiteSpace(CnhOrgaotext.Text) ? null : CnhOrgaotext.Text
                };
                if (PessoaList.SelectedIndex == 0)
                {
                    if (CPFMask.Text != "")
                    {
                        reg.Cpf = CPFMask.Text;
                    }
                }
                else
                {
                    if (CNPJMask.Text != "")
                    {
                        reg.Cnpj = CNPJMask.Text;
                    }
                }

                reg.Juridica = JuridicaCheck.Checked ? true : false;
                if (DataNasctoMask.MaskCompleted && gtiCore.IsDate(DataNasctoMask.Text))
                {
                    reg.Data_nascimento = Convert.ToDateTime(DataNasctoMask.Text);
                }
                else
                {
                    reg.Data_nascimento = null;
                }
                if (ProfissaoList.SelectedIndex > -1)
                {
                    reg.Codprofissao = Convert.ToInt32(ProfissaoList.SelectedValue);
                }


                if (PaisRText.Tag.ToString() == "")
                {
                    PaisRText.Tag = "1";
                }
                if (PaisCText.Tag.ToString() == "")
                {
                    PaisCText.Tag = "1";
                }
                if (!string.IsNullOrWhiteSpace(LogradouroRText.Text))
                {
                    reg.Codpais        = PaisRText.Tag == null ? 0 : Convert.ToInt32(PaisRText.Tag.ToString());
                    reg.Siglauf        = UFRText.Text;
                    reg.Codcidade      = string.IsNullOrWhiteSpace(CidadeRText.Tag.ToString()) ? (short)0 : Convert.ToInt16(CidadeRText.Tag.ToString());
                    reg.Codbairro      = string.IsNullOrWhiteSpace(BairroRText.Tag.ToString())? (short)0 : Convert.ToInt16(BairroRText.Tag.ToString());
                    reg.Codlogradouro  = string.IsNullOrWhiteSpace(LogradouroRText.Tag.ToString()) ? 0 : Convert.ToInt32(LogradouroRText.Tag.ToString());
                    reg.Nomelogradouro = reg.Codcidade != 413 ? LogradouroRText.Text : "";
                    reg.Numimovel      = NumeroRText.Text == "" ? (short)0 : Convert.ToInt16(NumeroRText.Text);
                    reg.Complemento    = ComplementoRText.Text;
                    reg.Cep            = reg.Codcidade != 413 ? CepRText.Text == "" ? 0 : Convert.ToInt32(gtiCore.RetornaNumero(CepRText.Text)) : 0;
                    reg.Email          = EmailRText.Text;
                    reg.Etiqueta       = EtiquetaRCheck.Checked ? "S" : "N";
                    reg.Telefone       = string.IsNullOrWhiteSpace(FoneRText.Text) ? null : FoneRText.Text;
                    reg.Temfone        = TemFoneRCheck.Checked;
                    reg.Whatsapp       = WhatsAppRCheck.Checked;
                }

                if (!string.IsNullOrWhiteSpace(LogradouroCText.Text))
                {
                    reg.Codpais2        = PaisCText.Tag == null ? 0 : Convert.ToInt32(PaisCText.Tag.ToString());
                    reg.Siglauf2        = UFCText.Text;
                    reg.Codcidade2      = string.IsNullOrWhiteSpace(CidadeCText.Tag.ToString()) ? (short)0 : Convert.ToInt16(CidadeCText.Tag.ToString());
                    reg.Codbairro2      = string.IsNullOrWhiteSpace(BairroCText.Tag.ToString()) ? (short)0 : Convert.ToInt16(BairroCText.Tag.ToString());
                    reg.Codlogradouro2  = string.IsNullOrWhiteSpace(LogradouroCText.Tag.ToString()) ? 0 : Convert.ToInt32(LogradouroCText.Tag.ToString());
                    reg.Nomelogradouro2 = reg.Codcidade2 != 413 ? LogradouroCText.Text : "";
                    reg.Numimovel2      = NumeroCText.Text == "" ? (short)0 : Convert.ToInt16(NumeroCText.Text);
                    reg.Complemento2    = ComplementoCText.Text;
                    reg.Cep2            = reg.Codcidade2 != 413 ? CepCText.Text == "" ? 0 : Convert.ToInt32(gtiCore.RetornaNumero(CepCText.Text)) : 0;
                    reg.Email2          = EmailCText.Text;
                    reg.Etiqueta2       = EtiquetaCButton.Checked ? "S" : "N";
                    reg.Telefone2       = string.IsNullOrWhiteSpace(FoneCText.Text) ? null : FoneCText.Text;
                    reg.Temfone2        = TemFoneCCheck.Checked;
                    reg.Whatsapp2       = WhatsAppCCheck.Checked;
                }

                Cidadao_bll cidadaoRepository = new Cidadao_bll(_connection);
                Exception   ex;

                if (bAddNew)
                {
                    int nLastCod = cidadaoRepository.Incluir_cidadao(reg);
                    CodigoText.Text = nLastCod.ToString();
                    ControlBehaviour(true);
                }
                else
                {
                    reg.Codcidadao = Convert.ToInt32(CodigoText.Text);
                    ex             = cidadaoRepository.Alterar_cidadao(reg);
                    if (ex != null)
                    {
                        ErrorBox eBox = new ErrorBox("Atenção", ex.Message, ex);
                        eBox.ShowDialog();
                    }
                    else
                    {
                        Save_Historico(reg);
                        ControlBehaviour(true);
                    }
                }
            }
        }