private void btnSignup_Click(object sender, EventArgs e)
        {
            if (txtCourseId.Text == "")
                return;
            int costTimes;
            try
            {
                costTimes = int.Parse(txtSignupTimes.Text);
                if (costTimes <= 0)
                {
                    throw new ArgumentException();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请输入要报名的时长(必须为正整数)", "报名时长不合法", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                txtSignupTimes.Focus();
                return;
            }

            int balance;
            int cost;
            try
            {
                balance = int.Parse(txtBalance.Text);
                cost = int.Parse(txtCost.Text) * costTimes;

                if (balance < cost)
                {
                    MessageBox.Show("余额不足,请充值或减少所要报名的时长", "余额不足", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return;
                }
            }
            catch (Exception)
            {
                return;
            }

            ConfirmSignUpCoursesForm frmConfirmSignUpCourses = new ConfirmSignUpCoursesForm();
            if (dgvPreregStudents.SelectedRows.Count <= 0)
                return;
            DataGridViewRow row = dgvPreregStudents.SelectedRows[0];
            frmConfirmSignUpCourses.CourseType = lstCourseType.Text;
            frmConfirmSignUpCourses.CourseSubType = lstCourseSubtypes.Text;
            frmConfirmSignUpCourses.CourseName = txtCourseName.Text;

            frmConfirmSignUpCourses.CurrentDate = txtCurrentDate.Text;
            frmConfirmSignUpCourses.ExpireDate = txtExpireDate.Text;
            frmConfirmSignUpCourses.SignUpPeriod = txtSignupTimes.Text + "个" + lblCostType.Text;
            frmConfirmSignUpCourses.TotalCost = txtTotalCost.Text;

            frmConfirmSignUpCourses.StudentName = row.Cells["NameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentSex = row.Cells["SexColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentBirthday = row.Cells["BirthdayColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentAddress = row.Cells["AddressColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentPhone = row.Cells["TelephoneColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherName = row.Cells["FartherNameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherPhone = row.Cells["FartherTelColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherWork = row.Cells["FartherWorkColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherName = row.Cells["MotherNameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherPhone = row.Cells["MotherTelColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherWork = row.Cells["MotherWorkColumn"].Value.ToString();

            frmConfirmSignUpCourses.Text = "确认要为“" + txtName.Text + "”报名" + txtSignupTimes.Text
                + "个" + lblCostType.Text + "的“" + txtCourseName.Text + "”课程吗? 共需花费" + cost + "元。";
            if (frmConfirmSignUpCourses.ShowDialog() != DialogResult.OK)
                return;

            // 报名:
            // 1> 扣钱
            balance -= cost;
            studentsPreregTableAdapter.UpdateBalance(balance, txtID.Text);
            txtBalance.Text = balance.ToString();
            if (dgvPreregStudents.SelectedRows.Count > 0)
            {
                row.Cells["BalanceColumn"].Value = txtBalance.Text;
            }

            // 2> 添加报名信息
            studentCoursesTableAdapter.Insert(int.Parse(txtID.Text), int.Parse(txtCourseId.Text), DateTime.Parse(txtExpireDate.Text));

            // 3> 更新状态,报名成功
            studentsPreregTableAdapter.UpdateStatus(1, int.Parse(txtID.Text));

            MessageBox.Show("报名成功!", "报名成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void btnSignup_Click(object sender, EventArgs e)
        {
            if (txtCourseId.Text == "")
                return;

            int balance;
            int actualCost;
            try
            {
                balance = int.Parse(txtBalance.Text);
                actualCost = int.Parse(txtActualCostAmount.Text);

                if (balance < actualCost)
                {
                    MessageBox.Show("余额不足,请充值或减少所要报名的时长", "余额不足,无法报名", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return;
                }
            }
            catch (Exception)
            {
                return;
            }

            ConfirmSignUpCoursesForm frmConfirmSignUpCourses = new ConfirmSignUpCoursesForm();
            if (dgvPreregStudents.SelectedRows.Count <= 0)
                return;
            DataGridViewRow row = dgvPreregStudents.SelectedRows[0];
            frmConfirmSignUpCourses.CourseType = lstCourseType.Text;
            frmConfirmSignUpCourses.CourseSubType = lstCourseSubtypes.Text;
            frmConfirmSignUpCourses.CourseName = txtCourseName.Text;

            frmConfirmSignUpCourses.CurrentDate = dtCurrentDate.Value.ToString();
            if (txtExpireDate.Visible == true)
                frmConfirmSignUpCourses.ExpireDate = txtExpireDate.Text;
            else
                frmConfirmSignUpCourses.ExpireDate = dtExpireDate.Text;
            frmConfirmSignUpCourses.SignUpPeriod = txtSignupTimes.Text + "个" + lblCostType.Text;
            frmConfirmSignUpCourses.TotalCost = txtTotalCost.Text;

            frmConfirmSignUpCourses.Discount = cmbDiscount.Text;
            frmConfirmSignUpCourses.DiscountReason = txtDiscountReason.Text;
            frmConfirmSignUpCourses.ActualCostAmount = txtActualCostAmount.Text;

            frmConfirmSignUpCourses.StudentName = row.Cells["NameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentSex = row.Cells["SexColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentBirthday = row.Cells["BirthdayColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentAddress = row.Cells["AddressColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentPhone = row.Cells["TelephoneColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherName = row.Cells["FartherNameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherPhone = row.Cells["FartherTelColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherWork = row.Cells["FartherWorkColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherName = row.Cells["MotherNameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherPhone = row.Cells["MotherTelColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherWork = row.Cells["MotherWorkColumn"].Value.ToString();

            frmConfirmSignUpCourses.Text = "确认要为“" + txtName.Text + "”报名" + txtSignupTimes.Text
                + "个" + lblCostType.Text + "的“" + txtCourseName.Text + "”课程吗? 共需花费" + actualCost + "元。";
            if (frmConfirmSignUpCourses.ShowDialog() != DialogResult.OK)
                return;

            // 报名:
            // 1> 扣钱:
            // 1.1> 更新balance
            balance -= actualCost;
            studentsPreregTableAdapter.UpdateBalance(balance, txtID.Text);
            txtBalance.Text = balance.ToString();
            if (dgvPreregStudents.SelectedRows.Count > 0)
            {
                row.Cells["BalanceColumn"].Value = txtBalance.Text;
            }
            // 1.2> 添加扣钱记录
            studentCostTableAdapter.Insert(int.Parse(txtID.Text), int.Parse(txtCourseId.Text), int.Parse(txtCost.Text), dtCurrentDate.Value,
                int.Parse(cmbDiscount.SelectedValue.ToString()), int.Parse(txtActualCostAmount.Text), txtDiscountReason.Text, User.CurrentUser.UserName);

            // 2> 添加报名信息
            DateTime expireDate;
            if (txtExpireDate.Visible == true)
                expireDate = DateTime.Parse(txtExpireDate.Text);
            else
                expireDate = dtExpireDate.Value;
            studentCoursesTableAdapter.Insert(int.Parse(txtID.Text), int.Parse(txtCourseId.Text), expireDate, int.Parse(txtTotalCost.Text), int.Parse(txtSignupTimes.Text));

            // 3> 更新学生的学费过期时间
            studentsPreregTableAdapter.UpdateExpireTime(expireDate, int.Parse(txtID.Text));

            // 4> 更新状态,报名成功
            studentsPreregTableAdapter.UpdateStatus(1, int.Parse(txtID.Text));

            MessageBox.Show("报名成功!", "报名课程成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void btnSignUpCourses_Click(object sender, EventArgs e)
        {
            if (dgvStudents.SelectedRows.Count <= 0)
                return;
            int rowIndex = dgvStudents.CurrentRow.Index;
            DataGridViewRow row = dgvStudents.SelectedRows[0];

            CourseSignUpForm frmCourseSignUp = new CourseSignUpForm();
            frmCourseSignUp.CardNo = txtCardNo.Text;
            frmCourseSignUp.StudentName = txtName.Text;
            frmCourseSignUp.Balance = txtBalance.Text;
            frmCourseSignUp.row = row;
            if (frmCourseSignUp.ShowDialog() != DialogResult.OK)
                return;

            ConfirmSignUpCoursesForm frmConfirmSignUpCourses = new ConfirmSignUpCoursesForm();
            frmConfirmSignUpCourses.CourseType = frmCourseSignUp.CourseType;
            frmConfirmSignUpCourses.CourseSubType = frmCourseSignUp.CourseSubType;
            frmConfirmSignUpCourses.CourseName = frmCourseSignUp.CourseName;

            frmConfirmSignUpCourses.CurrentDate = DateTime.Now.ToLongDateString();
            frmConfirmSignUpCourses.ExpireDate = frmCourseSignUp.ExpireDate;
            frmConfirmSignUpCourses.SignUpPeriod = frmCourseSignUp.SignUpPeriod;
            frmConfirmSignUpCourses.TotalCost = frmCourseSignUp.TotalCost;

            frmConfirmSignUpCourses.Discount = frmCourseSignUp.Discount;
            frmConfirmSignUpCourses.DiscountReason = frmCourseSignUp.DiscountReason;
            frmConfirmSignUpCourses.ActualCostAmount = frmCourseSignUp.ActualCostAmount;

            frmConfirmSignUpCourses.StudentName = row.Cells["NameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentSex = row.Cells["SexColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentBirthday = row.Cells["BirthdayColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentAddress = row.Cells["AddressColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentPhone = row.Cells["PhoneColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherName = row.Cells["FartherNameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherPhone = row.Cells["FartherTelColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentFartherWork = row.Cells["FartherWorkColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherName = row.Cells["MotherNameColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherPhone = row.Cells["MotherTelColumn"].Value.ToString();
            frmConfirmSignUpCourses.StudentMotherWork = row.Cells["MotherWorkColumn"].Value.ToString();

            if (frmConfirmSignUpCourses.ShowDialog() != DialogResult.OK)
                return;

            // 报名:
            // 1> 扣钱:
            // 1.1> 更新balance
            frmCourseSignUp.Balance = txtBalance.Text;
            int balance = int.Parse(frmCourseSignUp.Balance);
            int actualCost = int.Parse(frmCourseSignUp.ActualCostAmount);
            balance -= actualCost;
            studentsTableAdapter.UpdateBalance(balance, int.Parse(txtID.Text));
            txtBalance.Text = balance.ToString();
            // 1.2> 添加扣钱记录
            studentCostTableAdapter1.InsertCostWithExpireTime(int.Parse(txtID.Text), frmCourseSignUp.CourseId,
                int.Parse(frmCourseSignUp.TotalCost), DateTime.Now,
                frmCourseSignUp.DiscountLevel,
                int.Parse(frmCourseSignUp.ActualCostAmount), frmCourseSignUp.DiscountReason, User.CurrentUser.UserName, DateTime.Parse(frmCourseSignUp.ExpireDate));

            // 2> 添加报名信息
            DateTime expireDate = DateTime.Parse(frmCourseSignUp.ExpireDate);
            studentCoursesTableAdapter.InsertStudentCourse(int.Parse(txtID.Text), frmCourseSignUp.CourseId,
                expireDate, int.Parse(frmCourseSignUp.TotalCost), int.Parse(frmCourseSignUp.SignUpTime));

            // 3> 更新学生的学费过期时间,看哪个过期时间更近
            studentsTableAdapter.UpdateExpireTime(expireDate, int.Parse(txtID.Text));

            MessageBox.Show("报名成功!", "报名课程成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            if (this.UserType == 0)
            {
                // 只加载被授权的学生
                this.studentsTableAdapter.FillByUserName(this.studentsDataSet.Students, this.UserName);
            }
            else
            {
                // 加载所有的学生
                this.studentsTableAdapter.FillByStatus(this.studentsDataSet.Students);
            }
            if (rowIndex >= 0)
            {
                this.dgvStudents.Rows[rowIndex].Selected = true;
                this.dgvStudents.CurrentCell = this.dgvStudents.Rows[rowIndex].Cells[0];
            }
        }