/// <summary>
 /// Method to write admin credentials into Db on starting application if the list of all users are empty
 /// </summary>
 /// <returns></returns>
 private tblUser WriteAdminInDb()
 {
     try
     {
         using (RecipeKeeperEntities context = new RecipeKeeperEntities())
         {
             if (UserList.Count() == 0)
             {
                 tblUser admin = new tblUser
                 {
                     username = "******",
                     password = PasswordHasher.Hash("Admin123"),
                     fullname = "Administrator",
                     role     = "admin"
                 };
                 context.tblUsers.Add(admin);
                 context.SaveChanges();
                 return(admin);
             }
             return(null);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Ejemplo n.º 2
0
        public void AppendXMLList()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new XmlWriter <User>();

            writer.Write <UserList>(users, XmlFile);

            ListSerializable <User> OtherUsers = new UserList();

            OtherUsers.Add(new User("lala", "lala"));
            OtherUsers.Add(new User("test", "test"));

            writer.Append <UserList>(OtherUsers, XmlFile, "users");

            IReader <User>    reader    = new XmlReader <User>("users", "user");
            Collection <User> usersList = reader.read <UserList>(XmlFile);

            Assert.AreEqual(4, usersList.Count);
            for (int i = 0; i < users.Count(); i++)
            {
                Assert.AreEqual(users[i].Name, usersList[i].Name);
                Assert.AreEqual(users[i].Firstname, usersList[i].Firstname);
            }

            for (int i = 0; i < OtherUsers.Count(); i++)
            {
                Assert.AreEqual(OtherUsers[i].Name, usersList[i + 2].Name);
                Assert.AreEqual(OtherUsers[i].Firstname, usersList[i + 2].Firstname);
            }
        }
Ejemplo n.º 3
0
        public void LoadUserList()
        {
            UserList users = new UserList();

            users.UserListLoad();

            int expected = 10;
            int actual   = users.Count();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        private void btnPrintAllUsersHours_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
            PrintDocument      p = new PrintDocument();

            int y            = 15; //y value on the page
            int itemsPerPage = 0;  //items per page
            int i            = 0;  //which line we're on

            p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
            {
                //reset the starting variables
                if (!e1.HasMorePages)
                {
                    y            = 15;
                    itemsPerPage = 0;
                    i            = 0;
                }

                while (userList.Count() > i)
                {
                    //draw the users name
                    e1.Graphics.DrawString(userList.ElementAt(i).Name, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(20, y, p.DefaultPageSettings.PrintableArea.Width, 50));
                    //draw their total hours
                    e1.Graphics.DrawString(Math.Round(userList.ElementAt(i).LoggedHours, 2).ToString(), new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(750, y, p.DefaultPageSettings.PrintableArea.Width, 50));

                    if (itemsPerPage < 35)
                    {
                        e1.HasMorePages = false;
                        y += 30;
                        itemsPerPage++;
                    }
                    else
                    {
                        e1.HasMorePages = true;
                        y            = 15;
                        itemsPerPage = 0;
                        return;
                    }
                    i++;
                }
            };

            //set the document to the one we just created
            printPreviewDialog1.Document = p;

            //set up the print preview
            printPreviewDialog1.Width         = 1367;
            printPreviewDialog1.Height        = 768;
            printPreviewDialog1.StartPosition = FormStartPosition.CenterParent;
            //show the print preview
            printPreviewDialog1.ShowDialog();
        }
Ejemplo n.º 5
0
        public User SelectByPassword(string password)
        {
            Command.CommandText = "SELECT * FROM User_Table WHERE [password] = @Password";

            //parameters
            Command.Parameters.Add(new OleDbParameter("@Password", password));

            UserList temp = new UserList(Select());

            if (temp.Count() == 1)
            {
                return(temp[0]);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public User SelectByUsername(string username)
        {
            Command.CommandText = "SELECT * FROM User_Table WHERE [username] = @Username";

            //parameters
            Command.Parameters.Add(new OleDbParameter("@Username", username));

            UserList temp = new UserList(Select());

            if (temp.Count() == 1)
            {
                return(temp[0]);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public User SelectById(int id)
        {
            Command.Parameters.Clear();

            Command.CommandText = "SELECT * FROM User_Table WHERE [ID] = @Id";

            //parameters
            Command.Parameters.Add(new OleDbParameter("@Id", id));

            UserList temp = new UserList(Select());

            if (temp.Count() == 1)
            {
                return(temp[0]);
            }
            return(null);
        }
Ejemplo n.º 8
0
        private void btnClock_Click(object sender, EventArgs e)
        {
            String strCurrentUserCode = txtUserCode.Text;
            User   curUser            = null;

            //run through all the users and find the matching user code
            for (int i = 0; userList.Count() > i; i++)
            {
                //if it matches clock in or out
                if (userList.ElementAt(i).UserID.Equals(strCurrentUserCode))
                {
                    curUser = userList[i];
                }
            }

            if (curUser == null)
            {
                if (strCurrentUserCode.Equals("+R+I+C+Ka"))
                {
                    System.Diagnostics.Process.Start("https://youtu.be/dQw4w9WgXcQ"); return;
                }

                NewUser newUser = new NewUser(this);

                newUser.ShowDialog();
                return;
            }

            if (curUser.IsClockedIn)
            {
                curUser.clockOut();
                PrintUserInfo(curUser);
            }
            else
            {
                curUser.clockIn();
                PrintUserInfo(curUser);
            }
            txtUserCode.Focus();
            txtUserCode.SelectAll();

            userList.Save();
        }
Ejemplo n.º 9
0
        public void TestReadJsonList()
        {
            ListSerializable <User> usersList = new UserList();

            usersList.Add(new User("Toto", "Titi"));
            usersList.Add(new User("Tata", "Roro"));

            new JsonWriter <User>().Write <UserList>(usersList, JsonFile);

            IReader <User>    reader = new JsonReader <User>();
            Collection <User> users  = reader.read <UserList>(JsonFile);

            Assert.AreEqual(usersList.Count(), users.Count);

            Assert.AreEqual(usersList[0].Name, users[0].Name);
            Assert.AreEqual(usersList[0].Firstname, users[0].Firstname);

            Assert.AreEqual(usersList[1].Name, users[1].Name);
            Assert.AreEqual(usersList[1].Firstname, users[1].Firstname);
        }
Ejemplo n.º 10
0
        public void AppendCsvListNoHeaderWriteButAddHeaderWithAppend()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new CsvWriter <User>(';');

            writer.Write <UserList>(users, CsvFile);

            ListSerializable <User> OtherUsers = new UserList();

            OtherUsers.Add(new User("lala", "lala"));
            OtherUsers.Add(new User("test", "test"));

            writer = new CsvWriter <User>(';', new StringList {
                "Name", "Firstname"
            });
            writer.Append <UserList>(OtherUsers, CsvFile, "users");

            IReader <User> reader = new CsvReader <User>(';', new StringList {
                "Name", "Firstname"
            });
            Collection <User> usersList = reader.read <UserList>(CsvFile);

            Assert.AreEqual(4, usersList.Count);
            for (int i = 0; i < users.Count(); i++)
            {
                Assert.AreEqual(users[i].Name, usersList[i].Name);
                Assert.AreEqual(users[i].Firstname, usersList[i].Firstname);
            }

            for (int i = 0; i < OtherUsers.Count(); i++)
            {
                Assert.AreEqual(OtherUsers[i].Name, usersList[i + 2].Name);
                Assert.AreEqual(OtherUsers[i].Firstname, usersList[i + 2].Firstname);
            }
        }
 public static bool CookieIdExist(int UserID)
 {
     return(UserList.Count(d => d.Id == UserID) == 0 || UserList.Any(d => d.Id == UserID && d.SessionId == CookieSessionId));
 }