Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Javier Serrano
Programación .NET II
Instituto IACC
28-07-2019
Desarrollo
Ejecución.
Acceso Conectado.
Selección de empleado.
Conexión y consultas:
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ControlGridview
{
public class ConexionDatos
{
public string _stringConexion =
"DataSource=localhost;Database=northwind;Uid=root;Pwd=root;Convert Zero Datetime=True";
public MySqlConnection conexion { get; set; }
public DataTable _dtOrdenes;
public ConexionDatos()
{
conexion = new MySqlConnection(_stringConexion);
}
Conectado:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControlGridview
{
public partial class Conectado : Form
{
SetControlesNoVisibles();
if (rb != null)
{
switch (rb.Name)
{
case "rbFechaEnvio":
this.dtpFechaEnvio.Visible = true;
break;
case "rbCarga":
this.txtCargaDesde.Visible = true;
this.txtCargaHasta.Visible = true;
this.lbdCarga.Visible = true;
this.lbhCarga.Visible = true;
break;
case "rbOrdenFecha":
this.dtpOrdenDesde.Visible = true;
this.dtpOrdenHasta.Visible = true;
this.lbdOrden.Visible = true;
this.lbhOrden.Visible = true;
break;
}
}
}
try
{
dgvOrdenes.DataSource = null;
var dtOrders = _cnn.GetOrdenesByIdEmpleado(id);
dgvOrdenes.DataSource = dtOrders;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
else if (rbFechaEnvio.Checked)
{
var fecha = dtpFechaEnvio.Value.ToString("yyyy/MM/dd");
expresion = $"shippedDate = '{fecha}'";
}
else
{
var fechaOrdeDesde = dtpOrdenDesde.Value.ToString("yyyy/MM/dd");
var fechaOrdeHasta = dtpOrdenHasta.Value.ToString("yyyy/MM/dd");
expresion = $" orderDate >= '{fechaOrdeDesde}' and orderDate <=
'{fechaOrdeHasta}'";
}
filas = temp.Select(expresion);
if (filas.Length > 0)
{
lblCoincidencias.Text = $"{filas.Length} Coincidencia";
if (rbFechaEnvio.Checked)
{
posicion = temp.Rows.IndexOf(filas[0]);
dgvOrdenes.CurrentCell = dgvOrdenes.Rows[posicion].Cells[0];
}
else
{
for (int i = 0; i < filas.Length - 1; i++)
{
posicion = temp.Rows.IndexOf(filas[i]);
dgvOrdenes[indiceColumna, posicion].Selected = true;
}
}
}
else
{
MessageBox.Show("No existe coincidencias para el criterio ingresado");
}
}
}
}
Desconectado:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControlGridview
{
public partial class Desconectado : Form
{
public ConexionDatos _cnn = new ConexionDatos();
DataTable dtDetalleOrden;
public Desconectado()
{
InitializeComponent();
CargarOrdenes();
CargarCombosBusqueda();
}
try
{
dgvDetalleOrden.DataSource = null;
var dtOrdersdetail = _cnn.GetOrdeneDetalleByIdorden(id);
dgvDetalleOrden.DataSource = dtOrdersdetail;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
this.cbPaises.DataSource = dtPaises;
this.cbPaises.DisplayMember = "Pais";
this.cbPaises.ValueMember = "Pais";
this.cbNombres.DataSource = dtNombres;
this.cbNombres.DisplayMember = "Nombres";
this.cbNombres.ValueMember = "Nombres";
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
if (rbViaAsc.Checked)
orden = ListSortDirection.Ascending;
if (rbViaDesc.Checked)
orden = ListSortDirection.Descending;
dgvOrdenes.Sort(columna, orden);
columna = dgvOrdenes.Columns["ShipCity"];
if (rbCiuAsc.Checked)
orden = ListSortDirection.Ascending;
if (rbCiuDesc.Checked)
orden = ListSortDirection.Descending;
dgvOrdenes.Sort(columna, orden);
}
}
}
Principal:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControlGridview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Contenidos Semana 7.