12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517 |
- 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;
- //离线标志
- 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_VP_Click(object sender, EventArgs e)
- {
- textBox_ProductTag.Text = "MM_MV1";
- comboBox_SysRunMode.Items.Clear();
- comboBox_SysRunMode.Items.Add("NONE");
- comboBox_SysRunMode.Items.Add("力矩");
- }
- 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_VP.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_VP.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_VP.Checked)
- {
- if (!myFtp.DirectoryExist("MC_VP_TEST/cfg", Date))
- myFtp.MakeDir("MC_VP_TEST/cfg" + "/" + Date);
- ServerPath = "MC_VP_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();
- int index_MosCal = Array.IndexOf(MosCalInfo.ToArray(), "[MosCalK]");
- int index_AngleCal = Array.IndexOf(MosCalInfo.ToArray(), "[AngleCal]");
- //导入模板文件
- 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[index_MosCal + 2].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[index_MosCal + 3].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[index_MosCal + 4].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[index_AngleCal + 2].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);
- }
- }
- }
- }
- }
|