-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddArticle.aspx.cs
126 lines (110 loc) · 3.73 KB
/
AddArticle.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
using AccessBd;
using Domain;
using Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace SalesSystem
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Security.Validation.IsAdmin(Session["user"]))
{
Response.Redirect("Login.aspx", false);
}
if (!IsPostBack)
{
try
{
ddlCategories.DataSource = Helper.Categories();
ddlCategories.DataValueField = "Id";
ddlCategories.DataTextField = "Description";
ddlCategories.DataBind();
ddlBrands.DataSource = Helper.Brands();
ddlBrands.DataValueField = "Id";
ddlBrands.DataTextField = "Description";
ddlBrands.DataBind();
}
catch (Exception ex)
{
Session.Add("error", ex);
Response.Redirect("error.aspx", false);
}
}
}
protected void btnAddArt_Click(object sender, EventArgs e)
{
Page.Validate();
if (string.IsNullOrEmpty(fileArticle.PostedFile.FileName) && (string.IsNullOrEmpty(txtUrl2.Text)))
{
pImgRequired.Visible = true;
return;
}
else
{
pImgRequired.Visible = false;
}
if (!Page.IsValid)
{
return;
}
ArticleAccess accessArt = new ArticleAccess();
var art = new Article();
try
{
art.Description = txtDescription.Text;
art.Price = decimal.Parse(txtPrice.Text);
art.CodArticle = txtCodArticle.Text;
art.Name = txtName.Text;
art.brand = new Brand();
art.brand.Id = int.Parse(ddlBrands.SelectedValue.ToString());
art.category = new Category();
art.category.Id = int.Parse(ddlCategories.SelectedValue.ToString());
//create de route "automatically"
//mappath = route of pokedexweb
//I get the last id and add 1
Article lastArt;
try
{
lastArt = accessArt.listArticle().Last();
}
catch (Exception ex)
{
throw ex;
}
int idSend = lastArt.Id + 1;
if (!string.IsNullOrEmpty(fileArticle.PostedFile.FileName))
{
string route = Server.MapPath("./Images/Imgs_Art/");
fileArticle.PostedFile.SaveAs(route + "ArtCod_" + idSend + ".jpg");
art.UrlImg = "ArtCod_" + idSend + ".jpg";
}
else if (!string.IsNullOrEmpty(txtUrl2.Text))
{
art.UrlImg = txtUrl2.Text;
}
try
{
accessArt.addArticle(art);
}
catch (Exception ex)
{
Session.Add("error", ex);
Response.Redirect("error.aspx", false);
}
Response.Redirect("Management.aspx?add=" + 1, false);
}
catch (Exception ex)
{
Session.Add("error", ex);
Response.Redirect("error.aspx", false);
}
}
}
}