This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuracion.cs
139 lines (119 loc) · 4.82 KB
/
Configuracion.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
/*
*****************************************************************
* Autor: Ravi Khubchandani
* Fecha de creacion: 2012-09-08
* Ultima modificacion:
* Autor Ultima modificacion:
* Version 1.0
*****************************************************************
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Virtual_Manager
{
public partial class Configuracion : Form
{
/// <summary>
/// Indica si se ha modificado algun campo de configuracion
/// </summary>
private bool _CModificada;
/// <summary>
/// Indica si se ha cambiado la imagen de perfil, hay que actualizarla
/// </summary>
private bool _ImgCambiada;
/// <summary>
/// Constructor vacio
/// </summary>
public Configuracion()
{
InitializeComponent();
// Hay dos indicadores porque si cambia una cosa no hace falta cambiar la otra
_CModificada = false;
_ImgCambiada = false;
}
private void BConfig_Cancelar_Click(object sender, EventArgs e)
{
// Es necesario hacer dispose porque aunque salgamos el archivo se queda como abierto
PBConfig_Perfil.Image.Dispose();
PBConfig_Perfil.Dispose();
this.Close();
}
/// <summary>
/// Al pulsar el boton de Aceptar, para guardar cambios de configuracion
/// </summary>
private void BConfig_Aceptar_Click(object sender, EventArgs e)
{
// Solo hace falta guardar cambios si se ha modificado un dato
if(_CModificada)
{
Globl.Config.Nick = TB_Config_Nick.Text;
Globl.Config.EMail = TB_Config_EMail.Text;
Globl.Config.ReqPass = CBConfig_Recordar.Checked;
FileStream stream = new FileStream(@"Usuarios\" + Globl.Config.Usuario + @"\config.dat", FileMode.Create);
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(Globl.Config.Nick);
writer.Write(Globl.Config.EMail);
writer.Write(Globl.Config.PassMD5);
writer.Write(Globl.Config.ReqPass);
writer.Close();
}
if(_ImgCambiada)
{
File.Delete(@"Perfiles\" + Globl.Config.Usuario + ".png");
File.Copy(OPFConfig_CambiarImg.FileName, @"Perfiles\" + Globl.Config.Usuario + ".png");
}
PBConfig_Perfil.Image.Dispose();
PBConfig_Perfil.Dispose();
this.Close();
}
private void Configuracion_Load(object sender, EventArgs e)
{
TB_Config_Nick.Text = Globl.Config.Nick;
TB_Config_EMail.Text = Globl.Config.EMail;
CBConfig_Recordar.Checked = Globl.Config.ReqPass;
if (Globl.getMD5("") == Globl.Config.PassMD5)
BConfig_CambiarPass.Text = "Proteger mediante contraseña";
// Si no tiene cambiada la imagen de perfil se muestra la de por defecto
if(File.Exists(@"Perfiles\" + Globl.Config.Usuario + ".png"))
PBConfig_Perfil.Load(@"Perfiles\" + Globl.Config.Usuario + ".png");
}
private void BConfig_CambiarImg_Click(object sender, EventArgs e)
{
OPFConfig_CambiarImg = new OpenFileDialog();
OPFConfig_CambiarImg.Filter = "Images (*.BMP;*.JPG;*.JPEG;*.PNG;*.TIFF;*.GIF)|*.BMP;*.JPG;*.JPEG;*.PNG;*.TIFF;*.GIF|All files (*.*)|*.*";
OPFConfig_CambiarImg.Multiselect = false;
OPFConfig_CambiarImg.RestoreDirectory = true;
if (OPFConfig_CambiarImg.ShowDialog() == DialogResult.OK)
{
PBConfig_Perfil.Image.Dispose();
PBConfig_Perfil.Image = new Bitmap(OPFConfig_CambiarImg.FileName);
_ImgCambiada = true;
}
OPFConfig_CambiarImg.Dispose();
}
private void ConfigChanged(object sender, EventArgs e)
{
_CModificada = true;
}
private void BConfig_CambiarPass_Click(object sender, EventArgs e)
{
CambiarPassword CambioPass;
if (Globl.getMD5("") == Globl.Config.PassMD5)
CambioPass = new CambiarPassword(true);
else
CambioPass = new CambiarPassword(false);
CambioPass.ShowDialog();
if (CambioPass.Aceptado)
{
BConfig_CambiarPass.Text = "Cambiar contraseña";
}
}
}
}