Está en la página 1de 14

Workshop Programming C Sharp 2009 Step by Step

http://systemtak.blogspot.com
[1]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
Workshop Course Schedule C Sharp (C # 3.0) Step by Step
1. Introduction
2. Tools Required
3. Basic Analysis System
4. Database XE SQL Server 2005
5. Tables
6. Stored Procedures
7. Connecting C # with SQL Server 2005 XE
8. User Interface Windows Forms C #
9. Reports
10.
Functionality Testing
http://systemtak.blogspot.com
[2]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
Introduction
To all my friends that start in the wonderful world of development or applicatio
n programming as they want to say, that I imagine have many doubts when they sta
rt a real project, this time I want to express in detail the sequence of steps t
hat lead us to obtain a Client / Server; "mini sys agenda." Our system will reco
rd contacts different professions, countries, which we have registered with the
need for their data to make it simple and understandable work with three tables
in the database. I hope that allows us to interact and this workshop is your com
plete satisfaction.
Sincerely,
Armando Tacza
IT Professional
http://systemtak.blogspot.com
[3]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
Tools Required Microsoft Visual Studio 2008 Microsoft SQL Server 2005 Express Ed
ition Microsoft Server Management Studio Express
Basic Analysis System
sys mini agenda will be analyzed basically as if you save a contact you have in
your
mobile phone, in order to make an Entity Relationship Model and work with more t
han one table is that we increase the detail Profession and Country. Database XE
Execute SQL Server 2005 MS SQL Server Management Studio:
The first time we started we show the following:
Click the Connect button:
Assign a password to the user sa order to connect through this user.
http://systemtak.blogspot.com
[4]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
SQL Server 2005 will begin again with the sa user and password.
Now create the database: Click Right: New Database Name: agenda
http://systemtak.blogspot.com
[5]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
Tb_profesion Tables
tb_pais
http://systemtak.blogspot.com
[6]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
tb_contacto
Relating Tables:
http://systemtak.blogspot.com
[7]
Email: atacza@gmail.com
Workshop Programming C Sharp 2009 Step by Step
Entity relationships are a given country have many contacts (ratio 1 to many) of
a profession we have many contacts (ratio 1 to many)
Stored Procedures (Lots of Reusable Code in the Server are scheduled through lan
guage Transact - SQL) shall be established as follows:
Basic will create the stored procedures: Insert, Update, Delete for each table.
Use names that start with sp_tbxxxxxx.
http://systemtak.blogspot.com
[8]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Stored Procedures for Table: tb_pais sp_tbPaisInsertar (use the following templa
te that SQL server is proposing)
- ================================================ - Template generated from Tem
plate Explorer using: - Create Procedure (New Menu). SQL --- Use the Specify Val
ues for Template Parameters - command (Ctrl-Shift-M) to fill in the parameter -
values below. --- This block of comments will Not be included in - the definitio
n of the procedure. - ================================================ SET ANSI_
NULLS ON GO SET QUOTED_IDENTIFIER ON GO - ======================================
== ===== - Author: <Author,,Name> - Create date: <Create Date,,> - Description:
<Description,,> - ============= CREATE PROCEDURE <Procedure_Name, sysname, =====
=========================== ProcedureName> - Add the parameters for the stored p
rocedure here <@ Param1, sysname, @ p1> <Datatype_For_Param1,, int> = <Default_V
alue_For_Param1,, 0>, <@ Param2, sysname, @ p2> <Datatype_For_Param2,, int> = <D
efault_Value_For_Param2,, 0> AS BEGIN - SET NOCOUNT ON added to Prevent extra re
sult sets from - interfering with SELECT statements. SET NOCOUNT ON - Insert sta
tements for procedure here SELECT <@ Param1, sysname, @ p1>, <@ Param2, sysname,
@ p2> END GO
Modified Template would look like:
- ================================================ - Template generated from Tem
plate Explorer using: - Create Procedure (New Menu). SQL --- Use the Specify Val
ues for Template Parameters - command (Ctrl-Shift-M) to fill in the parameter -
values below.€--- This block of comments will Not be included in - the definiti
on of the procedure. - ================================================ SET ANSI
_NULLS ON GO SET QUOTED_IDENTIFIER ON GO - =====================================
=== ===== - Author: <Armando Tacza> http://systemtak.blogspot.com [9] Email: ata
cza@gmail.com
C Sharp Programming Workshop step 2009
- Create date: <16/07/2009> - Description: for table <Procedimiento tb_pais> - =
======================== ==================== CREATE PROCEDURE sp_tbPaisInsertar
- Add the parameters for the stored procedure here @ NombrePais varchar (35) AS
BEGIN - SET NOCOUNT ON added to Prevent extra result sets from - interfering wi
th SELECT statements. SET NOCOUNT ON - Insert statements for procedure here INSE
RT INTO tb_pais (NombrePais) values (@ NombrePais) END GO Then modify the code b
y pressing the Run button and thus
we created a stored procedure.
http://systemtak.blogspot.com
[10]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
sp_tbPaisModificar (Procedure for Update)
CREATE PROCEDURE CodigoPais sp_tbPaisModificar @ int, @ NombrePais varchar (35)
AS BEGIN SET NOCOUNT ON; update September tb_pais NombrePais = @ NombrePais wher
e (CodigoPais = @ CodigoPais) END GO
sp_tbPaisEliminar (Procedure to End)
CREATE PROCEDURE CodigoPais sp_tbPaisEliminar @ int AS BEGIN SET NOCOUNT ON; del
ete from tb_pais where (CodigoPais = @ CodigoPais) END GO
sp_tbPaisListar (Procedure for List)
CREATE PROCEDURE sp_tbPaisListar AS BEGIN SET NOCOUNT ON; select * from order by
NombrePais tb_pais END GO
Stored Procedures for Table: tb_contacto sp_tbContactoInsertar (Procedure to Ins
ert Contact)
CREATE PROCEDURE sp_tbContactoInsertar @ ContactName varchar (45), @ DireccionCo
ntacto varchar (45), @ TelefonoContacto varchar (12), @ CelularContacto varchar
(12), @ EmailContacto varchar (20), @ FechaRegistro smalldatetime, @ CodigoProfe
sion int, int @ CodigoPais AS BEGIN SET NOCOUNT ON; insert into tb_contacto (Con
tactName, DireccionContacto, TelefonoContacto, CelularContacto, Email Contact, F
echaRegistro, CodigoProfesion, CodigoPais) values (@ ContactName, @ DireccionCon
tacto, @ TelefonoContacto, @ CelularContacto, @ EmailContac to, @ FechaRegistro,
@ CodigoProfesion, @ CodigoPais) END
sp_tbContactoModificar (Procedure for Modifying Contact)
http://systemtak.blogspot.com
[11]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
CREATE PROCEDURE [dbo]. [Sp_tbContactoModificar] @ CodigoContacto int, @ Contact
Name varchar (45), @ DireccionContacto varchar (45), @ TelefonoContacto varchar
(12), @ CelularContacto varchar (12), @ EmailContacto varchar (20), @ FechaRegis
tro smalldatetime, @ CodigoProfesion int, int @ CodigoPais
AS BEGIN SET NOCOUNT ON; update September tb_contacto ContactName = @ ContactNam
e, DireccionContacto = @ DireccionContacto, TelefonoContact o = @ TelefonoContac
to, CelularContacto = @ CelularContacto, EmailContacto EmailContacto = @ F = @ F
echaRegistro echaRegistro, CodigoProfesion = @ CodigoProfesion, CodigoPais = @ C
odigoPais where (CodigoContacto = @ CodigoContacto) END
sp_tbContactoEliminar (Procedure to Remove Contact)
CREATE PROCEDURE [dbo]. [Sp_tbContactoEliminar] @ CodigoContacto int AS BEGIN SE
T NOCOUNT ON; delete from tb_contacto where (CodigoContacto = @ CodigoContacto)
END
sp_tbContactoListar (Procedure for Contact List)
CREATE PROCEDURE [dbo]. [Sp_tbContactoListar] AS BEGIN SET NOCOUNT ON; select tb
_contacto.CodigoContacto, tb_contacto.NombreContacto, tb_contacto.DireccionConta
cto, tb_contacto.TelefonoContacto, tb_contacto.CelularContacto, tb_contacto.Emai
lContacto, tb_contacto.EmailContacto, tb_contacto.FechaRegistro, tb_pais. Nombre
Pais, tb_profesio n.NombreProfesion from tb_contacto, tb_pais, tb_profesion wher
e (tb_contacto.CodigoProfesion = tb_profesion.CodigoProfesion and tb_contacto.Co
digoPais = tb_pais.CodigoPais) END
sp_tbContactoListarPorPais (Procedure for List of Countries)
CREATE PROCEDURE [dbo]. [Sp_tbContactoListarPorPais] @ CodigoPais int AS BEGIN S
ET NOCOUNT ON; select tb_contacto.CodigoContacto, tb_contacto.NombreContacto, tb
_contacto.DireccionContacto, tb_contacto.TelefonoContacto, tb_contacto.CelularCo
ntacto, tb_contacto.EmailContacto, tb_contacto.EmailContacto, tb_contacto.FechaR
egistro , tb_pais.NombrePais, tb_profesio n.NombreProfesion from tb_contacto, tb
_pais, tb_profesion http://systemtak.blogspot.com [12] Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
where (tb_contacto.CodigoProfesion = tb_profesion.CodigoProfesion and tb_contact
o.CodigoPais = tb_pais.CodigoPais and tb_contacto.CodigoPais = @ CodigoPais) ord
er by tb_contacto.NombreContacto END
sp_tbContactoListarPorProfesion (Procedure List by Profession)
CREATE PROCEDURE [dbo]. [Sp_tbContactoListarPorProfesion] @ CodigoProfesion int
AS BEGIN SET NOCOUNT ON; select tb_contacto.CodigoContacto, tb_contacto.NombreCo
ntacto, tb_contacto.DireccionContacto, tb_contacto.TelefonoContacto, tb_contacto
.CelularContacto, tb_contacto.EmailContacto, tb_contacto.EmailContacto, tb_conta
cto.FechaRegistro, tb_pais.NombrePais, tb_profesio n.NombreProfesion from tb_con
tacto, tb_pais, tb_profesion where (tb_contacto.CodigoProfesion = tb_profesion.C
odigoProfesion and tb_contacto.CodigoPais = tb_pais.CodigoPais and tb_contacto.C
odigoProfesion = @ CodigoProfesion) order by tb_contacto.NombreContacto END
All codes so far are for SQL Server is: Server-Side
http://systemtak.blogspot.com
[13]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Starting with C # (Client Side) Create a folder on drive C of our PC (c: \ sysAg
enda) Run Visual Studio 2008, Click File>> New>> Project
Taking into account the Project Name, Location and Solution Name. You must have
a window like the following.
After giving Ud.Tendrá Click the following.
http://systemtak.blogspot.com
[14]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Connecting C # with SQL Server 2005 XE Click on the Data menu>> Show Data Source
s
Click Next
http://systemtak.blogspot.com
[15]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
We will create a new connection (Click on New Connection)
Click Continue
It is important that the Add Connection Server name is entered as follows.
Since SQL Server will do the following:
http://systemtak.blogspot.com
[16]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
In Add Connection must enter PCSERVER \ SQLEXPRESS
After entering Server name We select Use SQL Server Authentication User name Pas
sword Select the Database Click on OK
http://systemtak.blogspot.com
[17]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Then we have the following:
Click Next
Click Next, select tables and stored procedures.
We left the default DataSet name agendaDataSet
Finally Click Finish
http://systemtak.blogspot.com
[18]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
User Interface Windows Forms C # Considering our BD model with three tables, we
will develop the user interface for the main table (tb_contacto). Home Activity
properties window of Form1
TextBox1 StartPosition Form1 Name Name Text Name ReadOnly TextBox2 TextBox4 Text
Box3 Name Name Name TextBox6 TextBox5 DropDownStyle ComboBox2 Name Name Name Com
boBox1 DropDownStyle AllowUserToAddRows AllowUserToDeleteRows ReadOnly DataGridV
iew1 Name Name Text Button1 Button2 Button3 Name Text Name Text Name Text Button
4
True txtCodigo frmContacto txtNombres Contacts CenterScreen txtDireccion txtTele
fono txtCelular txtEmail cboProfesion DropDownList DropDownList cboPais dtgDetal
le True False False New btnGrabar btnNuevo btnEliminar Modify Delete Record btnM
odificar
[19]
http://systemtak.blogspot.com
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Button5 button6 Name Text Name Text Name Text Button7
Cancel btnCancel btnListar btnSalir Exit List
Our model would look like:
For purposes of ease must manually enter data to the tables and tb_pais tb_profe
sion Occupation: Management Accounting Law Engineering Social Sciences Country:
Colombia Mexico Peru Venezuela Argentina Chile
http://systemtak.blogspot.com
[20]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Creating a Connection Class Class: conexión.cs
Add a reference to the project right click>> Add Reference
http://systemtak.blogspot.com
[21]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
using System; using System.Collections.Generic; using System.Linq; using System.
Text; using System.Configuration; namespace sysAgenda (public class (public stri
ng connection LeerConexion () (try (return ConfigurationManager.ConnectionString
s ["sysAgenda.Properties. Settings.agendaConnectionString "]. ConnectionString;)
catch (Exception ex) (throw new Exception (ex.Message);))))
The connection string:
We obtain sysAgenda.Properties.Settings.agendaConnectionString Archive: app.conf
ig
http://systemtak.blogspot.com
[22]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
We will create the class: pais.cs, and contacto.cs profesion.cs pais.cs
using System; using System.Collections.Generic; using System.Linq; using System.
Text; using System.Data; using System.Data.SqlClient; namespace country sysAgend
a (public class (/ / Create a method that allows us to list the countries / / fr
om the stored procedure the sgte. public way ListarPais DataTable () (/ / Connec
tion instance of the connection cnn = new Connection (); SqlConnection cn = new
SqlConnection (cnn.LeerConexion ());€/ / Name of the stored procedure SqlComman
d cmd = new SqlCommand ("sp_tbPaisListar", cn) cmd.CommandType = CommandType.Sto
redProcedure; try (SqlDataAdapter da = new SqlDataAdapter (cmd); DataTable tb =
new DataTable () da.Fill ( tb) return (tb);) catch (Exception ex) (throw new Exc
eption (ex.Message);) finally (cn.Dispose (); cmd.Dispose ();))))
http://systemtak.blogspot.com
[23]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Class profesion.cs In our database we do not have the stored procedure to list p
rofession by what we create as follows.
CREATE PROCEDURE [dbo]. [sp_tbProfesionListar] AS BEGIN SET NOCOUNT ON; select *
from order by NombreProfesion tb_profesion END class code is: using System; usi
ng System.Collections.Generic; using System.Linq; using System.Text; using Syste
m.Data; using System.Data.SqlClient; namespace sysAgenda (public class DataTable
(public profession ListarProfesion () (Connection cnn = new Connection (); SqlC
onnection cn = new SqlConnection (cnn.LeerConexion ()) cmd = new SqlCommand SqlC
ommand ("sp_tbProfesionListar", cn) cmd.CommandType = CommandType.StoredProcedur
e; try (SqlDataAdapter da = new SqlDataAdapter (cmd); DataTable tb = new DataTab
le () da.Fill (tb) return (tb);) catch (Exception ex) (throw new Exception (ex.M
essage);) finally (cn.Dispose (); cmd.Dispose ();))))
http://systemtak.blogspot.com
[24]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Class: contacto.cs
using System; using System.Collections.Generic; using System.Linq; using System.
Text; using System.Data; using System.Data.SqlClient; namespace sysAgenda (publi
c class Contact (/ / Method to add Contact AgregarContacto public void (string x
NombreContacto, xDireccionContacto string, string xTelefonoContacto, xCelularCon
tacto string, string xEmailContacto, DateTime xFechaRegistro, xCodigoProfesion i
nt, int xCodigoPais) (Connection cnn = new Connection (); SqlConnection cn = new
SqlConnection (cnn.LeerConexion ()); SqlCommand cmd = new SqlCommand (sp_tbCont
actoInsertar ", cn) cmd.CommandType = CommandType.StoredProcedure; cmd.Parameter
s.AddWithValue (" @ ContactName "xNombreContacto); cmd.Parameters.AddWithValue (
" @ DireccionContacto "xDireccionContacto); cmd.Parameters.AddWithValue ( "@ Tel
efonoContacto" xTelefonoContacto); cmd.Parameters.AddWithValue ("@ CelularContac
to" xCelularContacto); cmd.Parameters.AddWithValue ("@ EmailContacto" xEmailCont
acto); cmd.Parameters.AddWithValue ("@ FechaRegistro" xFechaRegistro) cmd.Parame
ters.AddWithValue ("@ CodigoProfesion" xCodigoProfesion); cmd.Parameters.AddWith
Value ("@ CodigoPais" xCodigoPais); try (cn.Open () cmd.ExecuteNonQuery ();) cat
ch (Exception ex) (throw new Exception (ex.Message);) finally (cn.Dispose (); cm
d.Dispose ();))
/ / Method public void edit contact ModificarContacto (xCodigoContacto int, stri
ng xNombreContacto, xDireccionContacto string, xTelefonoContacto string, xCelula
rContacto string, xEmailContacto string, DateTime xFechaRegistro, xCodigoProfesi
on int, int xCodigoPais) (Connection cnn = new Connection (); SqlConnection cn =
new SqlConnection (cnn.LeerConexion ()); SqlCommand cmd = new SqlCommand ("sp_t
bContactoModificar", cn) cmd.CommandType = CommandType.StoredProcedure; cmd.Para
meters.AddWithValue ("@ CodigoContacto" xCodigoContacto); cmd.Parameters.AddWith
Value ( "@ ContactName" xNombreContacto); cmd.Parameters.AddWithValue ("@ Direcc
ionContacto" xDireccionContacto); http://systemtak.blogspot.com [25] Email: atac
za@gmail.com
C Sharp Programming Workshop step 2009
cmd.Parameters.AddWithValue ("@ TelefonoContacto" xTelefonoContacto); cmd.Parame
ters.AddWithValue ("@ CelularContacto" xCelularContacto); cmd.Parameters.AddWith
Value ("@ EmailContacto" xEmailContacto); cmd.Parameters.AddWithValue ("@ FechaR
egistro "xFechaRegistro); cmd.Parameters.AddWithValue (" @ CodigoProfesion "xCod
igoProfesion); cmd.Parameters.AddWithValue (" @ CodigoPais "xCodigoPais); try (c
n.Open () cmd.ExecuteNonQuery ();) catch (Exception ex) (throw new Exception (ex
.Message);) finally (cn.Dispose (); cmd.Dispose ();)) / / Method to remove conta
ct EliminarContacto public void (int xCodigoContacto) (cnn = new connection conn
ection (); SqlConnection cn = new SqlConnection (cnn.LeerConexion ()); SqlComman
d cmd = new SqlCommand ("sp_tbContactoEliminar", cn) cmd.CommandType = CommandTy
pe.StoredProcedure; cmd.Parameters.AddWithValue ("@ CodigoContacto" xCodigoConta
cto) ; try (cn.Open () cmd.ExecuteNonQuery ();) catch (Exception ex) (throw new
Exception (ex.Message);) finally (cn.Dispose (); cmd.Dispose ();)) public DataTa
ble ListarContacto () (Connection cnn = new Connection (); SqlConnection cn = ne
w SqlConnection (cnn.LeerConexion ()); SqlCommand cmd = new SqlCommand ("sp_tbCo
ntactoListar", cn) cmd.CommandType = CommandType.StoredProcedure; try (SqlDataAd
apter da = new SqlDataAdapter (cmd); DataTable tb = new DataTable () da.Fill (tb
); http://systemtak.blogspot.com
[26]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
return (tb);) catch (Exception ex) (throw new Exception (ex.Message);) finally (
cn.Dispose (); cmd.Dispose ();))))
The graphical interface will be as follows:
http://systemtak.blogspot.com
[27]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Development Code for the Form Controls: Form Variables scope
public partial class frmContacto: FORM (/ / Variable for Contact ID string ID; /
/ variable that would indicate / / if you click New or Edit private int temp =
0; / / to get the current date in a DateTime variable = DateTime fechaActual . N
ow;
Form Load Event ...
private void frmContacto_Load (object sender, EventArgs e) (/ / Management / Con
trols / For your better understanding we will make detailed txtNombres.ReadOnly
= true; txtDireccion.ReadOnly = true; txtTelefono.ReadOnly = true; txtCelular.Re
adOnly = true ; txtEmail.ReadOnly = true; cboProfesion.Enabled = false; cboPais.
Enabled = false, / / Buttons btnNuevo.Enabled = true; btnGrabar.Enabled = false;
btnModificar.Enabled = false; btnCancelar.Enabled = false; btnEliminar.Enabled
= false; btnListar.Enabled = true; btnSalir.Enabled = true, / / Grid dtgDetalle.
Enabled = true, / / Display the contents of MostrarGrid Grid (); MostrarPais ();
MostrarProfesion ();)
Procedures in the form
private void MostrarGrid () (contact = new contact person (); dtgDetalle.DataSou
rce = persona.ListarContacto ();) private void MostrarPais () (miPais country =
new Country (); cboPais.DataSource = miPais.ListarPais (); cboPais . DisplayMemb
er = "NombrePais" cboPais.ValueMember = "CodigoPais";) http://systemtak.blogspot
.com
[28]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
private void MostrarProfesion () (new profession profession miProfesion = (); cb
oProfesion.DataSource = miProfesion.ListarProfesion (); cboProfesion.DisplayMemb
er = "NombreProfesion" cboProfesion.ValueMember = "CodigoProfesion";)
NEW Button Click event
private void btnNuevo_Click (object sender, EventArgs e) (temp = 0; / / Values i
n White txtNombres.Text = ""; txtDireccion.Text = ""; txtTelefono.Text = ""; txt
Celular.Text = ""; txtEmail. Text = "" / / Controls txtNombres.ReadOnly = false;
txtDireccion.ReadOnly = false; txtTelefono.ReadOnly = false; txtCelular.ReadOnl
y = false; txtEmail.ReadOnly = false; cboProfesion.Enabled = true; cboPais.Enabl
ed = true; / / Buttons btnNuevo.Enabled = false; btnGrabar.Enabled = true; btnMo
dificar.Enabled = false; btnCancelar.Enabled = true; btnEliminar.Enabled = false
; btnListar.Enabled = false; btnSalir.Enabled = false, / / Grid dtgDetalle. Enab
led = false; / / Focus txtNombres.Focus ();)
REC button click event
private void btnGrabar_Click (object sender, EventArgs e) (if (txtNombres.Text.T
rim (). Length> 0) (Contact contact = new Person (); if (temp == 0) (Persona.Agr
egarContacto (txtNombres.Text, txtDireccion.Text, txtTelefono.Text, txtCelul ar.
Text, txtEmail.Text, fechaActual, Convert.ToInt32 (cboProfesion.SelectedValue.To
Stri ng ()), Convert.ToInt32 (cboPais.SelectedValue.ToString ()));) else ( Perso
na.ModificarContacto (Convert.ToInt32 (ID), txtNombres.Text, txtDireccion.Text,
txtTelefono.Text, txtCelular.Text, txtEmail.Text, fechaActual, http://systemtak.
blogspot.com
[29]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Convert.ToInt32 (cboProfesion.SelectedValue.ToString ()), Convert.ToInt32 (cboPa
is.SelectedValue.ToString ()));) / / layer controls txtNombres.ReadOnly = true;
txtDireccion.ReadOnly = true; txtTelefono.ReadOnly = true; txtCelular.ReadOnly =
true; txtEmail.ReadOnly = true; cboProfesion.Enabled = false; cboPais.Enabled =
false, / / Buttons btnNuevo.Enabled = true; btnGrabar.Enabled = false; btnModif
icar.Enabled = false; btnCancelar.Enabled = false; btnEliminar.Enabled = false;
btnListar.Enabled = true; btnSalir.Enabled = true, / / Grid dtgDetalle.Enabled =
true; dtgDetalle.Focus (); MostrarGrid ();))
MODIFY button click event
private void btnModificar_Click (object sender, EventArgs e) (if ((dtgDetalle.Ro
ws.Count> 0) & & (dtgDetalle.CurrentRow.Cells [0]. Value! = null)) (temp = a; ID
= dtgDetalle.CurrentRow. Cells [0]. Value.ToString (), / / layer controls txtNo
mbres.ReadOnly = false; txtDireccion.ReadOnly = false; txtTelefono.ReadOnly = fa
lse; txtCelular.ReadOnly = false; txtEmail.ReadOnly = false; cboProfesion.Enable
d = true; cboPais.Enabled = true, / / Buttons btnNuevo.Enabled = false; btnGraba
r.Enabled = true; btnModificar.Enabled = false; btnCancelar.Enabled = true; btnE
liminar.Enabled = false; btnListar.Enabled = false; btnSalir. Enabled = false; /
/ Grid dtgDetalle.Enabled = false;))
http://systemtak.blogspot.com
[30]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Click the Cancel button event
private void btnCancelar_Click (object sender, EventArgs e) (txtNombres.ReadOnly
= true; txtDireccion.ReadOnly = true; txtTelefono.ReadOnly = true; txtCelular.R
eadOnly = true; txtEmail.ReadOnly = true; cboProfesion.Enabled = false; cboPais.
Enabled = false, / / Buttons btnNuevo.Enabled = true; btnGrabar.Enabled = false;
btnModificar.Enabled = false; btnCancel . Enabled = false; btnEliminar.Enabled
= false; btnListar.Enabled = true; btnSalir.Enabled = true, / / Grid dtgDetalle.
Enabled = true; dtgDetalle.Focus ();)
EXIT button click event
private void btnSalir_Click (object sender, EventArgs e) (this.Close ();)
DELETE button click event
private void btnEliminar_Click (object sender, EventArgs e) (if ((dtgDetalle.Row
s.Count> 0) & & (dtgDetalle.CurrentRow.Cells [0]. Value! = null)) (DialogResult
result = MessageBox.Show ("This Insurance you want to Delete? "," Delete "Messag
eBoxButtons.YesNo, MessageBoxIcon.Question) if (result == DialogResult.Yes) (ID
= dtgDetalle.CurrentRow.Cells [0]. Value.ToString (); contact person = new Conta
ct (); persona.EliminarContacto (Convert.ToInt32 (ID)); MostrarGrid ();)) else (
MessageBox.Show ("No data was selected.", "Delete", MessageBoxButtons.OK, Messag
eBoxIcon.Warning);) )
http://systemtak.blogspot.com
[31]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Enter Cell Event of DataGrid View
private void dtgDetalle_CellEnter (object sender, DataGridViewCellEventArgs e) (
txtCodigo.Text = dtgDetalle.CurrentRow.Cells [0]. Value.ToString (); txtNombres.
Text = dtgDetalle.CurrentRow.Cells [1]. Value.ToString (); txtDireccion . Text =
dtgDetalle.CurrentRow.Cells [2]. Value.ToString (); txtTelefono.Text = dtgDetal
le.CurrentRow.Cells [3]. Value.ToString (); txtCelular.Text = dtgDetalle.Current
Row.Cells [4]. Value.ToString (); txtEmail.Text = dtgDetalle.CurrentRow.Cells [5
]. Value.ToString (); cboProfesion.Text = dtgDetalle.CurrentRow.Cells [8]. Value
.ToString (); cboPais.Text = dtgDetalle. CurrentRow.Cells [7]. Value.ToString ()
; / / You can Edit or Delete btnModificar.Enabled = true; btnEliminar.Enabled =
true;)
Reports Development of a system that emits virtually no report would not be doin
g full life cycle for that reason we will initiate a simple report for education
al purposes.
Add a new form to our project
Name: frmListaContactos
http://systemtak.blogspot.com
[32]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Drag the CrystalReportViewer control to the Form
Click the link to Wizard Data Source.
http://systemtak.blogspot.com
[33]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Click Create a New ...
Create the file with the name: rptListaContactos.rpt
Click Ok
http://systemtak.blogspot.com
[34]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
We will use the Wizard:
Select the Stored Procedure list contacts us.
http://systemtak.blogspot.com
[35]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
http://systemtak.blogspot.com
[36]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
After the wizard Click Finish
http://systemtak.blogspot.com
[37]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
The report is designed as a next window
Code in the form's Load event: frmListaContactos
using using using using using using using using System; System.Collections.Gener
ic; System.ComponentModel, System.Data, System.Drawing; System.Linq; System.Text
; System.Windows.Forms;
namespace (public partial class sysAgenda frmListaContactos: Form (public frmLis
taContactos () (InitializeComponent (); http://systemtak.blogspot.com [38]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
) Private void frmListaContactos_Load (object sender, EventArgs e) (contact = ne
w contact person (); rptListaContactos rptListaContactos rpt = new (); rpt.SetDa
taSource (persona.ListarContacto ()); this.crystalReportViewer1.ReportSource = r
pt; this.crystalReportViewer1 . DisplayGroupTree = false;)))
Again in our form:
List button click event
private void btnListar_Click (object sender, EventArgs e) (frm = new frmListaCon
tactos frmListaContactos (); frm.Show ();)
http://systemtak.blogspot.com
[39]
Email: atacza@gmail.com
C Sharp Programming Workshop step 2009
Functionality Test
Finally, the system will work. I appreciate having followed me up the last part
also hope that you are satisfied.
http://systemtak.blogspot.com
[40]
Email: atacza@gmail.com

También podría gustarte