コード例 #1
0
 public void Table(string id)
 {
     uiDataGridView1.Rows.Clear();
     using LendController lendMapper = new LendController();
     foreach (UserLend item in lendMapper.GetLendsByUid(id))  //对借过的所有书进行遍历,这里要小心啊,一定要将所有传入参数转化成string,否则无法export的!
     {
         uiDataGridView1.Rows.Add(item.LandNo.ToString(), item.BookID, item.BookName, item.LendTime.ToString(), getExpense(item).ToString());
     }
 }
コード例 #2
0
 private void buttonLend_Click(object sender, EventArgs e)
 {
     using LendController lendMapper = new LendController();
     if (lendMapper.ReturnBook(Convert.ToInt32(borrowNum)) > 1)
     {
         MessageBox.Show("Successful to lend back");
         Table(lenderId);
     }
     else
     {
         throw new Exception("Failed to lend back");
     }
 }
コード例 #3
0
 public void TableName(string lenderId) //check the books according to the name
 {
     uiDataGridView1.Rows.Clear();      //清空旧数据
     using LendController bookMapper = new LendController();
     foreach (var item in bookMapper.GetLendsByUid(lenderId))
     {
         if (item.BookName.Equals(uiTextBoxName.Text))
         {
             uiDataGridView1.Rows.Add(item.LandNo, item.BookID, item.BookName, item.LendTime, getExpense(item));
             return;
         }
     }
 }
コード例 #4
0
 public void TableID(string lenderId) //show data based on ID
 {
     uiDataGridView1.Rows.Clear();    //flush old data
     using LendController bookMapper = new LendController();
     foreach (var item in bookMapper.GetLendsByUid(lenderId))
     {
         if (item.BookID == uiTextboxID.Text)
         {
             uiDataGridView1.Rows.Add(item.LandNo, item.BookID, item.BookName, item.LendTime, getExpense(item));
             return;
         }
     }
 }
コード例 #5
0
ファイル: userBorrow.cs プロジェクト: WZY009/BookMS
        private void button1_Click(object sender, EventArgs e)
        {
            string BookIsbn = uiDataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            int    number   = int.Parse(uiDataGridView1.SelectedRows[0].Cells[4].Value.ToString());

            if (number < 1)
            {
                MessageBox.Show("The book is borrowed by other people so we suggest you to borrow it after someone lend it back", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                using LendController lendMapper = new LendController();
                UserController usermap  = new UserController();
                string         userName = usermap.GetById(userId).Name;
                if (lendMapper.LendBook(userId, BookIsbn) > 0)
                {
                    MessageBox.Show($"{userName} borrows {uiDataGridView1.SelectedRows[0].Cells[1].Value.ToString()} successfully!");
                    Table();
                }
            }
        }
コード例 #6
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            UserController usermap = new UserController();
            DialogResult   dr      = MessageBox.Show($"Confirm to change {textBoxName.Text}'s information?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (textBoxID.Text != "" && textBoxMajor.Text != "" && textBoxName.Text != "" && textBoxPassword.Text != "" && textBoxQID.Text != "" && textBoxAnswer.Text != "")
            {
                if (dr == DialogResult.OK)
                {
                    try {
                        if (textBoxID.Text.Equals(StuId))
                        {
                            User userChange = usermap.GetById(StuId);
                            userChange.Name = textBoxName.Text;
                            if (comboBox1.SelectedIndex == 0)
                            {
                                userChange.Sex = true;
                            }
                            else
                            {
                                userChange.Sex = false;
                            }
                            userChange.Major           = textBoxMajor.Text;
                            userChange.Password        = textBoxPassword.Text;
                            userChange.Question_id     = int.Parse(textBoxQID.Text);
                            userChange.Question_answer = textBoxAnswer.Text;
                            if (usermap.UpdateUserInfo(userChange) > 0)
                            {
                                MessageBox.Show("Successful to change information!");
                            }
                            else
                            {
                                MessageBox.Show("Failed to change your account information!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            User           oldUser = usermap.GetById(StuId);
                            LendController lendmap = new LendController();
                            // Lend lendList = lendmap.GetLendsByUid(StuId);
                            User userChange = new User();
                            userChange.Id        = textBoxID.Text;
                            userChange.PhotoPath = oldUser.PhotoPath;
                            userChange.Name      = textBoxName.Text;
                            if (comboBox1.SelectedIndex == 0)
                            {
                                userChange.Sex = true;
                            }
                            else
                            {
                                userChange.Sex = false;
                            }
                            userChange.Major           = textBoxMajor.Text;
                            userChange.Password        = textBoxPassword.Text;
                            userChange.Question_id     = int.Parse(textBoxQID.Text);
                            userChange.Question_answer = textBoxAnswer.Text;
                            if (usermap.AddUser(userChange) > 0 && lendmap.VerifyBook(lendmap.GetAllLends(), StuId, textBoxID.Text) != 0)
                            {
                                MessageBox.Show("Successful to change iinformation!");
                                usermap.DeleteById(StuId);
                            }

                            else
                            {
                                MessageBox.Show("Failed to change your account information!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    catch (Exception error) {
                        throw new Exception(error.Message);
                    }
                }
                Table();
            }
            else
            {
                MessageBox.Show("Please fulfill all the information!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }