This repository was archived by the owner on Nov 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
139 lines (117 loc) · 5.08 KB
/
main.py
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
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
import os.path
import sqlite3 as lite
from datetime import date
from widgets import *
class Main(App):
def build(self):
if not os.path.exists('./dados.db'):
self.conn = lite.connect('./dados.db')
cursor = self.conn.cursor()
cursor.execute('''CREATE TABLE cadastroInicio(
nome varchar(255) NOT NULL,
fazenda varchar(255) NOT NULL
)''')
cursor.execute('''CREATE TABLE equipamento(
desc_item varchar(255) NOT NULL,
valor_item integer NOT NULL,
tempoUso integer NOT NULL,
vidaUtil integer NOT NULL,
valorItemAtual integer NOT NULL
)''')
cursor.execute('''CREATE TABLE despesas(
dia_despesa date NOT NULL,
desc_despesa varchar(255) NOT NULL,
valor_despesa float NOT NULL,
despesa_totalGASTO float NOT NULL
)''')
cursor.execute('''CREATE TABLE venda(
item_vendido varchar(255) NOT NULL,
quantidade_item integer NOT NULL,
preco_item float NOT NULL
) ''')
cursor.execute('''CREATE TABLE propriedade (
endereco varchar(255)NOT NULL ,
tamanhoFaz float NOT NULL,
tamanhoLaminaDagua floatNOT NULL,
qtdTanques integer NOT NULL
)''')
self.conn = lite.connect('./dados.db')
cursor = self.conn.cursor()
cursor.execute("SELECT * FROM cadastroInicio")
dados = cursor.fetchall()
gerenciador = Gerenciador()
if len(dados) > 0:
gerenciador.current = 'home'
else:
gerenciador.current = 'login'
return gerenciador
def printlog(self, message):
with open('./log.txt', 'a') as f:
f.write(message + "\n")
def salvaLogin(self, pnome, pfazenda):
self.printlog(pnome.text)
self.printlog(pfazenda.text)
cursor = self.conn.cursor()
cursor.execute('INSERT INTO cadastroInicio (nome, fazenda) VALUES (?, ?)', (pnome.text, pfazenda.text))
self.conn.commit()
def guardaDados(self, descricaoitem, valoritem, tempoUsoitem, vidaUtilItem):
if not valoritem:
valoritem = 0.0
else:
valoritem = valoritem.replace(",", ".")
valoritem = float(valoritem)
if not vidaUtilItem:
vidaUtilItem = 0.0
else:
vidaUtilItem = float(vidaUtilItem)
if not tempoUsoitem:
tempoUsoitem = 0.0
else:
tempoUsoitem = float(tempoUsoitem)
if not vidaUtilItem:
perdaAnual = 0
else:
perdaAnual = valoritem / vidaUtilItem
valorItemAtual = valoritem - (tempoUsoitem * perdaAnual)
self.valoratualItem = (tempoUsoitem * perdaAnual - valoritem)
cursor = self.conn.cursor()
cursor.execute('''INSERT INTO equipamento (desc_item,valor_item,tempoUso,vidaUtil, valorItemAtual)
VALUES(?, ?, ?, ?, ?)''', (descricaoitem, valoritem, tempoUsoitem, vidaUtilItem, valorItemAtual))
self.conn.commit()
cursor = self.conn.cursor()
cursor.execute("SELECT valorItemAtual FROM equipamento ")
valorlidoteste = cursor.fetchall()
print(valorlidoteste) # CALCULA VALOR ATUAL DOS EQUIPAMENTOS
def despesas(self, dia_despesa, desc_despesa, valor_despesa):
cursor = self.conn.cursor()
cursor.execute('''INSERT INTO despesas (dia_despesa,
desc_despesa,
valor_despesa,
despesa_totalGASTO)
VALUES (?, ?, ?, 0)''',
(dia_despesa.text, desc_despesa.text, valor_despesa.text))
self.conn.commit()
cursor = self.conn.cursor()
data_escolhida = '0'
cursor.execute("SELECT SUM(valor_despesa) FROM despesas WHERE strftime('%m', dia_despesa ) = ? ",
data_escolhida)
DespesaDoMes = cursor.fetchall()
print(DespesaDoMes)
def venda(self, item_vendido, quantidade_item, preco_item):
cursor = self.conn.cursor()
cursor.execute('INSERT INTO venda (item_vendido, quantidade_item, preco_item) VALUES (?, ?, ?)',
(item_vendido.text, quantidade_item.text, preco_item.text))
self.conn.commit()
def propriedade(self, endereco, tamanhoFaz, tamanhoLaminaDagua, qtdTanques):
cursor = self.conn.cursor()
cursor.execute(
'INSERT INTO propriedade (endereco, tamanhoFaz ,tamanhoLaminaDagua ,qtdTanques) VALUES (?, ?, ?, ?)',
(endereco.text, tamanhoFaz.text, tamanhoLaminaDagua.text, qtdTanques.text))
self.conn.commit()
if __name__ == "__main__":
Main().run()