You are on page 1of 9

using

using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
System.Threading.Tasks;
MySql.Data.MySqlClient;

namespace MDIPRINCIPAL
{
public partial class AltaFacturas : Form
{
private MySqlConnection dbConnection;
public AltaFacturas()
{
InitializeComponent();
CargaCombo1();
CargaCombo2();
load_table();
}
private String gPrecioProduct = "";
private void CargaCombo1()
{
dbConnection = new MySqlConnection("Database=OXXO;Data
Source=localhost;User Id=root;Password=;");
dbConnection.Open();
MySqlCommand command1 = dbConnection.CreateCommand();
command1.CommandText = "select cod_cliente, Nombre

from clientes order

by 1";
command1.ExecuteNonQuery();
MySqlDataAdapter da1 = new MySqlDataAdapter(command1);
DataTable dt = new DataTable();
da1.Fill(dt);
comboBox1.ValueMember = "cod_cliente";
comboBox1.DisplayMember = "Nombre";
comboBox1.DataSource = dt;
}

private void CargaCombo2()


{
dbConnection = new MySqlConnection("Database=OXXO;Data
Source=localhost;User Id=root;Password=;");
dbConnection.Open();
MySqlCommand command1 = dbConnection.CreateCommand();

command1.CommandText = "select cod_vendedor, Nombre

from Vendedores

order by 1";
command1.ExecuteNonQuery();
MySqlDataAdapter da1 = new MySqlDataAdapter(command1);
DataTable dt = new DataTable();
da1.Fill(dt);
comboBox2.ValueMember = "cod_vendedor";
comboBox2.DisplayMember = "Nombre";
comboBox2.DataSource = dt;
}
--------------------------------------------------------------------void load_table()
{
string constring = "Database=OXXO;Data Source=localhost;User
Id=root;Password=;";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand("call
Consulta_Linea_Factura('" + textBox1.Text + "');" , conDataBase);
try
{
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDataBase;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
----------------------------------------------------------------private void AltaFacturas_Load(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)


{

private void button2_Click(object sender, EventArgs e)


{
try
{
dbConnection = new MySqlConnection("Database=OXXO;Data
Source=localhost;User Id=root;Password=;");
dbConnection.Open();
MySqlCommand command1 = dbConnection.CreateCommand();
MySqlTransaction t1 = dbConnection.BeginTransaction();
try
{
command1.CommandText = "call Alta_Factura('" + textBox1.Text +
"','" + maskedTextBox1.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','"
+ comboBox1.SelectedValue.ToString() + "','" + comboBox2.SelectedValue.ToString() +
"')";
command1.ExecuteNonQuery();
t1.Commit();
MessageBox.Show("se Inserto Correctamente", "Ok");
dbConnection.Close();
}
catch (Exception e1)
{
t1.Rollback();
MessageBox.Show("no se pudo insertar debido a: " + e1);
}
}
catch
{
System.Console.WriteLine("Error de conexion.");
}

{
int primernumero;
int segundonumero;
int resultado;
try
{
primernumero = int.Parse(textBox6.Text);
segundonumero = int.Parse(textBox8.Text);
while ((segundonumero <= 7) || (primernumero <= 7))
{
segundonumero = int.Parse(textBox1.Text);
MessageBox.Show("Ingrese un nmero", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

resultado = primernumero * segundonumero;


textBox3.Text = resultado.ToString();
}
catch (FormatException)
{
MessageBox.Show("Ingrese slo nmeros mayores a 7", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
try
{
dbConnection = new MySqlConnection("Database=OXXO;Data
Source=localhost;User Id=root;Password=;");
dbConnection.Open();
MySqlCommand command1 = dbConnection.CreateCommand();
MySqlTransaction t1 = dbConnection.BeginTransaction();
try
{
command1.CommandText = "call Altas_Facturas ('" + textBox5.Text
+ "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" +
textBox9.Text + "','" + textBox1.Text + "')";
command1.ExecuteNonQuery();
t1.Commit();
MessageBox.Show("se Inserto Correctamente", "Ok");
dbConnection.Close();
}
catch (Exception e1)
{
t1.Rollback();
MessageBox.Show("no se pudo insertar debido a: " + e1);
}
}
catch
{
System.Console.WriteLine("Error de conexion.");
}
load_table();
}

//BOTONES Y NUMEROS
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

e.Handled = true;
return;
}
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox1.Text) &&
!string.IsNullOrEmpty(maskedTextBox1.Text) &&
!string.IsNullOrEmpty(textBox3.Text) &&
!string.IsNullOrEmpty(textBox4.Text) &&
!string.IsNullOrEmpty(comboBox1.Text) &&
!string.IsNullOrEmpty(comboBox2.Text)
;
button1.Enabled = bl;
}
private void maskedTextBox1_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox1.Text) &&
!string.IsNullOrEmpty(maskedTextBox1.Text) &&
!string.IsNullOrEmpty(textBox3.Text) &&
!string.IsNullOrEmpty(textBox4.Text) &&
!string.IsNullOrEmpty(comboBox1.Text) &&
!string.IsNullOrEmpty(comboBox2.Text)
;
button1.Enabled = bl;
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox1.Text) &&
!string.IsNullOrEmpty(maskedTextBox1.Text) &&
!string.IsNullOrEmpty(textBox3.Text) &&
!string.IsNullOrEmpty(textBox4.Text) &&
!string.IsNullOrEmpty(comboBox1.Text) &&

!string.IsNullOrEmpty(comboBox2.Text)
;
button1.Enabled = bl;
}
private void comboBox2_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox1.Text) &&
!string.IsNullOrEmpty(maskedTextBox1.Text) &&
!string.IsNullOrEmpty(textBox3.Text) &&
!string.IsNullOrEmpty(textBox4.Text) &&
!string.IsNullOrEmpty(comboBox1.Text) &&
!string.IsNullOrEmpty(comboBox2.Text)
;
button1.Enabled = bl;
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox1.Text) &&
!string.IsNullOrEmpty(maskedTextBox1.Text) &&
!string.IsNullOrEmpty(textBox3.Text) &&
!string.IsNullOrEmpty(textBox4.Text) &&
!string.IsNullOrEmpty(comboBox1.Text) &&
!string.IsNullOrEmpty(comboBox2.Text)
;
button1.Enabled = bl;
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox1.Text) &&
!string.IsNullOrEmpty(maskedTextBox1.Text) &&
!string.IsNullOrEmpty(textBox3.Text) &&
!string.IsNullOrEmpty(textBox4.Text) &&
!string.IsNullOrEmpty(comboBox1.Text) &&
!string.IsNullOrEmpty(comboBox2.Text)
;
button1.Enabled = bl;
}
//2 botones y numeros
private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{

MessageBox.Show("Solo se permiten Numeros", "Advertencia",


MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
private void textBox8_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
private void textBox9_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten Numeros", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}

private void textBox5_TextChanged(object sender, EventArgs e)


{
var bl = !string.IsNullOrEmpty(textBox5.Text) &&
!string.IsNullOrEmpty(textBox6.Text) &&
!string.IsNullOrEmpty(textBox7.Text) &&
!string.IsNullOrEmpty(textBox8.Text) &&
!string.IsNullOrEmpty(textBox9.Text)
;
button2.Enabled = bl;
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox5.Text) &&

!string.IsNullOrEmpty(textBox6.Text) &&
!string.IsNullOrEmpty(textBox7.Text) &&
!string.IsNullOrEmpty(textBox8.Text) &&
!string.IsNullOrEmpty(textBox9.Text)
;
button2.Enabled = bl;
}
private void textBox7_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox5.Text) &&
!string.IsNullOrEmpty(textBox6.Text) &&
!string.IsNullOrEmpty(textBox7.Text) &&
!string.IsNullOrEmpty(textBox8.Text) &&
!string.IsNullOrEmpty(textBox9.Text)
;
button2.Enabled = bl;
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox5.Text) &&
!string.IsNullOrEmpty(textBox6.Text) &&
!string.IsNullOrEmpty(textBox7.Text) &&
!string.IsNullOrEmpty(textBox8.Text) &&
!string.IsNullOrEmpty(textBox9.Text)
;
button2.Enabled = bl;
}
private void textBox9_TextChanged(object sender, EventArgs e)
{
var bl = !string.IsNullOrEmpty(textBox5.Text) &&
!string.IsNullOrEmpty(textBox6.Text) &&
!string.IsNullOrEmpty(textBox7.Text) &&
!string.IsNullOrEmpty(textBox8.Text) &&
!string.IsNullOrEmpty(textBox9.Text)
;
button2.Enabled = bl;
}
//texbox 5 es cantidad--- texbox 6 es cod_articulo--- texbox 7 es el precio
private void textBox6_Enter(object sender, EventArgs e)
{
{
gPrecioProduct = "";
dbConnection = new MySqlConnection("Database=OXXO;Data
Source=localhost;User Id=root;Password=;");
dbConnection.Open();
MySqlCommand command1 = dbConnection.CreateCommand();
command1.CommandText = "select precio from artuculos where
cod_Articulo = " + textBox7.Text;
using (MySqlDataReader reader = command1.ExecuteReader())
{
while (reader.Read())
{
gPrecioProduct = reader.GetString(0);
}

}
}
}
private void textBox6_KeyUp(object sender, KeyEventArgs e)
{
float lRes = 0;
try
{
lRes = float.Parse(gPrecioProduct) * float.Parse(textBox6.Text);
}
catch (Exception e1) { lRes = 0; }
textBox8.Text = lRes.ToString();
}

}
}

You might also like