public void Init_Edit() { StudentInfo _Contact = StudentInfoBLL.GetOneContactInfo(contact_ID_edit); if (_Contact != null) { textContactId.Text = _Contact.ContactId.ToString(); textName.Text = _Contact.Name; if (_Contact.Gender == "男") { radioMale.Checked = true; radioFemale.Checked = false; } else if (_Contact.Gender == "女") { radioMale.Checked = false; radioFemale.Checked = true; } textAge.Text = _Contact.Age.ToString(); dateTimePickerBirth.Text = _Contact.Birthdate.ToString(); textPhone.Text = _Contact.Phone; textEmail.Text = _Contact.Email; textAdrees.Text = _Contact.Adress; textProfession.Text = _Contact.Profession; } }
private void buttonUpdate_Click(object sender, EventArgs e) { StudentInfo contacts = new StudentInfo(); if (AllRight()) { contacts.ContactId = Int32.Parse(textContactId.Text); contacts.Name = textName.Text; contacts.Age = Int32.Parse(textAge.Text); contacts.Phone = textPhone.Text; contacts.Email = textEmail.Text; contacts.Profession = textProfession.Text; contacts.Adress = textAdrees.Text; if (radioMale.Checked) { contacts.Gender = "男"; } else if (radioFemale.Checked) { contacts.Gender = "女"; } contacts.Birthdate = DateTime.Parse(dateTimePickerBirth.Text); if (StudentInfoBLL.UpdateContactInfo(contacts)) { MessageBox.Show("修改成功"); this.Close(); } else { MessageBox.Show("修改失败!请输入完整有效信息!"); } } }
private void toolStripDelete_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 1) { if ( MessageBox.Show("确定要删除此学生信息?", "确定", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes ) { int selectrow = Int32.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString()); //int selectrow = dataGridView1.CurrentCell.RowIndex+1; if (StudentInfoBLL.DeleteContactInfo(selectrow)) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } InitContacts(); } } else { MessageBox.Show("请选一行后再点击!"); } }
private void btn_search_Click(object sender, EventArgs e) { if (cB_Search_Item.Text == string.Empty) { dGV_Search.DataSource = StudentInfoBLL.GetAllContactsInfo(StudentInfoBLL.Return_BasePath()); InitHeadTitle(); } else { if (textBox_Searchtext.Text != string.Empty) { StudentInfo contactSearch = new StudentInfo(); switch (cB_Search_Item.SelectedIndex) { case 0: contactSearch.ContactId = Int32.Parse(textBox_Searchtext.Text); break; case 1: contactSearch.Name = textBox_Searchtext.Text; break; } dGV_Search.DataSource = StudentInfoBLL.GetContactsList(contactSearch); InitHeadTitle(); } else { MessageBox.Show("请输入要查询的" + cB_Search_Item.Text); } } }
public FormSearch() { InitializeComponent(); dGV_Search.DataSource = StudentInfoBLL.GetAllContactsInfo(StudentInfoBLL.Return_BasePath()); InitHeadTitle(); }
private void toolStripBackUp_Click(object sender, EventArgs e) { //检查文件是否存在 if (!(File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"//myContacts_BackUp.xml"))) { StudentInfoBLL.CreateXml(StudentInfoBLL.Return_BackUpPath()); if (StudentInfoBLL.ChangeXml(StudentInfoBLL.Return_BasePath(), StudentInfoBLL.Return_BackUpPath())) { MessageBox.Show("备份成功!"); } } else if (MessageBox.Show("已有备份文件,是否覆盖?", "Confirm Message", MessageBoxButtons.OKCancel) == DialogResult.OK) { if (StudentInfoBLL.ChangeXml(StudentInfoBLL.Return_BasePath(), StudentInfoBLL.Return_BackUpPath())) { MessageBox.Show("备份成功"); } } }
void InitContacts()//初始化,获取文件信息 { if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"//myContacts.xml")) { dataGridView1.DataSource = StudentInfoBLL.GetAllContactsInfo(StudentInfoBLL.Return_BasePath()); } else { StudentInfoBLL.CreateXml(StudentInfoBLL.Return_BasePath()); dataGridView1.DataSource = StudentInfoBLL.GetAllContactsInfo(StudentInfoBLL.Return_BasePath()); } dataGridView1.Columns[0].HeaderText = "学生编号"; dataGridView1.Columns[1].HeaderText = "学生姓名"; dataGridView1.Columns[2].HeaderText = "学生性别"; dataGridView1.Columns[3].HeaderText = "专业"; dataGridView1.Columns[4].HeaderText = "学生年龄"; dataGridView1.Columns[5].HeaderText = "出生日期"; dataGridView1.Columns[6].HeaderText = "手机号码"; dataGridView1.Columns[7].HeaderText = "电子邮箱"; dataGridView1.Columns[8].HeaderText = "家庭住址"; }