171 lines
5.7 KiB
C#
171 lines
5.7 KiB
C#
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 System.Diagnostics;
|
|
|
|
namespace OrgSyncDGui
|
|
{
|
|
public partial class Win : Form
|
|
{
|
|
private Message win_msg;
|
|
private History history;
|
|
public Win()
|
|
{
|
|
InitializeComponent();
|
|
this.win_msg = new Message();
|
|
|
|
}
|
|
|
|
private void bTSFile_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
dialog.Multiselect = true;
|
|
dialog.Filter = "S files (*.dat)|*.dat";
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.tBSFile.Text = String.Join(",", dialog.FileNames);
|
|
}
|
|
}
|
|
|
|
private void bTDFile_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
dialog.Multiselect = true;
|
|
dialog.Filter = "D files (*.txt)|*.txt";
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.tBDFile.Text = String.Join(",", dialog.FileNames);
|
|
}
|
|
}
|
|
|
|
private void bTClearSFile_Click(object sender, EventArgs e)
|
|
{
|
|
this.tBSFile.Text = "";
|
|
}
|
|
|
|
private void bTClearDFile_Click(object sender, EventArgs e)
|
|
{
|
|
this.tBDFile.Text = "";
|
|
}
|
|
|
|
private void bTGenerateTaFile_Click(object sender, EventArgs e)
|
|
{
|
|
SaveFileDialog dialog = new SaveFileDialog();
|
|
dialog.Filter = "道亨TA files (*.TA)|*.TA";
|
|
String ta_file="";
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
ta_file=dialog.FileName;
|
|
string cmd = String.Format("{0} generate-ta-file --s_files {1} --d_files {2} --ta_file {3}", @"d:\code\OrgSyncD\cli.py", this.tBSFile.Text, this.tBDFile.Text, ta_file);
|
|
execute_cmd(cmd);
|
|
this.tBTaFile.Text = ta_file;
|
|
}
|
|
|
|
}
|
|
|
|
private void bTSyncronizeMileageToS_Click(object sender, EventArgs e)
|
|
{
|
|
string ta_file = this.tBTaFile.Text;
|
|
string cmd = String.Format("{0} sync-all-tower-mileage-to-s --s_files {1} --ta_file {2}", @"d:\code\OrgSyncD\cli.py", this.tBSFile.Text,ta_file);
|
|
execute_cmd(cmd);
|
|
}
|
|
|
|
private void execute_cmd(string cmd)
|
|
{
|
|
System.Diagnostics.Process exep = new System.Diagnostics.Process();
|
|
exep.StartInfo.FileName =@"c:\Python38\python.exe";
|
|
exep.StartInfo.Arguments = cmd;
|
|
exep.StartInfo.CreateNoWindow = true;
|
|
exep.StartInfo.UseShellExecute = false;
|
|
exep.StartInfo.RedirectStandardOutput = true;
|
|
exep.StartInfo.RedirectStandardError = true;
|
|
exep.Start();
|
|
exep.WaitForExit();//关键,等待外部程序退出后才能往下执行
|
|
StreamReader reader;
|
|
reader = exep.StandardOutput;
|
|
send_msg(reader.ReadToEnd());
|
|
send_msg(exep.StandardError.ReadToEnd());
|
|
}
|
|
|
|
|
|
private void send_msg(string msg)
|
|
{
|
|
this.win_msg.Show();
|
|
this.win_msg.tBMsg.Text=String.Format("{0}\n{1}",this.win_msg.tBMsg.Text,msg);
|
|
}
|
|
|
|
private void bTShowMsg_Click(object sender, EventArgs e)
|
|
{
|
|
this.win_msg.Show();
|
|
}
|
|
|
|
private void bTTaFile_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
dialog.Multiselect = true;
|
|
dialog.Filter = "TA files (*.TA)|*.TA";
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.tBTaFile.Text = String.Join(",", dialog.FileNames);
|
|
}
|
|
}
|
|
|
|
private void bTSyncTowerHeight_Click(object sender, EventArgs e)
|
|
{
|
|
string ta_file = this.tBTaFile.Text;
|
|
string cmd = String.Format("{0} sync-all-tower-height-from-ta-to-s --s_files {1} --ta_file {2}", @"d:\code\OrgSyncD\cli.py", this.tBSFile.Text, ta_file);
|
|
execute_cmd(cmd);
|
|
}
|
|
|
|
private void Win_Load(object sender, EventArgs e)
|
|
{
|
|
//加载历史记录
|
|
var process = Process.GetCurrentProcess();
|
|
string fullPath = process.MainModule.FileName;
|
|
string jsonFilePath=String.Format(@"{0}\history.json",Directory.GetParent(fullPath).ToString());
|
|
this.history = new History(jsonFilePath);
|
|
this.history.load();
|
|
if (this.history.history.ContainsKey("DFiles"))
|
|
{
|
|
this.tBDFile.Text = this.history.history["DFiles"];
|
|
}
|
|
if (this.history.history.ContainsKey("SFiles"))
|
|
{
|
|
this.tBSFile.Text = this.history.history["SFiles"];
|
|
}
|
|
if (this.history.history.ContainsKey("TaFile"))
|
|
{
|
|
this.tBTaFile.Text = this.history.history["TaFile"];
|
|
}
|
|
|
|
}
|
|
|
|
private void Win_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
this.history.history["DFiles"]=this.tBDFile.Text;
|
|
this.history.history["SFiles"]=this.tBSFile.Text;
|
|
this.history.history["TaFile"]=this.tBTaFile.Text;
|
|
this.history.save();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
this.tBTaFile.Text = "";
|
|
}
|
|
|
|
private void bTSyncMileageAndHeight_Click(object sender, EventArgs e)
|
|
{
|
|
this.bTSyncTowerHeight_Click(null, null);
|
|
bTSyncronizeMileageToS_Click(null, null);
|
|
|
|
}
|
|
|
|
}
|
|
}
|