-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBonusRanges.aspx.cs
175 lines (149 loc) · 5.16 KB
/
BonusRanges.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LuckPrize.Common.Data;
using System.Drawing;
namespace LuckPrize
{
public partial class BonusRanges : System.Web.UI.Page
{
bool odd = true;
UserTO userTO;
BonusRangesOnBuyTO rangeTO = new BonusRangesOnBuyTO();
protected void Page_Load(object sender, EventArgs e)
{
userTO = (UserTO)Session["user"];
if (Session["validated"] == null || (bool)Session["validated"] == false || userTO == null || userTO.access_level != Access_Level.Admin)
{
Response.Redirect("Default.aspx");
}
GenerateGrid();
if (Page.IsPostBack)
{
this.Validate();
}
else
{
Populate();
}
}
/// <summary>
///
/// </summary>
private void GenerateGrid()
{
grid.RowDataBound += new GridViewRowEventHandler(grid_RowDataBound);
grid.Width = new Unit(750, UnitType.Pixel);
grid.DataSource = Common.Data.BonusRangesOnBuy.GetBonusRangesTable();
grid.DataBind();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
//e.Row.Cells[2].Width = 130; // data
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.BackColor = Color.FromArgb(0xd0, 0xd0, 0xd0);
foreach (TableCell cell in e.Row.Cells)
{
cell.ForeColor = Color.Black;
cell.HorizontalAlign = HorizontalAlign.Left;
cell.BorderColor = Color.Black;
}
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
if (odd)
{
e.Row.BackColor = Color.WhiteSmoke;
}
else
{
e.Row.BackColor = Color.White;
}
for (int i = e.Row.Cells.Count - 1; i > 0; i--)
{
e.Row.Cells[i].Text = "<a href='BonusRanges.aspx?range_id=" + e.Row.Cells[0].Text + "' class='msglnk2b'>" + e.Row.Cells[i].Text + "</a>";
e.Row.Cells[i].ForeColor = Color.Black;
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Left;
}
//
TableCell cellCancel = new TableCell();
cellCancel.CssClass = "nomargin";
Button btnCancel = new Button();
btnCancel.CssClass = "nomargin";
btnCancel.Text = " X ";
btnCancel.Font.Size = 6;
btnCancel.Height = 14;
btnCancel.Attributes.Add("id", e.Row.Cells[0].Text);
btnCancel.Click += new EventHandler(btnCancel_Click);
cellCancel.Controls.Add(btnCancel);
cellCancel.Width = 30;
e.Row.Cells.Add(cellCancel);
}
odd = !odd;
}
void btnCancel_Click(object sender, EventArgs e)
{
Common.Data.BonusRangesOnBuy.Delete(int.Parse(((Button)sender).Attributes["id"]));
Response.Redirect("BonusRanges.aspx");
}
void Populate()
{
if (Request["range_id"] == null)
{
btnSubmit.Text = "Inserir";
return;
}
btnSubmit.Text = "Atualizar";
int id = int.Parse(Request["range_id"]);
rangeTO = Common.Data.BonusRangesOnBuy.GetBonusRange(id);
update_id.Value = id.ToString();
credits.Text = rangeTO.credits.ToString();
bonus_percent.Text = rangeTO.bonus_percentage.ToString();
}
void ProcessRegister()
{
try
{
rangeTO.id = 0;
rangeTO.credits = float.Parse(credits.Text);
rangeTO.bonus_percentage = float.Parse(bonus_percent.Text);
if (update_id.Value == "")
{
// inserir
Common.Data.BonusRangesOnBuy.Insert(rangeTO);
}
else
{
// atualizar
rangeTO.id = int.Parse(update_id.Value);
Common.Data.BonusRangesOnBuy.Update(rangeTO);
}
Response.Redirect("BonusRanges.aspx");
}
catch (Exception ex)
{
save_message.Text = "Erro nos dados!!!";
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
ProcessRegister();
}
}
}