private void btnAgendar_Click(object sender, EventArgs e) { clnAgenda ObjAgenda = new clnAgenda(); if (txtPesClien.Text == "" || comboBox2.Text == "" || comboBox1.Text == "" || comboBox4.Text == "" || dateTimePicker1.Text == "") { MessageBox.Show("TODOS OS CAMPOS SÃO OBRIGATÓRIOS ", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string formato = "dd/MM/yyyy HH:mm"; DataRowView servicoSelecionado = (DataRowView)comboBox2.SelectedItem; DataRowView especialistaSelecionado = (DataRowView)comboBox1.SelectedItem; string id_especialista = especialistaSelecionado["id_funcionario"].ToString(); DateTime dataInicio = DateTime.ParseExact(dateTimePicker1.Text + " " + comboBox4.Text, formato, System.Globalization.CultureInfo.CurrentCulture); DateTime dataFim = dataInicio.Add(TimeSpan.Parse(servicoSelecionado["Tempo_Atendimento"].ToString())); if (DateTime.Now < dataInicio && ObjAgenda.ValidarDataAgendamento(dataInicio.ToString(formato), dataFim.ToString(formato), id_especialista)) { ObjAgenda.Procedimento = servicoSelecionado["id_servico"].ToString(); ObjAgenda.Nome = Temp2; ObjAgenda.Especialista = id_especialista; ObjAgenda.Hora = comboBox4.Text; string data = dateTimePicker1.Text; ObjAgenda.Status = "AGENDADO"; ObjAgenda.Data = data; ObjAgenda.GravaNoBanco(); PreencherAgendamentos(); MessageBox.Show("AGENDADO COM SUCESSO", "AGENDAMENTO", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("PERIODO INDISPONÍVEL PARA AGENDAMENTO ", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }