Exemplo n.º 1
0
        private void TxtCodigoPedido_Leave(object sender, EventArgs e)
        {
            if (novoPedido)
            {
                if (TxtCodigoPedido.Text != "")
                {
                    PedidoNegocio pedidoNegocio = new PedidoNegocio();

                    if (pedidoNegocio.VerificarCodigo(Convert.ToInt32(TxtCodigoPedido.Text)))
                    {
                        MessageBox.Show("Código Já existe, digite outro código", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        TxtCodigoPedido.Focus();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void BtnAdicionarProduto_Click(object sender, EventArgs e)
        {
            try
            {
                if (TxtCodigoPedido.Text != "")
                {
                    if (TxtCodigoProduto.Text != "" && TxtNomeProduto.Text != "" && TxtQtde.Text != "" && TxtPaciente.Text != "")
                    {
                        if (novoItemPedido)
                        {
                            double valor = produtoNegocio.ProcurarPorCodigo(Convert.ToInt32(TxtCodigoProduto.Text));

                            if (DtpEntrega.Visible == true)
                            {
                                DgvItensProduto.Rows.Add("", TxtCodigoProduto.Text, TxtNomeProduto.Text, TxtPaciente.Text, valor, TxtQtde.Text, valor * Convert.ToInt32(TxtQtde.Text), DtpEntrega.Text);
                            }
                            else
                            {
                                DgvItensProduto.Rows.Add("", TxtCodigoProduto.Text, TxtNomeProduto.Text, TxtPaciente.Text, valor, TxtQtde.Text, valor * Convert.ToInt32(TxtQtde.Text), "");
                            }

                            LimparCampos();
                            SomarGridPedido();
                            CbxEntrega.Checked         = false;
                            BtnRemover.Visible         = true;
                            BtnEditar.Visible          = true;
                            BtnEntrega.Visible         = true;
                            BtnFinalizarPedido.Visible = true;
                            BtnAdicionarProduto.Text   = "Adicionar Produto";
                        }
                        else
                        {
                            double valor            = produtoNegocio.ProcurarPorCodigo(Convert.ToInt32(TxtCodigoProduto.Text));
                            int    codigoitempedido = 0;

                            if (DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value.ToString() != "")
                            {
                                codigoitempedido = Convert.ToInt32(DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value);
                            }

                            //DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = DtpEntrega.Value;

                            //DgvItensProduto.Rows.RemoveAt(DgvItensProduto.CurrentRow.Index);

                            if (DtpEntrega.Visible == true)
                            {
                                if (codigoitempedido != 0)
                                {
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value = codigoitempedido;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[1].Value = TxtCodigoProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[2].Value = TxtNomeProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[3].Value = TxtPaciente.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[4].Value = valor;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[5].Value = TxtQtde.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[6].Value = valor * Convert.ToInt32(TxtQtde.Text);
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = DtpEntrega.Text;
                                }
                                else
                                {
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value = "";
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[1].Value = TxtCodigoProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[2].Value = TxtNomeProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[3].Value = TxtPaciente.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[4].Value = valor;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[5].Value = TxtQtde.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[6].Value = valor * Convert.ToInt32(TxtQtde.Text);
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = "";
                                }
                            }
                            else
                            {
                                if (codigoitempedido != 0)
                                {
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value = codigoitempedido;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[1].Value = TxtCodigoProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[2].Value = TxtNomeProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[3].Value = TxtPaciente.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[4].Value = valor;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[5].Value = TxtQtde.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[6].Value = valor * Convert.ToInt32(TxtQtde.Text);
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = "";
                                    //DgvItensProduto.Rows.Add(codigoitempedido, TxtCodigoProduto.Text, TxtNomeProduto.Text, TxtPaciente.Text, valor, TxtQtde.Text, valor * Convert.ToInt32(TxtQtde.Text), "");
                                }
                                else
                                {
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value = "";
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[1].Value = TxtCodigoProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[2].Value = TxtNomeProduto.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[3].Value = TxtPaciente.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[4].Value = valor;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[5].Value = TxtQtde.Text;
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[6].Value = valor * Convert.ToInt32(TxtQtde.Text);
                                    DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = "";
                                    //DgvItensProduto.Rows.Add("", TxtCodigoProduto.Text, TxtNomeProduto.Text, TxtPaciente.Text, valor, TxtQtde.Text, valor * Convert.ToInt32(TxtQtde.Text), "");
                                }
                            }

                            LimparCampos();
                            SomarGridPedido();
                            CbxEntrega.Checked         = false;
                            BtnRemover.Visible         = true;
                            BtnEditar.Visible          = true;
                            BtnEntrega.Visible         = true;
                            BtnFinalizarPedido.Visible = true;
                            BtnAdicionarProduto.Text   = "Adicionar Produto";
                            BtnCancelar.Visible        = true;
                            novoItemPedido             = true;
                            DgvItensProduto.Enabled    = true;
                            BtnCancelar.Visible        = true;
                            BtnCancelarVoltar.Visible  = false;
                        }
                    }
                    else
                    {
                        if (TxtCodigoProduto.Enabled == false)
                        {
                            if (CbxEntrega.Checked)
                            {
                                DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = DtpEntrega.Value;
                            }
                            else
                            {
                                DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value = "";
                            }

                            BtnAdicionarProduto.Text = "Adicionar Produto";
                            HabilitarBotoes();
                        }
                        else
                        {
                            if (TxtCodigoProduto.Text == "")
                            {
                                MessageBox.Show("Digite o Código do produto!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                TxtCodigoProduto.Focus();
                            }
                            else if (TxtNomeProduto.Text == "")
                            {
                                MessageBox.Show("Digite o Nome do produto!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                TxtNomeProduto.Focus();
                            }
                            else if (TxtQtde.Text == "")
                            {
                                MessageBox.Show("Digite a quantidade de produto!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                TxtQtde.Focus();
                            }
                            else if (TxtPaciente.Text == "")
                            {
                                MessageBox.Show("Digite o nome do Paciente que fez o pedido do produto!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                TxtPaciente.Focus();
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Digite o código do pedido", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    TxtCodigoPedido.Focus();
                }
            }
            catch
            {
                MessageBox.Show("Não foi possível salvar o produto, digite novamente.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }