GenerateParams.cs 27 KB

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