Está en la página 1de 26

AP7-AA4-Ev1-Desarrollo de aplicaciones Windows con C# y Visual Studio .

NET

ERMINSON GARCIA VICTORIA


USUARIO: Admin

CONTRASEÑA: Admin
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
class usuarios
usuarios:
:conexion
{

private
private str
strin
ing
g usuario;
priva
private
te str
strin
ing
g contrasena;

public usuarios() {
usuario = string
string.Empty;
.Empty;
contrasena = string
string.Empty;
.Empty;
this.sql
this.sql = string
string.Empty;
.Empty;

publi
public
c st
strin
ring
g Usuario
{
get {re
retu
turn
rn th
this
is.usuario;}
.usuario;}
set {this
this.usuario
.usuario = value
value;}
;}

publi
public
c st
strin
ring
g Contrasena
{
get {re
retu
turn
rn th
this
is.contrasena;}
.contrasena;}
set {this
this.contrasena
.contrasena = value
value;}
;}

public
public bo
bool
ol Buscar()
{
bool resultado = false
false;
;
this.sql
this.sql = string
string.Format(
.Format(@"SELECT
@"SELECT venUsuario FROM vendedores WHERE
venUsuario ='{0}' AND venContrasena ='{1}'",
='{1}'",this
this.usuario,
.usuario, this
this.contrasena);
.contrasena);
this.comandosql
this.comandosql = new SqlCommand
SqlCommand((this
this.sql,
.sql,this
this.cnn);
.cnn);
this.cnn.Open();
this.cnn.Open();
SqlDataReader reg = null
null;
;
reg = this
this.comandosql.ExecuteReader();
.comandosql.ExecuteReader();
if (reg.Read())
{
resultado = true
true;
;
mensajes= "Bienvenido datos correctos" ;

}
else
{
mensajes = "Datos incorrectos";
}

this
this.cnn.Close();
.cnn.Close();
return resultado;
}

}
}
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;
namespace WindowsFormsApplication1
{
publ
public
ic pa
part
rtia
ial
l cl
clas
ass
s Form2 : Form
{
public Form2()
{
InitializeComponent();
int a;
int b;
int c;

priva
private
te voi
void
d Form2_Load(object
Form2_Load(object sender, EventArgs e)

{
}

priva
private
te voi
void
d prodcuctosToolStripMenuItem_Click(
object sender, EventArgs e)
object
{
Form3 a = new Form3
Form3();
();
a.Show();
}

priva
private
te voi
void
d facturarToolStripMenuItem_Click(
object sender, EventArgs e)
object
{
Form4 b = new Form4
Form4();
();
b.Show();
}

priva
pri
{ vate
te voi
void
d inventarioToolStripMenuItem_Click(
object sender, EventArgs e)
object
Form5 c = new Form5
Form5();
();
c.Show();
}

priva
private
te voi
void
d clientesToolStripMenuItem_Click(
object sender, EventArgs e)
object
{
Clientes c = new Clientes
Clientes();
();
c.Show();
}
}
}
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.Data;

namespace WindowsFormsApplication1
{
publ
public
ic pa
part
rtia
ial
l cl
clas
ass
s Form3 : Form
{
combobox combo = new combobox
combobox();
();
agregarproducto c = new agregarproducto
agregarproducto();
();
public Form3()
{

InitializeComponent();
combo.Seleccionar(cob:comboBox2);
combo cb = new combo
combo();
();
cb.llenaritems(comboBox1);

}
priva
private
te voi
void
d tabPage2_Click(object sender, EventArgs e)
{

priva
private
te voi
void
d tabPage1_Click(object sender, EventArgs e)
{

}
priva
private
te voi
void
d textBox3_TextChanged(object sender, EventArgs e)
{

priva
private
te voi
void
d tabPage3_Click(object sender, EventArgs e)
{

priva
private
te voi
void
d tabPage4_Click(object sender, EventArgs e)
{

priva
private
te voi
void
d button1_Click(object sender, EventArgs e)
{

if (sql.Insertar(proCodigo.Text, proDescripcion.Text, proValor.Text,


proCantidad.Text) == true
true)
)

{
MessageBox.Show("datos
MessageBox.Show("datos insertados");
this.Refresh();
this.Refresh();
proCodigo.Clear();
proDescripcion.Clear();
proValor.Clear();
proCantidad.Clear();
this.Hide();
this.Hide();

}
else
{
MessageBox.Show(
MessageBox.Show("datos
"datos no insertados");
}
}

priva
private
te voi
void
d Form3_Load(object
Form3_Load(object sender, EventArgs e)
{
combo cb = new combo
combo();
();
cb.llenaritems(ComboProductoEliminar);
}

agregarproducto sql = new agregarproducto


agregarproducto();
();

priva
private
te voi
void
d dataGridView1_CellContentClick(
object sender,
object
DataGridViewCellEventArgs e)
{

priva
private
te voi
void
d textBox1_TextChanged(object sender, EventArgs e)
{

priva
private
te voi
void
d comboBox2_SelectedIndexChanged(
object sender, EventArgs e)
object
{
if (comboBox2.SelectedIndex > 0)
{
string[]
string[] valores = combo.captar_info(comboBox2.Text);
textBox7.Text = valores[0];
textBox6.Text = valores[1];
textBox5.Text = valores[2];
}
}

priva
private
te voi
void
d button3_Click(object sender, EventArgs e)
{

priva
private
te voi
void
d comboBox1_SelectedIndexChanged(object sender, EventArgs e)
object
{
SqlConnection conexen = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");
conexen.Open();

SqlCommand cmd = conexen.CreateCommand();

cmd.CommandType = CommandType
CommandType.Text;
.Text;
cmd.CommandText = "select * from productosT where proDescripcion like
('" + comboBox1.Text + "%')"
"%')";
;
cmd.ExecuteNonQuery();

DataTable dt = new DataTable


DataTable();
();
SqlDataAdapter da = new SqlDataAdapter
SqlDataAdapter(cmd);
(cmd);

da.Fill(dt);
dgv.DataSource = dt;
conexen.Close();
}

priva
private
te voi
void
d comboBox3_SelectedIndexChanged(object sender, EventArgs e)
object
{
if (ComboProductoEliminar.SelectedIndex > 0)
{
string[]
string[] valores = combo.captar_info(ComboProductoEliminar.Text);
codProductoSeleccionado.Text = valores[0];
}
}

priva
private
te voi
void
d button6_Click(object sender, EventArgs e)
{
if (sql.actualizar(textBox7.Text, comboBox2.Text, textBox6.Text,
textBox5.Text))
{
MessageBox.Show(
MessageBox.Show("Datos
"Datos Actualizado");
this.Hide();
this.Hide();

}
else MessageBox
MessageBox.Show(
.Show("Datos
"Datos No Actualizados");

priva
private
te voi
void
d button5_Click(object sender, EventArgs e)
{
if (sql.eliminar(codProductoSeleccionado.Text))
{
MessageBox.Show(
MessageBox.Show("Datos
"Datos Eliminados");
this.Hide();
this.Hide();

}
else MessageBox
MessageBox.Show(
.Show("Datos
"Datos No Eliminados");
}

}
}
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;

namespace WindowsFormsApplication1
{

publ
public
ic pa
part
rtia
ial
l cl
clas
ass
s Form4 : Form
{

facturacombo combo = new facturacombo


facturacombo();
();
agregarproducto c = new agregarproducto
agregarproducto();
();

double val;
double cant;
decimal resultado;
public Form4()
{
InitializeComponent();
combo.Seleccionar(cob: listaCli);
combo.SeleccionarProducto(cob: listaPro);
combo cb = new combo
combo();
();
cb.Users(username);

public SqlConnection conex = new SqlConnection


SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");

priva
private
te voi
void
d label2_Click(object sender, EventArgs e)
{

priva
private
te voi
void
d comboBox1_SelectedIndexChanged(
object sender, EventArgs e)
object
{
if (listaPro.SelectedIndex > 0)
{
string[]
string[] valores = combo.captar_productos(listaPro.Text);
CodPro.Text = valores[0];
Valor.Text = valores[1];
}
}

priva
private
te voi
void
d Agregarpro_Click(object sender, EventArgs e)
{

val = Convert
Convert.ToDouble(Valor.Text);
.ToDouble(Valor.Text);
cant = Convert
Convert.ToDouble(cantidad.Text);
.ToDouble(cantidad.Text);
resultado = Convert
Convert.ToDecimal(val
.ToDecimal(val * cant);

suma.Text = resultado.ToString();

DataGridViewRow fila = new DataGridViewRow


DataGridViewRow();
();
fila.CreateCells(dgv);
fila.Cells[0].Value = fecha.Text;
fila.Cells[1].Value = documento.Text;
fila.Cells[2].Value = suma.Text;
fila.Cells[3].Value = username.Text;

fila.Cells[4].Value =
fila.Cells[5].Value = CodPro.Text;
factura.Text;
fila.Cells[6].Value = cantidad.Text;

dgv.Rows.Add(fila);

fecha.Text = ""
"";
;
cantidad.Text = ""
"";
;
listaPro.Text = ""
"";
;
CodPro.Text = ""
"";
;
listaPro.ResetText();

decimal total = 0;
foreach (DataGridViewRow Row in dgv.Rows)
{
total += Convert.ToDecimal(Row.Cells[
Convert.ToDecimal(Row.Cells["colum4"
"colum4"].Value);
].Value);
}
valortotal.Text = Convert
Convert.ToString(total);
.ToString(total);

priva
private
te voi
void
d Form4_Load(object
Form4_Load(object sender, EventArgs e)
{
dgv.AllowUserToAddRows = false
false;
;
}
priva
private
te voi
void
d textBox3_TextChanged(object sender, EventArgs e)
{

priva
private
te voi
void
d listaCli_SelectedIndexChanged(
object sender, EventArgs e)
object
{
if (listaCli.SelectedIndex > 0)
{
string[]
string[] valores = combo.captar_info(listaCli.Text);
documento.Text = valores[0];
direccion.Text = valores[1];
telefono.Text = valores[2];
correo.Text = valores[3];

}
}

priva
private
te vo
void
id button2_Click(object sender, EventArgs e)
{
string consultar=("select
consultar=("select * from facturas where facNumero = '"+
'"+
factura.Text + "'"
"'");
);
if(
if(string
string.IsNullOrWhiteSpace(factura.Text))
.IsNullOrWhiteSpace(factura.Text))
{
MessageBox.Show(
MessageBox.Show("error"
"error");
);
}
else
{
if (consultar == factura.Text)

{ MessageBox.Show(
MessageBox.Show("Esta
"Esta factura ya existe");
}
else
{
try
{
foreach(
foreach(DataGridViewRow Row in dgv.Rows)
{
SqlCommand agregar = new SqlCommand
SqlCommand(
("insert into facturas
values (@facNumero, @facFecha, @facCliente, @facValortotal, @facVendedor)"
, conex);
conex.Open();
agregar.Parameters.Clear();

agregar.Parameters.AddWithValue("@facNumero"
"@facNumero",
,
Convert.ToString(factura.Text));
Convert.ToString(factura.Text));
agregar.Parameters.AddWithValue("@facFecha",
"@facFecha",
Convert.ToString(Row.Cells[
Convert.ToString(Row.Cells["colum2"
"colum2"].Value));
].Value));
agregar.Parameters.AddWithValue("@facCliente"
"@facCliente",
,
Convert.ToString(Row.Cells[
Convert.ToString(Row.Cells["colum3"
"colum3"].Value));
].Value));
agregar.Parameters.AddWithValue("@facValortotal"
"@facValortotal",
,
Convert.ToString(valortotal.Text));
Convert.ToString(valortotal.Text));
agregar.Parameters.AddWithValue("@facVendedor"
"@facVendedor",
,
Convert.ToString(Row.Cells[
Convert.ToString(Row.Cells["colum5"
"colum5"].Value));
].Value));

agregar.ExecuteNonQuery();
}

}
catch
{

}
finally
{

}
}

try
{
SqlCommand agregarPro = new SqlCommand
SqlCommand(
("insert into facturadetalleT
values (@facNumero, @facProducto, @facCantidad)"
, conex);

foreach (DataGridViewRow Row in dgv.Rows)


{

agregarPro.Parameters.Clear();
agregarPro.Parameters.AddWithValue("@facNumero"
"@facNumero",
,
Convert.ToString(Row.Cells[
Convert.ToString(Row.Cells["Column6"
"Column6"].Value));
].Value));
agregarPro.Parameters.AddWithValue("@facProducto"
"@facProducto",
,
Convert.ToInt32(Row.Cells[
Convert.ToInt32(Row.Cells["Column7"
"Column7"].Value));
].Value));

agregarPro.Parameters.AddWithValue(
Convert.ToInt32(Row.Cells[
Convert.ToInt32(Row.Cells["Column8"
"Column8"].Value));
].Value)); "@facCantidad",
"@facCantidad",

agregarPro.ExecuteNonQuery();

}
MessageBox.Show(
MessageBox.Show("Datos
"Datos agregados");

}
catch (Exception ex)
{
MessageBox.Show(
MessageBox.Show("Error
"Error al guardar"+ex);
}
finally
{
conex.Close();
}
}

priva
private
te void
void Quitarproduc_Click_1(object sender, EventArgs e)
{
dgv.Rows.Remove(dgv.CurrentRow);
}

priva
private
te voi
void
d valortotal_TextChanged(object sender, EventArgs e)
{
}

priva
private
te voi
void
d button1_Click(object sender, EventArgs e)
{

}
}

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;

namespace WindowsFormsApplication1
{

publ
public
ic pa
part
rtia
ial
l cl
clas
ass
s Form5 : Form
{
combobox combo = new combobox
combobox();
();
agregarproducto sql = new agregarproducto
agregarproducto();
();
public Form5()
{
InitializeComponent();
combo cb = new combo
combo();
();
cb.llenaritems(comboBox2);

}
priva
private
te voi
void
d Form5_Load(object
Form5_Load(object sender, EventArgs e)
{

priva
private
te voi
void
d comboBox2_SelectedIndexChanged_1(object sender, EventArgs e)
object
{
SqlConnection conex = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");
conex.Open();

SqlCommand cmd = conex.CreateCommand();

cmd.CommandType = CommandType
CommandType.Text;
.Text;

cmd.CommandText
('" + comboBox2.Text + "%')"= "select * from productosT where proDescripcion like
"%')";
;
cmd.ExecuteNonQuery();

DataTable dt = new DataTable


DataTable();
();
SqlDataAdapter da = new SqlDataAdapter
SqlDataAdapter(cmd);
(cmd);

da.Fill(dt);
dgv.DataSource = dt;
conex.Close();
}

}
}
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;

namespace WindowsFormsApplication1
{
publ
public
ic pa
part
rtia
ial
l cl
clas
ass
s Clientes : Form
{
agregarcliente c = new agregarcliente
agregarcliente();
();
public Clientes()
{
InitializeComponent();
}

priva
private
te voi
void
d Clientes_Load(object sender, EventArgs e)
{

}
agregarcliente sql = new agregarcliente
agregarcliente();
();
priva
private
te voi
void
d button1_Click(object sender, EventArgs e)
{
if (sql.Insertar(textBox1.Text, textBox2.Text, textBox3.Text,
textBox4.Text, textBox5.Text) ==true
==true)
)

{
MessageBox.Show("datos
MessageBox.Show("datos insertados");
this.Refresh();
this.Refresh();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
this.Hide();
this.Hide();

}
else
{
MessageBox.Show(
MessageBox.Show("datos
"datos no insertados");
}
}
}
}

CODIGO
CODIGO UTILIZADO
UTILIZ
UTILIZADO
UTILIZADO
ADO PARA
PARA LAS FUNCIONES
FUNCIONES

CONEXIÓN CON BASE DE DATOS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
class conexion
{
publi
public
c st
strin
ring
g cadenaconexion;
protecte
protected
d str
string
ing sql;
prote
protecte
cted
d in
int
t resultado;
protected SqlConnection cnn;
protected SqlCommand comandosql;
protecte
protected
d str
string
ing mensajes;

public conexion()
{
this.cadenaconexion
this.cadenaconexion = (@"Data
(@"Data Source=.;Initial Catalog =facturacion;
integrated security=true");

this.cnn
this.cnn = new SqlConnection
SqlConnection(
(this
this.cadenaconexion);
.cadenaconexion);
}

}
}

USUARIOS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class usuarios
usuarios:
:conexion
{

private
private str
strin
ing
g usuario;
priva
private
te str
strin
ing
g contrasena;

public usuarios() {

usuario = string
string.Empty;
.Empty;
contrasena = string
string.Empty;
.Empty;
this.sql
this.sql = string
string.Empty;
.Empty;

publi
public
c st
strin
ring
g Usuario
{
get {re
retu
turn
rn th
this
is.usuario;}
.usuario;}
set {this
this.usuario
.usuario = value
value;}
;}

publi
public
c st
strin
ring
g Contrasena
{

get
set {
{re
retu
turn
rn th
this
is.contrasena;}
.contrasena;}
this.contrasena
this.contrasena = value
value;}
;}

publ
public
ic bo
bool
ol Buscar()
{
bool resultado = false
false;
;
this.sql
this.sql = string
string.Format(
.Format(@"SELECT
@"SELECT venUsuario FROM vendedores WHERE
venUsuario ='{0}' AND venContrasena ='{1}'",this
this.usuario,
.usuario, this
this.contrasena);
.contrasena);
this.comandosql
this.comandosql = new SqlCommand
SqlCommand(
(this
this.sql,
.sql,this
this.cnn);
.cnn);
this.cnn.Open();
this.cnn.Open();
SqlDataReader reg = null
null;
;
reg = this
this.comandosql.ExecuteReader();
.comandosql.ExecuteReader();
if (reg.Read())
{

resultado = true
true;
;
mensajes= "Bienvenido datos correctos"
;

}
else
{
mensajes = "Datos incorrectos";
}

this.cnn.Close();
this.cnn.Close();
return resultado;
}

}
}
AGREGAR
AGREGAR PRODUCTO
PRODUC
PRODUCTO
TO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class agregarproducto
{
private SqlConnection conexion = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");
private DataSet ds;

public DataTable mostrardatos()


{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from productosT", conexion);
SqlDataAdapter ad = new SqlDataAdapter
SqlDataAdapter(cmd);
(cmd);
ds = new DataSet
DataSet();
();

ad.Fill(ds, "tabla");
"tabla"
conexion.Close(); );
return ds.Tables["tabla"
ds.Tables["tabla"];
];

public
public bo
bool
ol Insertar(string
Insertar(string proCodigo, string proDescripcion, string
proValor, string proCantidad)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("insert
"insert into productosT
values ({0}, '{1}', '{2}', '{3}')", ne
new
w st
stri
ring
ng[]
[] { proCodigo, proDescripcion,
proValor, proCantidad }), conexion);
int filasafectadas = cmd.ExecuteNonQuery();
conexion.Close();
if (filasafectadas > 0) re
retu
turn
rn tr
true
ue;
;

else
else re
retu
turn
rn fa
fals
lse
e;

publ
public
ic bo
bool
ol actualizar(string
actualizar(string proCodigo, string proDescripcion, string
proValor, string proCantidad)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("update
"update productosT set
proDescripcion = '{0}', proValor = '{1}', proCantidad = '{2}' where proCodigo =
{3}",
{3}", ne
new
w st
stri
ring
ng[]
[] { proDescripcion, proValor, proCantidad, proCodigo}), conexion);
int filasafectadas = cmd.ExecuteNonQuery();
conexion.Close();
if (filasafectadas > 0) re
retu
turn
rn tr
true
ue;
;
else
else re
retu
turn
rn fa
fals
lse
e;
}

public DataTable Buscar(string


Buscar(string proDescripcion)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("select
"select * from productosT
where proDescripcion = '{1}'", proDescripcion), conexion);
SqlDataAdapter ad = new SqlDataAdapter
SqlDataAdapter(cmd);
(cmd);
ds = new DataSet
DataSet();
();
ad.Fill(ds, "tabla"
"tabla");
);
conexion.Close();
return ds.Tables["tabla"
ds.Tables["tabla"];
];

publ
public
ic bo
bool
ol eliminar(string
eliminar(string proCodigo)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("delete
"delete from productosT
where proCodigo = {0}",proCodigo), conexion);
int filasafectadas = cmd.ExecuteNonQuery();
conexion.Close();
if (filasafectadas > 0) re
retu
turn
rn tr
true
ue;
;
else
else re
retu
turn
rn fa
fals
lse
e;

}
}

AGREGAR CLIENTE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
class agregarcliente
{
private SqlConnection conexion = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");
private DataSet ds;
publ
public
ic bo
bool
ol Insertar(string
Insertar(string cliDocumento, string cliNombre, string cliDireccion,
string cliTelefono,string
cliTelefono,string cliCorreo)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("insert
"insert into clientes
values ({0}, '{1}', '{2}', '{3}', '{4}')", ne
new
w st
stri
ring
ng[]
[] { cliDocumento, cliNombre,
cliDireccion, cliTelefono, cliCorreo }), conexion);
int filasafectadas = cmd.ExecuteNonQuery();
conexion.Close();
if (filasafectadas > 0) re
retu
turn
rn tr
true
ue;
;
else
else re
retu
turn
rn fa
fals
lse
e;

}
}

AGREGAR
AGREGAR FACTURA
FACTURA

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class agregarfactura
{
private SqlConnection conexion = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");
private DataSet ds;

public DataTable mostrardatos()


{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from facturas", conexion);
SqlDataAdapter ad = new SqlDataAdapter
SqlDataAdapter(cmd);
(cmd);
ds = new DataSet
DataSet();
();
ad.Fill(ds, "tabla"
"tabla");
);
conexion.Close();
return ds.Tables["tabla"
ds.Tables["tabla"];
];

publ
public
ic bo
bool
ol ConsecutivoFactura(string facNumero, string facFecha, string
facCliente, string facValortotal, string facVendedor)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("insert
"insert into facturas
values ({0}, '{1}', '{2}', '{3}','{4}')", ne
neww st
stri
ring
ng[]
[] { facNumero, facFecha,
facCliente, facValortotal, facVendedor }), conexion);
int filasafectadas = cmd.ExecuteNonQuery();
conexion.Close();
if (filasafectadas > 0) re
retu
turn
rn tr
true
ue;
;
else
else re
retu
turn
rn fa
fals
lse
e;

}
publ
public
ic bo
bool
ol FacturaDetalle(string facNumero, string facProducto, string
FacCantidad)
{
conexion.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
(string
string.Format(
.Format("insert
"insert into productosT
values ({0}, '{1}', '{2}')", ne
new
w st
stri
ring
ng[]
[] { facNumero, facProducto, FacCantidad}),
conexion);
int filasafectadas = cmd.ExecuteNonQuery();
conexion.Close();
if (filasafectadas > 0) re
retu
turn
rn tr
true
ue;
;
else
else re
retu
turn
rn fa
fals
lse
e;

}
}

DEMAS CODIGO UTILIZADO

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
class combo
{
SqlCommand cmd;
SqlConnection cnn;
SqlDataReader dr;

public combo()
{
try
{
cnn = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");
cnn.Open();
}
catch (Exception ex)
{

}
}

publ
public
ic vo
void
id llenaritems(ComboBox
llenaritems(ComboBox cb)
{
try
{
SqlDataReader dr;
cmd = new SqlCommand
SqlCommand(
("select proDescripcion from productosT"
, cnn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
cb.Items.Add(dr["proDescripcion"
cb.Items.Add(dr["proDescripcion"].ToString());
].ToString());
}

}
catch (Exception ex)
{

}
}

publ
pu
{ blic
ic vo
void
id Users(ComboBox
Users(ComboBox cb)
try
{
SqlDataReader dr;
cmd = new SqlCommand
SqlCommand(
("select venUsuario from vendedores"
, cnn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
cb.Items.Add(dr["venUsuario"
cb.Items.Add(dr["venUsuario"].ToString());
].ToString());
}

}
catch (Exception ex)
{

} }

}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
class combobox
{
SqlConnection con = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");

publ
public
ic vo
void
id Seleccionar(ComboBox
Seleccionar(ComboBox cob)
{
cob.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from productosT", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
cob.Items.Add(dr[1].ToString());
}
con.Close();
cob.Items.Insert(0, "---seleccione un Item---");
Item---");
cob.SelectedIndex = 0;

publi
public
c st
strin
ring
g[] captar_info(string proDescripcion)
{
con.Open();

SqlCommand
proDescripcion='" cmd = new SqlCommand
SqlCommand(
+ proDescripcion + "'"
"'", ("select * from productosT where
, con);
SqlDataReader dr = cmd.ExecuteReader();
string[]
string[] resultado = null
null;
;
while (dr.Read())
{
string[]
string[] valores =
{
dr[0].ToString(),
dr[2].ToString(),
dr[3].ToString(),

};
resultado = valores;
}
con.Close();

return resultado;
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class facturacombo
{
SqlConnection con = new SqlConnection
SqlConnection(
("Data Source=.;Initial
Catalog=facturacion;Integrated Security=True");

publ
public
ic vo
void
id Seleccionar(ComboBox
Seleccionar(ComboBox cob)
{
cob.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from clientes", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
cob.Items.Add(dr[1].ToString());
}
con.Close();
cob.Items.Insert(0, "---Seleccione a el Cliente---");
Cliente---");
cob.SelectedIndex = 0;

publi
public
c st
strin
ring
g[] captar_info(string proDescripcion)
{

con.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from clientes where
cliNombre='" + proDescripcion + "'"
"'",
, con);
SqlDataReader dr = cmd.ExecuteReader();
string[]
string[] resultado = null
null;
;
while (dr.Read())
{
string[]
string[] valores =
{
dr[0].ToString(),
dr[2].ToString(),
dr[3].ToString(),
dr[4].ToString(),

};
resultado = valores;

}
con.Close();
return resultado;

publ
public
ic vo
void
id SeleccionarProducto(ComboBox cob)
{
cob.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from productosT", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
cob.Items.Add(dr[1].ToString());
}
con.Close();
cob.Items.Insert(0, "---Seleccione un producto---");
cob.SelectedIndex = 0;

public
public st
strin
ring
g[] captar_productos(string
captar_productos(string Descripcion)
{
con.Open();
SqlCommand cmd = new SqlCommand
SqlCommand(
("select * from productosT where
proDescripcion='" + Descripcion + "'"
"'",
, con);
SqlDataReader dr = cmd.ExecuteReader();
string[]
string[] resultado = null
null;
;
while (dr.Read())
{
string[]
string[] valores =
{
dr[0].ToString(),
dr[2].ToString(),
dr[3].ToString(),

};
resultado = valores;
}
con.Close();
return resultado;

}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
stat
static
ic cla
class
ss Program

{ /// <su
<summ
mmary
ary>
>
/// The main entry point for the application.
/// </s
</sum
ummar
mary>
y>
[STAThread
STAThread]
]
stat
static
ic vo
void
id Main()
{
Application.EnableVisualStyles();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(
Application.SetCompatibleTextRenderingDefault(false
false);
);
Application.Run(
Application.Run(new
new Form1
Form1());
());
}
}
}

También podría gustarte