public CredentialedForm(credentialed c) { InitializeComponent(); ControlsUtil.SetBackColor(this.Controls); try { SplashScreenManager.ShowForm(null, typeof(PleaseWaitForm), false, false, false); if (c == null) { c = new credentialed(); _address = new address(); btnInactive.Enabled = false; IsNew = true; } else { peLogo.Image = new FTPUtil().getImageFromFile(c.directory_logo); pCNPJ.Enabled = false; _address = address.SingleOrDefault(c.address_id); pData.Enabled = true; if (c.inactive) { btnInactive.Visible = false; btnSave.Visible = false; //pData.Enabled = false; } else btnReceivePayment.Enabled = true; IsNew = false; } bdgStates.DataSource = state.Fetch(""); bdgCredentialed.DataSource = c; bdgAddress.DataSource = _address; } catch (Exception ex) { XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException)); btnSave.Enabled = false; } finally { SplashScreenManager.CloseForm(false); } }
private void btnSearchCNPJ_Click(object sender, EventArgs e) { if (!validatorCNPJ.Validate()) return; try { //validações var countcnpj = credentialed.repo.ExecuteScalar<string>("SELECT COUNT(id) FROM credentialeds WHERE cnpj=@0", tfCNPJ.EditValue); if (!countcnpj.Equals(DBNull.Value) && !String.IsNullOrEmpty(countcnpj)) { if (Convert.ToInt32(countcnpj) >= 1) { DialogResult rs = XtraMessageBox.Show("CNPJ já consta cadastrado, deseja carregar os dados?", "Cadore Tecnologia", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (rs == DialogResult.No) return; credentialed cre = credentialed.SingleOrDefault("WHERE cnpj=@0", tfCNPJ.EditValue); bdgAddress.DataSource = address.SingleOrDefault(cre.address_id); bdgCredentialed.DataSource = cre; peLogo.Image = new FTPUtil().getImageFromFile(cre.directory_logo); pCNPJ.Enabled = false; pData.Enabled = true; IsNew = false; return; } } SearchCPFCNPJUtil cc = new SearchCPFCNPJUtil(); if (cc.Search(Document.CNPJ, tfCNPJ.Text)) { credentialed cre = new credentialed() { registered_at = null, inactived_at = null }; address d = new address(); cre.cnpj = cc.NCNPJ; cre.company_name = cc.RAZAOSOCIAL; cre.fantasy_name = cc.FANTASIA; cre.opening_at = Convert.ToDateTime(cc.ABERTURA); d.name = cc.ENDERECO; d.number = cc.NUMERO; d.complement = cc.COMPLEMENTO; d.district = cc.BAIRRO; d.cep = cc.CEP; state st = state.SingleOrDefault("WHERE symbol=@0", cc.UF); d.state_id = st != null ? st.id : 0; List<city> lci = city.Fetch("WHERE name ILIKE @0 AND state_id=@1", city.Concat(cc.CIDADE), st.id); d.city_id = lci[0] != null ? lci[0].id : 0; string[] f = cc.TELEFONE.Replace(" ", "").Split('/'); if (f.Length >= 1) cre.phone_fixed = f[0]; if (f.Length >= 2) cre.phone_mobile = f[1]; bdgAddress.DataSource = d; bdgCredentialed.DataSource = cre; pCNPJ.Enabled = false; pData.Enabled = true; } } catch (Exception ex) { XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException)); } }