Usuário com melhor resposta
enviar valor de uma variavel para outro form

Pergunta
-
ola
estou com esse codigo:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Loja.BLL;
using Loja.DAL;
using Loja.Modelos;
namespace Loja.UIWindows
{
public partial class VendasForm2 : Form
{
public int quantidade;
public Boolean passe;
public decimal somando;
public Boolean comparar;
public static object total2;
public VendasForm2()
{
InitializeComponent();
}
public void AtualizaGrid()
{
// Comunicação com a Camada BLL
//VendasBLL obj = new VendasBLL();
ProdutosBLL obj = new ProdutosBLL();
produtosDataGridView.DataSource = obj.Listagem();
idprodutotextBox.Text = produtosDataGridView[0, produtosDataGridView.CurrentRow.Index].Value.ToString();
ProdutotextBox.Text = produtosDataGridView[1, produtosDataGridView.CurrentRow.Index].Value.ToString();
//valor_text.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
ClientesBLL obj2 = new ClientesBLL();
clientesDataGridView.DataSource = obj2.Listagem();
codigoclientetextBox.Text = clientesDataGridView[0, clientesDataGridView.CurrentRow.Index].Value.ToString();
clientetextBox.Text = clientesDataGridView[1, clientesDataGridView.CurrentRow.Index].Value.ToString();
descontotextBox.Text = clientesDataGridView[8, clientesDataGridView.CurrentRow.Index].Value.ToString();
//v_total.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
entradatextBox.Text = "0,00";
}
private void VendasForm2_Load(object sender, EventArgs e)
{
tipocomboBox.Text = "Dinheiro";
quantidadetextBox.Focus();
// AtualizaGrid();
//VendasBLL obj = new VendasBLL();
passe = true;
comparar = true;
//quantidadetextBox.Text = Convert.ToString(quantidade);
ProdutosBLL obj = new ProdutosBLL();
produtosDataGridView.DataSource = obj.Listagem();
idprodutotextBox.Text = produtosDataGridView[0, produtosDataGridView.CurrentRow.Index].Value.ToString();
ProdutotextBox.Text = produtosDataGridView[1, produtosDataGridView.CurrentRow.Index].Value.ToString();
valor_text.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
ClientesBLL obj2 = new ClientesBLL();
clientesDataGridView.DataSource = obj2.Listagem();
codigoclientetextBox.Text = clientesDataGridView[0, clientesDataGridView.CurrentRow.Index].Value.ToString();
clientetextBox.Text = clientesDataGridView[1, clientesDataGridView.CurrentRow.Index].Value.ToString();
descontotextBox.Text = clientesDataGridView[8, clientesDataGridView.CurrentRow.Index].Value.ToString();
//v_total.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
entradatextBox.Text = "0,00";
}
private void produtosDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
//valortextBox.Text = "0";
// Atualizando os objetos TextBox
//Atualizando os objetos TextBox
idprodutotextBox.Text = produtosDataGridView[0, produtosDataGridView.CurrentRow.Index].Value.ToString();
ProdutotextBox.Text = produtosDataGridView[1, produtosDataGridView.CurrentRow.Index].Value.ToString();
//tipoTextBox.Text = produtosDataGridView[2, produtosDataGridView.CurrentRow.Index].Value.ToString();
//codigocompraTextBox.Text = produtosDataGridView[3, produtosDataGridView.CurrentRow.Index].Value.ToString();
//int comp;
//comp = produtosDataGridView[4, produtosDataGridView.CurrentRow.Index].Value.ToInt32();
//custoTextBox.Text = produtosDataGridView[5, produtosDataGridView.CurrentRow.Index].Value.ToString();
valor_text.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
//descontotextBox.Text = produtosDataGridView[7, produtosDataGridView.CurrentRow.Index].Value.ToString();
//combopossibilidade.SelectedValue = produtosDataGridView[8, produtosDataGridView.CurrentRow.Index].Value.ToString();
// v_total.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
entradatextBox.Text = "0,00";
if (passe == true)
{
v_total.Text = produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int comp;
comp = Convert.ToInt32(produtosDataGridView[4, produtosDataGridView.CurrentRow.Index].Value.ToString());
int comp2 = Convert.ToInt32(quantidadetextBox.Text);
if (comp >= comp2)
{
decimal valor = Convert.ToDecimal(valor_text.Text);
int quantidade2 = Convert.ToInt32(quantidadetextBox.Text);
valor = Convert.ToDecimal(valor_text.Text);
quantidade = int.Parse(quantidadetextBox.Text);
total2 = valor * quantidade;
valor_total.Text = Convert.ToString(total2);
valor = 0;
quantidade2 = quantidade;
VendaInformation venda = new VendaInformation();
venda.QUANTIDADE = int.Parse(quantidadetextBox.Text);
//venda.IDCLIENTE = Convert.ToInt32(clientecomboBox.SelectedValue);
venda.IDCLIENTE = int.Parse(codigoclientetextBox.Text);
//venda.IDPRODUTO = (int)produtocomboBox.SelectedValue;
venda.IDPRODUTO = Convert.ToInt32(idprodutotextBox.Text);
venda.DATA_DE_COMPRA = DateTime.Now;
venda.TIPO_DE_COMPRA = tipocomboBox.Text;
venda.FATURADO = false;
venda.VALOR_TOTAL = Convert.ToDecimal(valor_total.Text);
VendasBLL obj = new VendasBLL();
obj.Incluir(venda);
MessageBox.Show("A venda foi realizada com sucesso!");
}
//AtualizaGrid();
else
MessageBox.Show("erro! Você esta tentando vender mais do que tem no estoque");
AtualizaGrid();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tipocomboBox_SelectedIndexChanged(object sender, EventArgs e)
{
tipocomboBox.Text = tipocomboBox.SelectedItem.ToString();
}
private void troco_Click(object sender, EventArgs e)
{
decimal calculo = Convert.ToDecimal(entradatextBox.Text);
decimal resto;
decimal custo = Convert.ToDecimal(v_total.Text);
resto = calculo - custo;
troco_text.Text = Convert.ToString(resto);
}
private void clientesDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
codigoclientetextBox.Text = clientesDataGridView[0, clientesDataGridView.CurrentRow.Index].Value.ToString();
clientetextBox.Text = clientesDataGridView[1, clientesDataGridView.CurrentRow.Index].Value.ToString();
descontotextBox.Text = clientesDataGridView[8, clientesDataGridView.CurrentRow.Index].Value.ToString();
}
private void valor_totaltextBox_MouseUp(object sender, MouseEventArgs e)
{
}
private void quantidadetextBox_TextChanged(object sender, EventArgs e)
{
if (quantidadetextBox.Text.Trim().Length == 0)
{
quantidadetextBox.Text = "0";
}
if (passe == true)
{
decimal valor = Convert.ToDecimal(valor_text.Text);
int quantidade2 = Convert.ToInt32(quantidadetextBox.Text);
// Boolean teste = true;
object total;
quantidade = int.Parse(quantidadetextBox.Text);
total2 = valor * quantidade;
v_total.Text = Convert.ToString(total2);
quantidade2 = quantidade;
decimal guarda3;
this.guarda = Convert.ToDecimal(total2);
label17.Text = Convert.ToString(somando);
}
}
private void entradatextBox_TextChanged(object sender, EventArgs e)
{
if (entradatextBox.Text.Trim().Length == 0)
{
entradatextBox.Text = "0,00";
}
decimal calculo = Convert.ToDecimal(entradatextBox.Text);
decimal resto;
decimal custo = Convert.ToDecimal(v_total.Text);
resto = calculo - custo;
troco_text.Text = Convert.ToString(resto);
}
private void quantidadetextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(!(Char.IsDigit(e.KeyChar)))
{
e.Handled=true;
}
}
private void entradatextBox_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (!(Char.IsDigit(e.KeyChar)))
{
e.Handled = true;
}
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button3_Click_1(object sender, EventArgs e)
{
decimal precocompra = Convert.ToDecimal(produtosDataGridView[6, produtosDataGridView.CurrentRow.Index].Value.ToString());
decimal MarkUp = Convert.ToDecimal(descontotextBox.Text);
decimal precovenda = precocompra * (1 - MarkUp / 100);
valor_text.Text = Math.Round(precovenda, 2).ToString();
}
private void button4_Click(object sender, EventArgs e)
{
//valor_text.Text = "0";
// quantidadetextBox.Text = "1";
//descontotextBox.Text = "";
// v_total.Text = "0";
// troco_text.Text = "0";
//valor_text.Text = "0";
Fechar_vendaForm obj = new Fechar_vendaForm();
obj.Show();
}
private void button2_Click(object sender, EventArgs e)
{
BuscaForm obj = new BuscaForm();
obj.Show();
}
private void button5_Click(object sender, EventArgs e)
{
ProdutosDAL obj = new ProdutosDAL();
produtosDataGridView.DataSource = obj.procurar(procurar_text.Text);
}
public decimal guarda;
}
}porem queria enviar o resultado do calculo total2 para outro form, porem ele sempre enviar para esse textbox de outro formo o valor 0, como resolvo isso???
Aprendendo e evoluindo
Respostas
-
existe outro tópico onde a dúvida é como "pegar" um valor de outro form.
é mais ou menos o q vc quer:
http://social.msdn.microsoft.com/Forums/pt-BR/vscsharppt/thread/5e786a6e-b745-4f7a-b55b-bcb2aa0edf05
- Sugerido como Resposta RicardoAlves segunda-feira, 2 de agosto de 2010 12:48
- Marcado como Resposta Harley AraujoModerator quarta-feira, 4 de agosto de 2010 17:35
-
Olá meu caro eu faço o seguinte sei q não é o mais correto nem o mais elegante mas funfa perfeitamente eu crio uma variavel statica no form2 e ao instancia-lo no form1 eu atribuo primeiro o valor desta váriavel mais ou menos assim
FORM2
public static VariavelBoleana;
public Form2()
{
initializeComponent();
VariavelBoleana = false;
}
e agora no FORM1
CRIEI UM BOTÃO PARA ABRIR E MUDAR O VALOR DA PROPRIEDADE
public Form1()
{
initializeComponent();
}
public void button1Form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
Form2.VariavelBoleana = true;
Form2.Show();
}
E NOVAMENTE NO FORM2 CRIO UM BOTÃO PARA MOSTRAR O VALOR DA VARIAVEL;
public void buttonForm2_Click(object sender, EventArgs e)
{
MessageBox.Show(VariavelBoleana.ToString());
}
Se te ajudar não sqça de marcar
Att Edney
- Marcado como Resposta Harley AraujoModerator quarta-feira, 4 de agosto de 2010 17:35
Todas as Respostas
-
existe outro tópico onde a dúvida é como "pegar" um valor de outro form.
é mais ou menos o q vc quer:
http://social.msdn.microsoft.com/Forums/pt-BR/vscsharppt/thread/5e786a6e-b745-4f7a-b55b-bcb2aa0edf05
- Sugerido como Resposta RicardoAlves segunda-feira, 2 de agosto de 2010 12:48
- Marcado como Resposta Harley AraujoModerator quarta-feira, 4 de agosto de 2010 17:35
-
Olá meu caro eu faço o seguinte sei q não é o mais correto nem o mais elegante mas funfa perfeitamente eu crio uma variavel statica no form2 e ao instancia-lo no form1 eu atribuo primeiro o valor desta váriavel mais ou menos assim
FORM2
public static VariavelBoleana;
public Form2()
{
initializeComponent();
VariavelBoleana = false;
}
e agora no FORM1
CRIEI UM BOTÃO PARA ABRIR E MUDAR O VALOR DA PROPRIEDADE
public Form1()
{
initializeComponent();
}
public void button1Form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
Form2.VariavelBoleana = true;
Form2.Show();
}
E NOVAMENTE NO FORM2 CRIO UM BOTÃO PARA MOSTRAR O VALOR DA VARIAVEL;
public void buttonForm2_Click(object sender, EventArgs e)
{
MessageBox.Show(VariavelBoleana.ToString());
}
Se te ajudar não sqça de marcar
Att Edney
- Marcado como Resposta Harley AraujoModerator quarta-feira, 4 de agosto de 2010 17:35
-