private static void Import() { //文件名 string fileName; //绝对路径 while (true) { ShowMsg("请输入文件的绝对路径:"); fullPath = Console.ReadLine(); fileName = Path.GetFileName(fullPath); if (!CheckedFileExist(fullPath)) { ShowMsg("不存在指定文件,请重新输入"); continue; } else { break; } } //while (true) //{ // ShowMsg("请输入文件名:"); // fileName = Console.ReadLine(); // if (!CheckedFileExist(Path.Combine(sourcePath, fileName))) // { // ShowMsg("不存在指定文件"); // continue; // } // else // { // break; // } //} //string fileName = "999测试群组二.txt"; //2 文件格式验证 if (Utils.ImportExportUtils.FileFormateValidation(fullPath)) { groupBLL = new BLL.P_GroupBLL(); departmentBLL = new BLL.P_DepartmentBLL(); personBLL = new BLL.P_PersonBLL(); r_personBLL = new PMS.BLL.P_PersonInfoBLL(); var list = LoadFile(fullPath, fileName); if(list.Count < 1) { ShowMsg("文件内容格式错误,请检查联系人信息是否完整,电话位数是否正确,并按说明要求导入"); } else { DBOperate(list); ShowMsg("导入联系人成功!共录入:" + list.Count() + " 人"); } } else { ShowMsg("文件名格式错误,请按说明要求导入"); } ShowMsg("点击任意键退出"); Console.ReadKey(); }
/// <summary> /// 2. 导出通讯录程序 /// </summary> private static void Export() { //2.1 选择导出路径 while (true) { ShowMsg("请输入想要导出的路径:"); sourcePath = Console.ReadLine(); if (!CheckedDirExist(sourcePath)) { ShowMsg("路径不存在请重新输入"); continue; } else { break; } } groupBLL = new BLL.P_GroupBLL(); departmentBLL = new BLL.P_DepartmentBLL(); personBLL = new BLL.P_PersonBLL(); r_personBLL = new PMS.BLL.P_PersonInfoBLL(); //2.3 导出的群组 var list = DBOperate(); //2.4 写入文件 SaveFile(sourcePath,list); ShowMsg("导出联系人成功!共导出:" + list.Count() + " 人"); ShowMsg("点击任意键退出"); Console.ReadKey(); }