private void btnAdd_Click(object sender, EventArgs e) { if (checkTxt() && dgvList.Rows.Count > 1) { try { db_students studentModel = new db_students(); DataTable dt = studentModel.GetList(" stuName='" + txtStuName.Text.Trim() + "' and idcard='" + txtIdCard.Text.Trim() + "' and examNameID='" + publicModel.examName + "'").Tables[0]; if (dt.Rows.Count > 0) { MessageBox.Show("已存在相同的信息!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { studentModel.stuName = txtStuName.Text.Trim(); studentModel.IdCard = txtIdCard.Text.Trim(); studentModel.examNameID = publicModel.examName; db_exam modelexam = new db_exam(txtIdCard.Text.Trim(), publicModel.examName); string kcName = modelexam == null ? "" : modelexam.kaochangName; studentModel.kaochangName = kcName; studentModel.status = "异常"; studentModel.prushTime = ""; studentModel.sex = ""; studentModel.nation = ""; studentModel.birthday = ""; studentModel.address = ""; studentModel.qianzhengjiguan = ""; studentModel.youxiaoqixian = ""; studentModel.applyNo = ""; if (getStuExamRandomNum(kcName)) { studentModel.stuNo = printStuNo; studentModel.Add(); MessageBox.Show("添加成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //更改导入学生签到状态 modelexam.status = "已签到"; modelexam.Update(); return; } else { MessageBox.Show("添加失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } else { MessageBox.Show("请输入考生信息,再添加!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }
/// <summary> /// 读取身份证信息 /// </summary> /// <param name="_kaochangName">考场名称</param> public void FillData(string _kaochangName) { try { getFillIdCardData(true); //string[] idline = File.ReadAllLines("idcard.txt"); //int idlength = idline.Length; //for (int idindex = 0; idindex < idlength; idindex++) //{ // if (idline[idindex] == idcardnum) // { // newflag = false; // break; // } //} if (!newflag) { if (idnum < 10 && idnum >= 0) { printStuNo = "00" + idnum.ToString(); } else if (idnum > 99) { printStuNo = idnum.ToString(); } else { printStuNo = "0" + idnum.ToString(); } lblExamNo.Visible = true; lblExamNo.Text = printStuNo; //记录刷卡用户 db_students studentsModel = new db_students(); studentsModel.stuName = lblName.Text.ToString(); studentsModel.stuNo = lblExamNo.Text.ToString(); studentsModel.IdCard = lblIdCard.Text.ToString(); studentsModel.prushTime = DateTime.Now.ToLongDateString(); studentsModel.sex = lblSex.Text.ToString(); studentsModel.nation = lblNation.Text.ToString(); studentsModel.birthday = lblBirthday.Text.ToString(); studentsModel.address = lblAddress.Text.ToString(); studentsModel.qianzhengjiguan = lblDept.Text.ToString(); studentsModel.youxiaoqixian = lblValidDate.Text.ToString(); studentsModel.applyNo = ""; studentsModel.status = "正常"; studentsModel.kaochangName = _kaochangName; studentsModel.examNameID = publicModel.examName; try { studentsModel.Add(); } catch { MessageBox.Show("录入失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } ////创建当前DOM对象的代码片段 //XmlDocumentFragment MyResultFra = AddId.CreateDocumentFragment(); ////获得具有[考生编号流水号]属性的[考生员工]节点 //XmlNode Mynode = AddId.SelectSingleNode("//添加考生[@考生编号流水号]"); ////获取当前[考生编号流水号]的值 //ResultId = int.Parse(Mynode.Attributes["考生编号流水号"].Value); ////修改[考生编号流水号] //ResultId++; //Mynode.Attributes["考生编号流水号"].Value = ResultId.ToString(); ////创建一个<新考生>节点 //XmlElement ResultElementRoot = AddId.CreateElement("新考生"); ////创建一个<考生编号>属性,并把他绑定到<新考生>节点 //XmlAttribute Myatt = AddId.CreateAttribute("考生编号"); //Myatt.Value = ResultId.ToString(); //ResultElementRoot.SetAttributeNode(Myatt); ////1创建一个<考生号>节点 //XmlElement MyEmpNum = AddId.CreateElement("考生号"); //MyEmpNum.InnerText = id.ToString(); ////2创建一个<姓名>节点 //XmlElement MyEmpName = AddId.CreateElement("姓名"); //MyEmpName.InnerText = lblName.Text; ////3创建一个<身份证号>节点 //XmlElement MyEmpBirthday = AddId.CreateElement("身份证号"); //MyEmpBirthday.InnerText = lblIdCard.Text; ////把以上的节点添加到<新员工>的子节点中 //ResultElementRoot.AppendChild(MyEmpNum); //ResultElementRoot.AppendChild(MyEmpName); //ResultElementRoot.AppendChild(MyEmpBirthday); ////添加<新考生>节点到 MyDocFrag 对象中 //MyResultFra.AppendChild(ResultElementRoot); ////获得具有[考生编号流水号]属性的[添加考生]节点 //XmlNode TempNode = AddId.SelectSingleNode("//添加考生[@考生编号流水号]"); ////把代码片段添加到DOM对象中 //TempNode.AppendChild(MyResultFra); //AddId.Save("xmlAddId.xml"); //StreamWriter swr = new StreamWriter("idcard.txt"); //向创建的文件中写入内容 StreamWriter swr = File.AppendText("idcard.txt"); swr.Write(idcardnum); swr.Write("\r\n"); //关闭当前文件写入流 swr.Close(); } else { MessageBox.Show("此身份证已签到!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); newflag = true; lblExamNo.Visible = false; //DialogResult result = MessageBox.Show("此身份证已签到,是否替换?", "询问", // MessageBoxButtons.OKCancel, MessageBoxIcon.Question); //if (result == DialogResult.OK) //{ // newflag = false; // string[] txtline = File.ReadAllLines("randno.txt"); // int txtlength = txtline.Length; // Random rm = new Random(); // id = rm.Next(1, txtlength); // StreamReader reader = new StreamReader("randno.txt"); // string text = reader.ReadToEnd(); // reader.Close(); // //string[] textlines = Regex.Split(text, Environment.NewLine); // StringBuilder str = new StringBuilder(); // for (int i = 0; i < txtlength; i++) // { // if (i == id) // continue; // idnum = int.Parse(txtline[id]); // str.AppendLine(txtline[i]); // } // StreamWriter writer = new StreamWriter("randno.txt"); // writer.Write(str.ToString()); // writer.Close(); // lblExamNo.Visible = true; // lblExamNo.Text = idnum.ToString(); //} //else //{ // //this.Close(); //} } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }