Beispiel #1
0
        private void nbtn_Click(object sender, EventArgs e)
        {
            try
            {
                var factory = new FactroryVoter() as ICreateVoters; //factory that creates voters
                voter = factory.createVoter();                      //create default Voter with the factory
                DataRow t = voter.SearchVoter(IDtextBox.Text);      //search for voter datarow in database
                voter = factory.createVoter(t);                     //create Voter with datarow details

                KalpiCodetextBox.Text     = voter.KalpiCode;
                FirstNametextBox.Text     = voter.FName;
                LastNametextBox.Text      = voter.LName;
                UserNametextBox.Text      = voter.username;
                PasswordtextBox.Text      = voter.Passowrd;
                PermissiontextBox.Text    = voter.Permission;
                DOBtextBox.Text           = voter.DOB.ToString();
                AddresstextBox.Text       = voter.Address;
                AreatextBox.Text          = voter.Area;
                CitytextBox.Text          = voter.City;
                TelltextBox.Text          = voter.Tell;
                AccomulateIDtextBox.Text  = voter.AccomId;
                IsBlockedcheckBox.Checked = voter.IsBlocked;
                IsVotedcheckBox.Checked   = voter.IsVoted;
            }
            catch
            {
                MessageBox.Show("The voter not exist in the system");
            }
        }
        /// <summary>
        /// The Elections Manager removes an area manager
        /// </summary>
        /// <returns></returns> The result succeed/failed
        public int removeAreaManager(string id)
        {
            var   factory = new FactroryVoter() as ICreateVoters;
            Voter v       = factory.createVoter();

            v.Id = id;
            return(v.removeAreaManager());
        }
Beispiel #3
0
        /// <summary>
        /// method that adds a voter with the given id to the kalpi of the kalpi manager that calls the method
        /// </summary>
        /// <param name="id">id of voter that is added</param>
        /// <param name="kalpiCode">kalpi code of current kalpi manager</param>
        /// <returns>1 id added successfully, 0 - therwise</returns>
        public int addNewVoterToKalpi(string id, string kalpiCode)
        {
            var   factory = new FactroryVoter() as ICreateVoters;
            Voter v       = factory.createVoter();

            v.Id        = id;
            v.KalpiCode = kalpiCode;
            return(v.addNewVoterToKalpi(kalpiCode));
        }
Beispiel #4
0
        /// <summary>
        /// method that removes a voter with a given id from the kalpi of the kalpi manager that calls the method
        /// </summary>
        /// <param name="id">id of the voter that needs to be removed</param>
        /// <param name="kalpiCode">the current kalpi code of the voter</param>
        /// <returns>1 if remove was successfull, 0- otherwise</returns>
        public int removeVoterKalpi(string id, string kalpiCode)
        {
            var   factory = new FactroryVoter() as ICreateVoters;
            Voter v       = factory.createVoter();

            v.Id        = id;
            v.KalpiCode = kalpiCode;
            return(v.removeVoterFromKalpi());
        }
Beispiel #5
0
        /// <summary>
        /// the method searches for a voter in the data base
        /// </summary>
        /// <param name="id">the id of the wanted voter</param>
        /// <returns>if the voter was found in the database, a new instance with his details is returned, else null is returned</returns>
        public Voter searchVoterById(string id)
        {
            SqlParameter[] parm = new SqlParameter[1];
            parm[0] = new SqlParameter("@id", id);
            DataTable t = sqlConnection.getTableBycommand("SearchVoter", parm);

            try
            {
                var factory = new FactroryVoter() as ICreateVoters;
                return(factory.createVoter(t.Rows[0]));
            }
            catch (IndexOutOfRangeException) { return(null); }
        }
 /// <summary>
 /// search for kalpi manager by his id, and return an object with his details if was found.
 /// </summary>
 /// <param name="id">the id of the kalpi manager</param>
 /// <param name="area">the area to which the kalpi manager belongs</param>
 /// <returns>Voter which holds a kalpi manager, if he was found in the database, null-otherwise</returns>
 public Voter SearchKalpiManager(string id, string area)
 {
     try
     {
         con.sqlCommand("SearchKalpiManager");
         con.InsertValstring("@id", id);
         con.InsertValstring("@area", area);
         con.InsertValstring("@permission", "2");
         DataTable mngr    = con.GetData("SearchKalpiManager");
         var       factory = new FactroryVoter() as ICreateVoters;
         return(factory.createVoter(mngr.Rows[0]));
     }
     catch
     {
         return(null);
     }
 }
        /// <summary>
        /// The Elections Manager adds new area manager
        /// </summary>
        /// <returns></returns> The result succeed/failed
        public int addnewAreaManager(string id, string firstName, string lastName, string userName, string password, string permission, DateTime dob, string address, string area, string city, string tell, string accomid)
        {
            var   factory = new FactroryVoter() as ICreateVoters;
            Voter v       = factory.createVoter();

            v.Id         = id;
            v.FName      = firstName;
            v.LName      = lastName;
            v.username   = userName;
            v.Passowrd   = password;
            v.Permission = permission;
            v.DOB        = dob;
            v.Address    = address;
            v.Area       = area;
            v.City       = city;
            v.Tell       = tell;
            v.AccomId    = accomid;

            return(v.addNewAreaManager(id, firstName, lastName, userName, password, permission, dob, address, area, city, tell, accomid));
        }
Beispiel #8
0
        public Boolean login(string id, string username, string password)//this function check the details accordingly to the data base.
        {
            con.sqlCommand("login");
            con.InsertValstring("@id", id.Trim());
            con.InsertValstring("@username", username.Trim());
            con.InsertValstring("@password", password.Trim());
            DataTable temp = con.GetData("login");

            if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == "")) //check if One or more of the fields are empty.
            {
                MessageBox.Show("One or more of the fields are empty");
                return(false);
            }
            try
            {
                int.Parse(textBox1.Text);//check id field - contain only numbers.
            }
            catch
            {
                MessageBox.Show("Invalid input in Id Field");
                return(false);
            }
            if (temp.Rows.Count > 0)
            {
                var factory = new FactroryVoter() as ICreateVoters;
                user = factory.createVoter(temp.Rows[0]);//if the user found in data base
                return(true);
            }
            else
            {
                MessageBox.Show("Doesn't Exist In Data Base!!");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";//clean fields
                return(false);
            }
        }
Beispiel #9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            using (Login login = new Login())              //open login window.
            {
                if (login.ShowDialog() == DialogResult.OK) //if all details of the user are matched to data base.
                {
                    voter = (Voter)login.get();
                    var factory = new FactroryVoter() as ICreateVoters; //factory that creates voters
                    voter = factory.createVoter(voter);                 //create a user according to permission
                    if (voter.LastConnection.AddMonths(2) < DateTime.Now.Date)
                    {
                        try
                        {
                            String val = RemoveVoter(voter.Id);
                            if (val == "1")
                            {
                                MessageBox.Show("The user can not enter to system , due the fact that the user not enter to system more then 2 months ");
                                this.Close();
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else if (Math.Abs((voter.LastConnection - DateTime.Now.Date).TotalDays) <= 61 && Math.Abs((voter.LastConnection - DateTime.Now.Date).TotalDays) >= 29)
                    {
                        using (changePass changepass = new changePass(voter))
                        {
                            if (!(changepass.ShowDialog() == DialogResult.OK))
                            {
                                this.Close();
                            }
                            else
                            {
                                UpdateLastDate(voter.Id);
                            }
                        }
                    }
                    else
                    {
                        //update date lsat
                        try
                        {
                            UpdateLastDate(voter.Id);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            this.Close();
                        }
                    }
                }
            }

            try
            {
                OpenMenu command = new OpenMenu(); //create a new command, that opens user menues
                command.execute(voter);            //open the correct menu of current user
            }
            catch
            {
            }
            finally
            {
                this.Close();
            }
        }