سؤال

I have another problem that I can't solve

I have a following code that adds a user (first name, last name and age) into a treeview. It all works well except for one small thing: it works well only when you add an user for the first time. When you hit add and then try to add yet another user it will attempt to add 2 users, then 3, 4 and so on, increasing with each addition. Here's the code that catches the click event:

onClicked (dodajUczBt gui) (dodajUcz gui dbh stores)

and here's the function dodajUcz that handles the click:

dodajUcz gui dbh stores =
    do  entrySetText (nImie gui) ""
        entrySetText (nNazwisko gui) ""
        entrySetText (nWiek gui) ""
        onClicked (cancelAddUczBt gui) (widgetHide (dodajUzDialog gui))
        onClicked (zapiszUczBtn gui) procADD
        windowPresent (dodajUzDialog gui)
    where procADD = do
            ucz <- getUczestnik
            let store = uczestnicy stores
            New.listStoreAppend store ucz
            dlugosc <- New.listStoreGetSize store
            labelSetText (lblLiczbaUcz gui) $ "Liczba uczestników: "++ show dlugosc 
            widgetHide (dodajUzDialog gui)
            addUser ucz dbh
          getUczestnik = do
                                imie <- entryGetText (nImie gui)
                                nazwisko <- entryGetText (nNazwisko gui)
                                wiek <- entryGetText (nWiek gui)
                                let wiek' = read wiek :: Integer
                                return $ Uczestnik 0 imie nazwisko wiek' False

Uczestnik is an algebraic data type and addUser is a function that adds an Uczestnik into database. gui is also an algebraic data type GUI,that holds all the gui elements created by castToXml

It seems to me that widgetHide is the main problem, because even if you don't do anything (just open the dialog and then close it) it'll try to add 2 users the next time you open it.

Any ideas how to solve this problem? Any help would be greatly appreciated :)

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top