-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData.cs
142 lines (129 loc) · 4.7 KB
/
Data.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace RoboIME_store
{
public partial class Data : Form
{
public Data()
{
InitializeComponent();
this.Text = "Lojinha RoboIME";
atualizarTblGeral();
atualizarTblNomes();
}
string KeyNomes = "";
private void atualizarTblGeral()
{
string query = "select MbrItem, MbrQte, MbrPreço from CntTbl where MbrName='"+KeyNomes+"'";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new RoboStoreDBDataSet();
sda.Fill(ds);
DataGeral.DataSource = ds.Tables[0];
Con.Close();
}
private void atualizarTblNomes()
{
string query = "select MbrName from CntTbl";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new RoboStoreDBDataSet();
sda.Fill(ds);
DataNomes.DataSource = ds.Tables[0];
Con.Close();
}
SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\enzog\source\repos\RoboIME_store\RoboStoreDB.mdf;Integrated Security=True;Connect Timeout=30");
private void somarConta()
{
Decimal total = 0;
foreach (DataGridViewRow row in DataGeral.Rows)
{
total += Convert.ToDecimal(row.Cells[1].Value) * Convert.ToDecimal(row.Cells[2].Value);
}
totalTxt.Text= "" + total;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void DataNomes_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
Nome.Text = DataNomes.SelectedRows[0].Cells[0].Value.ToString();
if (Nome.Text == "")
{
KeyNomes = "";
}
else
{
KeyNomes = DataNomes.SelectedRows[0].Cells[0].Value.ToString();
atualizarTblGeral();
somarConta();
}
}
private void delBtn_Click(object sender, EventArgs e)
{
if (KeyNomes == "")
{
MessageBox.Show("Selecione o Histório de Compras a ser deletada!");
}
else
{
var result = MessageBox.Show("Você deseja remover todo o histórico de compras de "+KeyNomes+"?", "Form Closing",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
Con.Open();
string query = "Delete from CntTbl where MbrName ='" + KeyNomes + "';";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Histórico Deletado!");
Con.Close();
atualizarTblGeral();
atualizarTblNomes();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
}
private void rtnBtn_Click(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
Compras Comp = new Compras();
Comp.StartPosition = FormStartPosition.CenterScreen;
Comp.Show();
this.Hide();
}
private void label4_Click(object sender, EventArgs e)
{
Membros Mbr = new Membros();
Mbr.StartPosition = FormStartPosition.CenterScreen;
Mbr.Show();
this.Hide();
}
private void Logout_Click(object sender, EventArgs e)
{
Login Obj = new Login();
Obj.StartPosition = FormStartPosition.CenterScreen;
Obj.Show();
this.Hide();
}
private void Data_Load(object sender, EventArgs e)
{
}
}
}