【实例简介】
1.附加数据库StudyCard
2.修改app.config密码为你本地sql server的密码
3. 运行即可看到如下截图
【实例截图】
管理员账号如下:
【核心代码】
using Bll;
using Microsoft.Win32;
using Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Brainscape_WPF
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.ResizeMode = ResizeMode.CanMinimize;
MangerBinding(ManagerNum, 1);//管理员页面显示
UserBinding(UserNum, 1);
SubjectBinding();
string activeDir = @"D:\Brainscape";
string newPath = System.IO.Path.Combine(activeDir, "SubjectImages");
System.IO.Directory.CreateDirectory(newPath);
SubjectMessage m = new SubjectMessage();
EditSubjectGrid.DataContext = m;
SectionMessage sm = new SectionMessage();
EditSectionGrid.DataContext = sm;
cbQuery();
cbQuery2();
}
public int ManagerType;
public string ManagerID;
const int ManagerNum =11; //表示管理员每页显示多少条记录
const int UserNum = 11; //表示用户每页显示多少条记录
private string filePath;
private string serverPath;
#region 管理员
List selectManager = new List();//保存选中要批量删除的管理员
private void btnMoreManagerDelete_Click(object sender, RoutedEventArgs e)//管理员批量删除按钮
{
if (ManagerType == 0)
{
if (selectManager.Count != 0)
{
if (MessageBox.Show("是否删除该管理员的信息!", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
foreach (ManagerMessage u in selectManager)
{
ManagerMessageBll.DelManager(u); //循环遍历删除里面的记录
}
}
else
{
selectManager.Clear();
}
MangerBinding(ManagerNum, 1); //刷新
}
else
MessageBox.Show("请选择要删除的管理员");
}
else
{
MessageBox.Show("您没有权限执行此操作!");
}
}
private void CheckBoxManager_Click(object sender, RoutedEventArgs e)//选中要删除的管理员
{
CheckBox dg = sender as CheckBox;
ManagerMessage u = new ManagerMessage();
u.ID = int.Parse(dg.Tag.ToString());
var bl = dg.IsChecked;
if (bl == true)
{
selectManager.Add(u); //如果选中就保存
}
else
{
// f = false;
selectManager.Remove(u); //如果选中取消就删除里面
}
}
private void MangerBinding(int number, int currentSize)//管理员显示页面
{
// number表示每个页面显示的记录数 currentSize表示当前显示页数
List infoList = new List();
infoList = Bll.ManagerMessageBll.Query(); //获取数据源
int count = infoList.Count; //获取记录总数
label16.Content = count; //显示管理员总人数
int pageSize = 0; //pageSize表示总页数
if (count % number == 0)
{
pageSize = count / number;
}
else
{
pageSize = count / number 1;
}
tbkTotal.Text = pageSize.ToString();
tbkCurrentsize.Text = currentSize.ToString();
infoList = infoList.Take(number * currentSize).Skip(number * (currentSize - 1)).ToList(); //刷选第currentSize页要显示的记录集
ManagerGrid.ItemsSource = infoList; //重新绑定ManagerGrid
}
private void btnUp_Click(object sender, RoutedEventArgs e)//管理员上一页
{
int currentsize = int.Parse(tbkCurrentsize.Text); //获取当前页数
if (currentsize > 1)
{
MangerBinding(ManagerNum, currentsize - 1); //调用分页方法
}
}
private void btnNext_Click(object sender, RoutedEventArgs e)//管理员下一页
{
int total = int.Parse(tbkTotal.Text); //总页数
int currentsize = int.Parse(tbkCurrentsize.Text); //当前页数
if (currentsize < total)
{
MangerBinding(ManagerNum, currentsize 1); //调用分页方法
}
}
private void btnGo_Click(object sender, RoutedEventArgs e)//管理员跳转页面
{
if (IsInteger(tbxPageNum.Text) && tbxPageNum.Text != "")
{
int pageNum = int.Parse(tbxPageNum.Text);
int total = int.Parse(tbkTotal.Text); //总页数
if (pageNum >= 1 && pageNum <= total)
{
MangerBinding(ManagerNum, pageNum); //调用分页方法
}
}
tbxPageNum.Text = "";
}
private void btnManagerAdd_Click(object sender, RoutedEventArgs e)//管理员添加按钮
{
if (ManagerType == 0)
{
EditManagers edit = new EditManagers();
edit.EditModel = true;
edit.WindowStartupLocation = WindowStartupLocation.CenterOwner;
edit.Owner = this;
edit.ShowDialog();
MangerBinding(ManagerNum, 1);
}
else
{
MessageBox.Show("您没有权限执行此操作!");
}
}
private void btnManagerUpdate_Click(object sender, RoutedEventArgs e)//管理员修改按钮
{
if (ManagerType == 0)
{
EditManagers edit = new EditManagers();
edit.EditModel = false;
int num = ManagerGrid.SelectedIndex;
if (num >= 0)
{
//获取选中行
ManagerMessage mm = (ManagerMessage)ManagerGrid.SelectedValue;
edit.EditGrid.DataContext = mm;
edit.WindowStartupLocation = WindowS