public void FillCliente() { try { if (comboBoxEmpresa.SelectedIndex != -1) { comboBoxCliente.Text = ""; Library.Empresa empresa = (Library.Empresa)comboBoxEmpresa.SelectedItem; comboBoxCliente.DisplayMember = "nome"; comboBoxCliente.ValueMember = "id"; comboBoxCliente.Items.Clear(); foreach (Library.TermoCompromisso tc in Library.TermoCompromissoBD.FindAdvanced(new QItem("e.id", empresa.Id), new QItem("ORDER BY", "c.nome"))) { if (tc.Status == (int)TCStatus.aberto || tc.Status == (int)TCStatus.notificando) { comboBoxCliente.Items.Add(tc.Cliente); } } } } catch (Exception ex) { Console.WriteLine(ex); } }
private void buttonVincular_Click(object sender, EventArgs e) { Library.Cliente cliente = (Library.Cliente)comboBoxCliente.SelectedItem; Library.Empresa empresa = (Library.Empresa)comboBoxEmpresa.SelectedItem; List <Library.TermoCompromisso> termos = Library.TermoCompromissoBD.FindAdvanced(new QItem("c.id", cliente.Id), new QItem("e.id", empresa.Id)); if (termos.Count >= 1) { string msg = string.Format("Já existe um vinculo entre o cliente \"{0}\" com a empresa \"{1}\"", cliente.Nome, empresa.Nome); MessageBox.Show(msg, "Vincular Cliente/Empresa"); } else { string msg = string.Format("Deseja mesmo vincular o cliente \"{0}\" com a empresa \"{1}\"?", cliente.Nome, empresa.Nome); if (MessageBox.Show(msg, "Vincular Cliente/Empresa", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (cliente != null && empresa != null) { Library.TermoCompromisso tc = new Library.TermoCompromisso(); tc.Cliente = cliente; tc.Empresa = empresa; tc.Data = DateTime.Now; tc.Status = (int)Library.TCStatus.aberto; Library.TermoCompromissoBD.Save(tc); } } } LoadTermosCompromissos(); }
public void FillCliente() { try { if (comboBoxEmpresa.SelectedIndex != -1) { DSettings set = new DSettings(); DAppSettings.Load(set); comboBoxCliente.Text = ""; Library.Empresa empresa = (Library.Empresa)comboBoxEmpresa.SelectedItem; comboBoxCliente.DisplayMember = "nome"; comboBoxCliente.ValueMember = "id"; comboBoxCliente.Items.Clear(); foreach (Library.TermoCompromisso tc in Library.TermoCompromissoBD.FindAdvanced(new QItem("e.id", empresa.Id), new QItem("tc.status", (int)Library.TCStatus.notificando), new QItem("ORDER BY", "c.nome"))) { List <Library.Notificacao> notificacoes = Library.NotificacaoBD.FindAdvanced(new QItem("tc.id", tc.Id)); if (notificacoes != null) { if (notificacoes.Count == 3) { DateTime data33 = notificacoes[2].Data.AddDays(set.textBoxNotificacao2).Date; if (data33 <= DateTime.Today) { comboBoxCliente.Items.Add(tc.Cliente); } } } } } } catch (Exception ex) { Console.WriteLine(ex); } }
static public Library.Empresa FindById(long idEmpresa) { NpgsqlConnection conexao = null; NpgsqlDataAdapter dap = null; DataSet ds = null; Library.Empresa Empresa = null; try { conexao = new NpgsqlConnection(global::Connection.Connection.StringPostgree()); dap = new NpgsqlDataAdapter("SELECT * FROM \"Empresa\" WHERE id='" + idEmpresa + "'", conexao); ds = new DataSet(); dap.Fill(ds, "Empresa"); if (ds.Tables["Empresa"].Rows.Count == 1) { Empresa = new Empresa(); Empresa.Id = (long)ds.Tables["Empresa"].Rows[0]["id"]; Empresa.Bairro = ds.Tables["Empresa"].Rows[0]["bairro"].ToString(); Empresa.Celular = ds.Tables["Empresa"].Rows[0]["celular"].ToString(); Empresa.Cep = ds.Tables["Empresa"].Rows[0]["cep"].ToString(); Empresa.Cpf = ds.Tables["Empresa"].Rows[0]["cpf"].ToString(); Empresa.Cnpj = ds.Tables["Empresa"].Rows[0]["cnpj"].ToString(); Empresa.Cidade = ds.Tables["Empresa"].Rows[0]["cidade"].ToString(); Empresa.Email = ds.Tables["Empresa"].Rows[0]["email"].ToString(); Empresa.Endereco = ds.Tables["Empresa"].Rows[0]["endereco"].ToString(); Empresa.Estado = ds.Tables["Empresa"].Rows[0]["estado"].ToString(); Empresa.Fax = ds.Tables["Empresa"].Rows[0]["fax"].ToString(); Empresa.InscricaoEstadual = ds.Tables["Empresa"].Rows[0]["inscricaoEstadual"].ToString(); if (Empresa.Nascimento != null) { Empresa.Nascimento = (DateTime?)ds.Tables["Empresa"].Rows[0]["nascimento"]; } else { Empresa.Nascimento = null; } Empresa.Nome = ds.Tables["Empresa"].Rows[0]["nome"].ToString(); Empresa.NomeContato = ds.Tables["Empresa"].Rows[0]["nomeContato"].ToString(); Empresa.NomeFantasia = ds.Tables["Empresa"].Rows[0]["nomeFantasia"].ToString(); Empresa.Observacoes = ds.Tables["Empresa"].Rows[0]["observacoes"].ToString(); Empresa.Pessoa = ds.Tables["Empresa"].Rows[0]["pessoa"].ToString(); Empresa.Rg = ds.Tables["Empresa"].Rows[0]["Rg"].ToString(); Empresa.ReferenciaComercial = ds.Tables["Empresa"].Rows[0]["referenciaComercial"].ToString(); Empresa.Site = ds.Tables["Empresa"].Rows[0]["site"].ToString(); Empresa.Telefone = ds.Tables["Empresa"].Rows[0]["telefone"].ToString(); Empresa.DataCadastro = (DateTime)ds.Tables["Empresa"].Rows[0]["dataCadastro"]; return(Empresa); } else { return(null); } } catch (Exception ex) { Library.Classes.Logger.Error(ex);; } finally { conexao.Close(); dap.Dispose(); ds.Dispose(); } return(null); }
static public List <Library.Empresa> FindAdvanced(params Library.Classes.QItem[] args) { NpgsqlDataReader rdr = null; NpgsqlConnection conexao = null; try { conexao = new NpgsqlConnection(global::Connection.Connection.StringPostgree()); using (NpgsqlCommand comando = new NpgsqlCommand()) { string query = "SELECT * FROM \"Empresa\" AS e "; int p = 0; string pre = ""; foreach (Library.Classes.QItem qi in args) { if (p == 0) { pre = "WHERE "; } else { pre = "AND "; } p++; switch (qi.Campo) { case "e.id": query += pre + "(e.id = @id)"; comando.Parameters.AddWithValue("@id", qi.Objeto); break; case "e.nome LIKE %%": query += pre + "(e.nome IILIKE '%' || @nome || '%')"; comando.Parameters.AddWithValue("@nome", qi.Objeto); break; case "e.pessoa": query += pre + "(e.pessoa = @pessoa)"; comando.Parameters.AddWithValue("@pessoa", qi.Objeto); break; case "ORDER BY": query += " ORDER BY " + qi.Objeto; break; } } comando.CommandText = query; comando.Connection = conexao; conexao.Open(); rdr = comando.ExecuteReader(); } List <Library.Empresa> empresas = new List <Library.Empresa>(); while (rdr.Read()) { Library.Empresa empresa = new Empresa(); empresa.Id = (long)rdr["id"]; empresa.Bairro = rdr["bairro"].ToString(); empresa.Celular = rdr["celular"].ToString(); empresa.Cep = rdr["cep"].ToString(); empresa.Cpf = rdr["cpf"].ToString(); empresa.Cnpj = rdr["cnpj"].ToString(); empresa.Cidade = rdr["cidade"].ToString(); empresa.Email = rdr["email"].ToString(); empresa.Endereco = rdr["endereco"].ToString(); empresa.Estado = rdr["estado"].ToString(); empresa.Fax = rdr["fax"].ToString(); empresa.InscricaoEstadual = rdr["inscricaoEstadual"].ToString(); // //// DateTime nasc = DateTime.MinValue; DateTime.TryParse(rdr["nascimento"].ToString(), out nasc); empresa.Nascimento = nasc; // //// empresa.Nome = rdr["nome"].ToString(); empresa.NomeContato = rdr["nomeContato"].ToString(); empresa.NomeFantasia = rdr["nomeFantasia"].ToString(); empresa.Observacoes = rdr["observacoes"].ToString(); empresa.Pessoa = rdr["pessoa"].ToString(); empresa.Rg = rdr["Rg"].ToString(); empresa.ReferenciaComercial = rdr["referenciaComercial"].ToString(); empresa.Site = rdr["site"].ToString(); empresa.Telefone = rdr["telefone"].ToString(); empresa.DataCadastro = DateTime.Parse(rdr["dataCadastro"].ToString()); empresas.Add(empresa); } return(empresas); } catch (Exception ex) { Library.Classes.Logger.Error(ex);; } finally { if (conexao != null) { conexao.Close(); } } return(null); }