Ejemplo n.º 1
0
        //打开excel的题库,将其转换成list格式,并初始化两个列表
        private void OpenFileBtn_Click(object sender, EventArgs e)
        {
            // string strOdbcConn;
            if (OpenFileDlg.ShowDialog() == DialogResult.OK)
            {
                _FileName = OpenFileDlg.FileName;
            }
            if (!string.IsNullOrEmpty(_FileName))
            {
                if (TimuList == null)
                {
                    TimuList = new List <TiMuItem>();
                }
                else
                {
                    TimuList.Clear();
                }

                if (TimuWrongList == null)
                {
                    TimuWrongList = new List <TiMuItem>();
                }
                else
                {
                    TimuWrongList.Clear();
                }

                //选择题库的按钮禁用
                this.OpenFileBtn.Enabled = false;
                this.Cursor = Cursors.WaitCursor;

                ReadExcel readExcel = new ReadExcel();
                string[,] readResult = readExcel.OpenExcel(_FileName, "A", "D");
                readResult.GetLength(0);

                for (int i = 0; i < readResult.GetLength(0); i++)
                {
                    TiMuItem item = new TiMuItem();
                    item.XuHao   = int.Parse(readResult[i, 0]);
                    item.Type    = readResult[i, 1];
                    item.Content = readResult[i, 2];
                    item.Answer  = readResult[i, 3];
                    TimuList.Add(item);
                }



                /*
                 * int[,,,] arr = new int[9, 8, 7, 6];
                 *  arr.Rank;//返回4
                 *  arr.GetLength(0);//返回9
                 *  arr.GetLength(1);//返回8
                 *  arr.GetLength(2);//返回7
                 *  arr.GetLength(3);//返回6
                 *  arr.GetUpperBound(0)+1;//返回9
                 *  arr.Length;//返回3024
                 *
                 */

                //strOdbcConn = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source={0}; Extended Properties=Excel 8.0;", _FileName);
                //using (OleDbConnection OleDb = new OleDbConnection(strOdbcConn))
                //{
                //    OleDb.Open();
                //    //"select * from [Sheet1$] where 类型='多选题'"
                //    OleDbCommand oleCommmand = new OleDbCommand("select * from [Sheet1$];", OleDb);
                //    OleDbDataReader dr = oleCommmand.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        TiMuItem item = new TiMuItem();
                //        item.XuHao = int.Parse(dr[0].ToString());
                //        item.Type = dr[1].ToString();
                //        item.Content = dr[2].ToString();
                //        item.Answer = dr[3].ToString();
                //        TimuList.Add(item);

                //    }
                //    dr.Close();

                //}
                this.groupBox1.Visible = true;

                this.label1.Text     = "题目总数:" + TimuList.Count.ToString();
                this.Cursor          = Cursors.Default;
                this.NextBtn.Visible = true;
            }
        }