public static void ExportSingleData(string folder, List <T> list) { if (list != null && list.Count > 0) { FormatterSerializerBll <T> .ExportData(Path.Combine(folder, typeof(T).Name + DateTime.Now.ToString("yyyyMMddhhmmss") + ".wdb"), list); } }
public static void BackuData(string folder, string name) { var list = new BaseBllImpl <T>().SelectAll(); if (list != null && list.Count > 0) { FormatterSerializerBll <T> .ExportData(Path.Combine(folder, name + ".wdb"), list); } }
/// <summary> /// 导入数据 /// </summary> /// <param name="fullName"></param> public static void DaoRuData(string fullName) { var imps = FormatterSerializerBll <T> .ImportData(fullName); var dataBll = new BaseBllImpl <T>(); foreach (var imp in imps) { imp.Id = ""; dataBll.Add(imp); } }
/// <summary> /// 添加数据 /// </summary> /// <param name="fullName"></param> public static void InsertData(string fullName) { var imps = FormatterSerializerBll <T> .ImportData(fullName); var dataBll = new BaseBllImpl <T>(); foreach (var imp in imps) { dataBll.Delete(p => p.Id == imp.Id); dataBll.Add(imp); } }
/// <summary> /// 导入全部数据 /// </summary> private void AddAllData() { string path = string.Empty; FolderBrowserDialog browserDialog = new FolderBrowserDialog(); browserDialog.ShowNewFolderButton = false; if (browserDialog.ShowDialog() == DialogResult.OK) { path = browserDialog.SelectedPath; } if (string.IsNullOrEmpty(path)) { MessageBox.Show(this, "未选择导入文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DirectoryInfo directory = new DirectoryInfo(path); FileInfo[] files = directory.GetFiles(); if (files == null || files.Count() == 0) { MessageBox.Show(this, string.Format(directory.Name + "文件夹中没有文件,无法导入!"), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool boo = true; using (var ssm = new SplashScreenManager(this, typeof(SysWaitForm), true, true)) { ssm.ShowWaitForm(); ssm.SetWaitFormDescription("正在导入..."); //遍历所有文件 try { foreach (var file in files) { if (file.Length == 0) { continue; } if (file.Name.Contains("Command")) { var personFileList = FormatterSerializerBll <Command> .ImportData(file.FullName); var commandList = DbFactory.CommandBll.SelectAll(); foreach (var o in personFileList) { var oCount = commandList.Where(p => p.Cmd.Equals(o.Cmd) || p.Cmd.StartsWith(o.Cmd + "(")).ToList().Count(); o.Cmd = oCount == 0 ? o.Cmd : o.Cmd + "(" + oCount + ")"; o.Id = null; DbFactory.CommandBll.Insert(o); } continue; } else if (file.Name.Contains("Dut")) { var personFileList = FormatterSerializerBll <Dut> .ImportData(file.FullName); var DutList = DbFactory.DutBll.SelectAll(); foreach (var o in personFileList) { var oCount = DutList.Where(p => p.Name.Equals(o.Name) || p.Name.StartsWith(o.Name + "(")).ToList().Count(); o.Name = oCount == 0 ? o.Name : o.Name + "(" + oCount + ")"; o.Id = null; DbFactory.DutBll.Insert(o); } continue; } else if (file.Name.Contains("Project")) { var personFileList = FormatterSerializerBll <Project> .ImportData(file.FullName); var ProjectList = DbFactory.ProjectBll.SelectAll(); foreach (var o in personFileList) { var oCount = ProjectList.Where(p => p.Name.Equals(o.Name) || p.Name.StartsWith(o.Name + "(")).ToList().Count(); o.Name = oCount == 0 ? o.Name : o.Name + "(" + oCount + ")"; o.Id = null; DbFactory.ProjectBll.Insert(o); } continue; } else if (file.Name.Contains("TestCase")) { var personFileList = FormatterSerializerBll <TestCase> .ImportData(file.FullName); var TestCaseList = DbFactory.TestCaseBll.SelectAll(); foreach (var o in personFileList) { var oCount = TestCaseList.Where(p => p.Name.Equals(o.Name) || p.Name.StartsWith(o.Name + "(")).ToList().Count(); o.Name = oCount == 0 ? o.Name : o.Name + "(" + oCount + ")"; o.Id = null; DbFactory.TestCaseBll.Insert(o); } continue; } else if (file.Name.Contains("TestDevice")) { var personFileList = FormatterSerializerBll <TestDevice> .ImportData(file.FullName); var TestDeviceList = DbFactory.TestDeviceBll.SelectAll(); foreach (var o in personFileList) { var oCount = TestDeviceList.Where(p => p.DeviceCode.Equals(o.DeviceCode) || p.DeviceCode.StartsWith(o.DeviceCode + "(")).ToList().Count(); o.DeviceCode = oCount == 0 ? o.DeviceCode : o.DeviceCode + "(" + oCount + ")"; o.Id = null; DbFactory.TestDeviceBll.Insert(o); } continue; } else if (file.Name.Contains("TestParams")) { var personFileList = FormatterSerializerBll <TestParams> .ImportData(file.FullName); var TestParamsList = DbFactory.TestParamsBll.SelectAll(); foreach (var o in personFileList) { var oCount = TestParamsList.Where(p => p.Name.Equals(o.Name) || p.Name.StartsWith(o.Name + "(")).ToList().Count(); o.Name = oCount == 0 ? o.Name : o.Name + "(" + oCount + ")"; o.Id = null; DbFactory.TestParamsBll.Insert(o); } continue; } else { continue; } } if (boo == true) { ssm.CloseWaitForm(); MessageBox.Show(this, "数据导入完毕!", "提示", MessageBoxButtons.OK); } } catch (Exception) { ssm.CloseWaitForm(); MessageBox.Show(this, "导入的数据格式不正确!", "提示", MessageBoxButtons.OK); boo = false; } } }