Esempio n. 1
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            folder = new ClassFolder();
            string[]      files      = Directory.GetFiles(folder.getEntry());
            XmlSerializer serializer = new XmlSerializer(typeof(Entry));

            Stream stream;

            foreach (var f in files)
            {
                stream = File.Open(f, FileMode.Open);

                Entry get = (Entry)serializer.Deserialize(stream);

                if (get.vote > algovote)
                {
                    algovote  = get.vote;
                    algoentry = get.entry;
                }
                stream.Close();
            }
            frmSummarize sum = new frmSummarize(algoentry);

            sum.Txtwinner.Text = algoentry;
            sum.TxtVotes.Text  = algovote.ToString();
            sum.Show();
        }
Esempio n. 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            folder = new ClassFolder();
            XmlSerializer serializer = new XmlSerializer(typeof(UserConcrete));

            if (File.Exists(folder.getUser() + txtUser.Text + ".xml") || File.Exists(folder.getAdmin() + txtUser.Text + ".xml"))
            {
                Stream stream;
                if (txtUser.Text == "glenn")
                {
                    stream = File.Open(folder.getAdmin() + txtUser.Text + ".xml", FileMode.Open);
                }
                else
                {
                    stream = File.Open(folder.getUser() + txtUser.Text + ".xml", FileMode.Open);
                }

                UserConcrete user = (UserConcrete)serializer.Deserialize(stream);
                if (user.password == txtPass.Text)
                {
                    if (user.type == "Voter")
                    {
                        if (ok == true)
                        {
                            stream.Close();
                            frmSummarize sum = new frmSummarize(entryname);
                            sum.LblNameContest.Text = namecontest;
                            sum.Txtwinner.Text      = entryname;
                            sum.TxtVotes.Text       = votes.ToString();
                            sum.Show();
                            this.Hide();
                        }
                        else
                        {
                            stream.Close();
                            MessageBox.Show("Welcome " + user.Display());
                            frmVoter voteform = new frmVoter(txtUser.Text);
                            voteform.TxtName.Text    = user.firstname + " " + user.lastname;
                            voteform.TxtUser.Text    = user.username;
                            voteform.TxtUser.Enabled = false;
                            voteform.TxtName.Enabled = false;
                            voteform.Show();
                            this.Hide();
                        }
                    }
                    else if (user.type == "Entry")
                    {
                        if (ok == true)
                        {
                            stream.Close();
                            frmSummarize sum = new frmSummarize(entryname);
                            sum.LblNameContest.Text = namecontest;
                            sum.Txtwinner.Text      = entryname;
                            sum.TxtVotes.Text       = votes.ToString();
                            sum.Show();
                            this.Hide();
                        }
                        else
                        {
                            frmOrganizer organform;
                            string[]     files = Directory.GetFiles(folder.getContest());
                            foreach (var f in files)
                            {
                                if (File.Exists(f))
                                {
                                    XmlSerializer serializer1   = new XmlSerializer(typeof(Contest));
                                    Stream        conteststream = File.Open(f, FileMode.Open);
                                    Contest       contest       = (Contest)serializer1.Deserialize(conteststream);


                                    expires  = contest.specificDate.ToLongDateString() + contest.specificDate.ToLongTimeString();
                                    contest1 = contest.contest;
                                    conteststream.Close();
                                }
                                else
                                {
                                    MessageBox.Show("No Contest");
                                }
                            }
                            MessageBox.Show("Welcome " + user.Display());
                            getname   = user.username;
                            type      = user.type;
                            organform = new frmOrganizer(contest1, getname, type);

                            organform.LblContestName.Text = contest1;
                            organform.BtnSetting.Enabled  = false;
                            organform.BtnVoters.Enabled   = false;
                            organform.BtnUsers.Enabled    = false;

                            organform.LblDate.Text = expires;
                            organform.Show();
                        }
                    }
                    else
                    {
                        if (ok == true)
                        {
                            stream.Close();
                            frmSummarize sum = new frmSummarize(entryname);
                            sum.LblNameContest.Text = namecontest;
                            sum.Txtwinner.Text      = entryname;
                            sum.TxtVotes.Text       = votes.ToString();
                            sum.Show();
                            this.Hide();
                        }
                        else
                        {
                            frmOrganizer organform;


                            string[] files = Directory.GetFiles(folder.getContest());

                            foreach (var f in files)
                            {
                                XmlSerializer serializer1   = new XmlSerializer(typeof(Contest));
                                Stream        conteststream = File.Open(f, FileMode.Open);
                                Contest       contest       = (Contest)serializer1.Deserialize(conteststream);

                                expires  = contest.specificDate.ToLongDateString() + contest.specificDate.ToLongTimeString();
                                contest1 = contest.contest;
                                conteststream.Close();
                                fa = true;
                            }
                            if (!checkfile(fa))
                            {
                                frmContest contest = new frmContest();
                                contest.Show();
                                this.Hide();
                            }
                            else
                            {
                                MessageBox.Show("Welcome " + user.Display());
                                organform = new frmOrganizer(contest1, getname, type);
                                organform.LblContestName.Text = contest1;
                                organform.BtnSetting.Enabled  = true;
                                organform.BtnVoters.Enabled   = true;
                                organform.BtnUsers.Enabled    = true;
                                organform.LblDate.Text        = expires;
                                organform.Show();
                                this.Hide();
                            }
                        }
                    }
                }
                stream.Close();
            }
            else
            {
                MessageBox.Show("Invalid Username or Password");
            }
        }