Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string excelfilename = "";

            try
            {
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    excelfilename = this.openFileDialog1.FileName.Trim();

                    FileStream   fs       = new FileStream(excelfilename, FileMode.Open, FileAccess.Read);
                    HSSFWorkbook workbook = new HSSFWorkbook(fs);
                    HSSFSheet    sheet    = workbook.GetSheetAt(0);
                    ArrayList    shx      = new ArrayList();
                    if (sheet != null)
                    {
                        int zhang = sheet.LastRowNum;
                        for (int i = 1; i <= sheet.LastRowNum; i++)
                        {
                            string   string1 = "";
                            HSSFCell cell    = sheet.GetRow(i).GetCell(0);
                            if (cell.CellType == 3)
                            {
                                int dn = i + 1;
                                MessageBox.Show("第 " + dn.ToString() + " 行空行!", "管理系统提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                return;
                            }
                            if (cell.CellType == 0)
                            {
                                string1 = sheet.GetRow(i).GetCell(0).NumericCellValue.ToString();
                            }
                            else
                            {
                                string1 = sheet.GetRow(i).GetCell(0).StringCellValue.ToString();
                            }
                            if (string1.Length != 12)
                            {
                                int dn = i + 1;
                                MessageBox.Show("第 " + dn.ToString() + " 行代码位数不是12位!", "管理系统提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                return;
                            }
                            string ss = string1 + sheet.GetRow(i).GetCell(1).StringCellValue;
                            shx.Add(ss);
                        }
                    }
                    fs.Close();
                    fs.Dispose();
                    Tools.Uitl uitl = new Uitl();
                    uitl.DrawTree_XZC(this.treeView1, shx);//画节点树
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "管理系统提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (DocumentLock documentLock = AcadApplication.DocumentManager.MdiActiveDocument.LockDocument()) //锁住文档以便进行写操作
            {
                string connectionString = Uitl.GetConnectionString();                                            //写连接字符串
                string selstring        = "SELECT * FROM DataDic";

                if (Tools.DataBasic.Create_Dic_table(connectionString))
                {
                    SqlConnection connection = new SqlConnection(connectionString);
                    connection.Open();
                    SqlDataAdapter Adapter = DataBasic.Dic_Initadapter(selstring, connectionString);
                    DataSet        dataset = new DataSet();
                    Adapter.Fill(dataset, "DataDic");//填充Dataset
                    System.Data.DataTable TB    = dataset.Tables["DataDic"];
                    Tools.Uitl            uitl  = new Uitl();
                    ArrayList             array = new ArrayList();
                    int count = TB.Rows.Count;
                    #region 将DataTable的代码和名称天然数组
                    for (int i = 0; i < count; i++)
                    {
                        DataRow row  = TB.Rows[i];
                        string  xzdm = row[0].ToString().Trim();
                        if (xzdm.Length != 12)
                        {
                            return;
                        }
                        array.Add(xzdm + row[1].ToString().Trim());
                    }
                    #endregion
                    uitl.DrawTree_XZC(this.treeView1, array);//画节点树
                    Adapter.Dispose();
                    connection.Close();
                }
            }
        }