1
13693261870
2022-11-12 789027cd17a31a439efeef8ba1ef61705ba43edc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Community.DAL;
using Community.Excel.Common;
using Community.Model.Build;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
 
namespace Community.Excel
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
 
        private void FrmMain_Load(object sender, EventArgs e)
        {
            SQLiteHelper.DB = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Community.db");
        }
 
        private void btnReadXls_Click(object sender, EventArgs e)
        {
            try
            {
                string xls = this.txtXls.Text.Trim();
                string str = this.txtSplit.Text.Trim();
                string name = this.txtName.Text.Trim();
                string strSheet = this.txtSheet.Text.Trim();
 
                int sheet = 0;
                if (!int.TryParse(strSheet, out sheet))
                {
                    MessageBox.Show("Excel表格的Sheet必须为整数!");
                    return;
                }
 
                DataTable dt = XlsTools.ReadXls(xls, sheet);
                if (dt == null || dt.Rows.Count < 2)
                {
                    MessageBox.Show("Excel表格为空!");
                    return;
                }
 
                string[] strs = str.Split(new char[] { ',' });
                List<House> list = XlsTools.ProcessData(strs, name, dt);
                if (list == null || list.Count == 0)
                {
                    return;
                }
 
                int count = XlsTools.InsertHouse(list);
                MessageBox.Show(string.Format("插入了 {0} 条数据!", count));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
    }
}