示例#1
0
        public override bool Submit()
        {
            if (!base.Submit())
            {
                return(false);
            }

            using (SnokyeContainer container = new SnokyeContainer())
            {
                string hashValue = Password.GetMD5();
#if DEBUG
                if (!container.UserInfoSet.Any())
                {
                    UserInfo __admin = new UserInfo {
                        DisplayName = "系统管理员", Password = "******".GetMD5(), UserName = "******", UserGuid = Guid.NewGuid()
                    };
                    container.AddToUserInfoSet(__admin);

                    for (int i = 0; i < 100; i++)
                    {
                        //0xB0A1 - 0xF7FE
                        UserInfo u = new UserInfo
                        {
                            UserName    = "******" + i,
                            DisplayName = "User" + i,
                            Password    = "******".GetMD5()
                        };
                        container.AddToUserInfoSet(u);

                        container.SaveChanges();
                    }
                }
#endif
                var user = container.UserInfoSet.FirstOrDefault(u => u.UserName == UserName && u.Password == hashValue);

                if (user == null)
                {
                    ValidateFailed?.Invoke(nameof(UserName), "用户名不存在或密码错误!");
                    return(false);
                }
                if (user.Disabled)
                {
                    ValidateFailed?.Invoke(nameof(UserName), "该用户已被禁用!");
                    return(false);
                }

                ClientInfo.CurrentUser = user;
                ClientInfo.UserProfile = new ServerUserProfile(user.UserGuid);
            }

            if (RememberPwd)
            {
                LocalUserProfile.SaveContent(UserName, "password", Password);
            }
            else
            {
                LocalUserProfile.Delete(UserName, "password");
            }
            return(true);
        }
示例#2
0
        public static void SaveFormState(Form frm, string title, ViewModelBase vm = null)
        {
            string    profileName = (frm.GetType().FullName + "_" + title + (vm == null ? "" : vm.GetType().FullName));
            FormState profile     = new FormState {
                WindowState = frm.WindowState, Location = frm.Location, Size = frm.Size
            };

            LocalUserProfile.Save(ClientInfo.CurrentUser.UserName, profileName, profile);
        }
示例#3
0
 private void SaveUserHistory()
 {
     if (cRememberPwd.Checked)
     {
         LocalUserProfile.SaveContent(_vm.UserName, "password", _vm.Password);
     }
     else
     {
         LocalUserProfile.Delete(_vm.UserName, "password");
     }
 }
示例#4
0
        public static void LoadFormState(Form frm, string title, ViewModelBase vm = null)
        {
            string    profileName = (frm.GetType().FullName + "_" + title + (vm == null ? "" : vm.GetType().FullName));
            FormState profile     = LocalUserProfile.GetProfile <FormState>(ClientInfo.CurrentUser.UserName, profileName);

            if (profile != null)
            {
                frm.WindowState = profile.WindowState;
                if (frm.WindowState != FormWindowState.Maximized)
                {
                    frm.StartPosition = FormStartPosition.Manual;
                    frm.Location      = profile.Location;
                    frm.Size          = profile.Size;
                }
            }
        }
示例#5
0
        private void LoadUserHistory()
        {
            //只加载最近10个
            var dirs = new DirectoryInfo(LocalUserProfile.UserProfileDirecotry).GetDirectories().OrderByDescending(d => d.LastWriteTime).Take(10);

            foreach (var d in dirs)//每个目录一个用户(的所有设置)
            {
                //找密码
                string pwd = LocalUserProfile.GetProfileContent(d.Name, "password");
                _userHistory[d.Name] = pwd;
                cmbUserName.Items.Add(d.Name);
            }
            if (_userHistory.Any())
            {
                _vm.UserName = _userHistory.Keys.First();
            }
        }
示例#6
0
        public VMLoginForm()
        {
            //加载登录记录
            //只加载最近10个
            var dirs = new DirectoryInfo(LocalUserProfile.UserProfileDirecotry).GetDirectories().OrderByDescending(d => d.LastWriteTime).Take(10);

            foreach (var d in dirs)//每个目录一个用户(的所有设置)
            {
                //找密码
                string pwd = LocalUserProfile.GetProfileContent(d.Name, "password");
                _userHistory[d.Name] = pwd;
            }
            UserHistory = _userHistory.Keys.ToArray();
            if (UserHistory.Length > 0)
            {
                UserName    = UserHistory[0];
                Password    = _userHistory[UserName];
                RememberPwd = Password != null;
            }
        }
示例#7
0
        private void bOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            var query = from bar in flowLayoutPanel1.Controls.OfType <AdvFilterBar>()
                        let f = bar.GetFilter()
                                where f.HasValue
                                select f.Value;

            if (!query.Any())
            {
                Result = null;
                return;
            }

            string filter = '(' + string.Join(") AND (", query.Select(f => f.Key).ToArray()) + ')';
            var    parms  = query.Select(f => f.Value).ToArray();

            Result = new KeyValuePair <string, SqlParameter[]>(filter, parms);
            #region 保存过滤
#if !DEBUG
            try
            {
#endif
            var queryFilter = from bar in flowLayoutPanel1.Controls.OfType <AdvFilterBar>()
                              where bar.GetFilter().HasValue
                              select new FilterProfile
            {
                SelectedField    = bar.cmbField.SelectedValue.ToString(),
                NotChecked       = bar.cNot.Checked,
                SelectedOperator = bar.cmbOperator.SelectedValue.ToString(),
                ValueObject      = bar.GetValueEditorValue(),
            };
            LocalUserProfile.Save(ClientInfo.CurrentUser.UserName, _listForm.GetType().FullName + "_AdvFilter", queryFilter.ToArray());
#if !DEBUG
        }

        catch { }
#endif
            #endregion
        }
示例#8
0
        private void AdvFilterForm_Load(object sender, EventArgs e)
        {
            #region 加载保存的过滤
#if !DEBUG
            try
            {
#endif

            FilterProfile[] profile = LocalUserProfile.GetProfile <FilterProfile[]>(ClientInfo.CurrentUser.UserName, _listForm.GetType().FullName + "_AdvFilter");

            if (profile != null)
            {
                flowLayoutPanel1.Controls.Clear();

                foreach (FilterProfile p in profile)
                {
                    AdvFilterBar bar = new AdvFilterBar
                    {
                        Name       = "bf" + _filterCount++,
                        DataSource = _dataSource,
                    };
                    bar.Load += (object s, EventArgs ea) =>
                    {
                        AdvFilterBar b = (AdvFilterBar)s;
                        b.cmbField.SelectedValue    = p.SelectedField;
                        b.cNot.Checked              = p.NotChecked;
                        b.cmbOperator.SelectedValue = p.SelectedOperator;

                        if (b.ValueEditor is DateTimePicker dtp)
                        {
                            dtp.Value = Convert.ToDateTime(p.ValueObject);
                        }
                        else if (b.ValueEditor is RadioButton r)
                        {
                            if (Convert.ToBoolean(p.ValueObject))
                            {
                                r.Checked = true;
                            }
                            else
                            {
                                ((RadioButton)b.Controls[r.Name + 1]).Checked = true;
                            }
                        }
                        else if (b.ValueEditor is NumericUpDown n)
                        {
                            n.Value = Convert.ToDecimal(p.ValueObject);
                        }
                        else if (b.ValueEditor is TextBox t)
                        {
                            t.Text = p.ValueObject.ToString();
                        }
                    };

                    this.flowLayoutPanel1.Controls.Add(bar);
                }
            }
#if !DEBUG
        }

        catch { }
#endif
            #endregion
        }