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
|
package main
import (
"os"
//"github.com/atotto/encoding/csv"
//"io"
_ "fmt"
"time"
"bufio"
"strconv"
"encoding/csv"
)
func ExportTasks(in []Task,filename string) {
file ,err := os.Create(filename)
checkErr(err)
defer file.Close()
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
str := []string{Sint(i.Id),Sint(i.Projectid),i.Start.Format(time.RFC3339),i.Stop.Format(time.RFC3339),i.Taskname,i.Comment,Sint(i.Checkout)}
w.Write(str)
//w.WriteStruct(i)
}
}
func ExportProjects(in []Project,filename string) {
file ,err := os.Create(filename)
checkErr(err)
defer file.Close()
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
str := []string{Sint(i.Id),i.Name,i.Comment,i.First.Format(time.RFC3339),i.Last.Format(time.RFC3339),Sint(i.Finished),Sint(i.Customer)}
w.Write(str)
//w.Write([]string{" Fuck","Master","Flash"})
//w.WriteStruct(i)
}
}
func ExportCustomers(in []Customer,filename string) {
file ,err := os.Create(filename)
checkErr(err)
defer file.Close()
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
str := []string{Sint(i.Id),i.Company,i.Name,i.Address,Sflo(i.Satz),i.Lastbill.Format(time.RFC3339)}
w.Write(str)
//w.WriteStruct(i)
}
}
// Import an array of Tasks from a csv of given filename
func ImportTasks(filename string) ([]Task) {
var tsk []Task
//w := NewReader(strings.NewReader())
f, _ := os.Open(filename)
// Create a new reader.
r := csv.NewReader(bufio.NewReader(f))
//err := r.ReadStructAll(&cust)
//checkErr(err)
lines, err := r.ReadAll()
checkErr(err)
for _, line := range lines {
id, err := strconv.Atoi(line[0])
checkErr(err)
pr, err := strconv.Atoi(line[1])
checkErr(err)
sta,err := time.Parse(time.RFC3339,line[2])
checkErr(err)
sto,err := time.Parse(time.RFC3339,line[3])
checkErr(err)
ch, err := strconv.Atoi(line[6])
checkErr(err)
data := Task{
Id: id,
Projectid: pr,
Start: sta,
Stop: sto,
Taskname: line[4],
Comment: line[5],
Checkout: ch,
}
tsk=append(tsk,data)
}
return tsk
}
// Import an array of Customers from a csv of given filename
func ImportCustomers(filename string) ([]Customer) {
var cust []Customer
//w := NewReader(strings.NewReader())
f, _ := os.Open(filename)
// Create a new reader.
r := csv.NewReader(bufio.NewReader(f))
//err := r.ReadStructAll(&cust)
//checkErr(err)
lines, err := r.ReadAll()
checkErr(err)
for _, line := range lines {
id, err := strconv.Atoi(line[0])
checkErr(err)
sat,err := strconv.ParseFloat(line[4],64)
checkErr(err)
tim,err := time.Parse(time.RFC3339,line[5])
checkErr(err)
data := Customer{
Id: id,
Company: line[1],
Name: line[2],
Address: line[3],
Satz: sat,
Lastbill: tim,
}
cust=append(cust,data)
}
return cust
}
// Import an array of Projects from a csv of given filename
func ImportProjects(filename string) (prjs []Project) {
//w := NewReader(strings.NewReader())
f, _ := os.Open(filename)
// Create a new reader.
r := csv.NewReader(bufio.NewReader(f))
//err := r.ReadStructAll(&cust)
//checkErr(err)
lines, err := r.ReadAll()
checkErr(err)
for _, line := range lines {
id, err := strconv.Atoi(line[0])
checkErr(err)
fir,err := time.Parse(time.RFC3339,line[3])
checkErr(err)
las,err := time.Parse(time.RFC3339,line[4])
checkErr(err)
fin,err := strconv.Atoi(line[5])
checkErr(err)
cu,err := strconv.Atoi(line[6])
checkErr(err)
data := Project{
Id: id,
Name: line[1],
Comment: line[2],
First: fir,
Last: las,
Finished: fin,
Customer: cu,
}
prjs=append(prjs,data)
}
return
}
|