예제 #1
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            horario = string.Empty;
            criatextoHorario();
            //Formata Visual
            SidePanel.Height = btnSalvar.Height;
            SidePanel.Top    = btnSalvar.Top;
            //Verifica se todos os campos estão preenchidos
            if (cmbCampo.Text == "" || dtpReserva.Text == "" || dgvClientes.Rows.Count == 0 || vezes == 0)
            {
                //Mensagem para o usuário
                MessageBox.Show("Informe todos os campos!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                Conexao conexao = new Conexao();
                conexao.conectar();

                if (funcao == "ADICIONAR")
                {
                    SqlCommand cmd = new SqlCommand("sp_Ins_HorariosReserva", conexao.conexao);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@ID_Cliente", dgvClientes.CurrentRow.Cells[0].Value);
                    cmd.Parameters.AddWithValue("@ID_Campo", cmbCampo.SelectedValue);
                    cmd.Parameters.AddWithValue("@HR_Reservada", horario.Trim());
                    cmd.Parameters.AddWithValue("@ST_Horario", "True");
                    cmd.Parameters.AddWithValue("@DT_Reserva", dtpReserva.Value);
                    cmd.Parameters.AddWithValue("@TP_Reservado", 1);
                    cmd.Parameters.AddWithValue("@Vl_Reserva", Double.Parse(txtValorCampo.Text.Replace("R$", "")) * vezes);
                    SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                    if (dr.Read())
                    {
                        idReserva = int.Parse(dr[("Retorno")].ToString());
                        criarFinanceiro(idReserva, LoginUsuario.getUsuarioId());
                    }
                    else
                    {
                        idReserva = 0;
                    }
                }
                else
                {
                    SqlCommand cmd = new SqlCommand("sp_Ins_HorariosReserva", conexao.conexao);
                    cmd.Parameters.AddWithValue("@ID_Cliente", dgvClientes.CurrentRow.Cells[0].Value);
                    cmd.Parameters.AddWithValue("@ID_Campo", cmbCampo.SelectedValue);
                    cmd.Parameters.AddWithValue("@HR_Reservada", " ");//Verificar CheckBox
                    cmd.Parameters.AddWithValue("@ST_Horario", "True");
                    cmd.Parameters.AddWithValue("@DT_Reserva", dtpReserva.Value);
                    cmd.Parameters.AddWithValue("@TP_Reservado", 1);
                    cmd.Parameters.AddWithValue("@Vl_Reserva", Double.Parse(txtValorCampo.Text.Replace("R$", "")));
                    cmd.ExecuteReader(CommandBehavior.SingleRow);
                }
                conexao.desconectar();
                DialogResult iResposta;
                iResposta = MessageBox.Show("Deseja receber a reserva?", "Confirmar!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (iResposta.ToString() == "Yes")
                {
                    LoginUsuario.reserva(Convert.ToInt32(idReserva));
                    frmRecebimento frmRecebimento = new frmRecebimento();
                    frmRecebimento.ShowDialog();
                }
                iResposta = MessageBox.Show("Deseja imprimir o comprovante?", "Confirmar!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (iResposta.ToString() == "Yes")
                {
                    Imprimir();
                }
                controleBotao(true);
                atualizaGridView();
                idReserva = 0;
            }
        }