Example #1
0
 /*
  *  获取excel表格字段或者txt数据
  */
 private void obtainFieldButton_Click(object sender, EventArgs e)
 {
     if (this.txtFile.Text.Equals("") || this.txtFile.Text.Equals(String.Empty))
     {
         return;
     }
     if (NameUnit.fileType.Equals("txt") || NameUnit.fileType.Equals("csv"))
     {
         finish = ImportFile.readFile(ref this.excelData, this.txtFile.Text, NameUnit.fileType, type = 1);
     }
     else
     {
         finish = ImportFile.readFile(ref this.excelData, this.txtFile.Text, NameUnit.fileType, type = 0);
     }
     //if (this.excelData.Rows.Count == 0)
     //    return;
     //写入列表
     this.excelFieldList.Items.Clear();
     for (int i = 0; i < this.excelData.Columns.Count; i++)
     {
         this.excelFieldList.Items.Add(this.excelData.Columns[i].ColumnName);
     }
 }
Example #2
0
        void importData(int type)
        {
            int i = 0;

            if (!importDataTable())
            {
                MessageBox.Show("数据库插入失败,请重试", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!this.finish)
            {
                MessageBox.Show("导入数据成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //
            Console.WriteLine("第" + ++i + "次导入");
            while (this.finish)
            {
                this.finish = ImportFile.readFile(ref this.excelData, this.txtFile.Text, NameUnit.fileType, type);
                if (!importDataTable())
                {
                    MessageBox.Show("数据库插入失败,请重试", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Console.WriteLine("第" + ++i + "次导入");
            }

            if (!importDataTable())
            {
                MessageBox.Show("数据库插入失败,请重试", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("导入数据成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }