private void btnSalvarFunc_Click(object sender, EventArgs e) { if (txtNomeFuncionario.Text == "") { MessageBox.Show("O campo 'Nome' é obrigatório", "Preencha o Nome", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { String nome = txtNomeFuncionario.Text.Replace("'", "''"); String telefone = txtTelFuncionario.Text.Replace("'", "''"); if (!is_editing) //salvando.. { try { c.ExecutaQuery("insert into funcionario (nome, telefone) values('" + nome + "', '" + telefone + "')"); ut.preencheGrid(grdFunc, sQueryCarregaGrid); BtnLimparCli_Click(new Object(), new EventArgs()); } catch (Exception ex) { MessageBox.Show("Erro ao cadastrar funcionário: " + ex.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else //editando... { c.ExecutaQuery("update funcionario set nome='" + nome + "', telefone= '" + telefone + "' where id =" + grdFunc[0, grdFunc.CurrentRow.Index].Value.ToString()); ut.preencheGrid(grdFunc, sQueryCarregaGrid); BtnLimparCli_Click(new Object(), new EventArgs()); } } is_editing = false; }
private void BtnSalvarFPgto_Click(object sender, EventArgs e) { if (txtFPgto.Text == "") { MessageBox.Show("O campo 'Forma de Pagamento' é obrigatório", "Preencha a forma de pagamento", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { String fpgto = txtFPgto.Text.Replace("'", "''"); if (!is_editing) //salvando.. { try { c.ExecutaQuery("insert into forma_pgto (descricao) values('" + fpgto + "')"); ut.preencheGrid(grdFPgto, sQueryCarregaGrid); BtnLimparFPgto_Click(new Object(), new EventArgs()); } catch (Exception ex) { MessageBox.Show("Erro ao cadastrar forma de pagamento: " + ex.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else //editando... { c.ExecutaQuery("update forma_pgto set descricao='" + fpgto + "' where id =" + grdFPgto[0, grdFPgto.CurrentRow.Index].Value.ToString()); ut.preencheGrid(grdFPgto, sQueryCarregaGrid); BtnLimparFPgto_Click(new Object(), new EventArgs()); } } is_editing = false; }
private void btnSalvarDespesasGerais_Click(object sender, EventArgs e) { if (txtDescricaoDespesasGerais.Text != "" && txtValorDespesasGerais.Text != "") { txtValorDespesasGerais.Text = txtValorDespesasGerais.Text.Replace(",", "."); if (!updating_despesas_gerais) //salvando .... { try { double price; price = double.Parse(txtValorDespesasGerais.Text, System.Globalization.CultureInfo.InvariantCulture); String sPrice = price.ToString().Replace(",", "."); // MessageBox.Show(price.ToString()); // MessageBox.Show(price.ToString("#.#0")); c.ExecutaQuery("insert into despesas (descricao, valor, data, deletado) values('" + txtDescricaoDespesasGerais.Text.ToString() + "'," + sPrice + ",cast('" + txtDataDespesasGerais.Value.ToString("yyyy-MM-dd") + "' as date), 0)"); preencheGridDespesasGerais(txtDataDespesasGerais.Value.ToString("yyyy-MM-dd"), txtDataDespesasGerais.Value.ToString("yyyy-MM-dd")); btnLimparDespesasGerais_Click(new Object(), new EventArgs()); } catch (Exception ex) { MessageBox.Show("Verifique se os campos estão preenchidos corretamente !"); } } else //atualizando.... { try { double price; price = double.Parse(txtValorDespesasGerais.Text, System.Globalization.CultureInfo.InvariantCulture); String sPrice = price.ToString().Replace(",", "."); // MessageBox.Show(sPrice); // MessageBox.Show(price.ToString("#.#0")); c.ExecutaQuery("update despesas set descricao='" + txtDescricaoDespesasGerais.Text.ToString() + "', valor=" + sPrice + ", data=cast('" + txtDataDespesasGerais.Value.ToString("yyyy-MM-dd") + "' as date) where id=" + grdDespesasGerais[0, grdDespesasGerais.CurrentRow.Index].Value.ToString()); preencheGridDespesasGerais(txtDataDespesasGerais.Value.ToString("yyyy-MM-dd"), txtDataDespesasGerais.Value.ToString("yyyy-MM-dd")); btnLimparDespesasGerais_Click(new Object(), new EventArgs()); } catch (Exception ex) { MessageBox.Show("Verifique se os campos estão preenchidos corretamente !"); } } } else { MessageBox.Show("Preencha os campos", "erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BtnDeletetarProc_Click(object sender, EventArgs e) { if (MessageBox.Show("Tem certeza que deseja deletar o Procedimento " + grdProcedimento[0, grdProcedimento.CurrentRow.Index].Value.ToString() + " - " + grdProcedimento[1, grdProcedimento.CurrentRow.Index].Value.ToString() + "?", "Certeza?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { c.ExecutaQuery("update procedimento set deletado=1 where id =" + grdProcedimento[0, grdProcedimento.CurrentRow.Index].Value.ToString()); ut.preencheGrid(grdProcedimento, sQueryCarregaGrid); for (j = 0; j < grdProcedimento.RowCount; j++) { grdProcedimento[2, j].Value = string.Format(CultureInfo.GetCultureInfo("pt-BR"), "{0:C}", Convert.ToDecimal(grdProcedimento[2, j].Value.ToString().Replace(".", ","))); } BtnLimparProc_Click(new Object(), new EventArgs()); } }
private void BtnCancel_Click(object sender, EventArgs e) { if (MessageBox.Show("Deseja cancelar a venda?", "Certeza?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { c.ExecutaQuery("update vendas set cancelado=1 where id=" + idvenda.ToString()); MessageBox.Show("CANCELADO!", "Canceled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); lblCancelado.Visible = true; } }
private void BtnConcluirPedido_Click(object sender, EventArgs e) { if (grdVenda.Rows.Count > 0) { if (cboFormaPgto.SelectedIndex != -1) { //salvando.. if (MessageBox.Show("Concluir venda " + txtNumVenda.Text.ToString() + "?", "Concluir", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int idCliente = 0; if (cboClientes.SelectedValue != null) { if (Convert.ToInt32(cboClientes.SelectedValue.ToString()) > 0) { idCliente = Convert.ToInt32(cboClientes.SelectedValue.ToString()); } } int idFormaPgto = 0; if (Convert.ToInt32(cboFormaPgto.SelectedValue.ToString()) > 0) { idFormaPgto = Convert.ToInt32(cboFormaPgto.SelectedValue.ToString()); } String vl_total = txtValorTotal.Text; //nunca salvo o valor com desconto.. devo sempre fazer a multiplicacao para saber o valor do pedido. //descontoAplicado vai com 0 se nao tiver.. if (decimal.Parse(vl_total) >= 1000) { vl_total = vl_total.Replace(".", ""); vl_total = vl_total.Replace(",", ""); vl_total = vl_total.Insert(vl_total.Length - 2, "."); } String sQuerySalvar = "insert into vendas(id_cliente, id_forma_pgto, desconto, nome_cliente, valor_total, data)"; sQuerySalvar += " values (" + idCliente.ToString() + "," + idFormaPgto.ToString() + "," + descontoAplicado.ToString().Replace(",", ".") + ",'" + cboClientes.Text + "'," + vl_total.Replace(",", ".") + ", getdate())"; sQuerySalvar += " SELECT SCOPE_IDENTITY() as idVenda"; int num_ped = 0; try { num_ped = int.Parse(c.RetornaQuery(sQuerySalvar, "idVenda")); } catch (Exception ex) { // MessageBox.Show("Erro ao concluir venda:\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); goto DEUERRO; } if (num_ped != 0) { String idProcedimento = "null"; String idAdicional = "null"; String idFuncionario = "null"; String sQuerySalvarItens = ""; for (int i = 0; i < grdVenda.Rows.Count; i++) { if (grdVenda.Rows[i].Cells[5].Value.ToString() != "desconto") { if (grdVenda.Rows[i].Cells[5].Value.ToString() == "procedimento") { idProcedimento = grdVenda.Rows[i].Cells[4].Value.ToString(); idFuncionario = grdVenda.Rows[i].Cells[6].Value.ToString(); } else if (grdVenda.Rows[i].Cells[5].Value.ToString() == "adicional") { idAdicional = grdVenda.Rows[i].Cells[4].Value.ToString(); } String sItenVl; if (decimal.Parse(grdVenda.Rows[i].Cells[3].Value.ToString().Replace("R$ ", "")) >= 1000) { sItenVl = grdVenda.Rows[i].Cells[3].Value.ToString().Replace(".", ""); sItenVl = sItenVl.Replace(",", ""); sItenVl = sItenVl.Replace("R$ ", ""); sItenVl = sItenVl.Insert(sItenVl.Length - 2, "."); } else { sItenVl = grdVenda.Rows[i].Cells[3].Value.ToString().Replace(",", "."); sItenVl = sItenVl.Replace("R$ ", ""); } sQuerySalvarItens = "insert into vendas_itens(id_venda, id_procedimento, id_adicional, id_func, vl_total_item)"; sQuerySalvarItens += " values (" + num_ped.ToString() + "," + idProcedimento + "," + idAdicional + "," + idFuncionario + "," + sItenVl + ")"; idProcedimento = "null"; idAdicional = "null"; idFuncionario = "null"; c.ExecutaQuery(sQuerySalvarItens); } } MessageBox.Show("Venda gravada com sucesso.", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); cboClientes.SelectedIndex = -1; cboClientes.Text = ""; cboFuncionarios.SelectedIndex = -1; cboProcedimento.SelectedIndex = -1; cboAdicional.SelectedIndex = -1; cboFormaPgto.SelectedIndex = -1; chkDesconto.Checked = false; txtDesconto.Text = ""; txtDesconto.Enabled = false; btnAddDesconto.Enabled = false; grdVenda.Rows.Clear(); txtValorTotal.Text = ""; txtValorTotComDesconto.Text = ""; lblRSDesconto.Visible = false; lblTotDesconto.Visible = false; txtValorTotComDesconto.Visible = false; btnDelItem.Enabled = false; btnDelItem.Visible = false; int id = c.RetornaIdVendaAtual(); txtNumVenda.Text = id.ToString().PadLeft(6, '0'); } } } else { MessageBox.Show("Selecione uma forma de pagamento.", "Forma de Pagamento", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Insira pelo menos um ítem.", "Insira um ítem.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } DEUERRO : int a = 0; //do nothing }
private void BtnSalvarAdicional_Click(object sender, EventArgs e) { if (txtDescAdicional.Text == "") { MessageBox.Show("O campo 'Adicional' é obrigatório", "Preencha o Adicional", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { txtValorAdicional.Text = txtValorAdicional.Text.Replace(".", ","); txtValorAdicional.Text = string.Format("{0:C}", Convert.ToDecimal(txtValorAdicional.Text.ToString())); txtValorAdicional.Text = txtValorAdicional.Text.Replace("R$ ", ""); String adicional = txtDescAdicional.Text.Replace("'", "''"); decimal Valor; String sValorAdic; try { if (Convert.ToDecimal(txtValorAdicional.Text, CultureInfo.CurrentCulture) >= 1000) { sValorAdic = txtValorAdicional.Text.Replace(".", ""); sValorAdic = sValorAdic.Replace(",", ""); sValorAdic = sValorAdic.Insert(sValorAdic.Length - 2, "."); } Valor = Convert.ToDecimal(txtValorAdicional.Text, CultureInfo.CurrentCulture); } catch (Exception) { MessageBox.Show("Formato de Valor inválido. Por favor, insira um valor válido. Ex: 12,50", "Ooops..", MessageBoxButtons.OK, MessageBoxIcon.Error); goto BYE; } String sValor = Valor.ToString().Replace(",", "."); if (!is_editing) //salvando.. { try { c.ExecutaQuery("insert into adicional (descricao, valor) values('" + adicional + "', " + sValor + ")"); ut.preencheGrid(grdAdicional, sQueryCarregaGrid); for (j = 0; j < grdAdicional.RowCount; j++) { grdAdicional[2, j].Value = string.Format(CultureInfo.GetCultureInfo("pt-BR"), "{0:C}", Convert.ToDecimal(grdAdicional[2, j].Value.ToString().Replace(".", ","))); } BtnLimparAdicional_Click(new Object(), new EventArgs()); } catch (Exception ex) { MessageBox.Show("Erro ao cadastrar adicional: " + ex.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else //editando... { c.ExecutaQuery("update adicional set descricao='" + adicional + "', valor= " + sValor + " where id =" + grdAdicional[0, grdAdicional.CurrentRow.Index].Value.ToString()); ut.preencheGrid(grdAdicional, sQueryCarregaGrid); for (j = 0; j < grdAdicional.RowCount; j++) { grdAdicional[2, j].Value = string.Format(CultureInfo.GetCultureInfo("pt-BR"), "{0:C}", Convert.ToDecimal(grdAdicional[2, j].Value.ToString().Replace(".", ","))); } BtnLimparAdicional_Click(new Object(), new EventArgs()); } } is_editing = false; BYE : var a = 1; }