private void Save() { ControlUtils.ShowLoading(this.loading, "保存中……"); bool isAutoSearch = cbNeedAutoSearchDel.IsChecked == true; lock (sync) { if (!IsUpdating) { IsUpdating = true; var delieryConfig = GetPageConfig(ImportDataType.交割单); var softConfig = GetPageConfig(ImportDataType.软件委托); if (SelectedTable != null) { SaveOneTable(SelectedTable, delieryConfig, softConfig); } else if (MatchConfigData.Count > 0) { List <string> groupNames = new List <string>(); foreach (string item in listBoxMatched.Items) { var groupName = item.GetFileName().GetGroupName(); if (item.GetImportType() == ImportDataType.软件委托 && !string.IsNullOrEmpty(groupName) && !groupNames.Contains(groupName)) { groupNames.Add(groupName.ToUpper()); } } listBoxMatched.ItemsSource = null; listBoxNotMatched.ItemsSource = NotMatchConfigData.Select(_ => _.TableName.GetFileName()); MatchConfigData.Clear(); var saving = new Action(() => { SaveMatchedTables(delieryConfig, softConfig); }); var completeUIAction = new Action(() => { ControlUtils.HideLoading(this.loading); if (OnDBChangeComplete != null) { OnDBChangeComplete.Invoke(); } if (cbNeedAutoSearchDel.IsChecked == true) { AutoSaveDelivery(groupNames, this.dpDate.SelectedDate.Value); } }); CommonUtils.RunAsync(this.Dispatcher, saving, null, null, completeUIAction); } IsUpdating = false; } } }
private void SaveOneTable(DataTable dt, Dictionary <string, string> deliConfig, Dictionary <string, string> softConfig) { string msg; bool isSuccess = true; bool isDeli = cboDataType.SelectedIndex == 0; Task.Run(() => { using (DataComparisionDataset db = new DataComparisionDataset()) { if (isDeli) { isSuccess = SaveAsDeliveryData(dt, db, deliConfig, true, out msg); } else { isSuccess = SaveAsSoftwareData(dt, db, softConfig, true, out msg); } } this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { MessageBox.Show(isSuccess ? "保存完毕!" : msg); if (isSuccess && !isDeli) { if (OnImportComplete != null) { //批量的软件委托,或者单独一个。 var listGroupName = new List <string>(); foreach (DataRow row in dt.Rows) { var groupName = row["组合号"].ToString(); if (!string.IsNullOrEmpty(groupName) && !listGroupName.Contains(groupName)) { listGroupName.Add(groupName.ToUpper()); } } OnImportComplete.Invoke(listGroupName, this.dpDate.SelectedDate.Value); } List <string> groupNames = new List <string>(); foreach (DataRow row in dt.Rows) { var group = (row["组合号"] + "").ToUpper(); if (!groupNames.Contains(group)) { groupNames.Add(group); } } if (cbNeedAutoSearchDel.IsChecked == true) { AutoSaveDelivery(groupNames, this.dpDate.SelectedDate.Value); } } if (NotMatchConfigData.Contains(dt)) { NotMatchConfigData.Remove(dt); listBoxNotMatched.ItemsSource = NotMatchConfigData.Select(_ => _.TableName.GetFileName()); } SelectedTable = null; ControlUtils.HideLoading(this.loading); dgImportData.ItemsSource = null; if (OnDBChangeComplete != null) { OnDBChangeComplete.Invoke(); } })); }); }