You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
6.8 KiB
C#

using DevExpress.Mvvm.POCO;
using DevExpress.Xpo.Helpers;
using IpcClassNs;
using IPCLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RunWellSectionApp
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
// IpcTcpClass m_ipcWellPole = null;
public string workDirPath = "";
public string prjfileNamePath = "";
public Form1()
{
InitializeComponent();
// InitIpc();
}
void InitIpc()
{
//if(m_ipcWellPole != null)
//{
// if(m_ipcWellPole.m_bConn == false)
// {
// m_ipcWellPole.ReBuildTcp();
// m_ipcWellPole.m_tcp.PacketReceived += OnPacketReceived;
// m_ipcWellPole.m_tcp.Connected += OnConnected;
// m_ipcWellPole.m_tcp.Disconnected += OnDisconnected;
// m_ipcWellPole.m_tcp.ErrorOccurred += OnErrorOccurred;
// }
//}
//else
//{
// m_ipcWellPole = new IpcTcpClass();
// m_ipcWellPole.m_tcp.PacketReceived += OnPacketReceived;
// m_ipcWellPole.m_tcp.Connected += OnConnected;
// m_ipcWellPole.m_tcp.Disconnected += OnDisconnected;
// m_ipcWellPole.m_tcp.ErrorOccurred += OnErrorOccurred;
//}
}
//private void OnConnected()
//{
// if (InvokeRequired) { Invoke(new Action(OnConnected)); return; }
// m_ipcWellPole.m_bConn = true;
// UpdateStatus("B 已连接");
//}
//private void OnDisconnected(string msg)
//{
// if (InvokeRequired) { Invoke(new Action(() => OnDisconnected(msg))); return; }
// UpdateStatus($"断开:{msg}");
// m_ipcWellPole.ReleaseTcp();
//}
//private void OnErrorOccurred(string msg, Exception ex)
//{
// if (InvokeRequired)
// {
// if (InvokeRequired) { Invoke(new Action(() => OnErrorOccurred(msg, ex))); return; }
// return;
// }
// string errorDetail = $"{msg}\n{ex.GetType().Name}: {ex.Message}";
// if (ex is SocketException sockEx)
// {
// errorDetail += $"\nSocket 错误码:{sockEx.SocketErrorCode} ({sockEx.NativeErrorCode})";
// }
// UpdateStatus($"错误:{errorDetail}");
// m_ipcWellPole.ReleaseTcp();
//}
//private void OnPacketReceived(IPCLib.HeartbeatPacket packet)
//{
// // 线程安全更新 UI
// if (InvokeRequired) { Invoke(new Action(() => OnPacketReceived(packet))); return; }
// //logBox.AppendText($"[{DateTime.Now:HH:mm:ss}] 收到 B 心跳 Seq:{packet.SequenceId}\n");
// // 处理 B 发来的业务数据
// if (!string.IsNullOrEmpty(packet.Payload))
// {
// // logBox.AppendText($" >>> 业务数据:{packet.Payload}\n", Color.Blue);
// UpdateStatus(packet.Payload);
// }
// if (packet.Payload != null && packet.Payload.Length == 0)
// {
// string msg = $"hearg msg id= {packet.SequenceId}";
// UpdateStatus(msg);
// }
//}
private void UpdateStatus(string msg)
{
if (InvokeRequired) { Invoke(new Action(() => UpdateStatus(msg))); return; }
// labelStatus.Text = msg;
// logBox.AppendText($"[System] {msg}\n");
this.label1.Text = msg;
}
// 发送数据给 B (放入队列,由心跳带走)
private void btnSendData_Click(object sender, EventArgs e)
{
//if (_tcp != null)
//{
// _tcp.PushData(txtData.Text);
// // logBox.AppendText($"[System] 数据已放入发送队列\n");
// txtData.Clear();
//}
}
private void selectDBBtn_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog() // XtraOpenFileDialog()
{
Filter = "项目文件(*.kep)|*.kep",
RestoreDirectory = false,
Multiselect = false,
InitialDirectory = workDirPath,
};
if (ofd.ShowDialog() != DialogResult.OK)
{
return;
}
else
{
prjfileNamePath = ofd.FileName;
workDirPath = Path.GetDirectoryName(prjfileNamePath);
textBoxPath.Text = prjfileNamePath;
// this.wellDataTreeList.OpenWorkData(ofd.FileName);
}
}
//async Task
private async void runAppBtn_Click(object sender, EventArgs e)
{
startWellPole();
//runWellPole("", "");
//string fileName = ".\\KEVisualization_wellPole.exe";
//if (!File.Exists(fileName))
//{
// MessageBox.Show("没有井剖面启动程序");
// return;
//}
//InitIpc();
//m_ipcWellPole.m_Port = PortHelper.FindAvailablePort(6790);
//await m_ipcWellPole.m_tcp.StartServerAsync(m_ipcWellPole.m_Port);
//string args = $" \"workAreaPath={prjfileNamePath}\" \"port={m_ipcWellPole.m_Port}\"";
//var startInfo = new ProcessStartInfo
//{
// FileName = fileName,
// Arguments = args,
// UseShellExecute = false,
// CreateNoWindow = false
//};
//m_ipcWellPole.m_process = Process.Start(startInfo);
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
// _processB?.Kill();
//if(m_ipcWellPole != null)
// m_ipcWellPole.ReleaseTcp();
//if (m_ipcPipeWellPole != null)
// m_ipcPipeWellPole.m_Pipe.Dispose();
if (m_ipcMmfWellPole != null)
m_ipcMmfWellPole.Release();
base.OnFormClosing(e);
}
private void startWellPoleWithNewWellBtn_Click(object sender, EventArgs e)
{
createNewWellPole("X1-1-E916");
}
private void startWellPoleWithWellsSectionBtn_Click(object sender, EventArgs e)
{
List<string> wells = new List<string>();
wells.Add("X1-1-E916");
wells.Add("X1-1-E918");
wells.Add("X1-1-E920");
createNewWellsSection(wells);
}
}
}