diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2018-10-30 04:20:25 +0100 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2018-10-30 04:20:25 +0100 |
| commit | 0e7ea506b76660c91fa9f479f7de9c79304ae0dc (patch) | |
| tree | 93ac969c5999eed8a2a7d548f3cdb56da5dc20c7 /importexport.go | |
| parent | af56cfca0aca29efa7c507f75fabc2b090fbd4de (diff) | |
Import/Export ... thistime for real
Diffstat (limited to 'importexport.go')
| -rw-r--r-- | importexport.go | 132 |
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 +} |
