Hola dev como estan espero que bien, en este articulo les muestro a como crear una base de datos en sql server
jueves, 1 de septiembre de 2022
jueves, 18 de agosto de 2022
como imprimir comprobantes en c# (printDocument)
hey hola, nuevamente yo por aquí ,para compartirles este articulo a como hacer la impresion de comprobantes de pago en c#
controles a utilizar son:
primeramente Diseñamos nuestro formulario como la imagen siguiente
private void printDocument_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
//Image image =
panel1.BackgroundImage;
e.Graphics.DrawString("Tiket de ventas", new Font("Arial", 10,
FontStyle.Bold), Brushes.Black, new Point(30, 10));
e.Graphics.DrawString("_________________________________________", new Font("Arial", 6,
FontStyle.Regular), Brushes.Black, new Point(3, 20));
e.Graphics.DrawString("nro: 100", new Font("Arial", 10,
FontStyle.Bold), Brushes.Black, new Point(5, 40));
e.Graphics.DrawString("fecha de venta : 18/08/2022", new Font("Arial", 10,
FontStyle.Bold), Brushes.Black, new Point(5, 60));
}
private void button1_Click(object sender, EventArgs e)
{
//printDocument.Print();
PrintDocument pd
= new
PrintDocument();
//PaperSize ps
= new PaperSize("factura", 827, 1169);
PaperSize ps = new PaperSize("Boleta", 200, 600);
pd.PrintPage
+= new
PrintPageEventHandler(printDocument_PrintPage);
pd.PrintController = new StandardPrintController();
pd.DefaultPageSettings.Margins.Left = 0;
pd.DefaultPageSettings.Margins.Right = 0;
pd.DefaultPageSettings.Margins.Top = 0;
pd.DefaultPageSettings.Margins.Bottom = 0;
pd.DefaultPageSettings.PaperSize = ps;
pd.Print();
}
codigo para nuestro buton vista previa de impresion
private void button2_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document =
printDocument;
printPreviewDialog1.ShowDialog();
}
eso seria todo espero haber ayudado con este articulo.
gracias saludos.
jueves, 14 de abril de 2022
Leer datos XML en un conjunto de datos y mostrar en control datagridview en c# desarrollado en visual estudio 2022
ojo declarar variable AuthorsDataSet a nivel global public DataSet AuthorsDataSet = new DataSet();
public DataSet AuthorsDataSet = new DataSet();
codigo para button leer datos xml
private void leerdatosxml_Click(object sender, EventArgs e)
{
string filePath = "C:/Users/LENOVO/source/repos/xml-dataGridview/xml- dataGridview/bin/Debug/net6.0-windows/datos.xml";
AuthorsDataSet.ReadXml(filePath);
dataGridView1.DataSource = AuthorsDataSet;
dataGridView1.DataMember = "authors";
}
codigo para button mostrar esquema
{
System.IO.StringWriter swXML = new System.IO.StringWriter();
AuthorsDataSet.WriteXmlSchema(swXML);
textBox1.Text =
swXML.ToString();
}
eso seria todo .si desean el proyecto pueden descargar de nuestro repositorio en github
martes, 12 de abril de 2022
cargar datos a control combobox en c# desde base datos sql server 2022
hey bienvenido gracias por estar por aquí , yo de nuevo por aquí posteando este articulo a como cargar datos al control combobox desde una base de datos sql server.
diseño de nuestro formulario de practica como la imagen siguiente
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(@"Data
Source=CPIPRODESIGN\SQLEXPRESS;Initial Catalog=colegios;Integrated
Security=True");
cn.Open();
SqlCommand cm=new SqlCommand("select*from
alumnos",cn);
SqlDataReader dr
= cm.ExecuteReader();
while (dr.Read())
{
this.comboBox1.Items.Add(dr["nombres"].ToString());
}
}
domingo, 27 de marzo de 2022
como hacer un crud en c# y Postgresql 2022 (create,read,update,eliminar)
Hola bienvenidos amigos , nuevamente yo por aquí , En este post haremos un crud en c# con la base de datos en POSTGRESQL14
- creacion de base de datos
create table alumnos(
codigo serial,
nombres
varchar(80),
direccion
varchar(100),
primary
key(codigo)
)
insert into alumnos values('1','cristian patricio
izquierdo','lima los olivos')
insert into alumnos values('2','lili rodruguez salas','lima
los olivos')
insert into alumnos values('3','Yesenia silva salas','lima
los olivos')
select*from alumnos
NpgsqlConnection cn=new
NpgsqlConnection("Server=localhost;User
Id=postgres;Password=admin;Database=Colegio");
private void getAlumnos()
{
NpgsqlDataAdapter da=new NpgsqlDataAdapter("select*from
alumnos",cn);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource
= dt;
{
try
{
string a;
a = "insert
into alumnos values('" + txtcodigo.Text + "','" +
(txtnombres.Text) + "','" + (txtdireccion.Text) + "')";
NpgsqlCommand cmd = new NpgsqlCommand(a, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Registro guardado correctamente");
getAlumnos();
}
catch
(InvalidCastException ex)
{
throw ex;
}
}
//update alumnos
private void updateAlumnos()
{
try
{
string update;
update = "update
alumnos set nombres ='" + txtnombres.Text + "',direccion
='" + txtdireccion.Text + "' where codigo ='" +
txtcodigo.Text + "'";
NpgsqlCommand cmd = new NpgsqlCommand(update, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Registro actualizado correctamente");
getAlumnos();
}
catch
(InvalidCastException ex)
{
throw ex;
}
}
//delete alumnos
private void
deleteAlumnos()
{
try
{
string delete;
delete = "delete
from alumnos where codigo ='" +
txtcodigo.Text + "'";
NpgsqlCommand cmd = new NpgsqlCommand(delete, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Registro Eleminado correctamente");
getAlumnos();
}
catch (InvalidCastException ex)
{
throw ex;
}
}
//codigo para pasar datos de grid a sus respectivos textbox para eliminar o actualizar
private void
dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex
>= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
txtcodigo.Text = row.Cells["codigo"].Value.ToString();
txtnombres+.Text = row.Cells["Nombres"].Value.ToString();
txtdireccion.Text = row.Cells["Direccion"].Value.ToString();
}
}
domingo, 7 de noviembre de 2021
c# y SQLSERVER Consultar una fecha en rangos con datetimepicker.
hey hola ,yo de nuevo por aquí compartiendo este post de como hacer consultas con rango de fechas.
para este ejercicio primeramente creamos nuestro base de datos con su respectivo tabla.
script para la creacion de bd y tabla.
create database tuto
use tuto
--creacion de tablas
create table ventas(
id int primary key,
fecha datetime,
totalVentas decimal(10,2)
)
go
--creamos nuestro procedimiento
almacenado
alter procedure buscar
@fechainicial datetime,
@fechafinal datetime
as
select*from ventas where fecha between @fechainicial and @fechafinal
go
controles a utilizar son: datagridview, datepicker,label,button
private void
getVentas()
{
SqlDataAdapter da = new SqlDataAdapter("select*from ventas", cn);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
}
//metodo para buscar entre fechas.
private void
getVentasFecha()
{
SqlDataAdapter da = new SqlDataAdapter("buscar", cn);
da.SelectCommand.CommandType =
CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("@fechainicial",
SqlDbType.DateTime).Value = dateTimePicker1.Text;
da.SelectCommand.Parameters.Add("@fechafinal",
SqlDbType.DateTime).Value = dateTimePicker2.Text;
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
}