C#水准网间接平差简单程序

这是一个使用C#编写的水准网间接平差简单程序,通过读取txt文件数据,计算预估高差、矩阵B、权矩阵P,并进行高斯-约旦消元法求解,最后输出中误差结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog duq = new OpenFileDialog();
            duq.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            duq.Title = "Open txt File";

            if (duq.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string sr = duq.FileName;
            string[] st = File.ReadAllLines(sr);

            dataGridView1.Rows.Clear();

            foreach (string line in st)
            {
                    string[] fields = line.Split(',');
                    dataGridView1.Rows.Add(fields);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog duq2 = new OpenFileDialog();
            duq2.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            duq2.Title = "Open txt File";

            if (duq2.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string sr = duq2.FileName;
            string[] st = File.ReadAllLines(sr);

            dataGridView2.Rows.Clear();

            foreach (string line in st)
            {
                string[] fields = line.Split(',');
                dataGridView2.Rows.Add(fields);
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            List<string> x = new List<string>();//总点
            for (int i = 0; i < dataGridView1.RowCount - 1; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    x.Add(dataGridView1.Rows[i].Cells[j].Value.ToString());
                }
            }

            string[] x1 = x.Distinct().ToArray();//数组去重
            Array.Sort(x1);  // 对数组进行排序操作
            string message = string.Format("点为:{0}", string.Join(", ", x1));
            textBox1.Text = message;
            int count = x1.Length;
            string newstring = $"点数为{count}";
            textBox1.Text = textBox1.Text +"\r\n" +newstring;
            string[] y=new string[dataGridView2.RowCount-1];//已知点
            for (int i = 0; i < dataGridView2.RowCount - 1; i++)
            {
                y[i] = dataGridView2.Rows[i].Cells[0].Value.ToString();
            }
            string newtext = string.Format("已知点为:{0}", string.Join(",", y));
            textBox1.Text = textBox1.Text + "\r\n" + newtext;
            //计算预估高差
            double ha = Convert.ToDouble(dataGrid

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值