Programa de factura
Enviado por CecilA Vazquez • 3 de Noviembre de 2015 • Apuntes • 3.252 Palabras (14 Páginas) • 176 Visitas
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace pruebaoxxo
{
public partial class Facturas : Form
{
private MySqlConnection dbConcection;
public Facturas()
{
InitializeComponent();
CargaCombo();
CargaCombos();
load_table();
}
private void CargaCombo()
{
dbConcection = new MySqlConnection("Database=oxxo4;Data Source=localhost;User Id=root;Password=;");
dbConcection.Open();
MySqlCommand command1 = dbConcection.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 CargaCombos()
{
dbConcection = new MySqlConnection("Database=oxxo4;Data Source=localhost;User Id=root;Password=;");
dbConcection.Open();
MySqlCommand command1 = dbConcection.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;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
dbConcection = new MySqlConnection("Database=oxxo4;Data Source=localhost;User Id=root;Password=;");
dbConcection.Open();
MySqlCommand command1 = dbConcection.CreateCommand();
MySqlTransaction t1 =dbConcection.BeginTransaction();
try
{
command1.CommandText = "call alta_factura('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + comboBox1.SelectedValue.ToString() + "','" + comboBox2.SelectedValue.ToString() + "')";
command1.ExecuteNonQuery();
t1.Commit();
MessageBox.Show("se Inserto Correctamente","Ok");
dbConcection.Close();
}
catch(Exception e1)
{
t1.Rollback();
MessageBox.Show("no se pudo insertar debido a: "+ e1);
}
}
catch
{
System.Console.WriteLine("Error de conexion.");
}
}
void load_table()
{
string constring = "Database=oxxo4;Data Source=localhost;User Id=root;Password=;";
...