/// <summary> /// /// </summary> private void ImportFromFile() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "csv|*.csv"; List <TagViewModel> ltmp = new List <TagViewModel>(); if (ofd.ShowDialog().Value) { var stream = new StreamReader(File.Open(ofd.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)); while (!stream.EndOfStream) { string sval = stream.ReadLine(); if (!string.IsNullOrEmpty(sval)) { TagViewModel tm = TagViewModel.LoadFromCSVString(sval); ltmp.Add(tm); } } stream.Close(); } var tags = mSelectGroupTags.ToDictionary(e => e.RealTagMode.Id); foreach (var vv in ltmp) { if (tags.ContainsKey(vv.RealTagMode.Id)) { if (!DevelopServiceHelper.Helper.UpdateTag(GroupModel.Database, new Tuple <Cdy.Tag.Tagbase, Cdy.Tag.HisTag>(vv.RealTagMode, vv.HisTagMode))) { MessageBox.Show(string.Format(Res.Get("UpdateTagFail"), vv.RealTagMode.Name), Res.Get("erro"), MessageBoxButton.OK, MessageBoxImage.Error); break; } } else { int id; if (!DevelopServiceHelper.Helper.AddTag(GroupModel.Database, new Tuple <Cdy.Tag.Tagbase, Cdy.Tag.HisTag>(vv.RealTagMode, vv.HisTagMode), out id)) { MessageBox.Show(string.Format(Res.Get("AddTagFail"), vv.RealTagMode.Name), Res.Get("erro"), MessageBoxButton.OK, MessageBoxImage.Error); break; } else { vv.RealTagMode.Id = id; if (vv.HisTagMode != null) { vv.HisTagMode.Id = id; } vv.IsChanged = false; vv.IsNew = false; } } } System.Threading.Tasks.Task.Run(() => { mCurrentPageIndex--; ContinueQueryTags(); }); }
/// <summary> /// /// </summary> private void ImportFromFile() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "csv|*.csv"; List <TagViewModel> ltmp = new List <TagViewModel>(); if (ofd.ShowDialog().Value) { var stream = new StreamReader(File.Open(ofd.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)); while (!stream.EndOfStream) { string sval = stream.ReadLine(); if (!string.IsNullOrEmpty(sval)) { TagViewModel tm = TagViewModel.LoadFromCSVString(sval); ltmp.Add(tm); } } stream.Close(); } int mode = 0; var mm = new ImportModeSelectViewModel(); if (mm.ShowDialog().Value) { mode = mm.Mode; } else { return; } StringBuilder sb = new StringBuilder(); Task.Run(() => { ServiceLocator.Locator.Resolve <IProcessNotify>().BeginShowNotify(); //删除所有,重新添加 if (mode == 1) { DevelopServiceHelper.Helper.ClearTagByGroup(GroupModel.Database, GroupModel.FullName); } //var tags = mSelectGroupTags.ToDictionary(e => e.RealTagMode.Name); int tcount = ltmp.Count; int icount = 0; bool haserro = false; int id = 0; foreach (var vv in ltmp) { vv.RealTagMode.Group = this.GroupModel.FullName; //更新数据 if (!DevelopServiceHelper.Helper.Import(GroupModel.Database, new Tuple <Tagbase, HisTag>(vv.RealTagMode, vv.HisTagMode), mode, out id)) { sb.AppendLine(string.Format(Res.Get("AddTagFail"), vv.RealTagMode.Name)); haserro = true; } else { vv.IsNew = false; vv.IsChanged = false; } icount++; ServiceLocator.Locator.Resolve <IProcessNotify>().ShowNotifyValue(((icount * 1.0 / tcount) * 100)); } if (haserro) { string errofile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(ofd.FileName), "erro.txt"); System.IO.File.WriteAllText(errofile, sb.ToString()); if (MessageBox.Show(Res.Get("ImportErroMsg"), "", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { try { Process.Start(Path.GetDirectoryName(errofile)); } catch { } } } mCurrentPageIndex = -1; mTotalPageNumber = -1; ContinueQueryTags(); Application.Current?.Dispatcher.BeginInvoke(new Action(() => { ServiceLocator.Locator.Resolve <IProcessNotify>().EndShowNotify(); })); }); }