管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-27 2b8aed5af4cd96a6aafc6fdb7fd0b7e9352ed498
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using JavaCode.cs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace JavaCode
{
    public partial class FrmSEM : Form
    {
        public FrmSEM()
        {
            InitializeComponent();
        }
 
        private void btnCalc_Click(object sender, EventArgs e)
        {
            try
            {
                string xls = this.txtExcel.Text.Trim();
                string path = Path.GetDirectoryName(xls);
                if (string.IsNullOrWhiteSpace(xls) || !File.Exists(xls))
                {
                    MessageBox.Show("Excel文件路径为空或文件不存在!");
                    return;
                }
 
                DataTable dt = ReadExcel.ReadXls(xls, 0);
                if (null == dt || dt.Rows.Count == 0)
                {
                    MessageBox.Show("Excel内容为空!");
                    return;
                }
 
                List<Coord> list = ModelHandler.FillModel<Coord>(dt);
                if (null == list || list.Count == 0)
                {
                    MessageBox.Show("读取Excel内容为空!");
                    return;
                }
 
                int count = 0;
                foreach (Coord c in list)
                {
                    string db = Path.Combine(path, c.Name + ".sem");
                    if (!File.Exists(db)) continue;
 
                    SQLiteHelper.ConnectionString = string.Format("Data Source={0};Integrated Security=True;Max Pool Size=64", db);
 
                    string sql = string.Format("insert into POSITION (id, x, y, height) values ((select count(*)+1 from POSITION), {0}, {1}, {2})", c.X, c.Y, c.Z);
                    int rows = SQLiteHelper.ExecuteNonQuery(sql, null);
                    if (rows > 0)
                    {
                        count++;
                    }
                }
 
                MessageBox.Show("共更新了 " + count + " 个.sem文件!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
    }
 
    public class Coord
    {
        public string Name { set; get; }
 
        public string X { set; get; }
 
        public string Y { set; get; }
 
        public string Z { set; get; }
    }
}