private bool checarDatas(reserva n) { using (hotelEntities ef = new hotelEntities()) { var listaReservas = ef.vw_reservas .Where(e => e.numero == this.temp_quarto.numero && DateTime.Compare(e.dt_inicio, n.dt_termino) <= 0 && DateTime.Compare(e.dt_termino, n.dt_inicio) >= 0) .ToList(); int max = this.Operacao == 'n' ? 0 : 1; if (listaReservas.Count > max) { MessageBox.Show( "Há reservas em conflito!", "Cadastrar Reserva", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { return(true); } } }
private void btnExcluir_Click(object sender, EventArgs e) { if (dgvQuartos.CurrentRow != null) { DialogResult opcao = MessageBox.Show( "Tem certeza que deseja excluir esse quarto?", "Excluir quarto", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (opcao.Equals(DialogResult.Yes)) { int id = Convert.ToInt32(dgvQuartos.CurrentRow.Cells["id"].Value.ToString()); using (hotelEntities ef = new hotelEntities()) { var escolhido = ef.quarto.Find(id); ef.quarto.Remove(escolhido); ef.SaveChanges(); } CarregarGrid(); } } else { MessageBox.Show( "Nenhum quarto selecionado!", "Excluir quarto", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CarregarGrid(string termos = "") { using (hotelEntities ef = new hotelEntities()) { var listaReservas = ef.reserva .Where(r => r.ativo == true) .Select(r => new { ID = r.id, Inicio = r.dt_inicio, Termino = r.dt_termino, Quarto = r.quarto.numero, Cliente = r.cliente.primeiro_nome + " " + r.cliente.ultimo_nome, Status = r.dt_entrada == null ? "Pendente" : r.dt_saida == null ? "Em aberto" : "Encerrada" }); if (!cbMostrarEncerradas.Checked) { listaReservas = listaReservas .Where(r => !r.Status.Equals("Encerrada")); } listaReservas = listaReservas.OrderBy(r => r.Inicio); var listaReservasList = listaReservas.ToList(); if (!termos.Equals("")) { listaReservasList = listaReservasList.FindAll(r => r.Cliente.ToUpper().StartsWith(termos.ToUpper()) || r.Quarto.ToString().StartsWith(termos)); } dgvReservas.DataSource = listaReservasList; } }
private void btnSalvar_Click(object sender, EventArgs e) { cliente c; bool valido = checarCampos(out c); if (this.Operacao.Equals('n') && valido) { using (hotelEntities ef = new hotelEntities()) { ef.cliente.Add(c); ef.SaveChanges(); } } if (this.Operacao.Equals('e') && valido) { int _id = this.escolhidoId; using (hotelEntities ef = new hotelEntities()) { cliente novo = ef.cliente.Find(_id); novo.primeiro_nome = c.primeiro_nome; novo.ultimo_nome = c.ultimo_nome; novo.doc_rg = c.doc_rg; novo.doc_cpf = c.doc_cpf; novo.dt_nasc = c.dt_nasc; ef.SaveChanges(); } } if (valido) { limparCampos(); tcCliente.SelectedTab = tpgClientes; CarregarGrid(); } }
private void btnCheckin_Click(object sender, EventArgs e) { if (dgvQuartos.CurrentRow != null) { DialogResult conf = MessageBox.Show( "Realmente deseja realizar check-in?", "Atualizar Reserva", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (conf == DialogResult.Yes) { int _id = Convert.ToInt32(dgvQuartos.CurrentRow.Cells["id"].Value.ToString()); using (hotelEntities ef = new hotelEntities()) { var escolhido = ef.reserva.Find(_id); escolhido.dt_entrada = DateTime.Now; ef.SaveChanges(); } CarregarGrid(); } } else { MessageBox.Show( "Nenhuma reserva foi selecionada!", "Checkin de reserva", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CarregarGrid(string termos = "") { using (hotelEntities ef = new hotelEntities()) { var dados = ef.cliente .Where(c => c.ativo == true) .Select(c => new { ID = c.id, PrimeiroNome = c.primeiro_nome, UltimoNome = c.ultimo_nome, RG = c.doc_rg }) .ToList(); var autoCompleteDados = ef.cliente .Where(c => c.ativo == true) .Select(c => c.primeiro_nome) .ToArray <string>(); if (!termos.Equals("")) { dados = dados.FindAll(c => c.PrimeiroNome.ToUpper().StartsWith(termos.ToUpper()) || c.UltimoNome.ToUpper().StartsWith(termos.ToUpper()) || c.RG.Replace(",", string.Empty).StartsWith(termos)); } dgvClientes.DataSource = dados; var source = new AutoCompleteStringCollection(); source.AddRange(autoCompleteDados); txtTermo.AutoCompleteMode = AutoCompleteMode.Append; txtTermo.AutoCompleteCustomSource = source; txtTermo.AutoCompleteSource = AutoCompleteSource.CustomSource; } }
private void CarregarGrid() { using (hotelEntities ef = new hotelEntities()) { var dados = ef.cliente .Where(c => c.ativo == true) .Select(c => new { c.id, c.primeiro_nome, c.ultimo_nome, c.doc_rg }) .ToList(); dgvClientes.DataSource = dados; } }
private void CarregarGrid() { using (hotelEntities ef = new hotelEntities()) { var dados = ef.quarto .Where(q => q.ativo == true) .Select(q => new { q.id, q.numero, q.andar, q.preco, q.tipo, q.tamanho }) .ToList(); dgvQuartos.DataSource = dados; } }
private void preencherCampos(int _id) { using (hotelEntities ef = new hotelEntities()) { cliente c = ef.cliente.Find(_id); txtPrimeiroNome.Text = c.primeiro_nome; txtUltimoNome.Text = c.ultimo_nome; txtRG.Text = c.doc_rg; txtCPF.Text = c.doc_cpf; txtDtNasc.Text = c.dt_nasc.ToString(); } }
private void preencherCampos(int _id) { this.escolhidoId = _id; using (hotelEntities ef = new hotelEntities()) { reserva r = ef.reserva.Find(_id); txtCliente.Text = r.cliente.primeiro_nome + r.cliente.ultimo_nome; this.temp_cliente = r.cliente; txtQuarto.Text = r.quarto.numero.ToString(); this.temp_quarto = r.quarto; txtDtInicio.Value = r.dt_inicio; txtDtTermino.Value = r.dt_termino; } }
private bool checarCampos(out reserva r) { DateTime dt_inicio = DateTime.MinValue, dt_termino = DateTime.MinValue; string mensagem = ""; if (txtCliente.Text.Equals("") || this.temp_cliente == null) { mensagem += "Cliente\n"; } if (txtQuarto.Text.Equals("") || this.temp_quarto == null) { mensagem += "Quarto\n"; } if (!DateTime.TryParse(txtDtInicio.Value.ToString(), out dt_inicio)) { mensagem += "Data de Início\n"; } if (!DateTime.TryParse(txtDtTermino.Value.ToString(), out dt_termino)) { mensagem += "Data de Término\n"; } if (dt_inicio.CompareTo(dt_termino) > 0) { mensagem += "Data de término anterior a data de início\n"; } if (!mensagem.Equals("")) { MessageBox.Show( "As seguintes informações estão inválidas:\n" + mensagem, "Salvar Reserva", MessageBoxButtons.OK, MessageBoxIcon.Error); r = null; return(false); } else { using (hotelEntities ef = new hotelEntities()) { r = new reserva(); r.dt_cadastro = DateTime.Now; r.dt_inicio = dt_inicio; r.dt_termino = dt_termino; r.ativo = true; } return(true); } }
private void CarregarGrid() { using (hotelEntities ef = new hotelEntities()) { var listaReservas = ef.reserva .Where(r => r.ativo == true && !(r.dt_entrada != null && r.dt_saida != null)) .Select(r => new { Cliente = r.cliente.ultimo_nome, Quarto = r.quarto.numero, Dias = EntityFunctions.DiffDays(r.dt_inicio, r.dt_termino) }) .Take(10).ToList(); dgvUltimasReservas.DataSource = listaReservas; } }
private void CarregarGrid(string termos = "") //TODO: criar procedure que selecione somente quartos disponíveis { using (hotelEntities ef = new hotelEntities()) { if (cbDisponiveis.Checked) { var listaQuartos = ef.vw_quartos .Select(q => new { ID = q.id, Numero = q.numero, Andar = q.andar, Preco = q.preco }) .ToList(); if (!termos.Equals("")) { listaQuartos = listaQuartos.FindAll(q => q.Numero.ToString().StartsWith(termos) || q.Preco.ToString().StartsWith(termos) || q.Andar.ToString().StartsWith(termos)); } dgvQuartos.DataSource = listaQuartos; } else { var listaQuartos = ef.quarto .Where(q => q.ativo == true) .Select(q => new { ID = q.id, Numero = q.numero, Andar = q.andar, Preco = q.preco }) .ToList(); if (!termos.Equals("")) { listaQuartos = listaQuartos.FindAll(q => q.Numero.ToString().StartsWith(termos) || q.Preco.ToString().StartsWith(termos) || q.Andar.ToString().StartsWith(termos)); } dgvQuartos.DataSource = listaQuartos; } } }
private void preencherCampos(int id) { using (hotelEntities ef = new hotelEntities()) { var escolhido = ef.quarto.Find(id); txtNumero.Text = escolhido.numero.ToString(); txtAndar.Text = escolhido.andar.ToString(); txtCamas.Text = escolhido.qtd_camas.ToString(); txtPreco.Text = escolhido.preco.ToString(); cbTipo.SelectedIndex = escolhido.tipo - 1; cbTamanho.SelectedIndex = escolhido.tamanho - 1; Console.WriteLine(escolhido.comodidade.Count); foreach (comodidade c in escolhido.comodidade) { clbComodidades.SetItemChecked(c.id - 1, true); } } }
private void btnSalvar_Click(object sender, EventArgs e) { reserva r; bool valido; valido = checarCampos(out r); if (valido) { valido = checarDatas(r); } if (valido && this.Operacao == 'n') { using (hotelEntities ef = new hotelEntities()) { r.cliente = ef.cliente.Find(this.temp_cliente.id); r.quarto = ef.quarto.Find(this.temp_quarto.id); ef.reserva.Add(r); ef.SaveChanges(); } } if (valido && this.Operacao == 'e') { int _id = this.escolhidoId; using (hotelEntities ef = new hotelEntities()) { reserva novo = ef.reserva.Find(_id); novo.cliente = ef.cliente.Find(this.temp_cliente.id); novo.quarto = ef.quarto.Find(this.temp_quarto.id); novo.dt_inicio = r.dt_inicio; novo.dt_termino = r.dt_termino; ef.SaveChanges(); } } if (valido) { limparCampos(); tcReserva.SelectedTab = tpgReservas; CarregarGrid(); } }
private void btnOk_Click(object sender, EventArgs e) { if (dgvReservas.CurrentRow != null) { int _id = Convert.ToInt32(dgvReservas.CurrentRow.Cells["ID"].Value.ToString()); using (hotelEntities ef = new hotelEntities()) { this.escolhido = ef.reserva.Find(_id); } this.DialogResult = DialogResult.OK; } else { MessageBox.Show( "Nenhuma reserva foi selecionada!", "Pesquisar Reserva", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CarregarGrid() { using (hotelEntities ef = new hotelEntities()) { var reservas = ef.vw_reservas .Select(r => new { ID = r.id, DataInicio = r.dt_inicio, DataEntrada = r.dt_entrada, DataTermino = r.dt_termino, DataSaida = r.dt_saida, Cliente = r.primeiro_nome, Quarto = r.numero, Status = r.dt_entrada == null ? "Pendente" : "Em aberto" }) .ToList(); dgvQuartos.DataSource = reservas; } }
private void btnSalvar_Click(object sender, EventArgs e) { bool valido = false; if (this.Operacao.Equals('n')) { quarto q = checarCampos(out valido); if (valido) { quarto novo = new quarto(); novo.numero = q.numero; novo.andar = q.andar; novo.tipo = q.tipo + 1; novo.tamanho = q.tamanho + 1; novo.qtd_camas = q.qtd_camas; novo.preco = q.preco; novo.ativo = true; using (hotelEntities ef = new hotelEntities()) { foreach (int indexChecked in clbComodidades.CheckedIndices) { novo.comodidade.Add( ef.comodidade.Find(indexChecked + 1)); } ef.quarto.Add(novo); ef.SaveChanges(); } } } else if (this.Operacao.Equals('e')) { quarto q = checarCampos(out valido); if (valido) { using (hotelEntities ef = new hotelEntities()) { int id = this.escolhidoId; quarto novo = ef.quarto.Find(id); novo.numero = q.numero; novo.andar = q.andar; novo.tipo = q.tipo + 1; novo.tamanho = q.tamanho + 1; novo.qtd_camas = q.qtd_camas; novo.preco = q.preco; novo.comodidade.Clear(); foreach (int indexChecked in clbComodidades.CheckedIndices) { novo.comodidade.Add( ef.comodidade.Find(indexChecked + 1)); } ef.SaveChanges(); } } } if (valido) { limparCampos(); tcQuarto.SelectedTab = tpgQuartos; CarregarGrid(); } }
private void btnOk_Click(object sender, EventArgs e) { if (dgvQuartos.CurrentRow != null) { int escolhido_id = Convert.ToInt32(dgvQuartos.CurrentRow.Cells["id"].Value); using (hotelEntities ef = new hotelEntities()) { this.escolhido = ef.quarto.Find(escolhido_id); if (ef.vw_reservas.ToList().Exists(r => r.fk_quarto == escolhido_id)) { if (msg == null) { botoes = MessageBoxButtons.YesNo; msg = "Este quarto está ocupado.\nDeseja ver a reserva associada?"; } else { botoes = MessageBoxButtons.OK; } DialogResult res = MessageBox.Show( msg, "Pesquisar Quarto", botoes, MessageBoxIcon.Warning); if (res == DialogResult.Yes) { List <reserva> reservas = ef.reserva .Where(r => r.fk_quarto == this.escolhido.id && r.dt_saida == null) .ToList(); foreach (reserva r in reservas) { this.escolhido.reserva.Add(r); } } else { this.escolhido.reserva = new List <reserva>(); this.escolhido.reserva.Clear(); } } else { this.escolhido.reserva = new List <reserva>(); this.escolhido.reserva.Clear(); } this.DialogResult = DialogResult.OK; } } else { MessageBox.Show( "Nenhum quarto foi selecionado!", "Pesquisar Quarto", MessageBoxButtons.OK, MessageBoxIcon.Error); } }