数据输入窗体及相关代码
This commit is contained in:
@@ -277,14 +277,17 @@ namespace kcsj.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 把数据交给主窗体
|
// 把数据交给主窗体
|
||||||
|
DataStore.SetData(knownPoints, observations, "文件导入");
|
||||||
|
|
||||||
ImportedKnownPoints = knownPoints;
|
ImportedKnownPoints = knownPoints;
|
||||||
ImportedObservations = observations;
|
ImportedObservations = observations;
|
||||||
|
|
||||||
MessageBox.Show("数据导入成功!");
|
MessageBox.Show("数据导入成功!");
|
||||||
LogService.AddLog("数据导入成功!");
|
LogService.AddLog("文件数据导入成功!");
|
||||||
|
|
||||||
this.DialogResult = DialogResult.OK;
|
this.DialogResult = DialogResult.OK;
|
||||||
this.Close();
|
this.Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Generated
+1
@@ -82,6 +82,7 @@
|
|||||||
btnDataInspect.TabIndex = 2;
|
btnDataInspect.TabIndex = 2;
|
||||||
btnDataInspect.Text = "数据检查";
|
btnDataInspect.Text = "数据检查";
|
||||||
btnDataInspect.UseVisualStyleBackColor = true;
|
btnDataInspect.UseVisualStyleBackColor = true;
|
||||||
|
btnDataInspect.Click += btnDataInspect_Click;
|
||||||
//
|
//
|
||||||
// btnStartAdjust
|
// btnStartAdjust
|
||||||
//
|
//
|
||||||
|
|||||||
+35
-3
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using kcsj.Models;
|
||||||
|
using kcsj.Services;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@@ -7,12 +9,12 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using kcsj.Services;
|
|
||||||
|
|
||||||
namespace kcsj.Forms
|
namespace kcsj.Forms
|
||||||
{
|
{
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -45,7 +47,12 @@ namespace kcsj.Forms
|
|||||||
{
|
{
|
||||||
FileInputForm form = new FileInputForm();
|
FileInputForm form = new FileInputForm();
|
||||||
|
|
||||||
form.ShowDialog();
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LogService.AddLog("主窗体已接收文件导入数据。");
|
||||||
|
LogService.AddLog($"已知点数量:{DataStore.KnownPoints.Count}");
|
||||||
|
LogService.AddLog($"观测数据数量:{DataStore.Observations.Count}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void 手动输入ToolStripMenuItem_Click(object sender, EventArgs e)
|
private void 手动输入ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
@@ -74,5 +81,30 @@ namespace kcsj.Forms
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnDataInspect_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DataCheckResult result = DataCheck.Check(DataStore.KnownPoints, DataStore.Observations);
|
||||||
|
|
||||||
|
LogService.AddLog(result.ToLogText());
|
||||||
|
LogService.AddLog(Environment.NewLine);
|
||||||
|
|
||||||
|
if (!result.IsValid)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
"数据检查未通过,请查看日志信息。",
|
||||||
|
"数据检查",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Warning);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(
|
||||||
|
"数据检查通过,可以进行平差计算。",
|
||||||
|
"数据检查",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+13
-13
@@ -34,7 +34,7 @@
|
|||||||
PointName = new DataGridViewTextBoxColumn();
|
PointName = new DataGridViewTextBoxColumn();
|
||||||
Elevation = new DataGridViewTextBoxColumn();
|
Elevation = new DataGridViewTextBoxColumn();
|
||||||
GroupObservation = new GroupBox();
|
GroupObservation = new GroupBox();
|
||||||
dataGridView1 = new DataGridView();
|
dgvObservationInput = new DataGridView();
|
||||||
StartPoint = new DataGridViewTextBoxColumn();
|
StartPoint = new DataGridViewTextBoxColumn();
|
||||||
EndPoint = new DataGridViewTextBoxColumn();
|
EndPoint = new DataGridViewTextBoxColumn();
|
||||||
HeightDifference = new DataGridViewTextBoxColumn();
|
HeightDifference = new DataGridViewTextBoxColumn();
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
GroupKnown.SuspendLayout();
|
GroupKnown.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dgvKnownInput).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dgvKnownInput).BeginInit();
|
||||||
GroupObservation.SuspendLayout();
|
GroupObservation.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dgvObservationInput).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// TitleManualInput
|
// TitleManualInput
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
//
|
//
|
||||||
// GroupObservation
|
// GroupObservation
|
||||||
//
|
//
|
||||||
GroupObservation.Controls.Add(dataGridView1);
|
GroupObservation.Controls.Add(dgvObservationInput);
|
||||||
GroupObservation.Location = new Point(481, 50);
|
GroupObservation.Location = new Point(481, 50);
|
||||||
GroupObservation.Name = "GroupObservation";
|
GroupObservation.Name = "GroupObservation";
|
||||||
GroupObservation.Size = new Size(771, 408);
|
GroupObservation.Size = new Size(771, 408);
|
||||||
@@ -101,15 +101,15 @@
|
|||||||
GroupObservation.TabStop = false;
|
GroupObservation.TabStop = false;
|
||||||
GroupObservation.Text = "观测值";
|
GroupObservation.Text = "观测值";
|
||||||
//
|
//
|
||||||
// dataGridView1
|
// dgvObservationInput
|
||||||
//
|
//
|
||||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dgvObservationInput.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView1.Columns.AddRange(new DataGridViewColumn[] { StartPoint, EndPoint, HeightDifference, Distance });
|
dgvObservationInput.Columns.AddRange(new DataGridViewColumn[] { StartPoint, EndPoint, HeightDifference, Distance });
|
||||||
dataGridView1.Location = new Point(15, 29);
|
dgvObservationInput.Location = new Point(15, 29);
|
||||||
dataGridView1.Name = "dataGridView1";
|
dgvObservationInput.Name = "dgvObservationInput";
|
||||||
dataGridView1.RowHeadersWidth = 62;
|
dgvObservationInput.RowHeadersWidth = 62;
|
||||||
dataGridView1.Size = new Size(730, 355);
|
dgvObservationInput.Size = new Size(730, 355);
|
||||||
dataGridView1.TabIndex = 0;
|
dgvObservationInput.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// StartPoint
|
// StartPoint
|
||||||
//
|
//
|
||||||
@@ -175,7 +175,7 @@
|
|||||||
GroupKnown.ResumeLayout(false);
|
GroupKnown.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)dgvKnownInput).EndInit();
|
((System.ComponentModel.ISupportInitialize)dgvKnownInput).EndInit();
|
||||||
GroupObservation.ResumeLayout(false);
|
GroupObservation.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
((System.ComponentModel.ISupportInitialize)dgvObservationInput).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
private GroupBox GroupObservation;
|
private GroupBox GroupObservation;
|
||||||
private DataGridViewTextBoxColumn PointName;
|
private DataGridViewTextBoxColumn PointName;
|
||||||
private DataGridViewTextBoxColumn Elevation;
|
private DataGridViewTextBoxColumn Elevation;
|
||||||
private DataGridView dataGridView1;
|
private DataGridView dgvObservationInput;
|
||||||
private DataGridViewTextBoxColumn StartPoint;
|
private DataGridViewTextBoxColumn StartPoint;
|
||||||
private DataGridViewTextBoxColumn EndPoint;
|
private DataGridViewTextBoxColumn EndPoint;
|
||||||
private DataGridViewTextBoxColumn HeightDifference;
|
private DataGridViewTextBoxColumn HeightDifference;
|
||||||
|
|||||||
+143
-1
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using kcsj.Models;
|
||||||
|
using kcsj.Services;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@@ -12,6 +14,117 @@ namespace kcsj.Forms
|
|||||||
{
|
{
|
||||||
public partial class ManualInputForm : Form
|
public partial class ManualInputForm : Form
|
||||||
{
|
{
|
||||||
|
private string GetCellString(DataGridViewRow row, string columnName)
|
||||||
|
{
|
||||||
|
object value = row.Cells[columnName].Value;
|
||||||
|
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.ToString().Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<KnownPoint> ReadKnownPointsFromGrid()
|
||||||
|
{
|
||||||
|
List<KnownPoint> knownPoints = new List<KnownPoint>();
|
||||||
|
|
||||||
|
foreach (DataGridViewRow row in dgvKnownInput.Rows)
|
||||||
|
{
|
||||||
|
if (row.IsNewRow)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string pointName = GetCellString(row, "PointName");
|
||||||
|
string elevationText = GetCellString(row, "Elevation");
|
||||||
|
|
||||||
|
if (pointName == "" && elevationText == "")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointName == "")
|
||||||
|
{
|
||||||
|
throw new Exception("已知点点名不能为空。");
|
||||||
|
}
|
||||||
|
|
||||||
|
double elevation;
|
||||||
|
|
||||||
|
if (!double.TryParse(elevationText, out elevation))
|
||||||
|
{
|
||||||
|
throw new Exception("已知点 " + pointName + " 的高程不是有效数字。");
|
||||||
|
}
|
||||||
|
|
||||||
|
KnownPoint point = new KnownPoint(pointName, elevation);
|
||||||
|
knownPoints.Add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (knownPoints.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("至少需要输入一个已知点。");
|
||||||
|
}
|
||||||
|
|
||||||
|
return knownPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Observation> ReadObservationsFromGrid()
|
||||||
|
{
|
||||||
|
List<Observation> observations = new List<Observation>();
|
||||||
|
|
||||||
|
foreach (DataGridViewRow row in dgvObservationInput.Rows)
|
||||||
|
{
|
||||||
|
if (row.IsNewRow)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string fromPoint = GetCellString(row, "StartPoint");
|
||||||
|
string toPoint = GetCellString(row, "EndPoint");
|
||||||
|
string heightDiffText = GetCellString(row, "HeightDifference");
|
||||||
|
string distanceText = GetCellString(row, "Distance");
|
||||||
|
|
||||||
|
if (fromPoint == "" && toPoint == "" && heightDiffText == "" && distanceText == "")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromPoint == "")
|
||||||
|
{
|
||||||
|
throw new Exception("观测数据起点不能为空。");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toPoint == "")
|
||||||
|
{
|
||||||
|
throw new Exception("观测数据终点不能为空。");
|
||||||
|
}
|
||||||
|
|
||||||
|
double heightDiff;
|
||||||
|
double distance;
|
||||||
|
|
||||||
|
if (!double.TryParse(heightDiffText, out heightDiff))
|
||||||
|
{
|
||||||
|
throw new Exception(fromPoint + " 到 " + toPoint + " 的高差不是有效数字。");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!double.TryParse(distanceText, out distance))
|
||||||
|
{
|
||||||
|
throw new Exception(fromPoint + " 到 " + toPoint + " 的路线长不是有效数字。");
|
||||||
|
}
|
||||||
|
|
||||||
|
Observation observation = new Observation(fromPoint, toPoint, heightDiff, distance);
|
||||||
|
observations.Add(observation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (observations.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("至少需要输入一条观测数据。");
|
||||||
|
}
|
||||||
|
|
||||||
|
return observations;
|
||||||
|
}
|
||||||
|
|
||||||
public ManualInputForm()
|
public ManualInputForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -19,12 +132,41 @@ namespace kcsj.Forms
|
|||||||
|
|
||||||
private void btnCancel_Click(object sender, EventArgs e)
|
private void btnCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
MessageBox.Show("您取消了输入!");
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnOK_Click(object sender, EventArgs e)
|
private void btnOK_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<KnownPoint> knownPoints = ReadKnownPointsFromGrid();
|
||||||
|
List<Observation> observations = ReadObservationsFromGrid();
|
||||||
|
|
||||||
|
DataStore.SetData(knownPoints, observations, "手动输入");
|
||||||
|
|
||||||
|
MessageBox.Show(
|
||||||
|
"手动输入数据已保存",
|
||||||
|
"提示",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Information
|
||||||
|
);
|
||||||
|
|
||||||
|
LogService.AddLog("手动输入数据。已知点数量: " + knownPoints.Count + ",观测数据数量: " + observations.Count);
|
||||||
|
this.DialogResult = DialogResult.OK;
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
ex.Message,
|
||||||
|
"输入错误",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Warning
|
||||||
|
);
|
||||||
|
|
||||||
|
LogService.AddLog("手动输入数据时发生错误: " + ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user