using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Windows.Forms; using System.Xml.Serialization; using System.Text.RegularExpressions; using System.Net; namespace MOTINOVA_Motor_Factory_Set { public partial class ExportForm : Form { //参数按照字典类型存储 Dictionary Params1 = new Dictionary(); Dictionary Params2 = new Dictionary(); Dictionary MotorParam = new Dictionary(); Dictionary Otherinfo = new Dictionary(); Dictionary TestThData = new Dictionary(); //文件路径 public string FilePath = ""; public ExportForm() { InitializeComponent(); } private void ExportForm_Load(object sender, EventArgs e) { } private void SetDefault() { //参数1 Params1.Clear(); Params1.Add("启动模式", 2); Params1.Add("停机时间", 100); Params1.Add("限速值", 25); Params1.Add("下降速度", 3); Params1.Add("前飞", 14); Params1.Add("后飞", 9); Params1.Add("限流", 15); Params1.Add("温度预警", 95); Params1.Add("温度保护", 125); Params1.Add("码表", 0x55);//有,不支持无码表 Params1.Add("轮胎周长", 219);//cm Params1.Add("系列号", 0); Params1.Add("ECO增益", 100);//放大100倍 Params1.Add("ECO加速", 100); Params1.Add("NORM增益", 100); Params1.Add("NORM加速", 100); Params1.Add("SPORT增益", 100); Params1.Add("SPORT加速", 100); Params1.Add("TURBO增益", 100); Params1.Add("TURBO加速", 100); Params1.Add("SMART增益", 100); Params1.Add("SMART加速", 100); Params1.Add("车速级数", 1); Params1.Add("踏频启动", 2); Params1.Add("指拨模式", 0x55); Params1.Add("速度信号来源", 0x55);//传感器 Params1.Add("周长微调", 0); Params1.Add("低压保护", 3100);//mV Params1.Add("推行限速", 60);//放大10倍 Params1.Add("推行转速", 135); //参数2 Params2.Clear(); Params2.Add("姿态传感器", 0x55);//不支持 Params2.Add("俯仰角零偏", 0); Params2.Add("横滚角零偏", 0); Params2.Add("尾灯模式", 2); Params2.Add("前灯电压", 12); Params2.Add("尾灯电压", 12); //马达参数 MotorParam.Clear(); MotorParam.Add("额定功率", 250); MotorParam.Add("额定转速", 1200); MotorParam.Add("定子电阻", 10); MotorParam.Add("定子Lq", 10); MotorParam.Add("定子Ld", 10); MotorParam.Add("反电动势", 36000); MotorParam.Add("额定电压", 36); //其它信息 Otherinfo.Clear(); Otherinfo.Add("生产商", "TTIUM"); Otherinfo.Add("生产地", "WUHAN"); Otherinfo.Add("生产日期", "20200901"); Otherinfo.Add("校验密钥", "AVONITOM"); Otherinfo.Add("信息1", ""); Otherinfo.Add("信息2", ""); Otherinfo.Add("信息3", ""); //测试阈值 TestThData.Clear(); TestThData.Add("空载电流", 1000); TestThData.Add("车速", 150); TestThData.Add("指拨转速", 1200); TestThData.Add("零偏最小值", 200); TestThData.Add("零偏最大值", 1800); TestThData.Add("标定系数最小值", 25); TestThData.Add("标定系数最大值", 75); TestThData.Add("启动值最小值", 350); TestThData.Add("启动值最大值", 750); } private void ParamsDisplayUpdate() { //参数1 if (Params1["启动模式"] == 1) { comboBox_StartMode.Text = "柔和"; } else if (Params1["启动模式"] == 2) { comboBox_StartMode.Text = "正常"; } else if (Params1["启动模式"] == 3) { comboBox_StartMode.Text = "强劲"; } textBox_StopTime.Text = Params1["停机时间"].ToString(); textBox_SpeedLimit.Text = Params1["限速值"].ToString(); textBox_Dec.Text = Params1["下降速度"].ToString(); textBox_T_Front.Text = Params1["前飞"].ToString(); textBox_T_Tail.Text = Params1["后飞"].ToString(); textBox_MaxCurrent.Text = Params1["限流"].ToString(); textBox_NTC_Alarm.Text = Params1["温度预警"].ToString(); textBox_NTC_Ptotect.Text = Params1["温度保护"].ToString(); if (Params1["码表"] == 0x55) { comboBox_NoPBU.Text = "有"; } else if (Params1["码表"] == 0xAA) { comboBox_NoPBU.Text = "无"; } textBox_WheelSize.Text = Params1["轮胎周长"].ToString(); textBox_Serial.Text = Params1["系列号"].ToString(); textBox_ECO_Gain.Text = ((float)(Params1["ECO增益"]) / 100.0f).ToString("#0.00"); textBox_ECO_Acc.Text = ((float)(Params1["ECO加速"]) / 100.0f).ToString("#0.00"); textBox_NORM_Gain.Text = ((float)(Params1["NORM增益"]) / 100.0f).ToString("#0.00"); textBox_NORM_Acc.Text = ((float)(Params1["NORM加速"]) / 100.0f).ToString("#0.00"); textBox_SPORT_Gain.Text = ((float)(Params1["SPORT增益"]) / 100.0f).ToString("#0.00"); textBox_SPORT_Acc.Text = ((float)(Params1["SPORT加速"]) / 100.0f).ToString("#0.00"); textBox_TURBO_Gain.Text = ((float)(Params1["TURBO增益"]) / 100.0f).ToString("#0.00"); textBox_TURBO_Acc.Text = ((float)(Params1["TURBO加速"]) / 100.0f).ToString("#0.00"); textBox_SMART_Gain.Text = ((float)(Params1["SMART增益"]) / 100.0f).ToString("#0.00"); textBox_SMART_Acc.Text = ((float)(Params1["SMART加速"]) / 100.0f).ToString("#0.00"); textBox_SpeedSensor.Text = Params1["车速级数"].ToString(); textBox_CadenceStart.Text = Params1["踏频启动"].ToString(); if (Params1["指拨模式"] == 0x55) { comboBox_GasMode.Text = "不支持"; } else if (Params1["指拨模式"] == 0xAA) { comboBox_GasMode.Text = "支持"; } if (Params1["速度信号来源"] == 0x55) { comboBox_SpeedSensor.Text = "传感器"; } else if (Params1["速度信号来源"] == 0xAA) { comboBox_SpeedSensor.Text = "踏频"; } else if (Params1["速度信号来源"] == 0xEE) { comboBox_SpeedSensor.Text = "通信"; } textBox_WheelSizeAdj.Text = Params1["周长微调"].ToString(); textBox_UV_Protect.Text = Params1["低压保护"].ToString(); textBox_Walk_SpeedLimit.Text = ((float)(Params1["推行限速"]) / 10.0f).ToString("#0.0"); textBox_WalkSpeed.Text = Params1["推行转速"].ToString(); //参数2 if (Params2["姿态传感器"] == 0x55) { comboBox_AstSensor.Text = "不支持"; } else if (Params1["姿态传感器"] == 0xAA) { comboBox_AstSensor.Text = "支持"; } textBox_Angle_P.Text = ((float)(Params2["俯仰角零偏"]) / 10.0f).ToString("#0.0"); textBox_Angle_R.Text = ((float)(Params2["横滚角零偏"]) / 10.0f).ToString("#0.0"); if (Params2["尾灯模式"] == 1) { comboBox_LightMode.Text = "模式 1"; } else if (Params2["尾灯模式"] == 2) { comboBox_LightMode.Text = "模式 2"; } else if (Params2["尾灯模式"] == 3) { comboBox_LightMode.Text = "模式 3"; } else if (Params2["尾灯模式"] == 4) { comboBox_LightMode.Text = "模式 4"; } if (Params2["前灯电压"] == 6) { comboBox_HeadLightVol.Text = "6V"; } else if (Params2["前灯电压"] == 12) { comboBox_HeadLightVol.Text = "12V"; } else if (Params2["前灯电压"] == 0xFF) { comboBox_HeadLightVol.Text = "随电池"; } else if (Params2["前灯电压"] == 0) { comboBox_HeadLightVol.Text = "硬件配置"; } if (Params2["尾灯电压"] == 6) { comboBox_TailLightVol.Text = "6V"; } else if (Params2["尾灯电压"] == 12) { comboBox_TailLightVol.Text = "12V"; } else if (Params2["尾灯电压"] == 0xFF) { comboBox_TailLightVol.Text = "随电池"; } else if (Params2["尾灯电压"] == 0) { comboBox_TailLightVol.Text = "硬件配置"; } //马达参数 textBox_RatePower.Text = MotorParam["额定功率"].ToString(); textBox_RateSpeed.Text = MotorParam["额定转速"].ToString(); textBox_RotorR.Text = MotorParam["定子电阻"].ToString(); textBox_Rotor_Lq.Text = MotorParam["定子Lq"].ToString(); textBox_Rotor_Ld.Text = MotorParam["定子Ld"].ToString(); textBox_E.Text = MotorParam["反电动势"].ToString(); textBox_Rate_Vol.Text = MotorParam["额定电压"].ToString(); //其它信息 textBox_Mac.Text = Otherinfo["生产商"].ToString(); textBox_Mac_Addr.Text = Otherinfo["生产地"].ToString(); textBox_Mac_Date.Text = Otherinfo["生产日期"].ToString(); textBox_Secrect.Text = Otherinfo["校验密钥"].ToString(); textBox_Info1.Text = Otherinfo["信息1"].ToString(); textBox_Info2.Text = Otherinfo["信息2"].ToString(); textBox_Info3.Text = Otherinfo["信息3"].ToString(); //测试阈值 textBox_NC_Current.Text = TestThData["空载电流"].ToString(); textBox_SpeedTh.Text = TestThData["车速"].ToString(); textBox_GasSpeedTh.Text = TestThData["指拨转速"].ToString(); textBox_Zero_Min.Text = TestThData["零偏最小值"].ToString(); textBox_Zero_Max.Text = TestThData["零偏最大值"].ToString(); textBox_K_Min.Text = ((float)(TestThData["标定系数最小值"]) / 100.0f).ToString("#0.00"); textBox_K_Max.Text = ((float)(TestThData["标定系数最大值"]) / 100.0f).ToString("#0.00"); textBox_Start_Min.Text = TestThData["启动值最小值"].ToString(); textBox_Start_Max.Text = TestThData["启动值最大值"].ToString(); } private bool DisplaySetToParams() { try { //参数1 Params1.Clear(); if (comboBox_StartMode.Text == "柔和") { Params1.Add("启动模式", 1); } else if (comboBox_StartMode.Text == "正常") { Params1.Add("启动模式", 2); } else if (comboBox_StartMode.Text == "强劲") { Params1.Add("启动模式", 3); } else { MessageBox.Show("请检查启动模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("停机时间", Convert.ToUInt16(textBox_StopTime.Text)); if (Params1["停机时间"] < 50 || Params1["停机时间"] > 500) { MessageBox.Show("停机时间有效值:50~500 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("限速值", Convert.ToUInt16(textBox_SpeedLimit.Text)); if (Params1["限速值"] < 5 || Params1["限速值"] > 80) { MessageBox.Show("限速值有效值:5~80 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("下降速度", Convert.ToUInt16(textBox_Dec.Text)); if (Params1["下降速度"] < 1 || Params1["下降速度"] > 5) { MessageBox.Show("下降速度有效值:1~5 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("前飞", Convert.ToUInt16(textBox_T_Front.Text)); if (Params1["前飞"] < 5 || Params1["前飞"] > 100) { MessageBox.Show("前飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("后飞", Convert.ToUInt16(textBox_T_Tail.Text)); if (Params1["后飞"] < 5 || Params1["后飞"] > 100) { MessageBox.Show("后飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("限流", Convert.ToUInt16(textBox_MaxCurrent.Text)); if (Params1["限流"] < 5 || Params1["限流"] > 25) { MessageBox.Show("限流有效值:5~25 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("温度预警", Convert.ToUInt16(textBox_NTC_Alarm.Text)); Params1.Add("温度保护", Convert.ToUInt16(textBox_NTC_Ptotect.Text)); if (comboBox_NoPBU.Text == "有") { Params1.Add("码表", 0x55); } else if (comboBox_NoPBU.Text == "无") { Params1.Add("码表", 0xAA); } else { MessageBox.Show("请检查无码表设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Params1.Add("轮胎周长", Convert.ToUInt16(textBox_WheelSize.Text)); if (Params1["轮胎周长"] < 100 || Params1["轮胎周长"] > 250) { MessageBox.Show("轮胎周长有效值:100~250 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("系列号", Convert.ToUInt16(textBox_Serial.Text)); if (Params1["系列号"] < 1 || Params1["系列号"] > 16) { MessageBox.Show("系列号有效值:1~16 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Params1.Add("ECO增益", Convert.ToUInt16(float.Parse(textBox_ECO_Gain.Text) * 100));//放大100倍 Params1.Add("ECO加速", Convert.ToUInt16(float.Parse(textBox_ECO_Acc.Text) * 100)); Params1.Add("NORM增益", Convert.ToUInt16(float.Parse(textBox_NORM_Gain.Text) * 100)); Params1.Add("NORM加速", Convert.ToUInt16(float.Parse(textBox_NORM_Acc.Text) * 100)); Params1.Add("SPORT增益", Convert.ToUInt16(float.Parse(textBox_SPORT_Gain.Text) * 100)); Params1.Add("SPORT加速", Convert.ToUInt16(float.Parse(textBox_SPORT_Acc.Text) * 100)); Params1.Add("TURBO增益", Convert.ToUInt16(float.Parse(textBox_TURBO_Gain.Text) * 100)); Params1.Add("TURBO加速", Convert.ToUInt16(float.Parse(textBox_TURBO_Acc.Text) * 100)); Params1.Add("SMART增益", Convert.ToUInt16(float.Parse(textBox_SMART_Gain.Text) * 100)); Params1.Add("SMART加速", Convert.ToUInt16(float.Parse(textBox_SMART_Acc.Text) * 100)); Params1.Add("车速级数", Convert.ToUInt16(textBox_SpeedSensor.Text)); Params1.Add("踏频启动", Convert.ToUInt16(textBox_CadenceStart.Text)); if (comboBox_GasMode.Text == "不支持") { Params1.Add("指拨模式", 0x55); } else if (comboBox_GasMode.Text == "支持") { Params1.Add("指拨模式", 0xAA); } else { MessageBox.Show("请检查指拨模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (comboBox_SpeedSensor.Text == "传感器") { Params1.Add("速度信号来源", 0x55); } else if (comboBox_SpeedSensor.Text == "踏频") { Params1.Add("速度信号来源", 0xAA); } else if (comboBox_SpeedSensor.Text == "通信") { Params1.Add("速度信号来源", 0xEE); } else { MessageBox.Show("请检查速度信号来源设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Params1.Add("周长微调", Convert.ToUInt16(textBox_WheelSizeAdj.Text)); Params1.Add("低压保护", Convert.ToUInt16(textBox_UV_Protect.Text));//mV Params1.Add("推行限速", Convert.ToUInt16(float.Parse(textBox_Walk_SpeedLimit.Text) * 10));//放大10倍 Params1.Add("推行转速", Convert.ToUInt16(textBox_WalkSpeed.Text)); //参数2 Params2.Clear(); if (comboBox_AstSensor.Text == "不支持") { Params2.Add("姿态传感器", 0x55); } else if (comboBox_AstSensor.Text == "支持") { Params2.Add("姿态传感器", 0xAA); } else { MessageBox.Show("请检查姿态传感器设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Params2.Add("俯仰角零偏", Convert.ToUInt16(float.Parse(textBox_Angle_P.Text) * 10)); Params2.Add("横滚角零偏", Convert.ToUInt16(float.Parse(textBox_Angle_R.Text) * 10)); if (comboBox_LightMode.Text == "模式 1") { Params2.Add("尾灯模式", 1); } else if(comboBox_LightMode.Text == "模式 2") { Params2.Add("尾灯模式", 2); } else if (comboBox_LightMode.Text == "模式 3") { Params2.Add("尾灯模式", 3); } else if (comboBox_LightMode.Text == "模式 4") { Params2.Add("尾灯模式", 4); } if (comboBox_HeadLightVol.Text == "6V") { Params2.Add("前灯电压", 6); } else if (comboBox_HeadLightVol.Text == "12V") { Params2.Add("前灯电压", 12); } else if (comboBox_HeadLightVol.Text == "随电池") { Params2.Add("前灯电压", 0xFF); } else if (comboBox_HeadLightVol.Text == "硬件配置") { Params2.Add("前灯电压", 0); } if (comboBox_TailLightVol.Text == "6V") { Params2.Add("尾灯电压", 6); } else if (comboBox_TailLightVol.Text == "12V") { Params2.Add("尾灯电压", 12); } else if (comboBox_TailLightVol.Text == "随电池") { Params2.Add("尾灯电压", 0xFF); } else if (comboBox_TailLightVol.Text == "硬件配置") { Params2.Add("尾灯电压", 0); } //马达参数 MotorParam.Clear(); MotorParam.Add("额定功率", Convert.ToUInt16(textBox_RatePower.Text)); MotorParam.Add("额定转速", Convert.ToUInt16(textBox_RateSpeed.Text)); MotorParam.Add("定子电阻", Convert.ToUInt16(textBox_RotorR.Text)); MotorParam.Add("定子Lq", Convert.ToUInt16(textBox_Rotor_Lq.Text)); MotorParam.Add("定子Ld", Convert.ToUInt16(textBox_Rotor_Ld.Text)); MotorParam.Add("反电动势", Convert.ToUInt16(textBox_E.Text)); MotorParam.Add("额定电压", Convert.ToUInt16(textBox_Rate_Vol.Text)); //其它信息 Otherinfo.Clear(); Otherinfo.Add("生产商", textBox_Mac.Text); Otherinfo.Add("生产地", textBox_Mac_Addr.Text); Otherinfo.Add("生产日期", textBox_Mac_Date.Text); Otherinfo.Add("校验密钥", textBox_Secrect.Text); Otherinfo.Add("信息1", textBox_Info1.Text); Otherinfo.Add("信息2", textBox_Info2.Text); Otherinfo.Add("信息3", textBox_Info3.Text); //测试阈值 TestThData.Clear(); TestThData.Add("空载电流", Convert.ToUInt16(textBox_NC_Current.Text)); TestThData.Add("车速", Convert.ToUInt16(textBox_SpeedTh.Text)); TestThData.Add("指拨转速", Convert.ToUInt16(textBox_GasSpeedTh.Text)); TestThData.Add("零偏最小值", Convert.ToUInt16(textBox_Zero_Min.Text)); TestThData.Add("零偏最大值", Convert.ToUInt16(textBox_Zero_Max.Text)); TestThData.Add("标定系数最小值", Convert.ToUInt16(float.Parse(textBox_K_Min.Text) * 100)); TestThData.Add("标定系数最大值", Convert.ToUInt16(float.Parse(textBox_K_Max.Text) * 100)); TestThData.Add("启动值最小值", Convert.ToUInt16(textBox_Start_Min.Text)); TestThData.Add("启动值最大值", Convert.ToUInt16(textBox_Start_Max.Text)); return true; } catch(Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } } private void button_Default_Click(object sender, EventArgs e) { SetDefault(); ParamsDisplayUpdate(); } private void button_Generate_Click(object sender, EventArgs e) { //空间内容更新到字典 if (DisplaySetToParams() == false) { MessageBox.Show("参数生成失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //保存为文件 if (textBox_Model.Text == string.Empty) //判断型号是否填写 { MessageBox.Show("请输入电机型号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (textBox_Client.Text == string.Empty) //判断客户号是否填写 { textBox_Client.Text = "STD"; } Regex Reg = new Regex(@"[V][0-9].[0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9]|[0-9][0-9]_20\d{6}"); if (Reg.IsMatch(textBox_FW_Version.Text) == false) //判断主控软件版本是否填写 { MessageBox.Show("主控软件版本格式不正确,例如V1.0.0.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Reg = new Regex(@"[V][0-9].[0-9].[0-9]_20\d{6}"); //判断TE软件版本是否填写 if (Reg.IsMatch(textBox_TE_FW_Version.Text) == false) //判断TE软件版本是否填写 { MessageBox.Show("TE软件版本格式不正确,例如V1.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (System.IO.Directory.Exists(FilePath) == false) System.IO.Directory.CreateDirectory(FilePath); string Datenow = DateTime.Now.ToString("yyyy-MM-dd") + "\\"; if (System.IO.Directory.Exists(FilePath + Datenow) == false) System.IO.Directory.CreateDirectory(FilePath + Datenow); string fileName = FilePath + Datenow + textBox_Model.Text + "_" + textBox_Client.Text + "_" + textBox_FW_Version.Text + "_" + textBox_TE_FW_Version.Text + "_" + ((textBox_Remark.Text == string.Empty) ? "" : textBox_Remark.Text + "_") + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".ttcfg"; using (StreamWriter file = new StreamWriter(fileName)) { //用户参数1 file.WriteLine("[{0}]", "用户参数1"); foreach (var entry in Params1) if (entry.Key == "码表") file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "有" : entry.Value == 0xAA ? "无" : "无效"); else if (entry.Key == "指拨模式") file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "不支持" : entry.Value == 0xAA ? "支持" : "无效"); else if (entry.Key == "速度信号来源") file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "传感器" : entry.Value == 0xAA ? "踏频" : entry.Value == 0xEE ? "通信" : "无效"); else file.WriteLine("{0},{1}", entry.Key, entry.Value); //用户参数2 file.WriteLine(""); file.WriteLine("[{0}]", "用户参数2"); foreach (var entry in Params2) if (entry.Key == "姿态传感器") file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "不支持" : entry.Value == 0xAA ? "支持" : "无效"); else if (entry.Key == "前灯电压") file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V"); else if (entry.Key == "尾灯电压") file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V"); else file.WriteLine("{0},{1}", entry.Key, entry.Value); //马达参数 file.WriteLine(""); file.WriteLine("[{0}]", "马达参数"); foreach (var entry in MotorParam) file.WriteLine("{0},{1}", entry.Key, entry.Value); //其它信息 file.WriteLine(""); file.WriteLine("[{0}]", "其它信息"); foreach (var entry in Otherinfo) file.WriteLine("{0},{1}", entry.Key, entry.Value); //测试阈值 file.WriteLine(""); file.WriteLine("[{0}]", "测试阈值"); foreach (var entry in TestThData) file.WriteLine("{0},{1}", entry.Key, entry.Value); } MessageBox.Show("参数已生成,进入文件管理页面查看!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //发送文件到服务器 if (StartForm.myFtp.IsNetConnected == true) { string DateNow = DateTime.Now.ToString("yyyy-MM-dd"); if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/cfg/", DateNow) == false) { StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/cfg/" + DateNow); } bool result = StartForm.myFtp.UploadFile(fileName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow); if (result == true) { MessageBox.Show("文件上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }