From eb0bc4dcfcf9154a0cf481b2eee64783e6a7ef75 Mon Sep 17 00:00:00 2001 From: hysn99 Date: Thu, 4 Apr 2024 18:50:16 +0300 Subject: [PATCH] excel input control --- app/lib/bot/luca.go | 90 +++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/app/lib/bot/luca.go b/app/lib/bot/luca.go index e29424c..d681c88 100644 --- a/app/lib/bot/luca.go +++ b/app/lib/bot/luca.go @@ -315,9 +315,6 @@ func (l *Luca) BordroTableMaping(frame *rod.Page, b *LucaBordro) ([]BordroPageSc //table := frame.MustElements(".i2") var mainText string for t := 0; t < len(table); t++ { - if t == 150 { - fmt.Print("asda") - } inputElement, err := table[t].Element("input") text, err := table[t].Text() fmt.Print(mainText) @@ -327,13 +324,13 @@ func (l *Luca) BordroTableMaping(frame *rod.Page, b *LucaBordro) ([]BordroPageSc if inputElement != nil { if mainText != "" { fmt.Print(t) - inputElement, err := table[t+1].Element("input") - if inputElement == nil { + elem, err := table[t+1].Element("input") + if elem == nil { mainText = "" fmt.Print("Hatalı Text") continue } - id, err := inputElement.Attribute("id") + id, err := elem.Attribute("id") fmt.Print(err) pageScript := BordroPageScript{ @@ -347,37 +344,33 @@ func (l *Luca) BordroTableMaping(frame *rod.Page, b *LucaBordro) ([]BordroPageSc mainText = "" } + } else { + if t <= len(table)-2 { + if text != "" { + aad, err := table[t+1].Element("input") + fmt.Print(err) + if aad != nil { + aa, err := aad.Attribute("type") + if err != nil { + return nil, err + } + if *aa != "hidden" { + id, err := aad.Attribute("id") + pageScript := BordroPageScript{ + Value: text, + Index: *id, + } + scriptIndexArray = append(scriptIndexArray, pageScript) + fmt.Print(aad, err, id, aa) + } + + } + + } + } + } - // Satırın özelliklerini al - - // Satırın textini al - fmt.Print(err) - - // for k, v := range b.Ucretler { - // fmt.Print(v, k) - // //table'da key--> k i bul, - // //takip eden ilk td'deki ilk input'a v'yi yaz - // //table'da k'yi bulmazsan ve v de değer varsa hata dön - // if strings.Contains(text, k) { - // Id := "" - // if id != nil { - // Id = *id - // fmt.Println("ID:", *id) - // } else { - // Id = "" - // } - // pageScript := BordroPageScript{ - // Value: text, - // Index: Id, - // } - - // scriptIndexArray = append(scriptIndexArray, pageScript) - // break - // } - // } - // Sonuçları yazdır ///text boşsa id de boş oluyo - } return scriptIndexArray, nil } @@ -593,12 +586,17 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro, lastItem bool) error { } rsp, err := l.BordroTableMaping(frame3, b) if len(rsp) == 0 { - //hata ver + return errors.New("Bordro Tablosu Çekilemedi") } fmt.Print(rsp) //rsp den dönden değerler ile matchlencek ve yazılcak for k, v := range b.Ucretler { + var elementInsertControl bool = true + tt := v.String() + fmt.Print(tt) + Wait(frame3, 100) for i := 0; i < len(rsp); i++ { + if k == rsp[i].Value { el, err := frame3.Element("#" + rsp[i].Index) @@ -606,10 +604,30 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro, lastItem bool) error { return err } err = el.Input(v.String()) + elementInsertControl = false //el.Eval(`this.dispatchEvent(new KeyboardEvent('keydown', {'key': 'Enter'}))`) break } } + if elementInsertControl { + if tt != "0" { + newBordroPage, err := frame3.Element("body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(4)") + newBordroPage.WaitLoad() + if err != nil { + return err + } + newBordroPage.Click(proto.InputMouseButtonLeft, 1) + err = WaitLoad(frame3) + if err != nil { + return err + } + err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1) + if err != nil { + return err + } + return errors.New(k + " Sütunu Bulunamadı Taslak Hatası, ") + } + } fmt.Print(v, k) }