/// <summary> /// 借入按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnBorrow_Click(object sender, RoutedEventArgs e) { //获取输入的物资拥有者授权码的密文 string ciphertext = Encrypt.GetCiphertext(txtOwnerAuthCode.Password, owner.SecurityStamp); //如果物资拥有者授权码验证成功 if (ciphertext.Equals(owner.AuthorizationCode)) { //向数据库中更新物资状态和当前持有者并接收更新结果 int result = StuffDAO.UpdateStateAndCurrentHolderByStuffId(stuff.StuffId, "LentOut", user.UserName); //如果更新成功,即数据库受影响行数为1 if (result == 1) { parentWindow.UpdateDataGrid("Borrow", null, "LentOut", user.UserName); MessageBox.Show("物资借入成功!", "借入成功", MessageBoxButton.OK, MessageBoxImage.None); } else { MessageBox.Show("物资借入失败,请稍后重试。", "借入失败", MessageBoxButton.OK, MessageBoxImage.Error); } //关闭本窗口 Close(); } else { MessageBox.Show("验证失败,请检查您的授权码是否正确并重试。", "验证失败", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 归还按钮的点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReturn_Click(object sender, RoutedEventArgs e) { //获取输入的当前物资拥有者授权码的密文 string ciphertext = Encrypt.GetCiphertext(txtOwnerAuthCode.Password, owner.SecurityStamp); //如果当前物资拥有者授权码验证失败 if (!ciphertext.Equals(owner.AuthorizationCode)) { MessageBox.Show("验证失败,请检查您的授权码是否正确并重试。", "验证失败", MessageBoxButton.OK, MessageBoxImage.Error); return; } //按物资Id号更新数据库中物资的状态当前持有者并接收更新结果 int result = StuffDAO.UpdateStateAndCurrentHolderByStuffId(stuff.StuffId, "Holding", owner.UserName); //如果更新成功,即数据库受影响行数为1 if (result == 1) { parentWindow.UpdateDataGrid("Return", null, null, null); MessageBox.Show("物资归还成功!", "归还成功", MessageBoxButton.OK, MessageBoxImage.None); } else { MessageBox.Show("物资归还失败,请稍后重试。", "归还失败", MessageBoxButton.OK, MessageBoxImage.Error); } //关闭本窗口 Close(); }
/// <summary> /// 删除物资按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemoveStuff_Click(object sender, RoutedEventArgs e) { //获取输入的主管老师授权码的密文 string ciphertext = Encrypt.GetCiphertext(txtHeadTeacherAuthCode.Password, headTeacher.SecurityStamp); //如果主管老师授权码验证失败 if (!ciphertext.Equals(headTeacher.AuthorizationCode)) { MessageBox.Show("验证失败,请检查您的授权码是否正确并重试。", "验证失败", MessageBoxButton.OK, MessageBoxImage.Error); return; } //按物资Id号从数据库中删除物资并接收删除结果 int result = StuffDAO.DeleteStuff(stuff.StuffId); //如果删除成功,即数据库受影响行数为1 if (result == 1) { parentWindow.UpdateDataGrid("Remove", null, null, null); MessageBox.Show("物资删除成功!", "删除成功", MessageBoxButton.OK, MessageBoxImage.None); } else { MessageBox.Show("物资删除失败,请稍后重试。", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error); } //关闭本窗口 Close(); }
/// <summary> /// 我的物资单选按钮被选中事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rdbMyStuffs_Checked(object sender, RoutedEventArgs e) { //从数据库中查找我的物资 List <Stuff> stuffs = StuffDAO.QueryStuffByOwner(user.UserName); //为数据网格添加数据源 dgrdStuffInfo.ItemsSource = stuffs; //显示添加物资按钮(实为一个可点击的图片) imgAddStuff.Visibility = Visibility.Visible; }
/// <summary> /// 全部物资单选按钮被选中事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rdbAllStuffs_Checked(object sender, RoutedEventArgs e) { //从数据库中查找全部物资 List <Stuff> stuffs = StuffDAO.QueryAllStuffs(); //为数据网格添加数据源 dgrdStuffInfo.ItemsSource = stuffs; //隐藏添加物资按钮(实为一个可点击的图片) imgAddStuff.Visibility = Visibility.Hidden; }
/// <summary> /// 借入物资单选按钮被选中事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rdbBorrowedStuffs_Checked(object sender, RoutedEventArgs e) { //从数据库中查找借入物资 List <Stuff> stuffs = StuffDAO.QueryStuffByCurrentHolder(user.UserName); //为数据网格添加数据源 dgrdStuffInfo.ItemsSource = stuffs; //隐藏添加物资按钮(实为一个可点击的图片) imgAddStuff.Visibility = Visibility.Hidden; }
/// <summary> /// 添加物资按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddStuff_Click(object sender, RoutedEventArgs e) { //如果主管老师信息为空 if (null == headTeacher) { MessageBox.Show("未查询到你所在实验室主管老师的账户信息,请先联系该老师注册本系统。", "主管老师不存在", MessageBoxButton.OK, MessageBoxImage.Information); Close(); return; } //判断整数数值的正则表达式 Regex regex = new Regex(@"^\d+$"); //获取输入的主管老师授权码的密文 string ciphertext = Encrypt.GetCiphertext(txtHeadTeacherAuthCode.Password, headTeacher.SecurityStamp); //如果输入合法,即: //1. 物资名称不为空; 2.物资估值为纯数字; 3.主管老师授权码验证成功 if (!txtStuffName.Text.Equals("") && regex.IsMatch(txtValueOfAssessment.Text) && ciphertext.Equals(headTeacher.AuthorizationCode)) { //构造新增物资对象 Stuff stuff = new Stuff() { StuffName = txtStuffName.Text, ValueOfAssessment = Int32.Parse(txtValueOfAssessment.Text), State = "Holding", Owner = user.UserName, CurrentHolder = user.UserName }; //向数据库中插入物资信息并接收插入操作结果 int result = StuffDAO.InsertStuff(stuff); //如果插入成功,即数据库受影响行数为1 if (result == 1) { //更新数据网格视图 parentWindow.UpdateDataGrid("Add", stuff, null, null); MessageBox.Show("物资添加成功!", "添加成功", MessageBoxButton.OK, MessageBoxImage.None); } else { MessageBox.Show("物资添加失败,请稍后重试。", "添加失败", MessageBoxButton.OK, MessageBoxImage.Error); } //关闭本窗口 Close(); } else { MessageBox.Show("输入有误,请检查后重试。", "输入有误", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 根据操作类型更新数据网格视图 /// </summary> /// <param name="Operation">操作类型</param> /// <param name="Stuff">物资对象</param> /// <param name="State">物资状态</param> /// <param name="CurrentHolder">物资的当前持有者</param> public void UpdateDataGrid(string Operation, Stuff Stuff, string State, string CurrentHolder) { //获取数据网格当前选中行的行号 int selectedIndex = dgrdStuffInfo.SelectedIndex; //根据操作类型更新数据网格视图 switch (Operation) { case "Borrow": //更新指定行第三列(物资状态) (dgrdStuffInfo.Columns[3].GetCellContent(dgrdStuffInfo.Items[selectedIndex]) as TextBlock).Text = State; //更新指定行第五列(当前持有者) (dgrdStuffInfo.Columns[5].GetCellContent(dgrdStuffInfo.Items[selectedIndex]) as TextBlock).Text = CurrentHolder; break; case "Return": case "Remove": //获取数据网格物资对象表 IList <Stuff> stuffs = dgrdStuffInfo.ItemsSource as List <Stuff>; //删除指定行 stuffs.RemoveAt(selectedIndex); //更新数据网格的数据源 dgrdStuffInfo.ItemsSource = null; dgrdStuffInfo.ItemsSource = stuffs; break; case "Add": //获取数据网格物资对象表 IList <Stuff> stuffsOfMine = dgrdStuffInfo.ItemsSource as List <Stuff>; //获取数据库为新行分配的Id号 Stuff.StuffId = StuffDAO.QueryMaxOfStuffId(); //添加新对象到对象表 stuffsOfMine.Add(Stuff); //更新数据网格的数据源 dgrdStuffInfo.ItemsSource = null; dgrdStuffInfo.ItemsSource = stuffsOfMine; break; } }