コード例 #1
0
ファイル: frmUsers.cs プロジェクト: khaikin/GymMgr
 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;
 }
コード例 #2
0
ファイル: AdoDal.cs プロジェクト: khaikin/GymMgr
        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;
        }
コード例 #3
0
ファイル: AdoDal.cs プロジェクト: khaikin/GymMgr
        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();
            }
        }
コード例 #4
0
ファイル: frmMain.cs プロジェクト: khaikin/GymMgr
        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;
        }