Beispiel #1
0
 //从Title面板中获取TitleInformation类信息
 private void getTitleInformation()
 {
     this.titleInformation       = new TitleInformation();
     this.titleInformation.Xxmc  = xxxxbox.Text.Trim();  //获取学校名称
     this.titleInformation.Xymc  = xyxxbox.Text.Trim();  //获取学院名称
     this.titleInformation.Zymc  = zyxxbox.Text.Trim();  //获取专业名称
     this.titleInformation.Bjmc  = bjxxbox.Text.Trim();  //获取班级名称
     this.titleInformation.Tbrmc = tbrxxbox.Text.Trim(); //获取填表人名称
     this.titleInformation.Lxdh  = lxdhbox.Text.Trim();  //联获取系方式
     this.titleInformation.Tbrq  = tbrqbox.Value;        //获取填表日期
 }
Beispiel #2
0
        //从指定文件中读出学生数据
        private bool openFile(string fileName)
        {
            bool result = false;

            try
            {
                DataSet myds = new DataSet();
                //获取全部数据
                String pOledbCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName +
                                   ";Extended Properties=Excel 8.0;";
                OleDbConnection  oledbCon  = new OleDbConnection(pOledbCon);  //创建Oledb数据库连接对象
                string           pExcelSql = "";                              //记录要执行的Excel查询语句
                OleDbDataAdapter oledba    = null;                            //创建Oledb数据桥连接器对象
                string           sheetName = "Sheet1";
                pExcelSql = String.Format("select * from [{0}$]", sheetName); //可以考虑修改为可配置
                oledba    = new OleDbDataAdapter(pExcelSql, pOledbCon);
                oledba.Fill(myds, sheetName);

                if (myds.Tables[0].Rows.Count > 4)
                {
                    ///初始化title信息
                    DataRow r0     = myds.Tables[0].Rows[0];
                    string  title1 = Convert.ToString(r0[0]);
                    title1 = title1.Trim();
                    if (!title1.Equals("人员基本信息表"))
                    {
                        string[] titles = title1.Split(' ');
                        this.titleInformation      = new TitleInformation();
                        this.titleInformation.Xxmc = titles[0];
                        this.titleInformation.Xymc = titles[1];
                        this.titleInformation.Zymc = string.IsNullOrEmpty(titles[2]) ? titles[2] : titles[2].Replace("人员基本信息表", "");
                    }
                    DataRow r1       = myds.Tables[0].Rows[1];
                    string  bjmcTemp = Convert.ToString(r1[1]);
                    if (!string.IsNullOrEmpty(bjmcTemp))
                    {
                        this.titleInformation.Bjmc = bjmcTemp;
                    }
                    string tbrmcTemp = Convert.ToString(r1[4]);
                    if (!string.IsNullOrEmpty(tbrmcTemp))
                    {
                        this.titleInformation.Tbrmc = tbrmcTemp;
                    }
                    string lxdhTemp = Convert.ToString(r1[7]);
                    if (!string.IsNullOrEmpty(lxdhTemp))
                    {
                        this.titleInformation.Lxdh = lxdhTemp;
                    }
                    DateTime dt = Convert.ToDateTime(r1[10]);
                    if (dt != null)
                    {
                        this.titleInformation.Tbrq = dt;
                    }
                    this.setTitleInformation();//设置title信息
                    ///初始化title信息
                    ///
                    for (int i = 3; i < myds.Tables[0].Rows.Count; i++)
                    {
                        DataRow     r   = myds.Tables[0].Rows[i];
                        StudentInfo stu = new StudentInfo();
                        stu.Bh      = BhCount;//获取学生临时编号
                        stu.Xm      = Convert.ToString(r[0]);
                        stu.Zjhm    = Convert.ToString(r[1]);
                        stu.Xb      = Convert.ToString(r[2]);
                        stu.Mz      = Convert.ToString(r[3]);
                        stu.Whcd    = Convert.ToString(r[4]);
                        stu.Zzmm    = Convert.ToString(r[5]);
                        stu.Zjxy    = Convert.ToString(r[6]);
                        stu.Hjdxzqh = Convert.ToString(r[7]);
                        stu.Hjdxz   = Convert.ToString(r[8]);
                        stu.Hkxz    = Convert.ToString(r[9]);
                        stu.Bzxx    = Convert.ToString(r[10]);
                        if (!stu.CheckAllEmpty())
                        {
                            this.StuList.Add(stu);//添加学生信息
                        }
                    }
                }
                checkTool.checkAndSetStuList(this.StuList); //检测学生列表并置空错误项
                result = true;                              //标记正常处理完成
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = false;
            }
            return(result);
        }