-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminReportes.aspx.cs
138 lines (120 loc) · 4.74 KB
/
AdminReportes.aspx.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.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
using System.Globalization;
namespace BackRSS
{
public partial class AdminReportes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnSubirReporte.Attributes.Add("onclick", "document.getElementById('" + FileUpload1.ClientID + "').click(); return false");
if (!IsPostBack)
{
if (Session["nombreCuenta"] == null)
{
Response.Redirect("Error404.html");
}
else if (Session["rol"].ToString() == "Usuario")
{
Response.Redirect("Error404.html");
}
else
{
if (Session["nombreUsuario"] != null)
{
Label1.Text = Session["nombreUsuario"].ToString();
}
if (Session["rol"] != null)
{
Label2.Text = Session["rol"].ToString();
}
llenarCombo();
}
}
}
protected void llenarGrid() {
string nombreProveedor = cmbProveedores.SelectedValue.ToString();
string folderPath = Server.MapPath("~/Back/Reportes/" + nombreProveedor + "/");
if (!Directory.Exists(folderPath)) {
dgvAdmReportes.DataSource = null;
dgvAdmReportes.DataBind();
}
else {
string[] filePaths = Directory.GetFiles(Server.MapPath("~/Back/Reportes/" + nombreProveedor + "/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
dgvAdmReportes.DataSource = files;
dgvAdmReportes.DataBind();
}
}
protected void DownloadFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
llenarGrid();
}
protected void DeleteFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
File.Delete(filePath);
llenarGrid();
}
private void llenarCombo()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conexion"].ConnectionString);
SqlCommand cmd = new SqlCommand("select DISTINCT nombreProveedor from PROVEEDORES", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
cmbProveedores.DataSource = ds;
cmbProveedores.DataTextField = "nombreProveedor";
cmbProveedores.DataValueField = "nombreProveedor";
cmbProveedores.DataBind();
}
protected void btnBuscarProveedor_Click(object sender, EventArgs e)
{
llenarGrid();
}
protected void btnCargarReporte_Click(object sender, EventArgs e)
{
UploadFile();
}
public void UploadFile()
{
string nombreProveedor = cmbProveedores.SelectedValue.ToString();
string folderPath = Server.MapPath("~/Back/Reportes/" + nombreProveedor + "/");
//Check whether Directory (Folder) exists.
if (!Directory.Exists(folderPath))
{
//If Directory (Folder) does not exists. Create it.
Directory.CreateDirectory(folderPath);
}
//Save the File to the Directory (Folder).
FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
FileUpload1.Dispose();
FileUpload1.FileContent.Close();
llenarGrid();
}
protected void cerrarSesion_Click(Object sender, EventArgs e)
{
Session["nombreCuenta"] = null;
Session["rol"] = null;
Session["nombreUsuario"] = null;
Response.Redirect("Login.aspx");
}
}
}