void worker_DoWork(object sender, DoWorkEventArgs e) { Dictionary <Guid, String> lineIDs = new Dictionary <Guid, String>(); List <String> moduleIDs = new List <String>(); string strModuleIDs = string.Empty; Dictionary <Guid, String> dModuleIDs = new Dictionary <Guid, String>(); foreach (TreeNode node in treeLines.Nodes[0].Nodes) { if (node.Checked) { lineIDs.Add(new Guid(node.Name), node.Text); } } foreach (TreeNode node in treeModule.Nodes[0].Nodes) { foreach (TreeNode n in node.Nodes) { if (n.Checked) { moduleIDs.Add(n.Name); strModuleIDs += string.Format("'{0}',", n.Name); dModuleIDs.Add(new Guid(n.Name), n.Text); } } } if (moduleIDs.Count == 0 || lineIDs.Count == 0) { MessageBox.Show("请至少选则一条线路或一个模板!"); return; } strModuleIDs = strModuleIDs.Substring(0, strModuleIDs.Length - 1); string strFMsg = string.Empty; using (DataTable dtForbidLines = ModuleHelperClient.GetForbidLinesByModuleIDs(strModuleIDs, isModule ? 1 : 0)) { foreach (KeyValuePair <Guid, string> pair in lineIDs) { DataRow[] drModuleIDs = dtForbidLines.Select(string.Format("LineID='{0}'", pair.Key)); if (drModuleIDs != null && drModuleIDs.Length > 0) { bool bHasForbidModule = false; for (int j = 0; j < drModuleIDs.Length; j++) { string strFModuleID = drModuleIDs[j]["ModuleID"].ToString(); foreach (string moduleID in moduleIDs) { if (strFModuleID == moduleID) {//禁止发布 bHasForbidModule = true; if (string.IsNullOrEmpty(strFMsg)) { strFMsg = isModule ? "模板" : "表单"; } strFMsg += string.Format("<{0}>", dModuleIDs[new Guid(moduleID)]); } } } if (bHasForbidModule) { strFMsg += string.Format("已经设置不能发布到线路【{0}】", pair.Value); strFMsg += "\n"; } } } } if (!string.IsNullOrEmpty(strFMsg)) { MessageBox.Show(strFMsg); return; } Boolean flag = true; String msg = ""; BackgroundWorker worker = sender as BackgroundWorker; int i = 0; foreach (KeyValuePair <Guid, string> pair in lineIDs) { try { i = i + 1; ProgressScreen.Current.SetStatus = string.Format("正在发布线路:{0}...", pair.Value); worker.ReportProgress((int)(((float)i / (float)lineIDs.Count) * 100)); Boolean subFlag = LineHelperClient.SyncLineAndModule(moduleIDs, new List <Guid>() { pair.Key }, isModule, isRelationSheet); flag = flag & subFlag; if (!subFlag) { msg += "[" + pair.Value + "] "; } } catch { flag = false; } } String str = flag ? "全部更新成功" : "线路" + msg + "更新失败"; MessageBox.Show(str); }