diff --git a/Form1.Designer.cs b/Form1.Designer.cs deleted file mode 100644 index 2cd028f..0000000 --- a/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace kcsj -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Text = "Form1"; - } - - #endregion - } -} diff --git a/Form1.cs b/Form1.cs deleted file mode 100644 index 77e19a4..0000000 --- a/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace kcsj -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/Forms/DataInputForm.Designer.cs b/Forms/DataInputForm.Designer.cs new file mode 100644 index 0000000..4d3641a --- /dev/null +++ b/Forms/DataInputForm.Designer.cs @@ -0,0 +1,71 @@ +namespace kcsj.Forms +{ + partial class DataInputForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + DataFromFiles = new Button(); + button2 = new Button(); + SuspendLayout(); + // + // DataFromFiles + // + DataFromFiles.Location = new Point(57, 34); + DataFromFiles.Name = "DataFromFiles"; + DataFromFiles.Size = new Size(165, 68); + DataFromFiles.TabIndex = 0; + DataFromFiles.Text = "从文件读取"; + DataFromFiles.UseVisualStyleBackColor = true; + DataFromFiles.Click += DataFromFiles_Click; + // + // button2 + // + button2.Location = new Point(57, 119); + button2.Name = "button2"; + button2.Size = new Size(165, 74); + button2.TabIndex = 1; + button2.Text = "手动输入"; + button2.UseVisualStyleBackColor = true; + // + // DataInputForm + // + AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(288, 218); + Controls.Add(button2); + Controls.Add(DataFromFiles); + Name = "DataInputForm"; + Text = "数据输入"; + ResumeLayout(false); + } + + #endregion + + private Button DataFromFiles; + private Button button2; + } +} \ No newline at end of file diff --git a/Forms/DataInputForm.cs b/Forms/DataInputForm.cs new file mode 100644 index 0000000..11f127b --- /dev/null +++ b/Forms/DataInputForm.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace kcsj.Forms +{ + public partial class DataInputForm : Form + { + public DataInputForm() + { + InitializeComponent(); + } + + private void DataFromFiles_Click(object sender, EventArgs e) + { + FileInputForm form = new FileInputForm(); + + form.ShowDialog(); + } + } +} diff --git a/Form1.resx b/Forms/DataInputForm.resx similarity index 93% rename from Form1.resx rename to Forms/DataInputForm.resx index 1af7de1..8b2ff64 100644 --- a/Form1.resx +++ b/Forms/DataInputForm.resx @@ -1,17 +1,17 @@  - diff --git a/Forms/FileInputForm.Designer.cs b/Forms/FileInputForm.Designer.cs new file mode 100644 index 0000000..878c1dd --- /dev/null +++ b/Forms/FileInputForm.Designer.cs @@ -0,0 +1,185 @@ +namespace kcsj.Forms +{ + partial class FileInputForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + KnownPointFile = new Label(); + KonwnSFile = new Label(); + btnSubmitData = new Button(); + txtKnownPath = new TextBox(); + txtObservationPath = new TextBox(); + btnFileView1 = new Button(); + btnFileView2 = new Button(); + btnViewData = new Button(); + dgvKnownPoints = new DataGridView(); + dgvObservations = new DataGridView(); + txtKnownPoints = new Label(); + ((System.ComponentModel.ISupportInitialize)dgvKnownPoints).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dgvObservations).BeginInit(); + SuspendLayout(); + // + // KnownPointFile + // + KnownPointFile.AutoSize = true; + KnownPointFile.Location = new Point(37, 43); + KnownPointFile.Name = "KnownPointFile"; + KnownPointFile.Size = new Size(136, 24); + KnownPointFile.TabIndex = 0; + KnownPointFile.Text = "已知点文件路径"; + // + // KonwnSFile + // + KonwnSFile.AutoSize = true; + KonwnSFile.Location = new Point(37, 89); + KonwnSFile.Name = "KonwnSFile"; + KonwnSFile.Size = new Size(136, 24); + KonwnSFile.TabIndex = 1; + KonwnSFile.Text = "观测值文件路径"; + // + // btnSubmitData + // + btnSubmitData.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + btnSubmitData.Location = new Point(641, 38); + btnSubmitData.Name = "btnSubmitData"; + btnSubmitData.Size = new Size(106, 83); + btnSubmitData.TabIndex = 2; + btnSubmitData.Text = "导入数据"; + btnSubmitData.UseVisualStyleBackColor = true; + btnSubmitData.Click += btnSubmitData_Click; + // + // txtKnownPath + // + txtKnownPath.Location = new Point(190, 40); + txtKnownPath.Name = "txtKnownPath"; + txtKnownPath.Size = new Size(194, 30); + txtKnownPath.TabIndex = 3; + // + // txtObservationPath + // + txtObservationPath.Location = new Point(190, 91); + txtObservationPath.Name = "txtObservationPath"; + txtObservationPath.Size = new Size(194, 30); + txtObservationPath.TabIndex = 4; + // + // btnFileView1 + // + btnFileView1.Location = new Point(390, 38); + btnFileView1.Name = "btnFileView1"; + btnFileView1.Size = new Size(112, 34); + btnFileView1.TabIndex = 5; + btnFileView1.Text = "浏览"; + btnFileView1.UseVisualStyleBackColor = true; + btnFileView1.Click += btnFileView1_Click; + // + // btnFileView2 + // + btnFileView2.Location = new Point(390, 89); + btnFileView2.Name = "btnFileView2"; + btnFileView2.Size = new Size(112, 34); + btnFileView2.TabIndex = 6; + btnFileView2.Text = "浏览"; + btnFileView2.UseVisualStyleBackColor = true; + btnFileView2.Click += btnFileView2_Click; + // + // btnViewData + // + btnViewData.Location = new Point(529, 38); + btnViewData.Name = "btnViewData"; + btnViewData.Size = new Size(106, 83); + btnViewData.TabIndex = 7; + btnViewData.Text = "预览数据"; + btnViewData.UseVisualStyleBackColor = true; + btnViewData.Click += btnViewData_Click; + // + // dgvKnownPoints + // + dgvKnownPoints.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgvKnownPoints.Location = new Point(31, 154); + dgvKnownPoints.Name = "dgvKnownPoints"; + dgvKnownPoints.RowHeadersWidth = 62; + dgvKnownPoints.Size = new Size(710, 226); + dgvKnownPoints.TabIndex = 8; + // + // dgvObservations + // + dgvObservations.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgvObservations.Location = new Point(31, 409); + dgvObservations.Name = "dgvObservations"; + dgvObservations.RowHeadersWidth = 62; + dgvObservations.Size = new Size(710, 245); + dgvObservations.TabIndex = 9; + // + // txtKnownPoints + // + txtKnownPoints.AutoSize = true; + txtKnownPoints.Location = new Point(354, 127); + txtKnownPoints.Name = "txtKnownPoints"; + txtKnownPoints.Size = new Size(64, 24); + txtKnownPoints.TabIndex = 10; + txtKnownPoints.Text = "已知点"; + // + // FileInputForm + // + AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(769, 714); + Controls.Add(txtKnownPoints); + Controls.Add(dgvObservations); + Controls.Add(dgvKnownPoints); + Controls.Add(btnViewData); + Controls.Add(btnFileView2); + Controls.Add(btnFileView1); + Controls.Add(txtObservationPath); + Controls.Add(txtKnownPath); + Controls.Add(btnSubmitData); + Controls.Add(KonwnSFile); + Controls.Add(KnownPointFile); + MaximizeBox = false; + Name = "FileInputForm"; + Text = "文件读取"; + ((System.ComponentModel.ISupportInitialize)dgvKnownPoints).EndInit(); + ((System.ComponentModel.ISupportInitialize)dgvObservations).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label KnownPointFile; + private Label KonwnSFile; + private Button btnSubmitData; + private TextBox txtKnownPath; + private TextBox txtObservationPath; + private Button btnFileView1; + private Button btnFileView2; + private Button btnViewData; + private DataGridView dgvKnownPoints; + private DataGridView dgvObservations; + private Label txtKnownPoints; + } +} \ No newline at end of file diff --git a/Forms/FileInputForm.cs b/Forms/FileInputForm.cs new file mode 100644 index 0000000..6938bc3 --- /dev/null +++ b/Forms/FileInputForm.cs @@ -0,0 +1,299 @@ +using kcsj.Models; +using kcsj.Services; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Text; +using System.Windows.Forms; + +namespace kcsj.Forms +{ + public partial class FileInputForm : Form + { + // 保存解析后的已知点和观测值 + private List knownPoints = new List(); + private List observations = new List(); + + public List ImportedKnownPoints { get; private set; } + public List ImportedObservations { get; private set; } + + public FileInputForm() + { + InitializeComponent(); + + InitGridStyle(); + } + + // 初始化表格样式 + private void InitGridStyle() + { + dgvKnownPoints.ReadOnly = true; + dgvKnownPoints.AllowUserToAddRows = false; + dgvKnownPoints.AllowUserToDeleteRows = false; + dgvKnownPoints.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dgvKnownPoints.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + + dgvObservations.ReadOnly = true; + dgvObservations.AllowUserToAddRows = false; + dgvObservations.AllowUserToDeleteRows = false; + dgvObservations.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dgvObservations.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + } + + // 通用选择 TXT 文件函数 + private string SelectTxtFile(string title) + { + OpenFileDialog dialog = new OpenFileDialog(); + + dialog.Title = title; + dialog.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*"; + dialog.Multiselect = false; + + if (dialog.ShowDialog() == DialogResult.OK) + { + return dialog.FileName; + } + + return ""; + } + + // 浏览已知点文件 + private void btnFileView1_Click(object sender, EventArgs e) + { + string path = SelectTxtFile("选择已知点高程文件"); + + if (path != "") + { + txtKnownPath.Text = path; + } + } + + // 浏览观测值文件 + private void btnFileView2_Click(object sender, EventArgs e) + { + string path = SelectTxtFile("选择观测值文件"); + + if (path != "") + { + txtObservationPath.Text = path; + } + } + + // 按空格、Tab、英文逗号、中文逗号分割每一行 + private string[] SplitLine(string line) + { + return line.Split(new char[] { ' ', '\t', ',', ',' }, + StringSplitOptions.RemoveEmptyEntries); + } + + // 读取已知点 TXT + private List ReadKnownPoints(string filePath) + { + List result = new List(); + HashSet pointNames = new HashSet(); + + string[] lines = File.ReadAllLines(filePath, Encoding.UTF8); + + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i].Trim(); + + if (string.IsNullOrWhiteSpace(line)) + continue; + + if (line.StartsWith("#") || line.StartsWith("//")) + continue; + + string[] parts = SplitLine(line); + + if (parts.Length != 2) + { + throw new Exception($"已知点文件第 {i + 1} 行格式错误,应为:点名 高程"); + } + + string name = parts[0]; + + if (!double.TryParse(parts[1], out double elevation)) + { + throw new Exception($"已知点文件第 {i + 1} 行高程不是有效数字"); + } + + if (pointNames.Contains(name)) + { + throw new Exception($"已知点文件第 {i + 1} 行点名重复:{name}"); + } + + pointNames.Add(name); + result.Add(new KnownPoint(name, elevation)); + } + + if (result.Count == 0) + { + throw new Exception("已知点文件为空或没有有效数据"); + } + + return result; + } + + // 读取观测值 TXT + private List ReadObservations(string filePath) + { + List result = new List(); + + string[] lines = File.ReadAllLines(filePath, Encoding.UTF8); + + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i].Trim(); + + if (string.IsNullOrWhiteSpace(line)) + continue; + + if (line.StartsWith("#") || line.StartsWith("//")) + continue; + + string[] parts = SplitLine(line); + + if (parts.Length != 4) + { + throw new Exception($"观测文件第 {i + 1} 行格式错误,应为:起点 终点 高差 距离"); + } + + string from = parts[0]; + string to = parts[1]; + + if (from == to) + { + throw new Exception($"观测文件第 {i + 1} 行起点和终点不能相同"); + } + + if (!double.TryParse(parts[2], out double heightDiff)) + { + throw new Exception($"观测文件第 {i + 1} 行高差不是有效数字"); + } + + if (!double.TryParse(parts[3], out double distance)) + { + throw new Exception($"观测文件第 {i + 1} 行距离不是有效数字"); + } + + if (distance <= 0) + { + throw new Exception($"观测文件第 {i + 1} 行距离必须大于 0"); + } + + result.Add(new Observation(from, to, heightDiff, distance)); + } + + if (result.Count == 0) + { + throw new Exception("观测文件为空或没有有效数据"); + } + + return result; + } + + // 设置表格中文表头 + private void SetGridHeader() + { + if (dgvKnownPoints.Columns.Count > 0) + { + dgvKnownPoints.Columns["Name"].HeaderText = "点名"; + dgvKnownPoints.Columns["Elevation"].HeaderText = "高程"; + } + + if (dgvObservations.Columns.Count > 0) + { + dgvObservations.Columns["FromPoint"].HeaderText = "起点"; + dgvObservations.Columns["ToPoint"].HeaderText = "终点"; + dgvObservations.Columns["HeightDiff"].HeaderText = "高差"; + dgvObservations.Columns["Distance"].HeaderText = "距离"; + } + } + + // 点击“预览数据” + private void btnViewData_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(txtKnownPath.Text)) + { + MessageBox.Show("请先选择已知点高程文件"); + return; + } + + if (string.IsNullOrWhiteSpace(txtObservationPath.Text)) + { + MessageBox.Show("请先选择观测值文件"); + return; + } + + knownPoints = ReadKnownPoints(txtKnownPath.Text); + observations = ReadObservations(txtObservationPath.Text); + + dgvKnownPoints.DataSource = null; + dgvKnownPoints.DataSource = knownPoints; + + dgvObservations.DataSource = null; + dgvObservations.DataSource = observations; + + SetGridHeader(); + + MessageBox.Show("数据预览成功!"); + LogService.AddLog("数据预览成功!"); + + } + catch (Exception ex) + { + + dgvKnownPoints.DataSource = null; + dgvObservations.DataSource = null; + + MessageBox.Show($"数据预览失败:{ex.Message} "); + LogService.AddLog($"数据预览失败:{ex.Message} "); + } + } + + private void btnSubmitData_Click(object sender, EventArgs e) + { + try + { + // 如果还没有点“预览数据”,这里自动读取一次 + if (knownPoints == null || knownPoints.Count == 0 || + observations == null || observations.Count == 0) + { + if (string.IsNullOrWhiteSpace(txtKnownPath.Text)) + { + MessageBox.Show("请先选择已知点高程文件"); + return; + } + + if (string.IsNullOrWhiteSpace(txtObservationPath.Text)) + { + MessageBox.Show("请先选择观测值文件"); + return; + } + + knownPoints = ReadKnownPoints(txtKnownPath.Text); + observations = ReadObservations(txtObservationPath.Text); + } + + // 把数据交给主窗体 + ImportedKnownPoints = knownPoints; + ImportedObservations = observations; + + MessageBox.Show("数据导入成功!"); + LogService.AddLog("数据导入成功!"); + + this.DialogResult = DialogResult.OK; + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show("导入失败:" + ex.Message); + LogService.AddLog("导入失败:" + ex.Message); + } + } + } +} \ No newline at end of file diff --git a/Forms/FileInputForm.resx b/Forms/FileInputForm.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Forms/FileInputForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Forms/MainForm.Designer.cs b/Forms/MainForm.Designer.cs new file mode 100644 index 0000000..ea966b0 --- /dev/null +++ b/Forms/MainForm.Designer.cs @@ -0,0 +1,263 @@ +namespace kcsj.Forms +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + MainTitle = new Label(); + btnDataInput = new Button(); + btnDataInspect = new Button(); + btnStartAdjust = new Button(); + button2 = new Button(); + button3 = new Button(); + LOG = new RichTextBox(); + MainLog = new Label(); + ClearLog = new Button(); + menuStrip1 = new MenuStrip(); + 数据ToolStripMenuItem = new ToolStripMenuItem(); + 数据输入ToolStripMenuItem = new ToolStripMenuItem(); + 从文件ToolStripMenuItem = new ToolStripMenuItem(); + 手动输入ToolStripMenuItem = new ToolStripMenuItem(); + 删除当前数据ToolStripMenuItem = new ToolStripMenuItem(); + 数据检查ToolStripMenuItem = new ToolStripMenuItem(); + 开始平差ToolStripMenuItem = new ToolStripMenuItem(); + 查看结果ToolStripMenuItem = new ToolStripMenuItem(); + 输出报告ToolStripMenuItem = new ToolStripMenuItem(); + 关于ToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // MainTitle + // + MainTitle.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + MainTitle.AutoSize = true; + MainTitle.Font = new Font("微软雅黑", 12F, FontStyle.Bold, GraphicsUnit.Point, 134); + MainTitle.Location = new Point(236, 55); + MainTitle.Name = "MainTitle"; + MainTitle.Size = new Size(182, 31); + MainTitle.TabIndex = 0; + MainTitle.Text = "水准网平差程序"; + MainTitle.TextAlign = ContentAlignment.TopCenter; + // + // btnDataInput + // + btnDataInput.Location = new Point(30, 94); + btnDataInput.Name = "btnDataInput"; + btnDataInput.Size = new Size(202, 64); + btnDataInput.TabIndex = 1; + btnDataInput.Text = "数据输入"; + btnDataInput.UseVisualStyleBackColor = true; + btnDataInput.Click += btnDataInput_Click; + // + // btnDataInspect + // + btnDataInspect.Location = new Point(30, 164); + btnDataInspect.Name = "btnDataInspect"; + btnDataInspect.Size = new Size(202, 64); + btnDataInspect.TabIndex = 2; + btnDataInspect.Text = "数据检查"; + btnDataInspect.UseVisualStyleBackColor = true; + // + // btnStartAdjust + // + btnStartAdjust.Location = new Point(30, 234); + btnStartAdjust.Name = "btnStartAdjust"; + btnStartAdjust.Size = new Size(202, 64); + btnStartAdjust.TabIndex = 3; + btnStartAdjust.Text = "开始平差"; + btnStartAdjust.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(30, 304); + button2.Name = "button2"; + button2.Size = new Size(202, 64); + button2.TabIndex = 4; + button2.Text = "查看结果"; + button2.UseVisualStyleBackColor = true; + // + // button3 + // + button3.Location = new Point(30, 374); + button3.Name = "button3"; + button3.Size = new Size(202, 64); + button3.TabIndex = 5; + button3.Text = "输出报告"; + button3.UseVisualStyleBackColor = true; + // + // LOG + // + LOG.Location = new Point(275, 152); + LOG.Name = "LOG"; + LOG.ReadOnly = true; + LOG.Size = new Size(356, 286); + LOG.TabIndex = 6; + LOG.Text = ""; + // + // MainLog + // + MainLog.AutoSize = true; + MainLog.Font = new Font("微软雅黑", 10.5F, FontStyle.Bold, GraphicsUnit.Point, 134); + MainLog.Location = new Point(340, 101); + MainLog.Name = "MainLog"; + MainLog.Size = new Size(96, 28); + MainLog.TabIndex = 7; + MainLog.Text = "运行日志"; + // + // ClearLog + // + ClearLog.Location = new Point(456, 101); + ClearLog.Name = "ClearLog"; + ClearLog.Size = new Size(112, 34); + ClearLog.TabIndex = 8; + ClearLog.Text = "清除日志"; + ClearLog.UseVisualStyleBackColor = true; + ClearLog.Click += ClearLog_Click; + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(24, 24); + menuStrip1.Items.AddRange(new ToolStripItem[] { 数据ToolStripMenuItem, 开始平差ToolStripMenuItem, 查看结果ToolStripMenuItem, 输出报告ToolStripMenuItem, 关于ToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(644, 32); + menuStrip1.TabIndex = 9; + menuStrip1.Text = "menuStrip1"; + // + // 数据ToolStripMenuItem + // + 数据ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 数据输入ToolStripMenuItem, 删除当前数据ToolStripMenuItem, 数据检查ToolStripMenuItem }); + 数据ToolStripMenuItem.Name = "数据ToolStripMenuItem"; + 数据ToolStripMenuItem.Size = new Size(98, 28); + 数据ToolStripMenuItem.Text = "数据管理"; + // + // 数据输入ToolStripMenuItem + // + 数据输入ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 从文件ToolStripMenuItem, 手动输入ToolStripMenuItem }); + 数据输入ToolStripMenuItem.Name = "数据输入ToolStripMenuItem"; + 数据输入ToolStripMenuItem.Size = new Size(270, 34); + 数据输入ToolStripMenuItem.Text = "数据输入"; + // + // 从文件ToolStripMenuItem + // + 从文件ToolStripMenuItem.Name = "从文件ToolStripMenuItem"; + 从文件ToolStripMenuItem.Size = new Size(270, 34); + 从文件ToolStripMenuItem.Text = "从文件"; + 从文件ToolStripMenuItem.Click += 从文件ToolStripMenuItem_Click; + // + // 手动输入ToolStripMenuItem + // + 手动输入ToolStripMenuItem.Name = "手动输入ToolStripMenuItem"; + 手动输入ToolStripMenuItem.Size = new Size(270, 34); + 手动输入ToolStripMenuItem.Text = "手动输入"; + // + // 删除当前数据ToolStripMenuItem + // + 删除当前数据ToolStripMenuItem.Name = "删除当前数据ToolStripMenuItem"; + 删除当前数据ToolStripMenuItem.Size = new Size(270, 34); + 删除当前数据ToolStripMenuItem.Text = "删除当前数据"; + // + // 数据检查ToolStripMenuItem + // + 数据检查ToolStripMenuItem.Name = "数据检查ToolStripMenuItem"; + 数据检查ToolStripMenuItem.Size = new Size(270, 34); + 数据检查ToolStripMenuItem.Text = "数据检查"; + // + // 开始平差ToolStripMenuItem + // + 开始平差ToolStripMenuItem.Name = "开始平差ToolStripMenuItem"; + 开始平差ToolStripMenuItem.Size = new Size(98, 28); + 开始平差ToolStripMenuItem.Text = "开始平差"; + // + // 查看结果ToolStripMenuItem + // + 查看结果ToolStripMenuItem.Name = "查看结果ToolStripMenuItem"; + 查看结果ToolStripMenuItem.Size = new Size(98, 28); + 查看结果ToolStripMenuItem.Text = "查看结果"; + // + // 输出报告ToolStripMenuItem + // + 输出报告ToolStripMenuItem.Name = "输出报告ToolStripMenuItem"; + 输出报告ToolStripMenuItem.Size = new Size(98, 28); + 输出报告ToolStripMenuItem.Text = "输出报告"; + // + // 关于ToolStripMenuItem + // + 关于ToolStripMenuItem.Name = "关于ToolStripMenuItem"; + 关于ToolStripMenuItem.Size = new Size(62, 28); + 关于ToolStripMenuItem.Text = "关于"; + // + // MainForm + // + AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(644, 470); + Controls.Add(ClearLog); + Controls.Add(MainLog); + Controls.Add(LOG); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(btnStartAdjust); + Controls.Add(btnDataInspect); + Controls.Add(btnDataInput); + Controls.Add(MainTitle); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + MaximizeBox = false; + Name = "MainForm"; + Text = "水准网平差程序"; + Load += MainForm_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label MainTitle; + private Button btnDataInput; + private Button btnDataInspect; + private Button btnStartAdjust; + private Button button2; + private Button button3; + private RichTextBox LOG; + private Label MainLog; + private Button ClearLog; + private MenuStrip menuStrip1; + private ToolStripMenuItem 数据ToolStripMenuItem; + private ToolStripMenuItem 数据输入ToolStripMenuItem; + private ToolStripMenuItem 从文件ToolStripMenuItem; + private ToolStripMenuItem 手动输入ToolStripMenuItem; + private ToolStripMenuItem 删除当前数据ToolStripMenuItem; + private ToolStripMenuItem 数据检查ToolStripMenuItem; + private ToolStripMenuItem 开始平差ToolStripMenuItem; + private ToolStripMenuItem 查看结果ToolStripMenuItem; + private ToolStripMenuItem 输出报告ToolStripMenuItem; + private ToolStripMenuItem 关于ToolStripMenuItem; + } +} \ No newline at end of file diff --git a/Forms/MainForm.cs b/Forms/MainForm.cs new file mode 100644 index 0000000..33f8dad --- /dev/null +++ b/Forms/MainForm.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using kcsj.Services; + +namespace kcsj.Forms +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + private void btnDataInput_Click(object sender, EventArgs e) + { + DataInputForm form = new DataInputForm(); + form.ShowDialog(); + } + + private void MainForm_Load(object sender, EventArgs e) + { + LogService.OnLog += ShowLog; + + LogService.AddLog("程序启动成功。"); + } + private void ShowLog(string message) + { + LOG.AppendText(message + "\r\n"); + LOG.ScrollToCaret(); + } + + private void ClearLog_Click(object sender, EventArgs e) + { + LOG.Clear(); + } + + private void 从文件ToolStripMenuItem_Click(object sender, EventArgs e) + { + FileInputForm form = new FileInputForm(); + + form.ShowDialog(); + } + } +} diff --git a/Forms/MainForm.resx b/Forms/MainForm.resx new file mode 100644 index 0000000..b48baf1 --- /dev/null +++ b/Forms/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Models/KnownPoint.cs b/Models/KnownPoint.cs new file mode 100644 index 0000000..7c3db9f --- /dev/null +++ b/Models/KnownPoint.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace kcsj.Models +{ + public class KnownPoint + { + public string Name { get; set; } + public double Elevation { get; set; } + + public KnownPoint(string name, double elevation) + { + Name = name; + Elevation = elevation; + } + } +} diff --git a/Models/Observation.cs b/Models/Observation.cs new file mode 100644 index 0000000..0fc3143 --- /dev/null +++ b/Models/Observation.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace kcsj.Models +{ + public class Observation + { + public string FromPoint { get; set; } + public string ToPoint { get; set; } + public double HeightDiff { get; set; } + public double Distance { get; set; } + + public Observation(string fromPoint, string toPoint, double heightDiff, double distance) + { + FromPoint = fromPoint; + ToPoint = toPoint; + HeightDiff = heightDiff; + Distance = distance; + } + } +} diff --git a/Program.cs b/Program.cs index c58d6de..063dbe4 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,5 @@ +using kcsj.Forms; + namespace kcsj { internal static class Program @@ -11,7 +13,7 @@ namespace kcsj // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new Forms.MainForm()); } } } \ No newline at end of file diff --git a/Services/LogService.cs b/Services/LogService.cs new file mode 100644 index 0000000..cb38d88 --- /dev/null +++ b/Services/LogService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace kcsj.Services +{ + public static class LogService + { + public static event Action OnLog; + public static void AddLog(string message) + { + string time = DateTime.Now.ToString("HH:mm:ss"); + OnLog?.Invoke($"[{time}] {message}"); + } + + } +}