-
Notifications
You must be signed in to change notification settings - Fork 0
/
VendaPecas2.aspx.cs
201 lines (179 loc) · 8.44 KB
/
VendaPecas2.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SlnArCond
{
public partial class VendaPecas2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnBuscar_Click(object sender, EventArgs e)
{
string Descricao = txtBuscar.Text;
mPecas P = new mPecas();
List<pPecas> Lc = P.SelItens(Descricao);
gdvPecas.DataSource = Lc;
gdvPecas.DataBind();
}
protected void gdvPecas_SelectedIndexChanged(object sender, EventArgs e)
{
List<pPecas> LP = new List<pPecas>();
pPecas P = new pPecas();
P.Cod_Pecas = Convert.ToInt32(gdvPecas.SelectedRow.Cells[0].Text);
P.Descricao = gdvPecas.SelectedRow.Cells[1].Text;
P.Fabricante = gdvPecas.SelectedRow.Cells[2].Text;
P.Modelo = gdvPecas.SelectedRow.Cells[3].Text;
P.Valor_Saida = Convert.ToDecimal(gdvPecas.SelectedRow.Cells[4].Text);
P.Quantidade = Convert.ToInt32(gdvPecas.SelectedRow.Cells[5].Text);
LP.Add(P);
rptProduto.DataSource = LP;
rptProduto.DataBind();
}
protected void rptProduto_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
pPecas P = (pPecas)e.Item.DataItem;
Label lblCod_Pecas = (Label)e.Item.FindControl("lblCod_Pecas");
lblCod_Pecas.Text = P.Cod_Pecas.ToString();
Label lblDescricao = (Label)e.Item.FindControl("lblDescricao");
lblDescricao.Text = P.Descricao.ToString();
Label lblFabricante = (Label)e.Item.FindControl("lblFabricante");
lblFabricante.Text = P.Fabricante.ToString();
Label lblModelo = (Label)e.Item.FindControl("lblModelo");
lblModelo.Text = P.Modelo.ToString();
Label lblEstoque = (Label)e.Item.FindControl("lblEstoque");
lblEstoque.Text = P.Quantidade.ToString();
Label lblValor_Saida = (Label)e.Item.FindControl("lblValor_Saida");
lblValor_Saida.Text = P.Valor_Saida.ToString("#,##0.00");
}
}
protected void chkMais_CheckedChanged(object sender, EventArgs e)
{
CheckBox Chk = (CheckBox)sender;
RepeaterItem Rpt = (RepeaterItem)Chk.Parent;
TextBox txtQuantidade = (TextBox)Rpt.FindControl("txtQuantidade");
txtQuantidade.Enabled = Chk.Checked;
txtQuantidade.Text = (Chk.Checked ? "1" : "0");
Label lblValor_Saida = (Label)Rpt.FindControl("lblValor_Saida");
Label lblTotal = (Label)Rpt.FindControl("lblTotal");
lblTotal.Text = (Chk.Checked ? lblValor_Saida.Text : "0,00");
AtuTotais();
}
protected void txtQuantidade_TextChanged(object sender, EventArgs e)
{
TextBox txtQuantidade = (TextBox)sender;
RepeaterItem Rpt = (RepeaterItem)txtQuantidade.Parent;
Label lblValor_Saida = (Label)Rpt.FindControl("lblValor_Saida");
Label lblTotal = (Label)Rpt.FindControl("lblTotal");
Label lblEstoque = (Label)Rpt.FindControl("lblEstoque");
lblTotal.Text = (Convert.ToDecimal(txtQuantidade.Text) * Convert.ToDecimal(lblValor_Saida.Text)).ToString("#,##0.00");
AtuTotais();
}
public void AtuTotais()
{
decimal Vol = 0;
decimal Tot = 0;
List<pCarrinho> Lp = new List<pCarrinho>();
for (int i = 0; i < rptProduto.Items.Count; i++)
{
RepeaterItem Rpt = (RepeaterItem)rptProduto.Items[i];
CheckBox Chk = (CheckBox)Rpt.FindControl("ChkMais");
TextBox TxtQuantidade = (TextBox)Rpt.FindControl("TxtQuantidade");
Label lblEstoque = (Label)Rpt.FindControl("lblEstoque");
Label lblTotal = (Label)Rpt.FindControl("lblTotal");
int Q = 0;
int E = 0;
Q = Convert.ToInt32(TxtQuantidade.Text);
E = Convert.ToInt32(lblEstoque.Text);
if (Q > E)
{
Chk.Checked = false;
TxtQuantidade.Text = "0";
//TxtQuantidade.Text = string.Empty;
lblTotal.Text = "0,00";
TxtQuantidade.Enabled = false;
string mensagem = "Estoque Insuficiente!";
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('" + mensagem + "');", true);
}
else
{
}
if (Chk.Checked)
{
pCarrinho P = new pCarrinho();
Vol += Convert.ToDecimal(TxtQuantidade.Text);
//Label lblTotal = (Label)Rpt.FindControl("lblTotal");
Tot += Convert.ToDecimal(lblTotal.Text);
Label lblCod_Pecas = (Label)Rpt.FindControl("lblCod_Pecas");
P.Cod_Pecas = Convert.ToInt32(lblCod_Pecas.Text);
Label lblDescricao = (Label)Rpt.FindControl("lblDescricao");
P.Descricao = lblDescricao.Text.ToString();
P.pQuantidade = Convert.ToInt32(TxtQuantidade.Text);
Label lblValor_Saida = (Label)Rpt.FindControl("lblValor_Saida");
P.Valor_Saida = Convert.ToDecimal(lblValor_Saida.Text);
P.Quantidade = Convert.ToInt32(lblEstoque.Text);
Lp.Add(P);
#region backup
//Label lblValor_Entrada = (Label)Rpt.FindControl("lblValor_Entrada");
//P.Valor_Entrada = Convert.ToDecimal(lblValor_Entrada.Text);
//P.PUnit = Convert.ToDecimal(lblValor.Text);
#endregion
}
}
Session["Carrinho"] = Lp;
//RepeaterItem RptF = (RepeaterItem)rptProduto.Controls[rptProduto.Controls.Count - 1];
//Label lblVolume = (Label)RptF.FindControl("lblVolume");
//lblVolume.Text = Vol.ToString();
((rptProduto.Controls[rptProduto.Controls.Count - 1] as RepeaterItem).FindControl("lblVolume") as Label).Text = "Volume : " + Vol.ToString();
((rptProduto.Controls[rptProduto.Controls.Count - 1] as RepeaterItem).FindControl("lblTotalGeral") as Label).Text = "Total : R$" + Tot.ToString("#,##0.00");
}
protected void rptProduto_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
//case "Cancelar":
// ListarRpt();
// break;
case "Prosseguir":
if (Session["Carrinho"] != null && (Session["Carrinho"] as List<pCarrinho>).Count > 0)
{
Response.Redirect("ResumoVenda.aspx");
}
else
{
}
break;
}
}
public void EditarCarrinho()
{
List<pCarrinho> Lp = Session["Carrinho"] as List<pCarrinho>;
for (int i = 0; i < Lp.Count; i++)
{
for (int a = 0; a < rptProduto.Items.Count; a++)
{
RepeaterItem Rpt = (RepeaterItem)rptProduto.Items[i];
string lblCod_Pecas = (Rpt.FindControl("lblCod_Pecas") as Label).Text;
if (Lp[i].Cod_Pecas.ToString() == lblCod_Pecas)
{
(Rpt.FindControl("ChkMais") as CheckBox).Checked = true;
TextBox txtQuantidade = (TextBox)Rpt.FindControl("txtQuantidade");
txtQuantidade.Enabled = true;
txtQuantidade.Text = Lp[i].pQuantidade.ToString();
(Rpt.FindControl("lblTotal") as Label).Text = Lp[i].Total.ToString();
}
}
}
AtuTotais();
}
private void Msg(string Aviso)
{
Response.Write("<script>alert('" + Aviso + "');</script>");
}
}
}