-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuscarTecnico.cs
138 lines (118 loc) · 4.34 KB
/
BuscarTecnico.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SmartPhone7
{
public partial class BuscarTecnico : Form
{
public BuscarTecnico()
{
InitializeComponent();
}
// Cadena de conexión a la base de datos
Conexion conexion1 = new Conexion();
public int IdSeleccionado { get; set; }
public string NombreSeleccionado { get; set; }
private void MostrarTecnico()
{
using (SqlConnection conexion = new SqlConnection(conexion1.cadenaConexion))
{
string consulta = "SELECT * FROM Tecnicos";
DataTable dt = new DataTable();
try
{
conexion.Open();
SqlCommand comando = new SqlCommand(consulta, conexion);
SqlDataAdapter adaptador = new SqlDataAdapter(comando);
adaptador.Fill(dt);
adaptador.Dispose();
conexion.Close();
}
catch (Exception ex)
{
throw new Exception("Error al mostrar los tecnico: " + ex.Message);
}
DataGridViewTecnico.DataSource = dt;
}
}
private void BuscarTecnicos(string busqueda)
{
using (SqlConnection conexion = new SqlConnection(conexion1.cadenaConexion))
{
string consulta = "SELECT * FROM Tecnicos WHERE NombreTecnico LIKE @busqueda OR Cedula LIKE @busqueda OR PersonaContacto LIKE @busqueda OR CorreoElectronico LIKE @busqueda";
DataTable dt = new DataTable();
try
{
conexion.Open();
SqlCommand comando = new SqlCommand(consulta, conexion);
comando.Parameters.AddWithValue("@busqueda", "%" + busqueda + "%");
SqlDataAdapter adaptador = new SqlDataAdapter(comando);
adaptador.Fill(dt);
adaptador.Dispose();
conexion.Close();
}
catch (Exception ex)
{
throw new Exception("Error al buscar los tecnicos: " + ex.Message);
}
DataGridViewTecnico.DataSource = dt;
}
}
private void DataGridViewClientes_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (DataGridViewTecnico.SelectedRows.Count > 0)
{
// Obtiene el ID y el nombre de la celda seleccionada
IdSeleccionado = Convert.ToInt32(DataGridViewTecnico.SelectedRows[0].Cells["Id"].Value);
NombreSeleccionado = DataGridViewTecnico.SelectedRows[0].Cells["NombreTecnico"].Value.ToString();
// Cierra el formulario hijo
this.Close();
}
}
private void txtBuscar_TextChanged(object sender, EventArgs e)
{
BuscarTecnicos(txtBuscar.Text);
if (DataGridViewTecnico.Rows.Count < 1)
{
panelSearch.Visible = true;
}
else
{
panelSearch.Visible = false;
}
}
private void guna2CircleButton1_Click(object sender, EventArgs e)
{
Tecnicos formularioModal = new Tecnicos();
Form formularioDeFondo = UtilidadesFormularios.CrearFormularioDeFondo(Principal.ActiveForm);
UtilidadesFormularios.CentrarFormularioModal(formularioModal, Principal.ActiveForm);
formularioModal.ShowDialog(formularioDeFondo);
formularioModal.Dispose();
formularioDeFondo.Dispose();
formularioModal.Close();
MostrarTecnico();
}
private void EfectoModal_Tick(object sender, EventArgs e)
{
if (Opacity >= 1)
{
EfectoModal.Stop();
}
else
{
Opacity += 0.4;
}
}
private void BuscarTecnico_Load(object sender, EventArgs e)
{
MostrarTecnico();
}
}
}