-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormFolder.cs
143 lines (118 loc) · 4.91 KB
/
FormFolder.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
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;
namespace PBioManager
{
public partial class FormFolder : Form
{
private Guid _IdFolder;
public FormFolder()
{
InitializeComponent();
_IdFolder = Guid.Empty;
}
public FormFolder(Guid IdFolder)
{
InitializeComponent();
_IdFolder = IdFolder;
}
private void btnSave_Click(object sender, EventArgs e)
{
Save();
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
DialogResult resp = MessageBox.Show(
"Do you want to delete this folder?",
"Close",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question
);
if (resp.Equals(DialogResult.Yes))
{
WebappDBDataSet.CarpetaRow folder = this.webappDBDataSet.Carpeta.Where(f => f.IdCarpeta.Equals(_IdFolder)).Single();
int childrens = this.webappDBDataSet.Carpeta.Where(f => !f.IsIdCarpetaPadreNull() && f.IdCarpetaPadre.Equals(folder.IdCarpeta)).Count();
int files = this.webappDBDataSet.Archivo.Where(s => s.IdCarpeta.Equals(folder.IdCarpeta)).Count();
int simulations = this.webappDBDataSet.Simulacion.Where(s => s.IdCarpeta.Equals(folder.IdCarpeta)).Count();
//TODO Testear que no falle si intento borrar una carpeta que contenga archivos o alguna simulación
if (childrens > 0 || files > 0)
{
DialogResult alert = MessageBox.Show(
"There are childrens in this folder. Please delete them before delete the folder.",
"Close",
MessageBoxButtons.OK,
MessageBoxIcon.Stop
);
}
else if (simulations > 0)
{
DialogResult alert = MessageBox.Show(
"There are simulations in this folder. Please delete them before delete the folder.",
"Close",
MessageBoxButtons.OK,
MessageBoxIcon.Stop
);
}
else
{
folder.BeginEdit();
folder.Delete();
folder.EndEdit();
this.carpetaTableAdapter.Update(folder);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}
private void FormFolder_Load(object sender, EventArgs e)
{
// TODO: esta línea de código carga datos en la tabla 'webappDBDataSet.Carpeta' Puede moverla o quitarla según sea necesario.
this.carpetaTableAdapter.Fill(this.webappDBDataSet.Carpeta);
if (!_IdFolder.Equals(Guid.Empty))
{
WebappDBDataSet.CarpetaRow folder = this.webappDBDataSet.Carpeta.Where(f => f.IdCarpeta.Equals(_IdFolder)).Single();
txtName.Text = folder.Nombre;
txtUser.Text = folder.Usuario;
if (!folder.IsIdCarpetaPadreNull())
cbxRootFolder.SelectedValue = folder.IdCarpetaPadre;
lblCreationDate.Text = folder.FechaCreac_on.ToString();
btnDelete.Enabled = true;
btnDelete.Visible = true;
}
}
private void Save()
{
if (txtName.Text != "" && txtUser.Text != "")
{
if (_IdFolder.Equals(Guid.Empty))
{
WebappDBDataSetTableAdapters.CarpetaTableAdapter newFolder = new WebappDBDataSetTableAdapters.CarpetaTableAdapter();
_IdFolder = Guid.NewGuid();
newFolder.Insert(
_IdFolder,
txtName.Text,
cbxRootFolder.SelectedValue == null ? (Guid?)null : (Guid)cbxRootFolder.SelectedValue,
txtUser.Text,
DateTime.Now
);
}
else
{
WebappDBDataSet.CarpetaRow folder = this.webappDBDataSet.Carpeta.Where(f => f.IdCarpeta.Equals(_IdFolder)).Single();
folder.Nombre = txtName.Text;
folder.Usuario = txtUser.Text;
if (cbxRootFolder.SelectedValue != null)
folder.IdCarpetaPadre = (Guid)cbxRootFolder.SelectedValue;
this.carpetaTableAdapter.Update(folder);
}
}
}
}
}