示例#1
0
        /// <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);
            }
        }
示例#2
0
        /// <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();
        }