-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
252 lines (227 loc) · 8.58 KB
/
Form1.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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;
using System.Runtime.InteropServices;
using GYMNegocio;
using System.Data.SqlClient;
namespace xtremgym
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
frmRegistroDiario frmD = new frmRegistroDiario();
//variables para mover form principal
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(System.IntPtr hwnd, int wmsg, int wparm, int lparam);
//Icono para cerrar aplicacion
private void iconClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
//icono de maximizar
int lx, ly;
private void iconMaximizar_Click(object sender, EventArgs e)
{
//this.WindowState = FormWindowState.Maximized;
lx = this.Location.X;
ly = this.Location.Y;
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.Location = Screen.PrimaryScreen.WorkingArea.Location;
iconRestaurar.Visible = true;
iconMaximizar.Visible = false;
}
//icono de restaurar
private void iconRestaurar_Click(object sender, EventArgs e)
{
//this.WindowState = FormWindowState.Normal;
this.Size = new Size(900, 600);
this.Location = new Point(lx, ly);
iconMaximizar.Visible = true;
iconRestaurar.Visible = false;
}
//icono de minimizar
private void iconMinimizar_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
//Metodos para mover ventana
private void barraTitulo_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
}
//metodo para abrir un form hijo en un form padre
private void AbrirFormInPanel(object FormHijo)
{
if (this.panelContainer.Controls.Count > 0)
this.panelContainer.Controls.RemoveAt(0);
Form fh = FormHijo as Form;
fh.TopLevel = false;
fh.Dock = DockStyle.Fill;
this.panelContainer.Controls.Add(fh);
fh.Show();
}
//abre form cliente en form padre
private void btnClientes_Click(object sender, EventArgs e)
{
try
{
FormAbierto();
AbrirFormInPanel(new frmClientes());
}
catch(Exception ex)
{
MessageBox.Show("Error: "+ex.ToString(),"Error inesperado", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
//abre form membresia en form padre
private void btnMembresia_Click(object sender, EventArgs e)
{
try
{
FormAbierto();
AbrirFormInPanel(new frmMembresia());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//abre form reporte en form padre
private void btnReporte_Click(object sender, EventArgs e)
{
try
{
FormAbierto();
AbrirFormInPanel(new frmReportes());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//abre form usuario en form padre
private void btnUsuario_Click(object sender, EventArgs e)
{
try
{
FormAbierto();
AbrirFormInPanel(new frmUsuarios());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//abre form mantenimiento en form padre
private void button1_Click(object sender, EventArgs e)
{
try
{
FormAbierto();
AbrirFormInPanel(new frmMantenimientoDB());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
// Program.NomUse = Convert.ToString(Logear["UserName"]);
lbEsclavo.Text = Program.NomUse;
AbrirFormInPanel(new frmRegistroDiario());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnInicio_Click(object sender, EventArgs e)
{
try
{
FormAbierto();
AbrirFormInPanel(new frmRegistroDiario());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// muestra fecha y hora de la maquina
private void HoraFEcha_Tick(object sender, EventArgs e)
{
lavelTime.Text =DateTime.Now.ToString("HH:mm:ss");
lavelDate.Text =DateTime.Now.ToShortDateString();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
CNCaja Obcaja = new CNCaja();
Obcaja.DineroInicial = Program.DineroInicial;
Obcaja.DineroFinal = Program.DineroSuma + Program.DineroInicial;
Obcaja.FechaInicial = Program.FechaInicio;
Obcaja.IDUsuario = Program.IDUsuario;
Obcaja.CierreCaja();
MessageBox.Show(string.Format("Dinero ganado {0} -- Dinero Total {1} ", Program.DineroSuma, Program.DineroSuma + Program.DineroInicial));
}
// funcion para mover el form principal
protected override void WndProc(ref Message msj)
{
const int CoordenandaWFP = 0x84;
const int DesIzquierda = 16;
const int DesDerecha = 17;
if (msj.Msg == CoordenandaWFP)
{
int x = (int)(msj.LParam.ToInt64() & 0xFFFF);
int y = (int)((msj.LParam.ToInt64() & 0xFFFF0000) >> 16);
Point coordenadaArea = PointToClient(new Point(x, y));
Size TamañoAreaForm = ClientSize;
if (coordenadaArea.X >= TamañoAreaForm.Width -16 && coordenadaArea.Y >= TamañoAreaForm.Height-16 && TamañoAreaForm.Height >= 16)
{
msj.Result = (IntPtr)(IsMirrored ? DesIzquierda : DesDerecha);
return;
}
}
base.WndProc(ref msj);
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
frmNusuarios frmn = new frmNusuarios();
frmn.Show();
}
//metodo para cerrar form abierto
private void FormAbierto()
{
foreach (Form frm in Application.OpenForms)
{
if ((frm.GetType() == typeof(frmRegistroDiario))||
(frm.GetType() == typeof(frmClientes))||
(frm.GetType() == typeof(frmMembresia))||
(frm.GetType() == typeof(frmReportes))||
(frm.GetType() == typeof(frmUsuarios))||
(frm.GetType() == typeof(frmMantenimientoDB)))
{
frm.Close();
break;
}
}
}
}
}