界面设计

主程序代码 Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Matrix;
namespace indirect_adjustment
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
string localFilePath;
private void button1_Click(object sender, EventArgs e)
{
//选择文件
OpenFileDialog openFileDialog = new OpenFileDialog();
//打开的文件选择对话框上的标题
openFileDialog.Title = "请选择文件";
//设置文件类型
openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
//设置默认文件类型显示顺序
openFileDialog.FilterIndex = 1;
//保存对话框是否记忆上次打开的目录
openFileDialog.RestoreDirectory = true;
//设置是否允许多选
openFileDialog.Multiselect = false;
//按下确定选择的按钮
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//获得文件路径
localFilePath = openFileDialog.FileName.ToString();
//获取文件路径,不带文件名
string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
//获取文件名,带后缀名,不带路径
string fileNameWithSuffix = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
//去除文件后缀名
string fileNameWithoutSuffix = fileNameWithSuffix.Substring(0, fileNameWithSuffix.LastIndexOf("."));
//在文件名前加上时间
string fileNameWithTime = DateTime.Now.ToString("yyyy-MM-dd ");
//在文件名里加字符
string newFileName = localFilePath.Insert(1, "dameng");
MessageBox.Show("读取成功");
}
}
private void button2_Click(object sender, EventArgs e)
{
//读取数据
StreamReader rd = File.OpenText(localFilePath);
string s = rd.ReadLine();
string[] ss = s.Split(',');
int row = int.Parse(ss[0]); //行数
int col = int.Parse(ss[1]); //每行数据的个数
double[,] B = new double[row, col]; //数组
for (int i = 0; i < row; i++) //读入数据并赋予数组
{
string line = rd.ReadLine();
string[] data = line.Split(',');
for (int j = 0; j < col; j++)
{
B[i, j] = double.Parse(data[j]);
}
}
string a1 = rd.ReadLine();
string[] A1 = a1.Split(',');
double[,] I = new double[1,A1.GetLength(0)];
for (int i = 0; i < A1.GetLength(0); i++)
{
I[0,i] = double.Parse(A1[i]);
}
I = Ope.Tras(I);
string a2 = rd.ReadLine();
string[] A2 = a2.Split(',');
double[] S = new double[A2.GetLength(0)];
for (int i = 0; i < A2.GetLength(0); i++)
{
S[i] = double.Parse(A2[i]);
}
string a3 = rd.ReadLine();
string[] A3 = a3.Split(',');
double[,] X0 = new double[1,A3.GetLength(0)];
for (int i = 0; i < A3.GetLength(0); i++)
{
X0[0,i] = double.Parse(A3[i]);
}
X0 = Ope.Tras(X0);
string a4 = rd.ReadLine();
string[] A4 = a4.Split(',');
double[,] L = new double[1,A4.GetLength(0)];
for (int i = 0; i < A4.GetLength(0); i++)
{
L[0,i] = double.Parse(A4[i]);
}
L = Ope.Tras(L);
double[,] P = new double[S.GetLength(0), S.GetLength(0)];
P = Ope.Inv(Ope.Diag(S));
double[,] N = new double[B.GetLength(1), B.GetLength(1)];
N = Ope.Mul(Ope.Mul(Ope.Tras(B), P), B);
double[,] W = new double[B.GetLength(1), I.GetLength(0)];
W = Ope.Mul(Ope.Mul(Ope.Tras(B), P), I);
double[,] Delt_x = new double[N.GetLength(0), W.GetLength(1)];
Delt_x = Ope.Mul(Ope.Inv(N), W);
double[,] V = new double[I.GetLength(0), I.GetLength(1)];
V = Ope.Sub(Ope.Mul(B, Delt_x), I);
double n = V.GetLength(0);
double t = Delt_x.GetLength(0);
double r = n - t;
double[,] A5 = new double[V.GetLength(1), V.GetLength(1)];
A5 = Ope.Mul(Ope.Mul(Ope.Tras(V), P), V);
double a5=A5[0,0];
double sgm = Math.Sqrt(a5 / r);
double[,] Lp = new double[L.GetLength(0), L.GetLength(1)];
Lp = Ope.Add(L,Ope.Div(V,1000));
double[,] Xp = new double[X0.GetLength(0), X0.GetLength(1)];
Xp = Ope.Add(X0, Delt_x);
double[,] Qxx = new double[N.GetLength(0), N.GetLength(1)];
Qxx = Ope.Inv(N);
double[,] Dxx = new double[Qxx.GetLength(0), Qxx.GetLength(1)];
for (int i = 0; i < Qxx.GetLength(0); i++)
{
for (int j = 0; j < Qxx.GetLength(0); j++)
{
Dxx[i, j] = Math.Pow(sgm, 2) * Qxx[i, j];
}
}
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
localFilePath = saveFileDialog.FileName.ToString();
MessageBox.Show("保存成功");
}
double[] ID = { 1, 2, 3, 4, 5, 6, 7 };
// 创建文件
FileStream fs = new FileStream(localFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs); // 创建写入流
sw.WriteLine("\t\t\t\t\t\t观测信息表\n");
sw.WriteLine("id\t\t系数阵B\t\t常数项\t\t距离(km)\t观测值(m)\t改正数(mm)\t平差值(m)\n");
for (int i = 0; i < 7; i++)
{
sw.Write( ID[i]+ "\t");
for (int j = 0; j < 3; j++)
{
sw.Write(B[i,j] + "\t");
}
sw.Write(I[i,0] + "\t\t");
sw.Write(S[i] + "\t\t");
sw.Write(L[i,0] + "\t\t");
sw.Write(Math.Round(V[i,0],3) + "\t\t");
sw.Write(Math.Round(Lp[i,0],3) );
sw.WriteLine();
}
sw.Write("单位权中误差(mm)=" + Math.Round(sgm,3));
sw.WriteLine();
sw.Write("\t\t\t参数平差值及协方差阵");
sw.WriteLine();
sw.WriteLine("id\t参数平差值(m)\t改正数(mm)\t\t协方差阵\n");
for (int i = 0; i < 3; i++)
{
sw.Write(ID[i] + "\t");
sw.Write(Math.Round(Xp[i,0],3) + "\t\t");
sw.Write(Math.Round(Delt_x[i,0],3) + "\t\t");
for (int j = 0; j < 3; j++)
{
sw.Write(Math.Round(Dxx[i, j],3)+"\t");
}
sw.WriteLine();
}
sw.Close(); //关闭文件
}
}
}