コード例 #1
0
ファイル: MainForm.cs プロジェクト: rezaramadhan/Pemira2017
        private void STOP_VOTE(ListView listNIM, Button bGrant, TimerCountdown t, Label lTimer)
        {
            //hapus dari db Queue
            if (bGrant.Name == "buttonGrant1")
            {
                dbQBilik1.delNim(listNIM.Items[0].Text);
            }
            else
            {
                dbQBilik2.delNim(listNIM.Items[0].Text);
            }

            listNIM.Items.RemoveAt(0);

            // Add from listWaiting to bilik
            if (listViewWaiting.Items.Count > 0)
            {
                string s = listViewWaiting.Items[0].Text;
                listNIM.Items.Add(s);
                //DITAMBAHIN ALSON
                dbWaitingList.delNim(listViewWaiting.Items[0].Text);
                listViewWaiting.Items.RemoveAt(0);
            }
            //sleep selama sekian detik
            Thread.Sleep(3000);
            bGrant.Enabled = true;
            t.Stop();
            t.reset();

            lTimer.Text = TimerCountdown.MAXCOUNT.ToString();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: rezaramadhan/Pemira2017
        /*
         *  Initialize all data members in this class
         */
        private void InitializeVariable()
        {
            isTwice = new bool[MAXWAITING];
            isS1    = new bool[MAXWAITING];
            time    = new TimerCountdown[MAXWAITING];
            sock    = new ServerSocket[MAXWAITING];

            for (int i = 0; i < MAXWAITING; i++)
            {
                tag[i]        = (i + 1).ToString();
                time[i]       = new TimerCountdown(tag[i]);
                time[i].Tick += new EventHandler(time_Tick);
                sock[i]       = new ServerSocket(host[i], port);
            }
            dbImport.setImportStatusLabel(importStatusLabel);
            dbImport.updateImportStatusLabel();
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: rezaramadhan/Pemira2017
        /*
         * Event handler for when a timer ticks
         */
        private void time_Tick(object sender, EventArgs e)
        {
            TimerCountdown t = sender as TimerCountdown;
            Label          lTimer;
            Button         bGrant;
            ListView       listNIM;
            int            idx;
            string         data;

            if (t.Tag.ToString() == tag[0])
            {
                lTimer  = labelTimerBilik1;
                idx     = 0;
                bGrant  = buttonGrant1;
                listNIM = listViewBilik1;
            }
            else
            {
                idx     = 1;
                bGrant  = buttonGrant1;
                lTimer  = labelTimerBilik2;
                listNIM = listViewBilik2;
            }


            t.counter--;
            int count = t.counter;

            lTimer.Text = count.ToString();

            // Check if should choose K3M


            // Timer's empty, stop
            if (count <= 0)
            {
                try {
                    sock[idx].send("({timeout})");
                    //add to DB
                } catch (IOException excpt) {
                    MessageBox.Show("Client disconnected!");
                }

                if (isTwice[idx])
                {
                    t.counter = TimerCountdown.MAXCOUNT;

                    count        = t.counter;
                    isTwice[idx] = false;
                    t.Stop();
                    t.reset();
                    dbDpt.setChoiceMWAWM(listNIM.Items[0].Text, "A");
                }
                else
                {
                    sock[idx].disconnect();
                    //tandain NIM x udah vote di database
                    dbDpt.setSudahPilih(listNIM.Items[0].Text, true);
                    if (isS1[idx])
                    {
                        dbDpt.setChoiceKM(listNIM.Items[0].Text, "A");
                    }
                    else
                    {
                        dbDpt.setChoiceMWAWM(listNIM.Items[0].Text, "A");
                    }
                    STOP_VOTE(listNIM, bGrant, t, lTimer);
                }
            }
            else
            {
                try {
                    data = count.ToString();
                    sock[idx].send(data);
                } catch (IOException excp) {
                    t.Stop();
                    t.reset();
                    bGrant.Enabled = true;
                    MessageBox.Show("Client disconnected!");
                }
            }
        }