GenerateParams.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.Remoting.Messaging;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using static System.Net.WebRequestMethods;
  17. namespace Welling_Motor_Debug_Tool
  18. {
  19. public partial class GenerateParams : Form
  20. {
  21. //存储路径文件
  22. LocalInfo localInfo = new LocalInfo();
  23. //服务器配置
  24. string IP, Port, User, PassWD, ModelPath, CfgPath;
  25. //FTP
  26. ftp myFtp = new ftp();
  27. public GenerateParams()
  28. {
  29. InitializeComponent();
  30. }
  31. private void button_NoteRead_Click(object sender, EventArgs e)
  32. {
  33. //检查本地文件删除
  34. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  35. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  36. //下载远程文件
  37. myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath);
  38. //显示文件
  39. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName);
  40. string sLine = "";
  41. ArrayList arrText = new ArrayList();//创建一个动态数组
  42. while (sLine != null)
  43. {
  44. sLine = objReader.ReadLine();
  45. arrText.Add(sLine);
  46. }
  47. objReader.Close();
  48. richTextBox_Note.Clear();
  49. foreach (string sOutput in arrText)
  50. {
  51. richTextBox_Note.AppendText(sOutput + "\r\n");
  52. }
  53. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  54. }
  55. private void button_NoteWrite_Click(object sender, EventArgs e)
  56. {
  57. //检查本地并删除
  58. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  59. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  60. //保存
  61. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, richTextBox_Note.Text);
  62. //上传服务器
  63. if (!myFtp.DirectoryExist("/", "Note"))
  64. myFtp.MakeDir("/Note");
  65. bool result = myFtp.UploadFile(localInfo.LocalPath + localInfo.NoteFileName, "/Note");
  66. if (result)
  67. MessageBox.Show("上传完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  68. else
  69. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  70. }
  71. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  72. {
  73. //选中备忘录时自动读取更新
  74. if (tabControl1.SelectedIndex == 2)
  75. {
  76. //检查本地文件删除
  77. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  78. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  79. //下载远程文件
  80. myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath);
  81. //显示文件
  82. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName);
  83. string sLine = "";
  84. ArrayList arrText = new ArrayList();//创建一个动态数组
  85. while (sLine != null)
  86. {
  87. sLine = objReader.ReadLine();
  88. arrText.Add(sLine);
  89. }
  90. objReader.Close();
  91. richTextBox_Note.Clear();
  92. foreach (string sOutput in arrText)
  93. {
  94. richTextBox_Note.AppendText(sOutput + "\r\n");
  95. }
  96. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  97. }
  98. }
  99. private void GenerateParams_Load(object sender, EventArgs e)
  100. {
  101. //导入网络配置
  102. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  103. {
  104. //打开文件
  105. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  106. string sLine = "";
  107. ArrayList array_CfgInfo = new ArrayList();
  108. array_CfgInfo.Clear();
  109. while (sLine != null)
  110. {
  111. sLine = objReader.ReadLine();
  112. array_CfgInfo.Add(sLine);
  113. }
  114. objReader.Close();
  115. //解析配置文件
  116. try
  117. {
  118. //Server Set IP, Port, User, PassWS, ModelPath;
  119. IP = array_CfgInfo[12].ToString().Split(':')[1];
  120. Port = array_CfgInfo[13].ToString().Split(':')[1];
  121. User = array_CfgInfo[14].ToString().Split(':')[1];
  122. PassWD = array_CfgInfo[15].ToString().Split(':')[1];
  123. ModelPath = "ParamsMode";
  124. myFtp.FtpOption(IP, Port, User, PassWD);
  125. }
  126. catch (System.Exception)
  127. {
  128. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  129. }
  130. }
  131. else
  132. {
  133. MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  134. this.Close();
  135. }
  136. //检查网络
  137. if (myFtp.CheckFtp() == false)
  138. {
  139. label_Server_ComStatus.Text = "网络已断开";
  140. label_ServerStatus.BackColor = Color.Red;
  141. MessageBox.Show("网络断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  142. this.Close();
  143. }
  144. else
  145. {
  146. label_Server_ComStatus.Text = "网络已连接";
  147. label_ServerStatus.BackColor = Color.Green;
  148. }
  149. //加载模板文件
  150. comboBox_ModelFile.Items.Clear();
  151. string[] FileList = { "" };
  152. FileList = myFtp.GetFileNameList(ModelPath);
  153. comboBox_ModelFile.Items.Clear();
  154. foreach (var file in FileList)
  155. {
  156. if (file.Contains(".src"))
  157. {
  158. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  159. }
  160. }
  161. }
  162. private void button_ModeRefresh_Click(object sender, EventArgs e)
  163. {
  164. //加载模板文件
  165. comboBox_ModelFile.Items.Clear();
  166. string[] FileList = { "" };
  167. FileList = myFtp.GetFileNameList(ModelPath);
  168. comboBox_ModelFile.Items.Clear();
  169. foreach (var file in FileList)
  170. {
  171. if (file.Contains(".src"))
  172. {
  173. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  174. }
  175. }
  176. }
  177. private void comboBox_ModelFile_SelectedIndexChanged(object sender, EventArgs e)
  178. {
  179. button_ExportParams.Enabled = true;
  180. //下载文件
  181. if (System.IO.File.Exists(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text))//本地存在选定文件,先删除本地
  182. {
  183. System.IO.File.Delete(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  184. }
  185. myFtp.DownloadFile("ParamsMode/" + comboBox_ModelFile.Text, localInfo.LocalPath);
  186. //打开文件
  187. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  188. string sLine = "";
  189. ArrayList arrText = new ArrayList();//创建一个动态数组
  190. while (sLine != null)
  191. {
  192. sLine = objReader.ReadLine();
  193. arrText.Add(sLine);
  194. }
  195. objReader.Close();
  196. //加载文件
  197. do //基础参数界面
  198. {
  199. //建立字典,存放并获取每个命令的行号
  200. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  201. DicRowNum.Add("[整车参数]", 0);
  202. DicRowNum.Add("[控制参数]", 0);
  203. DicRowNum.Add("[助力参数]", 0);
  204. DicRowNum.Add("[调试参数]", 0);
  205. DicRowNum.Add("[生产信息]", 0);
  206. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  207. foreach (KeyValuePair<string, int> item in __dict)
  208. {
  209. foreach (string cmd in arrText)
  210. {
  211. if (cmd.Contains(item.Key))
  212. {
  213. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  214. break;
  215. }
  216. }
  217. }
  218. //遍历加载
  219. foreach (string index in DicRowNum.Keys)
  220. {
  221. int rowNum = DicRowNum[index]; //行号
  222. switch (index)
  223. {
  224. case "[整车参数]":
  225. {
  226. //轮胎周长
  227. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  228. //转把限速
  229. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  230. //推行限速
  231. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  232. //前牙盘
  233. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  234. //后牙盘
  235. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  236. //前灯电压
  237. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  238. if ((LightParams & 0x00FF) == 6)
  239. comboBox_BikeVolF.SelectedIndex = 0;
  240. else if ((LightParams & 0x00FF) == 12)
  241. comboBox_BikeVolF.SelectedIndex = 1;
  242. else
  243. comboBox_BikeVolF.SelectedIndex = -1;
  244. //后灯电压
  245. if (((LightParams >> 8) & 0x0F) == 6)
  246. comboBox_BikeVolB.SelectedIndex = 0;
  247. else if (((LightParams >> 8) & 0x0F) == 12)
  248. comboBox_BikeVolB.SelectedIndex = 1;
  249. else
  250. comboBox_BikeVolB.SelectedIndex = -1;
  251. //后灯模式c
  252. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  253. //启动模式
  254. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  255. //开机延迟
  256. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  257. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  258. //关机延迟
  259. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  260. //自动关机
  261. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  262. break;
  263. }
  264. case "[控制参数]":
  265. {
  266. //峰值电流
  267. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  268. //过压保护
  269. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  270. //欠压保护
  271. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  272. break;
  273. }
  274. case "[助力参数]":
  275. {
  276. //限速起始
  277. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  278. //限速结束
  279. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  280. break;
  281. }
  282. case "[调试参数]":
  283. {
  284. //运行模式
  285. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  286. {
  287. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  288. }
  289. else
  290. comboBox_SysRunMode.SelectedIndex = -1;
  291. //旋转方向
  292. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  293. //功率限幅
  294. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  295. break;
  296. }
  297. case "[生产信息]":
  298. {
  299. //生产商
  300. textBox_ProductMac.Text= arrText[rowNum + 1].ToString().Split(',')[1];
  301. //生产地
  302. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  303. //生产日期
  304. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  305. //生产标识
  306. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  307. break;
  308. }
  309. default:break;
  310. }
  311. }
  312. } while (false);
  313. do //高级参数界面
  314. {
  315. richTextBox_AdvanceParams.Clear();
  316. foreach (string sOutput in arrText)
  317. {
  318. richTextBox_AdvanceParams.AppendText(sOutput + "\r\n");
  319. }
  320. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 2);
  321. } while (false);
  322. }
  323. private void button_GenerateModelFile_Click(object sender, EventArgs e)
  324. {
  325. string DataFileName = "";
  326. string FileInfo = "";
  327. //填写文件名
  328. Scan ModeFileName = new Scan();
  329. ModeFileName.ShowDialog();
  330. if (ModeFileName.textBox_Scan.Text == string.Empty)
  331. {
  332. MessageBox.Show("文件名为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  333. return;
  334. }
  335. DataFileName = ModeFileName.textBox_Scan.Text + ".src";
  336. //核对文件名格式
  337. //...
  338. //获取模板文本信息写入文件
  339. FileInfo = richTextBox_AdvanceParams.Text;
  340. if (FileInfo == string.Empty)
  341. {
  342. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  343. return;
  344. }
  345. System.IO.File.WriteAllText(DataFileName, FileInfo);
  346. //模板文件上传服务器
  347. if (myFtp.CheckFtp() == true)
  348. {
  349. //上传文件
  350. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  351. if (result1 == true)
  352. {
  353. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  354. }
  355. else
  356. {
  357. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  358. }
  359. }
  360. else
  361. {
  362. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  363. }
  364. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  365. }
  366. private void button_ExportParams_Click(object sender, EventArgs e)
  367. {
  368. //检查
  369. if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked) == false)
  370. {
  371. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  372. return;
  373. }
  374. foreach (Control c in groupBox1.Controls)
  375. {
  376. if (c is TextBox)
  377. {
  378. if (c.Text == "")
  379. {
  380. MessageBox.Show("信息填写不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  381. return;
  382. }
  383. }
  384. }
  385. //分割参数
  386. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  387. try
  388. {
  389. //更新信息
  390. do
  391. {
  392. //建立字典,存放并获取每个命令的行号
  393. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  394. DicRowNum.Add("[整车参数]", 0);
  395. DicRowNum.Add("[控制参数]", 0);
  396. DicRowNum.Add("[助力参数]", 0);
  397. DicRowNum.Add("[调试参数]", 0);
  398. DicRowNum.Add("[生产信息]", 0);
  399. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  400. foreach (KeyValuePair<string, int> item in __dict)
  401. {
  402. for (int i = 0; i < lines.Length; i++)
  403. {
  404. if (lines[i].Contains(item.Key))
  405. {
  406. DicRowNum[item.Key] = i;
  407. break;
  408. }
  409. }
  410. }
  411. //遍历更新
  412. foreach (string index in DicRowNum.Keys)
  413. {
  414. int rowNum = DicRowNum[index]; //行号
  415. switch (index)
  416. {
  417. case "[整车参数]":
  418. {
  419. //轮胎周长
  420. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  421. //转把限速
  422. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  423. //推行限速
  424. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  425. //前牙盘
  426. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  427. //后牙盘
  428. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  429. //前后灯参数
  430. int LightParams = 0x0000;
  431. if (comboBox_BikeVolF.SelectedIndex == 0)
  432. LightParams |= 0x0006;
  433. else if (comboBox_BikeVolF.SelectedIndex == 1)
  434. LightParams |= 0x000C;
  435. else
  436. {
  437. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  438. return;
  439. }
  440. if (comboBox_BikeVolB.SelectedIndex == 0)
  441. LightParams |= 0x0600;
  442. else if (comboBox_BikeVolB.SelectedIndex == 1)
  443. LightParams |= 0x0C00;
  444. else
  445. {
  446. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  447. return;
  448. }
  449. if (comboBox_BikeModeB.SelectedIndex >= 0)
  450. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  451. else
  452. {
  453. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  454. return;
  455. }
  456. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  457. //启动模式
  458. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  459. //开机延迟
  460. int PowerTime = 0;
  461. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  462. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  463. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  464. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  465. break;
  466. }
  467. case "[控制参数]":
  468. {
  469. //峰值电流
  470. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  471. //过压保护
  472. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  473. //欠压保护
  474. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  475. break;
  476. }
  477. case "[助力参数]":
  478. {
  479. //限速起始
  480. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  481. //限速结束
  482. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  483. break;
  484. }
  485. case "[调试参数]":
  486. {
  487. //运行模式
  488. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  489. //旋转方向
  490. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  491. //功率限幅
  492. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  493. break;
  494. }
  495. case "[生产信息]":
  496. {
  497. //生产商
  498. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  499. //生产地
  500. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  501. //生产日期
  502. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  503. //产品标识
  504. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  505. break;
  506. }
  507. default: break;
  508. }
  509. }
  510. } while (false);
  511. //参数更新
  512. richTextBox_AdvanceParams.Clear();
  513. for (int i = 0; i < lines.Length; i++)
  514. {
  515. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  516. }
  517. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  518. }
  519. catch (System.Exception)
  520. {
  521. MessageBox.Show("参数更新失败", "提示", MessageBoxButtons.OK);
  522. return;
  523. }
  524. //确定本地保存路径
  525. string Date = DateTime.Now.ToString("yyyy-MM-dd");
  526. string LocalPath = localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + Date;
  527. if (!Directory.Exists(LocalPath))
  528. {
  529. Directory.CreateDirectory(LocalPath);
  530. }
  531. //确定远程保存路径
  532. string ServerPath = "";
  533. if (radioButton_HUB.Checked)
  534. {
  535. if (!myFtp.DirectoryExist("HUB_Control_TEST/cfg", Date))
  536. myFtp.MakeDir("HUB_Control_TEST/cfg" + "/" + Date);
  537. ServerPath = "HUB_Control_TEST/cfg" + "/" + Date;
  538. }
  539. else if (radioButton_MIGIC.Checked)
  540. {
  541. if (!myFtp.DirectoryExist("MIGIC_TEST/cfg", Date))
  542. myFtp.MakeDir("MIGIC_TEST/cfg" + "/" + Date);
  543. ServerPath = "MIGIC_TEST/cfg" + "/" + Date;
  544. }
  545. //确定文件名
  546. string fileName = "";
  547. fileName = textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  548. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + textBox_SoftwareVer.Text + "_" +
  549. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "-");
  550. //保存.src文件
  551. System.IO.File.WriteAllText(LocalPath + "\\" + fileName + ".src", richTextBox_AdvanceParams.Text);
  552. //检查是否存在转换工具
  553. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  554. {
  555. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  556. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  557. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  558. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  559. }
  560. else
  561. {
  562. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  563. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  564. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  565. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  566. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  567. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  568. }
  569. //转换.ttcfg文件
  570. ProcessStartInfo startInfo = new ProcessStartInfo();
  571. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  572. startInfo.Arguments = LocalPath + "\\" + fileName + ".src";
  573. System.Diagnostics.Process.Start(startInfo);
  574. Thread.Sleep(1000);
  575. //保存页面
  576. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  577. Graphics g = Graphics.FromImage(bit);
  578. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  579. bit.Save(LocalPath + "\\" + fileName + ".png");
  580. //生成pdf文件,上传服务器
  581. //上传
  582. bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath);
  583. bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath);
  584. bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath);
  585. if (result1 & result2 & result3)
  586. {
  587. MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK);
  588. }
  589. else
  590. {
  591. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK);
  592. }
  593. }
  594. }
  595. }