Mostrando entradas con la etiqueta Visual Studio NET. Mostrar todas las entradas
Mostrando entradas con la etiqueta Visual Studio NET. Mostrar todas las entradas
sábado, 8 de noviembre de 2014
Export to Excel using Developer Express
Private Sub btnExportarExcel_Click(sender As Object, e As EventArgs) Handles btnExportarExcel.Click
Me.GridView1.ExportToXls("linq.xls")
Process.Start("linq.xls")
End Sub
Aggregate Functions in LinQ
' CONSULTA QUE UTILIZA FUNCIONES AGREGADAS
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tbllinq = Aggregate invoice In tblinvoices
Where invoice.InvoiceDate > #1/1/2010#
Into Average(invoice.InvoiceTotal),
Sum(invoice.InvoiceTotal)
'MsgBox("Promedio = " & tbllinq.Average & "; Suma = " & tbllinq.Sum)
MsgBox(tbllinq.ToString())
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tbllinq = Aggregate invoice In tblinvoices
Where invoice.InvoiceDate > #1/1/2010#
Into Average(invoice.InvoiceTotal),
Sum(invoice.InvoiceTotal)
'MsgBox("Promedio = " & tbllinq.Average & "; Suma = " & tbllinq.Sum)
MsgBox(tbllinq.ToString())
Join in LinQ
' Consulta que utiliza join entre dos tablas
Me.GridView1.Columns.Clear()
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tblvendedor As List(Of Vendor) = VendorDB.GetVendors
Dim tbllinq = From invoices In tblinvoices
Join vendedor In tblvendedor
On invoices.VendorID Equals vendedor.VendorID
Where invoices.InvoiceTotal > 3000
Order By vendedor.Name
Select invoices.InvoiceNumber,
invoices.InvoiceDate,
invoices.InvoiceTotal,
vendedor.Name,
vendedor.State
gvEjemplo.DataSource = tbllinq.ToList
Me.GridView1.Columns.Clear()
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tblvendedor As List(Of Vendor) = VendorDB.GetVendors
Dim tbllinq = From invoices In tblinvoices
Join vendedor In tblvendedor
On invoices.VendorID Equals vendedor.VendorID
Where invoices.InvoiceTotal > 3000
Order By vendedor.Name
Select invoices.InvoiceNumber,
invoices.InvoiceDate,
invoices.InvoiceTotal,
vendedor.Name,
vendedor.State
gvEjemplo.DataSource = tbllinq.ToList
Date example in LinQ
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tbllinq = From invoices In tblinvoices
Where invoices.InvoiceDate >= #12/1/2009# And
invoices.InvoiceDate <= #5/31/2010#
Select invoices.InvoiceNumber,
invoices.InvoiceDate,
invoices.InvoiceTotal
Me.gvEjemplo.DataSource = tbllinq.ToList
Dim tbllinq = From invoices In tblinvoices
Where invoices.InvoiceDate >= #12/1/2009# And
invoices.InvoiceDate <= #5/31/2010#
Select invoices.InvoiceNumber,
invoices.InvoiceDate,
invoices.InvoiceTotal
Me.gvEjemplo.DataSource = tbllinq.ToList
Select in LinQ
Private Sub btnEjemplo7_Click(sender As Object, e As EventArgs) Handles btnEjemplo7.Click
' Consulta en linq que regresa de facturas mayores 2000
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tbllinq = From invoices In tblinvoices
Where invoices.InvoiceTotal > 2000
Order By invoices.InvoiceDate Descending
Select invoices.InvoiceNumber,
invoices.InvoiceTotal,
invoices.InvoiceDate
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
' Consulta en linq que regresa de facturas mayores 2000
Dim tblinvoices As List(Of Invoice) = InvoiceDB.GetInvoices
Dim tbllinq = From invoices In tblinvoices
Where invoices.InvoiceTotal > 2000
Order By invoices.InvoiceDate Descending
Select invoices.InvoiceNumber,
invoices.InvoiceTotal,
invoices.InvoiceDate
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
Get SQL data using LinQ Connection
Imports System.Data.SqlClient
Public Class InvoiceDB
Public Shared Function GetInvoices() _
As List(Of Invoice)
Dim invoiceList As New List(Of Invoice)
Dim connection As SqlConnection = LinqDB.GetConnection
Dim selectstatement As String =
"SELECT InvoiceID, VendorID, InvoiceNumber, InvoiceDate, InvoiceTotal, " &
"PaymentTotal, CreditTotal, TermsID, DueDate, PaymentDate " &
"FROM Invoices " &
"ORDER BY InvoiceDate"
Dim selectCommand As New SqlCommand(selectstatement, connection)
Try
connection.Open()
Dim reader As SqlDataReader = selectCommand.ExecuteReader()
Dim invoice As Invoice
Do While reader.Read
invoice = New Invoice
invoice.InvoiceID = CInt(reader("InvoiceID"))
invoice.VendorID = CInt(reader("VendorID"))
invoice.InvoiceNumber = reader("InvoiceNumber").ToString
invoice.InvoiceDate = CDate(reader("InvoiceDate"))
invoice.InvoiceTotal = CDec(reader("InvoiceTotal"))
invoice.PaymentTotal = CDec(reader("PaymentTotal"))
invoice.CreditTotal = CDec(reader("CreditTotal"))
invoice.TermsID = CDec(reader("TermsID"))
invoice.DueDate = CDate(reader("DueDate"))
If IsDBNull(reader("PaymentDate")) Then
invoice.PaymentDate = Nothing
Else
invoice.PaymentDate = CDate(reader("PaymentDate"))
End If
invoiceList.Add(invoice)
Loop
reader.Close()
Catch ex As SqlException
Throw ex
Finally
connection.Close()
End Try
Return invoiceList
End Function
End Class
Public Class InvoiceDB
Public Shared Function GetInvoices() _
As List(Of Invoice)
Dim invoiceList As New List(Of Invoice)
Dim connection As SqlConnection = LinqDB.GetConnection
Dim selectstatement As String =
"SELECT InvoiceID, VendorID, InvoiceNumber, InvoiceDate, InvoiceTotal, " &
"PaymentTotal, CreditTotal, TermsID, DueDate, PaymentDate " &
"FROM Invoices " &
"ORDER BY InvoiceDate"
Dim selectCommand As New SqlCommand(selectstatement, connection)
Try
connection.Open()
Dim reader As SqlDataReader = selectCommand.ExecuteReader()
Dim invoice As Invoice
Do While reader.Read
invoice = New Invoice
invoice.InvoiceID = CInt(reader("InvoiceID"))
invoice.VendorID = CInt(reader("VendorID"))
invoice.InvoiceNumber = reader("InvoiceNumber").ToString
invoice.InvoiceDate = CDate(reader("InvoiceDate"))
invoice.InvoiceTotal = CDec(reader("InvoiceTotal"))
invoice.PaymentTotal = CDec(reader("PaymentTotal"))
invoice.CreditTotal = CDec(reader("CreditTotal"))
invoice.TermsID = CDec(reader("TermsID"))
invoice.DueDate = CDate(reader("DueDate"))
If IsDBNull(reader("PaymentDate")) Then
invoice.PaymentDate = Nothing
Else
invoice.PaymentDate = CDate(reader("PaymentDate"))
End If
invoiceList.Add(invoice)
Loop
reader.Close()
Catch ex As SqlException
Throw ex
Finally
connection.Close()
End Try
Return invoiceList
End Function
End Class
Class example in Visual Studio
Public Class Invoice
Private m_InvoiceID As Integer
Private m_VendorID As Integer
Private m_InvoiceNumber As String
Private m_InvoiceDate As Date
Private m_InvoiceTotal As Decimal
Private m_PaymentTotal As Decimal
Private m_CreditTotal As Decimal
Private m_TermsID As Integer
Private m_DueDate As Date
Private m_PaymentDate As Nullable(Of Date)
Public Sub New()
End Sub
Public Property InvoiceID() As Integer
Get
Return m_InvoiceID
End Get
Set(ByVal value As Integer)
m_InvoiceID = value
End Set
End Property
Public Property VendorID() As Integer
Get
Return m_VendorID
End Get
Set(ByVal value As Integer)
m_VendorID = value
End Set
End Property
Public Property InvoiceNumber() As String
Get
Return m_InvoiceNumber
End Get
Set(ByVal value As String)
m_InvoiceNumber = value
End Set
End Property
Public Property InvoiceDate() As Date
Get
Return m_InvoiceDate
End Get
Set(ByVal value As Date)
m_InvoiceDate = value
End Set
End Property
Public Property InvoiceTotal() As Decimal
Get
Return m_InvoiceTotal
End Get
Set(ByVal value As Decimal)
m_InvoiceTotal = value
End Set
End Property
Public Property PaymentTotal() As Decimal
Get
Return m_PaymentTotal
End Get
Set(ByVal value As Decimal)
m_PaymentTotal = value
End Set
End Property
Public Property CreditTotal() As Decimal
Get
Return m_CreditTotal
End Get
Set(ByVal value As Decimal)
m_CreditTotal = value
End Set
End Property
Public Property TermsID() As Integer
Get
Return m_TermsID
End Get
Set(ByVal value As Integer)
m_TermsID = value
End Set
End Property
Public Property DueDate() As Date
Get
Return m_DueDate
End Get
Set(ByVal value As Date)
m_DueDate = value
End Set
End Property
Public Property PaymentDate() As Nullable(Of Date)
Get
If m_PaymentDate.HasValue Then
Return CDate(m_PaymentDate)
Else
Return Nothing
End If
End Get
Set(ByVal value As Nullable(Of Date))
m_PaymentDate = value
End Set
End Property
Public ReadOnly Property BalanceDue() As Decimal
Get
Return m_InvoiceTotal - m_PaymentTotal - m_CreditTotal
End Get
End Property
End Class
Private m_InvoiceID As Integer
Private m_VendorID As Integer
Private m_InvoiceNumber As String
Private m_InvoiceDate As Date
Private m_InvoiceTotal As Decimal
Private m_PaymentTotal As Decimal
Private m_CreditTotal As Decimal
Private m_TermsID As Integer
Private m_DueDate As Date
Private m_PaymentDate As Nullable(Of Date)
Public Sub New()
End Sub
Public Property InvoiceID() As Integer
Get
Return m_InvoiceID
End Get
Set(ByVal value As Integer)
m_InvoiceID = value
End Set
End Property
Public Property VendorID() As Integer
Get
Return m_VendorID
End Get
Set(ByVal value As Integer)
m_VendorID = value
End Set
End Property
Public Property InvoiceNumber() As String
Get
Return m_InvoiceNumber
End Get
Set(ByVal value As String)
m_InvoiceNumber = value
End Set
End Property
Public Property InvoiceDate() As Date
Get
Return m_InvoiceDate
End Get
Set(ByVal value As Date)
m_InvoiceDate = value
End Set
End Property
Public Property InvoiceTotal() As Decimal
Get
Return m_InvoiceTotal
End Get
Set(ByVal value As Decimal)
m_InvoiceTotal = value
End Set
End Property
Public Property PaymentTotal() As Decimal
Get
Return m_PaymentTotal
End Get
Set(ByVal value As Decimal)
m_PaymentTotal = value
End Set
End Property
Public Property CreditTotal() As Decimal
Get
Return m_CreditTotal
End Get
Set(ByVal value As Decimal)
m_CreditTotal = value
End Set
End Property
Public Property TermsID() As Integer
Get
Return m_TermsID
End Get
Set(ByVal value As Integer)
m_TermsID = value
End Set
End Property
Public Property DueDate() As Date
Get
Return m_DueDate
End Get
Set(ByVal value As Date)
m_DueDate = value
End Set
End Property
Public Property PaymentDate() As Nullable(Of Date)
Get
If m_PaymentDate.HasValue Then
Return CDate(m_PaymentDate)
Else
Return Nothing
End If
End Get
Set(ByVal value As Nullable(Of Date))
m_PaymentDate = value
End Set
End Property
Public ReadOnly Property BalanceDue() As Decimal
Get
Return m_InvoiceTotal - m_PaymentTotal - m_CreditTotal
End Get
End Property
End Class
Average in LinQ
Private Sub btnEjemplo4_Click(sender As Object, e As EventArgs) Handles btnEjemplo4.Click
Dim numeros() As Integer = {2, 4, 6, 8, 10}
Dim tbllinq = numeros.Average
Me.gvEjemplo.DataSource = tbllinq.ToString
End Sub
Dim numeros() As Integer = {2, 4, 6, 8, 10}
Dim tbllinq = numeros.Average
Me.gvEjemplo.DataSource = tbllinq.ToString
End Sub
String SQL Query in LinQ
Private Sub btnEjemplo3_Click(sender As Object, e As EventArgs) Handles btnEjemplo3.Click
Dim resultado As String
Dim animales() As String = {"perro", "gato", "raton", "jirafa", "gallina"}
Dim tbllinq = From v In animales
Where v.ToUpper Like "G*"
'Where v.ToUpper.Contains("G")
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
Dim resultado As String
Dim animales() As String = {"perro", "gato", "raton", "jirafa", "gallina"}
Dim tbllinq = From v In animales
Where v.ToUpper Like "G*"
'Where v.ToUpper.Contains("G")
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
Where and Order Commands in LinQ
Private Sub btnEjemplo1_Click(sender As Object, e As EventArgs) Handles btnEjemplo1.Click
' Consulta a arreglo de numeros
Dim resultado As String
Dim values() As Integer = {1, 10, 100, 5}
Dim tbllinq = From v In values
'Where v > 10
'Dim values() As Integer = {3, 10, -1, 30, -3}
'Dim tbllinq = From v In values
' Order By v Descending
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
' Consulta a arreglo de numeros
Dim resultado As String
Dim values() As Integer = {1, 10, 100, 5}
Dim tbllinq = From v In values
'Where v > 10
'Dim values() As Integer = {3, 10, -1, 30, -3}
'Dim tbllinq = From v In values
' Order By v Descending
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
LinQ in Visual Studio 2013
1) Insertar un Layout Control
2) Insertar LabelControl y SimpleButton
3) Insertar un DataGridView
4) Abrir un evento para el boton "Ejemplo1"
5) Copiar el siguiente codigo
Public Class frmLinQ
Private Sub btnEjemplo1_Click(sender As Object, e As EventArgs) Handles btnEjemplo1.Click
' Consulta a arreglo de numeros
Dim resultado As String
Dim values() As Integer = {1, 10, 100, 5}
Dim tbllinq = From v In values
Me.gvEjemplo.DataSource = tbllinq.ToList
End Sub
End Class
6) Ejecutar el proyecto
Change color theme in Visual Studio 2013
1) Clic in the menu "Tools > Options"
2) In Enviroment > General, select your favourite color theme "Blue", "Dark" and "Light"
sábado, 27 de septiembre de 2014
Get Current Selected Row
private void dgvTabla_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int fila;
fila = this.dgvTabla.CurrentCell.RowIndex;
MessageBox.Show(fila.ToString());
}
Select a C# Form for run it
Para seleccionar un determinado formulario C# y correrlo, abrimos del Proyecto la clase "Program.cs" y establecemos el nombre del formulario que deseamos inicie al presionar el botón "Run"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMiFormulario());
}
}
}
El nombre del formulario lo obtenemos del código fuente del mismo
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 WindowsFormsApplication1
{
public partial class frmMiFormulario: Form
{
public frmMiFormulario()
{
InitializeComponent();
}
...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMiFormulario());
}
}
}
El nombre del formulario lo obtenemos del código fuente del mismo
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 WindowsFormsApplication1
{
public partial class frmMiFormulario: Form
{
public frmMiFormulario()
{
InitializeComponent();
}
...
Suscribirse a:
Entradas (Atom)







