using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Remoting.Messaging; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using static System.Net.WebRequestMethods; using static Welling_Motor_Debug_Tool.mainForm; namespace Welling_Motor_Debug_Tool { public partial class GenerateParams : Form { //存储路径文件 LocalInfo localInfo = new LocalInfo(); //服务器配置 string IP, Port, User, PassWD, ModelPath, CfgPath; //FTP ftp myFtp = new ftp(); //高级参数修改标志 bool WriteLockStatus = true; public GenerateParams() { InitializeComponent(); } private void button_NoteRead_Click(object sender, EventArgs e) { //检查本地文件删除 if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName)) System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName); //下载远程文件 myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath); //显示文件 StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName); string sLine = ""; ArrayList arrText = new ArrayList();//创建一个动态数组 while (sLine != null) { sLine = objReader.ReadLine(); arrText.Add(sLine); } objReader.Close(); richTextBox_Note.Clear(); foreach (string sOutput in arrText) { richTextBox_Note.AppendText(sOutput + "\r\n"); } richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1); } private void button_NoteWrite_Click(object sender, EventArgs e) { //检查本地并删除 if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName)) System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName); //保存 System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, richTextBox_Note.Text); //上传服务器 if (!myFtp.DirectoryExist("/", "Note")) myFtp.MakeDir("/Note"); bool result = myFtp.UploadFile(localInfo.LocalPath + localInfo.NoteFileName, "/Note"); if (result) MessageBoxTimeOut.Show("上传完成", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { //选中备忘录时自动读取更新 if (tabControl1.SelectedIndex == 2) { //检查本地文件删除 if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName)) System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName); //下载远程文件 myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath); //显示文件 StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName); string sLine = ""; ArrayList arrText = new ArrayList();//创建一个动态数组 while (sLine != null) { sLine = objReader.ReadLine(); arrText.Add(sLine); } objReader.Close(); richTextBox_Note.Clear(); foreach (string sOutput in arrText) { richTextBox_Note.AppendText(sOutput + "\r\n"); } richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1); } //高级参数只读 richTextBox_AdvanceParams.ReadOnly = true; pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock; WriteLockStatus = true; } private void radioButton_MIGIC_Click(object sender, EventArgs e) { textBox_ProductTag.Text = "MM_MC1"; comboBox_SysRunMode.Items.Clear(); comboBox_SysRunMode.Items.Add("CITY"); comboBox_SysRunMode.Items.Add("MTB"); } private void radioButton_HUB_Click(object sender, EventArgs e) { textBox_ProductTag.Text = "GF_250_1"; comboBox_SysRunMode.Items.Clear(); comboBox_SysRunMode.Items.Add("踏频"); comboBox_SysRunMode.Items.Add("力矩"); } private void radioButton_HUB_FCT_Click(object sender, EventArgs e) { textBox_ProductTag.Text = "GF_250_1"; comboBox_SysRunMode.Items.Clear(); comboBox_SysRunMode.Items.Add("踏频"); comboBox_SysRunMode.Items.Add("力矩"); } private void comboBox_SysRunMode_Click(object sender, EventArgs e) { if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked | radioButton_HUB_FCT.Checked) == false) { MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button_ChangeModelFile_Click(object sender, EventArgs e) { string DataFileName = ""; string FileInfo = ""; if (comboBox_ModelFile.SelectedIndex == -1) { MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (MessageBox.Show("确认修改模板?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } //填写文件名 DataFileName = comboBox_ModelFile.Text; //分割参数更新参数内容 string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None); try { //更新信息 do { //建立字典,存放并获取每个命令的行号 Dictionary DicRowNum = new Dictionary(); DicRowNum.Add("[整车参数]", 0); DicRowNum.Add("[控制参数]", 0); DicRowNum.Add("[助力参数]", 0); DicRowNum.Add("[调试参数]", 0); DicRowNum.Add("[生产信息]", 0); Dictionary __dict = new Dictionary(DicRowNum); foreach (KeyValuePair item in __dict) { for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains(item.Key)) { DicRowNum[item.Key] = i; break; } } } //遍历更新 foreach (string index in DicRowNum.Keys) { int rowNum = DicRowNum[index]; //行号 switch (index) { case "[整车参数]": { //轮胎周长 lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text; //转把限速 lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text; //推行限速 lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text; //前牙盘 lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text; //后牙盘 lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text; //前后灯参数 int LightParams = 0x0000; if (comboBox_BikeVolF.SelectedIndex == 0) LightParams |= 0x0006; else if (comboBox_BikeVolF.SelectedIndex == 1) LightParams |= 0x000C; else { MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBox_BikeVolB.SelectedIndex == 0) LightParams |= 0x0600; else if (comboBox_BikeVolB.SelectedIndex == 1) LightParams |= 0x0C00; else { MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBox_BikeModeB.SelectedIndex >= 0) LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12); else { MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString(); //启动模式 lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString(); //开机延迟 int PowerTime = 0; PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text); PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8); PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12); lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString(); break; } case "[控制参数]": { //峰值电流 lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text; //过压保护 lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text; //欠压保护 lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text; break; } case "[助力参数]": { //限速起始 lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text; //限速结束 lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text; break; } case "[调试参数]": { //运行模式 lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString(); //旋转方向 lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString(); //功率限幅 lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text; break; } case "[生产信息]": { //生产商 lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text; //生产地 lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text; //生产日期 lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text; //产品标识 lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text; break; } default: break; } } } while (false); //参数更新 richTextBox_AdvanceParams.Clear(); for (int i = 0; i < lines.Length; i++) { richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n"); } richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1); } catch (System.Exception) { MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK); return; } //获取模板文本信息写入文件 FileInfo = richTextBox_AdvanceParams.Text; if (FileInfo == string.Empty) { MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } System.IO.File.WriteAllText(DataFileName, FileInfo); //模板文件上传服务器 if (myFtp.CheckFtp() == true) { //删除远程文件 myFtp.DeleteFile("/ParamsMode/" + DataFileName); //上传文件 bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode"); if (result1 == true) { MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName); } private void button_DeletModelFile_Click(object sender, EventArgs e) { if (comboBox_ModelFile.SelectedIndex == -1) { MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Login loginForm = new Login(); loginForm.ShowDialog(); if (loginForm.textBox_Passwd.Text == loginForm.UserAccount[loginForm.comboBox_User.Text])//检验模式所有用户支持 { if (!loginForm.comboBox_User.Text.Contains("工程参数配置")) { MessageBox.Show("权限不支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (myFtp.CheckFtp() == true) { //删除远程文件 myFtp.DeleteFile("/ParamsMode/" + comboBox_ModelFile.Text); comboBox_ModelFile.Items.Clear(); richTextBox_AdvanceParams.Clear(); MessageBox.Show("模板已删除,请刷新!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } /// /// 导入样机生产记录文件,可用于生成模板 /// /// /// private void button_LoadFile_Click(object sender, EventArgs e) { comboBox_ModelFile.SelectedIndex = -1; button_ExportParams.Enabled = true; //高级参数只读 richTextBox_AdvanceParams.ReadOnly = true; pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock; WriteLockStatus = true; //打开对话框选择文件 OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "请选择样机测试记录文件"; ofd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop); ofd.Filter = "文本文件(*.txt)|*.txt"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { //打开文件 StreamReader objReader = new StreamReader(ofd.FileName); string sLine = ""; ArrayList array_CfgInfo = new ArrayList(); array_CfgInfo.Clear(); while (sLine != null) { sLine = objReader.ReadLine(); array_CfgInfo.Add(sLine); } objReader.Close(); //转换为模板显示 try { string fileInfo = ""; fileInfo += "#说明\r\n"; fileInfo += "#0表示命令无效,1开启该命令的参数写入\r\n"; fileInfo += "\r\n"; fileInfo += "[型号],1\r\n"; fileInfo += "电机型号," + array_CfgInfo[5].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n"; fileInfo += "\r\n"; fileInfo += "[SN号],0\r\n"; fileInfo += "电机SN," + "\r\n"; fileInfo += "\r\n"; fileInfo += "[校验码],0\r\n"; fileInfo += "校验码," + "\r\n"; fileInfo += "\r\n"; fileInfo += "[自定义1],0\r\n"; fileInfo += "自定义字符串1," + "\r\n"; fileInfo += "\r\n"; fileInfo += "[自定义2],0\r\n"; fileInfo += "自定义字符串1," + "\r\n"; fileInfo += "\r\n"; fileInfo += "[自定义3],0\r\n"; fileInfo += "自定义字符串1," + "\r\n"; fileInfo += "\r\n"; fileInfo += "[生产信息],1\r\n"; fileInfo += "生产商," + "\r\n"; fileInfo += "生产地," + "\r\n"; fileInfo += "生产日期," + "\r\n"; fileInfo += "产品标识," + "\r\n"; fileInfo += "\r\n"; fileInfo += "[马达信息],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += array_CfgInfo[13].ToString().Replace('=',',').Replace(", ", "\r\n") + "\r\n"; fileInfo += "\r\n"; fileInfo += "[整车参数],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += array_CfgInfo[16].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += "\r\n"; fileInfo += "[控制参数],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += array_CfgInfo[19].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += "\r\n"; fileInfo += "[力矩传感器参数],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += "\r\n"; fileInfo += "[其它传感器参数],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += ("力矩传感器踏频脉冲数" + array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += "\r\n"; fileInfo += "[助力参数],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += "空,0\r\n"; fileInfo += array_CfgInfo[25].ToString().Split(new string[] { ", 助力转矩曲线编号" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(" ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[25].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[27].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[29].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[31].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[33].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[35].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[37].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[39].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[41].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[43].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[45].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[47].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[49].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[51].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("转矩曲线.a" + array_CfgInfo[53].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("踏频曲线.a" + array_CfgInfo[25].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("踏频曲线.a" + array_CfgInfo[27].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("踏频曲线.a" + array_CfgInfo[29].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("踏频曲线.a" + array_CfgInfo[31].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("踏频曲线.a" + array_CfgInfo[33].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += ("助力启动阈值" + array_CfgInfo[25].ToString().Split(new string[] { "助力启动阈值" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; fileInfo += "\r\n"; fileInfo += "[调试参数],1\r\n"; fileInfo += "存储标志,1\r\n"; fileInfo += array_CfgInfo[56].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n"; //加载高级界面 richTextBox_AdvanceParams.Clear(); richTextBox_AdvanceParams. AppendText(fileInfo); //加载简易界面 do //基础参数界面 { //内容转换行 ArrayList arrText = new ArrayList(fileInfo.Split(new string[] { "\r\n" }, StringSplitOptions.None));//创建一个动态数组 //建立字典,存放并获取每个命令的行号 Dictionary DicRowNum = new Dictionary(); DicRowNum.Add("[整车参数]", 0); DicRowNum.Add("[控制参数]", 0); DicRowNum.Add("[助力参数]", 0); DicRowNum.Add("[调试参数]", 0); DicRowNum.Add("[生产信息]", 0); Dictionary __dict = new Dictionary(DicRowNum); foreach (KeyValuePair item in __dict) { foreach (string cmd in arrText) { if (cmd.Contains(item.Key)) { DicRowNum[item.Key] = arrText.IndexOf(cmd); break; } } } //遍历加载 foreach (string index in DicRowNum.Keys) { int rowNum = DicRowNum[index]; //行号 switch (index) { case "[整车参数]": { //轮胎周长 textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1]; //转把限速 textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1]; //推行限速 textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1]; //前牙盘 textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1]; //后牙盘 textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1]; //前灯电压 ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]); if ((LightParams & 0x00FF) == 6) comboBox_BikeVolF.SelectedIndex = 0; else if ((LightParams & 0x00FF) == 12) comboBox_BikeVolF.SelectedIndex = 1; else comboBox_BikeVolF.SelectedIndex = -1; //后灯电压 if (((LightParams >> 8) & 0x0F) == 6) comboBox_BikeVolB.SelectedIndex = 0; else if (((LightParams >> 8) & 0x0F) == 12) comboBox_BikeVolB.SelectedIndex = 1; else comboBox_BikeVolB.SelectedIndex = -1; //后灯模式c comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1; //启动模式 comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1; //开机延迟 ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]); textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString(); //关机延迟 textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString(); //自动关机 textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString(); break; } case "[控制参数]": { //峰值电流 textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1]; //过压保护 textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1]; //欠压保护 textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1]; break; } case "[助力参数]": { //限速起始 textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1]; //限速结束 textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1]; break; } case "[调试参数]": { //运行模式 if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6)) { comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4; } else comboBox_SysRunMode.SelectedIndex = -1; //旋转方向 comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]); //功率限幅 textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1]; break; } case "[生产信息]": { //生产商 textBox_ProductMac.Text = arrText[rowNum + 1].ToString().Split(',')[1]; //生产地 textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1]; //生产日期 textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", ""); //生产标识 textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1]; break; } default: break; } } } while (false); MessageBoxTimeOut.Show("导入完成!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("导入错误,请检查导入文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void pictureBox1_Click(object sender, EventArgs e) { if (WriteLockStatus == true) { richTextBox_AdvanceParams.ReadOnly = false; pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock; WriteLockStatus = !WriteLockStatus; } else { richTextBox_AdvanceParams.ReadOnly = true; pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock; WriteLockStatus = !WriteLockStatus; } } private void GenerateParams_Load(object sender, EventArgs e) { //更新版本信息 label_Ver.Text = "版本: V" + mainForm.Version; label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss"); //导入网络配置 if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息 { //打开文件 StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName); string sLine = ""; ArrayList array_CfgInfo = new ArrayList(); array_CfgInfo.Clear(); while (sLine != null) { sLine = objReader.ReadLine(); array_CfgInfo.Add(sLine); } objReader.Close(); //解析配置文件 try { //Server Set IP, Port, User, PassWS, ModelPath; IP = array_CfgInfo[12].ToString().Split(':')[1]; Port = array_CfgInfo[13].ToString().Split(':')[1]; User = array_CfgInfo[14].ToString().Split(':')[1]; PassWD = array_CfgInfo[15].ToString().Split(':')[1]; ModelPath = "ParamsMode"; myFtp.FtpOption(IP, Port, User, PassWD, "admin", "ttium_admin"); } catch (System.Exception) { MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } //检查网络 if (myFtp.CheckFtp() == false) { label_Server_ComStatus.Text = "网络已断开"; label_ServerStatus.BackColor = Color.Red; MessageBox.Show("网络断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } else { label_Server_ComStatus.Text = "网络已连接: " + IP; label_ServerStatus.BackColor = Color.Green; } //加载模板文件 comboBox_ModelFile.Items.Clear(); string[] FileList = { "" }; FileList = myFtp.GetFileNameList(ModelPath); comboBox_ModelFile.Items.Clear(); foreach (var file in FileList) { if (file.Contains(".src")) { comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1)); } } } private void button_ModeRefresh_Click(object sender, EventArgs e) { //加载模板文件 comboBox_ModelFile.Items.Clear(); string[] FileList = { "" }; FileList = myFtp.GetFileNameList(ModelPath); comboBox_ModelFile.Items.Clear(); foreach (var file in FileList) { if (file.Contains(".src")) { comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1)); } } } private void comboBox_ModelFile_SelectedIndexChanged(object sender, EventArgs e) { button_ExportParams.Enabled = true; //高级参数只读 richTextBox_AdvanceParams.ReadOnly = true; pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock; WriteLockStatus = true; //下载文件 if (System.IO.File.Exists(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text))//本地存在选定文件,先删除本地 { System.IO.File.Delete(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text); } myFtp.DownloadFile("ParamsMode/" + comboBox_ModelFile.Text, localInfo.LocalPath); //打开文件 StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text); string sLine = ""; ArrayList arrText = new ArrayList();//创建一个动态数组 while (sLine != null) { sLine = objReader.ReadLine(); arrText.Add(sLine); } objReader.Close(); //加载文件 do //基础参数界面 { //建立字典,存放并获取每个命令的行号 Dictionary DicRowNum = new Dictionary(); DicRowNum.Add("[整车参数]", 0); DicRowNum.Add("[控制参数]", 0); DicRowNum.Add("[助力参数]", 0); DicRowNum.Add("[调试参数]", 0); DicRowNum.Add("[生产信息]", 0); Dictionary __dict = new Dictionary(DicRowNum); foreach (KeyValuePair item in __dict) { foreach (string cmd in arrText) { if (cmd.Contains(item.Key)) { DicRowNum[item.Key] = arrText.IndexOf(cmd); break; } } } //遍历加载 foreach (string index in DicRowNum.Keys) { int rowNum = DicRowNum[index]; //行号 switch (index) { case "[整车参数]": { //轮胎周长 textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1]; //转把限速 textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1]; //推行限速 textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1]; //前牙盘 textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1]; //后牙盘 textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1]; //前灯电压 ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]); if ((LightParams & 0x00FF) == 6) comboBox_BikeVolF.SelectedIndex = 0; else if ((LightParams & 0x00FF) == 12) comboBox_BikeVolF.SelectedIndex = 1; else comboBox_BikeVolF.SelectedIndex = -1; //后灯电压 if (((LightParams >> 8) & 0x0F) == 6) comboBox_BikeVolB.SelectedIndex = 0; else if (((LightParams >> 8) & 0x0F) == 12) comboBox_BikeVolB.SelectedIndex = 1; else comboBox_BikeVolB.SelectedIndex = -1; //后灯模式c comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1; //启动模式 comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1; //开机延迟 ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]); textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString(); //关机延迟 textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString(); //自动关机 textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString(); break; } case "[控制参数]": { //峰值电流 textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1]; //过压保护 textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1]; //欠压保护 textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1]; break; } case "[助力参数]": { //限速起始 textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1]; //限速结束 textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1]; break; } case "[调试参数]": { //运行模式 if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6)) { comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4; } else comboBox_SysRunMode.SelectedIndex = -1; //旋转方向 comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]); //功率限幅 textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1]; break; } case "[生产信息]": { //生产商 textBox_ProductMac.Text= arrText[rowNum + 1].ToString().Split(',')[1]; //生产地 textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1]; //生产日期 textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", ""); //生产标识 textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1]; break; } default:break; } } } while (false); do //高级参数界面 { richTextBox_AdvanceParams.Clear(); foreach (string sOutput in arrText) { richTextBox_AdvanceParams.AppendText(sOutput + "\r\n"); } richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 2); } while (false); } private void button_GenerateModelFile_Click(object sender, EventArgs e) { string DataFileName = ""; string FileInfo = ""; //填写文件名 Scan ModeFileName = new Scan(); ModeFileName.ShowDialog(); if (ModeFileName.textBox_Scan.Text == string.Empty) { MessageBox.Show("文件名为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DataFileName = ModeFileName.textBox_Scan.Text + ".src"; //核对文件名格式 //... //获取模板文本信息写入文件 FileInfo = richTextBox_AdvanceParams.Text; if (FileInfo == string.Empty) { MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } System.IO.File.WriteAllText(DataFileName, FileInfo); //模板文件上传服务器 if (myFtp.CheckFtp() == true) { //上传文件 bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode"); if (result1 == true) { MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName); } private void button_ExportParams_Click(object sender, EventArgs e) { //检查 if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked | radioButton_HUB_FCT.Checked) == false) { MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //不导出到本地时需填写完整订单信息 if (!checkBox_SyncFac.Checked) { foreach (Control c in groupBox1.Controls) { if (c is TextBox) { if (c.Text == "") { MessageBox.Show("信息填写不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (c.Text.Contains('_')) { if ((c.Name != "textBox_ProductTag") && (c.Name != "textBox_SoftwareVer")) { MessageBox.Show("\"" + c.Text + "\"" + "包含字符'_'", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } } } //分割参数 string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None); try { //更新信息 do { //建立字典,存放并获取每个命令的行号 Dictionary DicRowNum = new Dictionary(); DicRowNum.Add("[整车参数]", 0); DicRowNum.Add("[控制参数]", 0); DicRowNum.Add("[助力参数]", 0); DicRowNum.Add("[调试参数]", 0); DicRowNum.Add("[生产信息]", 0); Dictionary __dict = new Dictionary(DicRowNum); foreach (KeyValuePair item in __dict) { for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains(item.Key)) { DicRowNum[item.Key] = i; break; } } } //遍历更新 foreach (string index in DicRowNum.Keys) { int rowNum = DicRowNum[index]; //行号 switch (index) { case "[整车参数]": { //轮胎周长 lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text; //转把限速 lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text; //推行限速 lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text; //前牙盘 lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text; //后牙盘 lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text; //前后灯参数 int LightParams = 0x0000; if (comboBox_BikeVolF.SelectedIndex == 0) LightParams |= 0x0006; else if (comboBox_BikeVolF.SelectedIndex == 1) LightParams |= 0x000C; else { MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBox_BikeVolB.SelectedIndex == 0) LightParams |= 0x0600; else if (comboBox_BikeVolB.SelectedIndex == 1) LightParams |= 0x0C00; else { MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBox_BikeModeB.SelectedIndex >= 0) LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12); else { MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString(); //启动模式 lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString(); //开机延迟 int PowerTime = 0; PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text); PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8); PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12); lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString(); break; } case "[控制参数]": { //峰值电流 lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text; //过压保护 lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text; //欠压保护 lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text; break; } case "[助力参数]": { //限速起始 lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text; //限速结束 lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text; break; } case "[调试参数]": { //运行模式 lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString(); //旋转方向 lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString(); //功率限幅 lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text; break; } case "[生产信息]": { //生产商 lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text; //生产地 lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text; //生产日期 lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text; //产品标识 lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text; break; } default: break; } } } while (false); //参数更新 richTextBox_AdvanceParams.Clear(); for (int i = 0; i < lines.Length; i++) { richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n"); } richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1); } catch (System.Exception) { MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK); return; } //不导出本地时,上传服务器 if (!checkBox_SyncFac.Checked) { //确定本地保存路径 string Date = DateTime.Now.ToString("yyyy-MM-dd"); string LocalPath = localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + Date; if (!Directory.Exists(LocalPath)) { Directory.CreateDirectory(LocalPath); } //确定远程保存路径 string ServerPath = ""; if (radioButton_HUB.Checked) { if (!myFtp.DirectoryExist("HUB_Control_TEST/cfg", Date)) myFtp.MakeDir("HUB_Control_TEST/cfg" + "/" + Date); ServerPath = "HUB_Control_TEST/cfg" + "/" + Date; } else if (radioButton_MIGIC.Checked) { if (!myFtp.DirectoryExist("MIGIC_TEST/cfg", Date)) myFtp.MakeDir("MIGIC_TEST/cfg" + "/" + Date); ServerPath = "MIGIC_TEST/cfg" + "/" + Date; } else if (radioButton_HUB_FCT.Checked) { if (!myFtp.DirectoryExist("HUB_Control_FCT/cfg", Date)) myFtp.MakeDir("HUB_Control_FCT/cfg" + "/" + Date); ServerPath = "HUB_Control_FCT/cfg" + "/" + Date; } //确定文件名 string fileName = ""; fileName = textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" + textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + textBox_SoftwareVer.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "-"); //保存.src文件 System.IO.File.WriteAllText(LocalPath + "\\" + fileName + ".src", richTextBox_AdvanceParams.Text); //检查是否存在转换工具 if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile")) { Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile"); myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); } else { //程序使用最新版本 if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe")) System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"); myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); //库文件不更新 if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml")) myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll")) myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); } //转换.ttcfg文件 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"; startInfo.Arguments = "\"" + LocalPath + "\\" + fileName + ".src" + "\""; System.Diagnostics.Process.Start(startInfo); Thread.Sleep(1000); //保存页面 Double scaleX = PrimaryScreen.ScaleX; Double scaleY = PrimaryScreen.ScaleY; Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap Graphics g = Graphics.FromImage(bit); g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片 bit.Save(LocalPath + "\\" + fileName + ".png"); //生成pdf文件,上传服务器 //... //上传 bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath); bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath); bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath); if (result1 & result2 & result3) { MessageBoxTimeOut.Show("上传成功", "提示", 1000, MessageBoxButtons.OK); } else { MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK); } } //导出本地指定路径 else { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "配置文件(*.ttcfg)|*.ttcfg"; DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { string filePath = saveFileDialog.FileName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); //保存src文件 System.IO.File.WriteAllText(filePath + ".src", richTextBox_AdvanceParams.Text); //检查是否存在转换工具 if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile")) { Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile"); myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); } else { //程序使用最新版本 if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe")) System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"); myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); //库文件不更新 if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml")) myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll")) myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile"); } //转换.ttcfg文件 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"; startInfo.Arguments = filePath + ".src"; System.Diagnostics.Process.Start(startInfo); Thread.Sleep(1000); MessageBoxTimeOut.Show("导出本地完成", "提示", 1000, MessageBoxButtons.OK); } } } } }