private void FrmPedido_Load(object sender, EventArgs e) { LblCodigoEmpresa.Text = empresa.Codigo.ToString(); if (empresa.Empresanome == "") { LblEmpresaDentista.Text = empresa.Dentistadono; TxtCliente.Text = empresa.Dentistadono; TxtCliente.Enabled = false; } else { LblEmpresaDentista.Text = empresa.Empresanome; } produtos = produtoNegocio.ProcurarPorCodigoOuNome(0, ""); for (int t = 0; t < produtos.Count; t++) { TxtNomeProduto.AutoCompleteCustomSource.Add(produtos[t].Nome); } if (!novoPedido) { TxtCodigoPedido.Text = pedido.Codigo.ToString(); CarregaGridItemPedido(); TxtCodigoProduto.Focus(); SomarGridPedido(); } novoItemPedido = true; CbxEntrega.Checked = false; }
private void BtnEditar_Click(object sender, EventArgs e) { novoItemPedido = false; LblCodigoItemPedido.Text = DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[0].Value.ToString(); TxtCodigoProduto.Text = DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[1].Value.ToString(); TxtNomeProduto.Text = DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[2].Value.ToString(); TxtQtde.Text = DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[5].Value.ToString(); TxtPaciente.Text = DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[3].Value.ToString(); if (DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value == null) { CbxEntrega.Checked = true; DtpEntrega.Value = Convert.ToDateTime(DgvItensProduto.Rows[DgvItensProduto.CurrentRow.Index].Cells[7].Value); } DgvItensProduto.Enabled = false; TxtCodigoProduto.Focus(); BtnEditar.Visible = false; BtnCancelar.Visible = false; BtnRemover.Visible = false; BtnEntrega.Visible = false; BtnCancelarVoltar.Visible = true; BtnAdicionarProduto.Text = "Confirmar Edição"; }
private void LimparCampos() { TxtCodigoProduto.Text = ""; TxtNomeProduto.Text = ""; TxtQtde.Text = ""; TxtPaciente.Text = ""; TxtCodigoProduto.Focus(); }
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); } }