summaryrefslogtreecommitdiff
path: root/importexport.go
diff options
context:
space:
mode:
Diffstat (limited to 'importexport.go')
-rw-r--r--importexport.go132
1 files changed, 126 insertions, 6 deletions
diff --git a/importexport.go b/importexport.go
index 471a022..e1af448 100644
--- a/importexport.go
+++ b/importexport.go
@@ -2,9 +2,13 @@ package main
import (
"os"
- "github.com/atotto/encoding/csv"
- //"bufio"
- //"encoding/csv"
+ //"github.com/atotto/encoding/csv"
+ //"io"
+ _ "fmt"
+ "time"
+ "bufio"
+ "strconv"
+ "encoding/csv"
)
func ExportTasks(in []Task,filename string) {
@@ -15,7 +19,9 @@ func ExportTasks(in []Task,filename string) {
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
- w.WriteStruct(i)
+ 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)
}
}
@@ -27,7 +33,10 @@ func ExportProjects(in []Project,filename string) {
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
- w.WriteStruct(i)
+ 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)
}
}
@@ -39,6 +48,117 @@ func ExportCustomers(in []Customer,filename string) {
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
- w.WriteStruct(i)
+ 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
+}