private void cleanPicture() { try { string path = Environment.CurrentDirectory + @"\picture"; DirectoryInfo TheFolder = new DirectoryInfo(path); foreach (FileInfo NextFile in TheFolder.GetFiles())//遍历文件 { string fileName = (NextFile.Name); if (fileName == "defaultAvatar.jpg") { continue; } string[] s = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 2) { NextFile.Delete(); continue; } UInt32 uID = (UInt32)Convert.ToInt32(s[0]); //用户号 string userName = s[1].Replace(".jpg", ""); //姓名 int index = personnelManagement.uIDtoIndex(uID); if ((index < 0) || (personnelManagement.PersonList[index].name != userName)) { NextFile.Delete(); } } } catch (Exception ex) { output(ex.Message); } }
/// <summary> /// 将指定人员的数据从数据库读取并显示,方便编辑人员信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e) { SchoolInfoInit(); PersonnelManagement personnelManagement = new PersonnelManagement(); int rowIndex = dgvPerson.CurrentRow.Index; //获取选择行号 tbUID.Text = dgvPerson.Rows[rowIndex].Cells[0].Value.ToString(); uint uID = (UInt32)Convert.ToInt32(tbUID.Text); int index = personnelManagement.uIDtoIndex(uID); if (index < 0) { output("数据库中没有指定ID用户"); return; } tbName.Text = personnelManagement.PersonList[index].name; cbSex.Text = personnelManagement.PersonList[index].sex; tbStudentID.Text = personnelManagement.PersonList[index].studentID; string domitory = personnelManagement.PersonList[index].dormitory; byte one = (byte)domitory.LastIndexOf(")"); string Building = domitory.Substring(0, one + 1); string Floor = domitory.Substring(one + 1, 1); tbDomitory.Text = domitory.Substring(one + 2, 3); if (cbBuilding.Items.Contains(Building)) { cbBuilding.DropDownStyle = ComboBoxStyle.DropDownList; cbBuilding.Text = Building; } else { cbBuilding.DropDownStyle = ComboBoxStyle.Simple; cbBuilding.Text = Building; } if (cbFloor.Items.Contains(Floor)) { cbFloor.DropDownStyle = ComboBoxStyle.DropDownList; cbFloor.Text = Floor; } else { cbFloor.DropDownStyle = ComboBoxStyle.Simple; cbFloor.Text = Floor; } cbActiveState.Checked = personnelManagement.PersonList[index].activeState == 0 ? false : true; string authority = personnelManagement.PersonList[index].authority; cbAuthority = CheckBoxComboBoxOP.checkItem(cbAuthority, authority); string major = personnelManagement.PersonList[index].major; one = (byte)major.LastIndexOf(" "); string Institute = major.Substring(0, one); string Major = major.Substring(one + 1, major.Length - one - 1); if (cbInstitute.Items.Contains(Institute)) { cbInstitute.DropDownStyle = ComboBoxStyle.DropDownList; cbInstitute.Text = Institute; } else { cbInstitute.DropDownStyle = ComboBoxStyle.Simple; cbInstitute.Text = Institute; } if (cbMajor.Items.Contains(Major)) { cbMajor.DropDownStyle = ComboBoxStyle.DropDownList; cbMajor.Text = Major; } else { cbMajor.DropDownStyle = ComboBoxStyle.Simple; cbMajor.Text = Major; } //cbInstitute.Text = major.Substring(0, one); //cbMajor.Text = major.Substring(one + 1, major.Length - one - 1); tbQQ.Text = personnelManagement.PersonList[index].QQ; tbWeiXin.Text = personnelManagement.PersonList[index].weiXin; tbTel.Text = personnelManagement.PersonList[index].tel; dtpBirthday.Value = DateTime.Parse(personnelManagement.PersonList[index].birthday); cbIsLimitTime.Checked = personnelManagement.PersonList[index].isLimitTime == 0 ? false : true; dtpLimitTime.Value = DateTime.Parse(personnelManagement.PersonList[index].limitTime); tbRFID.Text = personnelManagement.PersonList[index].cardID.ToString("X8");; tbEigen1.Text = personnelManagement.PersonList[index].eigen[0]; tbEigen2.Text = personnelManagement.PersonList[index].eigen[1]; tbEigen3.Text = personnelManagement.PersonList[index].eigen[2]; tbEigen4.Text = personnelManagement.PersonList[index].eigen[3]; tbEigen5.Text = personnelManagement.PersonList[index].eigen[4]; fPath = Environment.CurrentDirectory + @"\picture\" + tbUID.Text.PadLeft(4, '0') + "_" + tbName.Text + ".jpg"; try { if (File.Exists(fPath) != true) { output("头像不存在!"); pbPortrait.Image = null; return; } pbPortrait.Image = Image.FromFile(Environment.CurrentDirectory + @"\picture\" + tbUID.Text.PadLeft(4, '0') + "_" + tbName.Text + ".jpg"); output("读取信息成功!"); } catch (Exception ex) { output(ex.Message); } }