/// <summary> /// 根据某一分类ID,获取两级子分类的ID,如果没有子分类,则返回传入分类ID本身 /// </summary> /// <param name="catalogId"></param> /// <returns></returns> public static int[] GetCatalogIds(int catalogId) { TMM.Service.DocService ds = new TMM.Service.DocService(); ds.Initialize(); List <int> l = new List <int>(); l.Add(catalogId); IList <S_Catalog> c1 = ds.SCatalogBll.GetSubList(catalogId); c1.ToList().ForEach(s => { l.Add(s.CatalogId); s.SubCatalog.ToList().ForEach(ss => l.Add(ss.CatalogId)); }); if (l.Count > 0) { return(l.ToArray()); } else { return(null); } }
private void btnUpdate2_Click(object sender, EventArgs e) { btnUpdate2.Enabled = false; var i = 0; progressBar1.Maximum = dataGridView1.Rows.Count; Thread t = new Thread(new ThreadStart(() => { TMM.Service.DocService bll = new TMM.Service.DocService(); bll.Initialize(); foreach (DataGridViewRow row in dataGridView1.Rows) { Thread.Sleep(10); //执行数据库操作 string err = string.Empty; UpdateDoc(row, bll, ref err); i++; progressBar1.Value = i; } btnUpdate2.Enabled = true; MessageBox.Show("批量操作更新完成"); })); t.IsBackground = true; t.Start(); }
/// <summary> /// 根据某一分类ID,获取两级子分类的ID,如果没有子分类,则返回传入分类ID本身 /// </summary> /// <param name="catalogId"></param> /// <returns></returns> public static int[] GetCatalogIds(int catalogId) { TMM.Service.DocService ds = new TMM.Service.DocService(); ds.Initialize(); List<int> l = new List<int>(); l.Add(catalogId); IList<S_Catalog> c1 = ds.SCatalogBll.GetSubList(catalogId); c1.ToList().ForEach(s => { l.Add(s.CatalogId); s.SubCatalog.ToList().ForEach(ss => l.Add(ss.CatalogId)); }); if (l.Count > 0) { return l.ToArray(); } else return null; }
private void UpdateDoc(DataGridViewRow dr, TMM.Service.DocService bll, ref string errMsg) { if (dr.Cells[0].Value == null) { return; } UpdateModel um = new UpdateModel(); um.Title = dr.Cells[0].Value.ToString(); um.Tags = dr.Cells[1].Value.ToString(); um.Intro = dr.Cells[2].Value.ToString(); var p = new Hashtable(); p.Add("Title", um.Title); try { var docList = bll.DDocInfoBll.GetList(p, null, 0, 1); if (docList != null) { var doc = docList.FirstOrDefault(); if (doc == null) { throw new Exception(string.Format("未找到标题为【{0}】的记录", um.Title)); } doc.Tags = um.Tags; doc.Description = um.Intro; //更新doc bll.DDocInfoBll.Update(doc); //更新tag if (!string.IsNullOrEmpty(doc.Tags)) { var tags = doc.Tags.Split(' '); foreach (var item in tags) { var tagModel = bll.DTagBll.Get(item); if (tagModel != null) { tagModel.UseCount += 1; bll.DTagBll.Update(tagModel); } else { tagModel = new TMM.Model.D_Tag(); tagModel.Tag = item; tagModel.UseCount = 1; bll.DTagBll.Insert(tagModel); } } } } } catch (Exception ex) { errMsg = ex.Message; } dr.Cells[3].Value = string.IsNullOrEmpty(errMsg) ? "Success" : errMsg; }
private void btnUpdate2_Click(object sender, EventArgs e) { btnUpdate2.Enabled = false; var i = 0; progressBar1.Maximum = dataGridView1.Rows.Count; Thread t = new Thread(new ThreadStart(() => { TMM.Service.DocService bll = new TMM.Service.DocService(); bll.Initialize(); foreach (DataGridViewRow row in dataGridView1.Rows) { Thread.Sleep(10); //执行数据库操作 string err = string.Empty; UpdateDoc(row,bll,ref err); i++; progressBar1.Value = i; } btnUpdate2.Enabled = true; MessageBox.Show("批量操作更新完成"); })); t.IsBackground = true; t.Start(); }