/// <summary> /// 导入VIN /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImportVin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { PorscheUtils utils = new PorscheUtils(true); FolderDialog openFolder = new FolderDialog(); try { if (openFolder.DisplayDialog() == DialogResult.OK) { // 获取用户选择的文件夹路径 string folderPath = openFolder.Path.ToString(); // 获取folderPath下以格式为utils.CocFileName的所有文件 List <string> fileNameList = utils.GetFileName(folderPath, utils.VinFileName); if (fileNameList.Count > 0) { string fileNameMsg = string.Empty; string returnMsg = string.Empty; // 获取全部车型参数数据,用作合并VIN数据 bool IsMainDataExist = utils.GetMainData(); bool IsLtggExist = utils.GetOtherMainData("LTGG"); bool IsLjExist = utils.GetOtherMainData("LJ"); bool IsZczbzlExist = utils.GetOtherMainData("ZCZBZL"); StringBuilder sbMsg = new StringBuilder("系统中不存在"); bool flag = false; if (!IsMainDataExist) { flag = true; sbMsg.Append("\r\n \t车型参数数据"); } if (!IsLtggExist) { flag = true; sbMsg.Append("\r\n \t轮胎规格数据"); } if (!IsLjExist) { flag = true; sbMsg.Append("\r\n \t轮距数据"); } if (!IsZczbzlExist) { flag = true; sbMsg.Append("\r\n \t整车整备质量数据"); } if (flag) { MessageBox.Show(sbMsg.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // 遍历读所有文件fileNameList foreach (string fileName in fileNameList) { // fileNameMsg += Path.GetFileName(fileName) + "\r\n"; // 导入filename文件信息 returnMsg += utils.ImportVinData(fileName, folderPath); } MessageForm mf = new MessageForm(returnMsg); Utils.SetFormMid(mf); mf.Text = "导入结果"; mf.ShowDialog(); } else { MessageBox.Show("目录" + folderPath + "下没有文件" + utils.VinFileName); } } } catch (Exception ex) { MessageBox.Show("导入失败:" + ex.Message); } }
/// <summary> /// /// </summary> /// <param name="importType"></param> /// <param name="paramName"></param> /// <param name="fileType">文件类别,如轮胎规格文件</param> protected void ImportOtherMainData(string importType, string paramName, string fileType) { string operateType = string.Empty; if (importType == "IMPORT") { operateType = "导入"; } else if (importType == "UPDATE") { operateType = "修改"; } PorscheUtils utils = new PorscheUtils(true); FolderDialog openFolder = new FolderDialog(); //openFolder. try { if (openFolder.DisplayDialog() == DialogResult.OK) { // 获取用户选择的文件夹路径 string folderPath = openFolder.Path.ToString(); // 获取folderPath下以格式为utils.CocFileName的所有文件 List <string> fileNameList = utils.GetFileName(folderPath, utils.GetMainFileName(fileType)); if (fileNameList.Count > 0) { string fileNameMsg = string.Empty; string returnMsg = string.Empty; List <string> mainUpdateList = new List <string>(); // 遍历读所有文件fileNameList foreach (string fileName in fileNameList) { fileNameMsg += Path.GetFileName(fileName) + "\r\n"; // 导入filename文件信息 returnMsg += utils.ImportOtherMainData(fileName, folderPath, paramName, importType, mainUpdateList); } if (string.IsNullOrEmpty(returnMsg)) { MessageForm mf = new MessageForm("以下文件" + operateType + "成功:\r\n" + fileNameMsg); Utils.SetFormMid(mf); mf.Text = operateType + "成功"; mf.ShowDialog(); } else { MessageForm mf = new MessageForm(returnMsg); Utils.SetFormMid(mf); mf.Text = operateType + "结果"; mf.ShowDialog(); } if (importType == "IMPORT") { switch (paramName) { case "LTGG": this.ShowOtherMainData("LTGG"); break; case "LJ": this.ShowOtherMainData("LJ"); break; case "ZCZBZL": this.ShowOtherMainData("ZCZBZL"); break; default: break; } } else if (importType == "UPDATE") { this.ShowUpdatedMainData(mainUpdateList); } } else { MessageBox.Show("目录" + folderPath + "下没有文件" + utils.MainFileName); } } } catch (Exception ex) { MessageBox.Show(operateType + "失败:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } }