private void button1_Click(object sender, EventArgs e)
        {
            if (this.tb_stunum.Text != "" && this.tb_sname.Text != "" && (this.radioButton1.Checked || this.radioButton2.Checked) && this.comboBox1.Text != "请选择年份" && this.comboBox2.Text != "请选择学院")
            {
                stunum = this.tb_stunum.Text;
                sname = this.tb_sname.Text;
                if (this.radioButton1.Checked)
                    gender = 1;
                else
                    gender = 0;
                startyear = this.comboBox1.Text;
                collegeid = int.Parse(this.comboBox2.SelectedValue.ToString());

                int sid = 0 ;
                StudentBusiness addStudentBusiness = new StudentBusiness();
                sid = addStudentBusiness.addstudent(stunum, sname, gender, startyear, collegeid);
                if (sid != 0)
                {
                    MessageBox.Show("成功!");
                }
                else
                {
                    MessageBox.Show("失败,请重试!");
                }
                this.Dispose();
            }
            else
            {
                MessageBox.Show("请填写所有信息!");
            }
        }
        public JsonResult Delete(string id)
        {
            string Message = string.Empty;
            bool   Error   = false;

            try
            {
                Business.StudentBusiness student = new Business.StudentBusiness();
                if (!String.IsNullOrEmpty(id))
                {
                    int identifier = int.Parse(id);
                    student.Delete(identifier);
                }
                else
                {
                    Error   = true;
                    Message = "El Identificador del studiante no puede ser nulo";
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                Error   = true;
            }
            return(Json(new { Message = Message, Error = Error }, JsonRequestBehavior.AllowGet));
        }
 public FmStudentMain(FmLogin fmLogin, UserModel userModel)
 {
     InitializeComponent();
     this.fmLogin = fmLogin;
     this.userModel = userModel;
     StudentBusiness sBusiness = new StudentBusiness();
     this.studentModel = sBusiness.getStuBySid(sBusiness.getSidByUid(userModel.Uid));
     fmLogin.Hide();
 }
        public JsonResult List(jQueryDataTableParamModel param)
        {
            Business.StudentBusiness student = new Business.StudentBusiness();
            List <string[]>          data    = new List <string[]>();
            var studentList = student.GetAll();

            foreach (Domain.Students item in studentList)
            {
                data.Add(new string[] { item.Id + string.Empty, item.firstName, item.lastName, item.age + string.Empty, item.gender, item.phoneNumber, "" });
            }

            return(Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = 10,
                iTotalDisplayRecords = 3,
                aaData = data
            },
                        JsonRequestBehavior.AllowGet));
        }
        public JsonResult Update(string id, string name, string lastName, string gender, string age, string phone)
        {
            string Message = string.Empty;

            name     = name.Replace('%', ' ');
            lastName = lastName.Replace('%', ' ');
            bool Error = false;

            try
            {
                Business.StudentBusiness student = new Business.StudentBusiness();
                if (!String.IsNullOrEmpty(id))
                {
                    int      identifier = int.Parse(id);
                    Students entity     = new Students
                    {
                        Id          = identifier,
                        firstName   = name,
                        lastName    = lastName,
                        gender      = gender,
                        age         = int.Parse(age),
                        phoneNumber = phone
                    };
                    student.Update(entity);
                }
                else
                {
                    Error   = true;
                    Message = "El Identificador del studiante no puede ser nulo";
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                Error   = true;
            }
            return(Json(new { Message = Message, Error = Error }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(StudentViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Business.StudentBusiness student    = new Business.StudentBusiness();
                    Domain.Students          newStudent = new Domain.Students
                    {
                        firstName   = model.firstName,
                        lastName    = model.lastName,
                        age         = model.age,
                        gender      = model.gender,
                        phoneNumber = model.phoneNumber
                    };
                    student.Save(newStudent);
                }
                else
                {
                    foreach (var item in ModelState.AsQueryable().ToList())
                    {
                        if (item.Value.Errors.Count > 0)
                        {
                            ModelState.AddModelError("Error", item.Value.Errors.First().ErrorMessage + string.Empty);
                        }
                    }
                }

                return(RedirectToAction("Index", model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);
                return(View(model));
            }
        }
 //显示最新的课表
 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {
     //MessageBox.Show(this.tabControl1.SelectedIndex.ToString());
     switch (this.tabControl1.SelectedIndex)
     {
         case 0: break;
         //刷新选课列表
         case 1: this.btn_refreshCL_Click(null, null); break;
         //刷新已选课
         case 2: this.button3_Click(null, null); break;
         //刷新我的课表
         case 3:
             int sid = new StudentBusiness().getSidByUid(userModel.Uid);
             List<CourseInfo> courseInfoList = new GetTimetableBusiness().getTimetable(this.studentModel.Sid);
             int section = 0;
             if (courseInfoList != null)
             {
                 foreach (CourseInfo courseInfo in courseInfoList)
                 {
                     section = courseInfo.sectionNom;
                     ((System.Windows.Forms.Label)(this.Controls.Find("lb_" + section.ToString(), true)[0])).Text = courseInfo.getCourseInfo();
                 }
             }
             this.tabPage3.Refresh();
             break;
         case 4: break;
     }
 }
 //学生列表编辑后保存
 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     StudentModel stuModelToBeUpdated = new StudentModel();
     StudentBusiness stuBusiness = new StudentBusiness();
     //int sid = int.Parse(this.dataGridView1.CurrentRow.Cells["sid"].Value.ToString());
     stuModelToBeUpdated.Sid = int.Parse(this.dataGridView1.CurrentRow.Cells["sid"].Value.ToString());
     stuModelToBeUpdated.Stunum = this.dataGridView1.CurrentRow.Cells["stunum"].Value.ToString();
     stuModelToBeUpdated.Sname = this.dataGridView1.CurrentRow.Cells["sname"].Value.ToString();
     stuModelToBeUpdated.Startyear = this.dataGridView1.CurrentRow.Cells["startyear"].Value.ToString();
     stuModelToBeUpdated.Gender = this.dataGridView1.CurrentRow.Cells["gender"].Value.ToString() == "男" ? 1 : 0;
     if (this.dataGridView1.CurrentCell.ColumnIndex == this.dataGridView1.Columns["collegeid"].Index)
     {
         stuModelToBeUpdated.Collegeid = int.Parse(this.dataGridView1.CurrentRow.Cells["collegeid"].Value.ToString());
     }
     else
     {
         stuModelToBeUpdated.Collegeid = int.Parse(this.dataGridView1.CurrentRow.Cells["college_id"].Value.ToString());
     }
     //stuModelToBeUpdated = stuBusiness.getStuBySid(sid);
     int result = stuBusiness.updatestudent(stuModelToBeUpdated);
     if (result != 0)
     {
         MessageBox.Show("更新成功");
     }
     else
     {
         MessageBox.Show("更新失败");
     }
 }
        //删除学生按钮
        private void button7_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                bool isDeleteOk = true;
                StudentBusiness stuBusiness = new StudentBusiness();
                DataGridViewSelectedRowCollection toBeDeletedRowsCollection = this.dataGridView1.SelectedRows;

                DataGridViewRow[] tobedeletedrows = new DataGridViewRow[toBeDeletedRowsCollection.Count];
                toBeDeletedRowsCollection.CopyTo(tobedeletedrows, 0);
                foreach (DataGridViewRow temp in tobedeletedrows)
                {
                    if (stuBusiness.deleteStudent(int.Parse(temp.Cells["sid"].Value.ToString())) == 0)
                        isDeleteOk = false;
                }
                if (isDeleteOk)
                {
                    MessageBox.Show("删除成功!");
                }
                else
                {
                    MessageBox.Show("删除出现错误,请刷新列表后重试!");
                }

            }
        }
 //刷新学生列表
 private void button6_Click(object sender, EventArgs e)
 {
     StudentBusiness stuBusiness = new StudentBusiness();
     DataTable dt = stuBusiness.getAllStudent();
     this.dataGridView1.AutoGenerateColumns = false;
     this.dataGridView1.DataSource = dt;
     DataGridViewComboBoxColumn cob = new DataGridViewComboBoxColumn();
     cob = (DataGridViewComboBoxColumn)this.dataGridView1.Columns["collegeid"];
     cob.DataSource = new CollegeBusiness().getAllCollege();
     cob.DisplayMember = "cname";
     cob.ValueMember = "cid";
 }