1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501 |
- 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;
- using NPOI;
- using NPOI.SS.UserModel;
- using NPOI.HSSF.UserModel;
- using NPOI.POIFS.FileSystem;
- using Spire.Xls;
- using Workbook = Spire.Xls.Workbook;
- using Spire.Xls.Core;
- namespace Welling_Motor_Debug_Tool
- {
- public partial class GenerateParams : Form
- {
- //存储路径文件
- LocalInfo localInfo = new LocalInfo();
- //服务器配置
- string IP, Port, User, PassWD, ModelPath, CfgPath;
- //离线标志
- bool Offline_Flag = false;
- //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<string, int> DicRowNum = new Dictionary<string, int>();
- DicRowNum.Add("[整车参数]", 0);
- DicRowNum.Add("[控制参数]", 0);
- DicRowNum.Add("[助力参数]", 0);
- DicRowNum.Add("[调试参数]", 0);
- DicRowNum.Add("[生产信息]", 0);
- Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
- foreach (KeyValuePair<string, int> 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);
- }
- }
- }
- /// <summary>
- /// 导入样机生产记录文件,可用于生成模板
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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";
- fileInfo += "\r\n";
- string FileVer = "";
- FileVer = array_CfgInfo[array_CfgInfo.Count - 2].ToString();
- if (FileVer.Contains("V2.0")) //2.0版本包含整车参数和用户骑行参数
- {
- fileInfo += "[整车参数2],1\r\n";
- fileInfo += "存储标志,1\r\n";
- fileInfo += array_CfgInfo[65].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
- fileInfo += "\r\n";
- fileInfo += "[用户骑行参数],1\r\n";
- fileInfo += "存储标志,1\r\n";
- fileInfo += array_CfgInfo[68].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
- }
- else //2.0版本前不包含整车参数和用户骑行参数,写0,不转换
- {
- fileInfo += "[整车参数2],0\r\n\r\n";
- fileInfo += "\r\n";
- fileInfo += "[用户骑行参数],0\r\n\r\n";
- fileInfo += "\r\n";
- }
-
- //加载高级界面
- richTextBox_AdvanceParams.Clear();
- richTextBox_AdvanceParams.AppendText(fileInfo);
- //加载简易界面
- do //基础参数界面
- {
- //内容转换行
- ArrayList arrText = new ArrayList(fileInfo.Split(new string[] { "\r\n" }, StringSplitOptions.None));//创建一个动态数组
- //建立字典,存放并获取每个命令的行号
- Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
- DicRowNum.Add("[整车参数]", 0);
- DicRowNum.Add("[控制参数]", 0);
- DicRowNum.Add("[助力参数]", 0);
- DicRowNum.Add("[调试参数]", 0);
- DicRowNum.Add("[生产信息]", 0);
- Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
- foreach (KeyValuePair<string, int> 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");
- //离线使用标志
- Offline_Flag = (mainform1.OfflineFlag == true);
- //模板文件服务器路径
- ModelPath = "ParamsMode";
- //FTP配置
- IP = mainform1.ServerIP;
- Port = mainform1.ServerPort;
- User = mainform1.ServerUser;
- PassWD = mainform1.ServerPassWd;
- myFtp.FtpOption(IP, Port, User, PassWD, "admin", "ttium_admin");
- //检查网络
- if (Offline_Flag != true)
- {
- 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));
- }
- }
- }
- else //离线状态仅支持本地
- {
- comboBox_ModelFile.Enabled = false;
- button_ModeRefresh.Enabled = false;
- button_GenerateModelFile.Enabled = false;
- button_DeletModelFile.Enabled = false;
- button_ChangeModelFile.Enabled = false;
- checkBox_SyncFac.Checked = true;
- tabPage_Note.Parent = null;
- }
- }
- 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 (comboBox_ModelFile.SelectedIndex < 0)
- return;
- //下载文件
- 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<string, int> DicRowNum = new Dictionary<string, int>();
- DicRowNum.Add("[整车参数]", 0);
- DicRowNum.Add("[控制参数]", 0);
- DicRowNum.Add("[助力参数]", 0);
- DicRowNum.Add("[调试参数]", 0);
- DicRowNum.Add("[生产信息]", 0);
- Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
- foreach (KeyValuePair<string, int> 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<string, int> DicRowNum = new Dictionary<string, int>();
- DicRowNum.Add("[整车参数]", 0);
- DicRowNum.Add("[控制参数]", 0);
- DicRowNum.Add("[助力参数]", 0);
- DicRowNum.Add("[调试参数]", 0);
- DicRowNum.Add("[生产信息]", 0);
- Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
- foreach (KeyValuePair<string, int> 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");
- //写入excel表格
- if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName)) //删除本地模板,从服务器下载最新模板
- {
- System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName);
- }
- myFtp.DownloadFile("Tools/GenerateParamsFile/" + localInfo.ExcelTempleFileName, localInfo.ToolsPath + "\\" + "GenerateParamsFile");
- string importExcelName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName;
- string exportExcelName = LocalPath + "\\" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
- textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".xls";
- try
- {
- string sLine = "";
- //读取力矩传感器范围
- StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.TorqueSensorFileName);
- List<string> TorqueInfo = new List<string>();
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- TorqueInfo.Add(sLine);
- }
- objReader.Close();
- //读取MOS校准参数
- objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
- sLine = "";
- List<string> MosCalInfo = new List<string>();
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- MosCalInfo.Add(sLine);
- }
- objReader.Close();
- //导入模板文件
- NPOI.SS.UserModel.IWorkbook workbook = WorkbookFactory.Create(importExcelName);
- //获取第一个工作薄
- ISheet sheet = workbook.GetSheetAt(0);
- //建立字典,获取并存放并获取每个命令的起始行号
- Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
- DicRowNum.Add("[马达信息]", 0);
- DicRowNum.Add("[整车参数]", 0);
- DicRowNum.Add("[控制参数]", 0);
- DicRowNum.Add("[其它传感器参数]", 0);
- DicRowNum.Add("[助力参数]", 0);
- DicRowNum.Add("[调试参数]", 0);
- Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
- foreach (KeyValuePair<string, int> item in __dict)
- {
- for (int i = 0; i < lines.Length; i++)
- {
- if (lines[i].Contains(item.Key))
- {
- DicRowNum[item.Key] = i;
- break;
- }
- }
- }
- #region 开始按行写入数据
- //第3行,文件信息
- IRow row = sheet.GetRow(2);
- row.GetCell(0).SetCellValue("文件信息 File Info:" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
- textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
- //第5行,第2列型号,定制功能使能标志
- row = sheet.GetRow(4);
- row.GetCell(1).SetCellValue(textBox_ProductName.Text);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[控制参数]"] + 15].Split(',')[1]);
- //第6行,第2列序列号,第10列力矩传感器零点范围
- row = sheet.GetRow(5);
- row.GetCell(1).SetCellValue("Same as marking label");
- row.GetCell(9).SetCellValue(TorqueInfo[0].Split(',')[1] + "-" + TorqueInfo[0].Split(',')[2]);
- //第7行,第2列PCBA板号,第10列力矩传感器标定1范围
- row = sheet.GetRow(6);
- row.GetCell(1).SetCellValue(textBox_PCBA.Text);
- row.GetCell(9).SetCellValue(TorqueInfo[1].Split(',')[0] + ": " + TorqueInfo[1].Split(',')[1] + "-" + TorqueInfo[1].Split(',')[2]);
- //第8行,第2列软件版本,第10列力矩传感器标定2范围
- row = sheet.GetRow(7);
- row.GetCell(1).SetCellValue(textBox_SoftwareVer.Text);
- row.GetCell(9).SetCellValue(TorqueInfo[2].Split(',')[0] + ": " + TorqueInfo[2].Split(',')[1] + "-" + TorqueInfo[2].Split(',')[2]);
- //第9行,第2列Bootloader版本,第10列力矩传感器标定3范围
- row = sheet.GetRow(8);
- row.GetCell(1).SetCellValue("250K");
- row.GetCell(9).SetCellValue(TorqueInfo[3].Split(',')[0] + ": " + TorqueInfo[3].Split(',')[1] + "-" + TorqueInfo[3].Split(',')[2]);
- //第10行,第2列静态母线电压范围,第10列力矩传感器标定4范围
- row = sheet.GetRow(9);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 12].Split(',')[1].Substring(0, 2) + " ± 1V");
- row.GetCell(9).SetCellValue(TorqueInfo[4].Split(',')[0] + ": " + TorqueInfo[4].Split(',')[1] + "-" + TorqueInfo[4].Split(',')[2]);
- //第11行,第2列静态母线电流范围,第10列力矩传感器踏频脉冲数
- row = sheet.GetRow(10);
- row.GetCell(1).SetCellValue("≤ 0.050 A");
- row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 2].Split(',')[1]);
- //第12行,第2列极对数,第10列车速传感器脉冲数
- row = sheet.GetRow(11);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 2].Split(',')[1]);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 3].Split(',')[1]);
- //第13行,第2列相电阻,第10列踏频传感器脉冲数
- row = sheet.GetRow(12);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 3].Split(',')[1]);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 4].Split(',')[1]);
- //第14行,第2列d轴电感,第10列助力启动阈值
- row = sheet.GetRow(13);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 4].Split(',')[1]);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 85].Split(',')[1]);
- //第15行,第2列q轴电感,第10列助力停机阈值
- row = sheet.GetRow(14);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 5].Split(',')[1]);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 86].Split(',')[1]);
- //第16行,第2列永磁体磁链,第10列限速起始值
- row = sheet.GetRow(15);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 6].Split(',')[1]);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 92].Split(',')[1] + " km/h");
- //第17行,第2列Id最小值,第10列限速停机值
- row = sheet.GetRow(16);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 8].Split(',')[1]);
- row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 93].Split(',')[1] + " km/h");
- //第18行,第2列额定转速,第10列运行模式
- row = sheet.GetRow(17);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 9].Split(',')[1] + " rpm");
- row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 2].Split(',')[1]);
- //第19行,第2列额定功率,第10列采样方式
- row = sheet.GetRow(18);
- UInt16 x = Convert.ToUInt16(lines[DicRowNum["[马达信息]"] + 10].Split(',')[1]);
- row.GetCell(1).SetCellValue((x >> 11).ToString() + ", " + (x & 0x07FF).ToString() + " W");
- row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 4].Split(',')[1]);
- //第20行,第2列额定电流,第10列旋转方向
- row = sheet.GetRow(19);
- x = Convert.ToUInt16(lines[DicRowNum["[马达信息]"] + 11].Split(',')[1]);
- row.GetCell(1).SetCellValue(((float)x / 100f).ToString("0.00") + " A");
- row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 5].Split(',')[1]);
- //第21行,第2列额定电压,第10列功率限幅
- row = sheet.GetRow(20);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 12].Split(',')[1].Substring(0, 2) + " V");
- row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 23].Split(',')[1]);
- //第22行,第2列轮胎周长,第10列MOS内阻校准1
- row = sheet.GetRow(21);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 2].Split(',')[1] + " cm");
- row.GetCell(9).SetCellValue(MosCalInfo[40].Split(':')[1].ToString().Replace(',', '-'));
- //第23行,第2列传动比,第10列MOS内阻校准2
- row = sheet.GetRow(22);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 3].Split(',')[1]);
- row.GetCell(9).SetCellValue(MosCalInfo[41].Split(':')[1].ToString().Replace(',', '-'));
- //第24行,第2列转把限速,第10列MOS内阻校准3
- row = sheet.GetRow(23);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 4].Split(',')[1] + " km/h");
- row.GetCell(9).SetCellValue(MosCalInfo[42].Split(':')[1].ToString().Replace(',', '-'));
- //第25行,第2列推行限速,第10列位置校准零点偏差
- row = sheet.GetRow(24);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 5].Split(',')[1] + " km/h");
- row.GetCell(9).SetCellValue("± " + MosCalInfo[53].Split(':')[1].ToString());
- //第26行,第2列前牙盘
- row = sheet.GetRow(25);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 6].Split(',')[1]);
- //第27行,第2列后牙盘
- row = sheet.GetRow(26);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 7].Split(',')[1]);
- //第28行,第2列前灯电压
- row = sheet.GetRow(27);
- row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) % 256).ToString() + " V");
- //第29行,第2列尾灯电压
- row = sheet.GetRow(28);
- row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) / 256 % 16).ToString() + " V");
- //第30行,第2列尾灯模式
- row = sheet.GetRow(29);
- row.GetCell(1).SetCellValue("Mode " + (Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) / 256 / 16).ToString());
- //第31行,第2列启动模式
- row = sheet.GetRow(30);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 12].Split(',')[1]);
- //第32行,第2列开机延迟
- row = sheet.GetRow(31);
- row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) / 256 / 16).ToString());
- //第33行,第2列关机延迟
- row = sheet.GetRow(32);
- row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) / 256 % 16).ToString());
- //第34行,第2列自动关机时间
- row = sheet.GetRow(33);
- row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) % 256).ToString() + " min");
- //第35行,第2列峰值电流
- row = sheet.GetRow(34);
- row.GetCell(1).SetCellValue(lines[DicRowNum["[控制参数]"] + 4].Split(',')[1]);
- #endregion
- using (FileStream file = System.IO.File.OpenWrite(exportExcelName))
- {
- workbook.Write(file);
- workbook.Close();
- }
- }
- catch (Exception ex)
- {
- throw (ex);
- }
- //生成pdf文件
- string exportPdfName = LocalPath + "\\" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
- textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".pdf";
- Workbook workbook_1 = new Workbook();//创建Workbook类的实例
- workbook_1.LoadFromFile(exportExcelName);//加载Excel工作簿
- workbook_1.SaveToFile(exportPdfName, FileFormat.PDF);//将整个工作薄保存为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);
- bool result4 = myFtp.UploadFile(exportExcelName, ServerPath);
- bool result5 = myFtp.UploadFile(exportPdfName, ServerPath);
- if (result1 & result2 & result3 & result4 & result5)
- {
- 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.Split('.')[0] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
- //保存src文件
- System.IO.File.WriteAllText(filePath + ".src", richTextBox_AdvanceParams.Text);
- //转换工具检查
- if (Offline_Flag != true) //在线时始终保持最新版本
- {
- 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");
- }
- }
- else //离线时使用本地
- {
- if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
- {
- MessageBoxTimeOut.Show("转换工具缺失,请连接服务器自动下载", "提示", 1000, MessageBoxButtons.OK);
- return;
- }
- }
-
- //转换.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);
- }
- }
- }
- }
- }
|