Esempio n. 1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     var newu = new User { Name = "חדש", UserName = "", Password = "" };
     _users.Add(newu);
     lstUsers.DataSource = null;
     lstUsers.DataSource = _users;
     lstUsers.SelectedItem = newu;
 }
Esempio n. 2
0
        public List<User> GetListOfUsers()
        {
            var dt = new DataTable();
            var lst = new List<User>();
            using (var con = new SqlConnection(_connectionString))
            {
                using (var data = new SqlDataAdapter("SELECT * FROM Users  ", con))
                {
                    data.Fill(dt);
                }
            }
            foreach (DataRow row in dt.Rows)
            {
                var user = new User { Id = (int)row["id"], UserName = row["UserName"].ToString(), Name = row["Name"].ToString(), Password = row["Password"].ToString().Base64Decode(), IsAdmin = row["IsAdmin"].ToString() == "True" };//.Base64Decode();
                lst.Add(user);
            }

            return lst;
        }
Esempio n. 3
0
        public void AddUpdateUser(User user)
        {
            var str = "";
            if (user.Id == 0) // new
            {
                str = string.Format(
                              "              INSERT INTO [dbo].[Users]  " +
                              "         ([Name] " +
                              "         ,[UserName] " +
                              "         ,[Password] " +
                              "         ,[IsAdmin]) " +
                              "   VALUES " +
                              "         (N'{0}' " +
                              "         ,N'{1}' " +
                              "         ,N'{2}' " +
                              "         ,{3})          ", user.Name, user.UserName, user.Password.Base64Encode(), user.IsAdmin ? "1" : "0");
            }
            else
            {
                str = string.Format(
                                                " UPDATE [dbo].[Users] " +
                                "   SET [Name] = N'{0}' " +
                                 "     ,[UserName] = N'{1}' " +
                                  "    ,[Password] = N'{2}' " +
                                   "   ,[IsAdmin] = {3} WHERE id= {4}", user.Name, user.UserName, user.Password.Base64Encode(), user.IsAdmin ? "1" : "0", user.Id);

            }

            using (var con = new SqlConnection(_connectionString))
            using (var comm = new SqlCommand(str, con))
            {
                con.Open();
                comm.ExecuteNonQuery();
            }
        }
Esempio n. 4
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            using (var frm = new frmLogIn())
            {
                frm.txtUser.Text = User;
                frm.ValidateUser = (u, p) =>
                {
                    if (u == "admin" && p == "5486")
                    {
                        _user = new User { IsAdmin = true, Name = "admin" };
                        return true;
                    }

                    _user = _dal.GetUser(u);

                    if (_user == null)
                        return false;

                    return _user.Password == p;
                };

                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    splitContainer1.Panel1.Enabled = true;
                    splitContainer1.Panel2.Controls.Clear();
                    splitContainer1.Panel2.Controls.Add(new ucClients() { Dock = DockStyle.Fill });

                    if (_user.IsAdmin)
                    {
                        usersToolStripMenuItem.Visible = true;
                        btnObligors.Visible = true;
                    }
                    else
                    {
                        usersToolStripMenuItem.Visible = false;
                        btnObligors.Visible = false;
                    }

                    this.Text = "Gym Manager " + _user.Name;

                    _loggedIn = true;
                    if (_user.Name != "admin")
                        User = _user.UserName;
                }
            }

            btnProgram.Enabled = false;
            btnSet.Enabled = false;
        }