Beispiel #1
0
        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            btnAnalyze.Enabled = false;
            lblAnalyInfo.Text  = "请稍候,正在分析...";


            Thread t = new Thread(a => {
                var list = new List <UpdateModel>();
                //载入txt文件
                var fs          = new FileInfo(openFileDialog1.FileName).OpenRead();
                StreamReader sr = new StreamReader(fs);
                var i           = 0;
                while (sr.Peek() > -1)
                {
                    var l = sr.ReadLine();
                    if (!string.IsNullOrEmpty(l))
                    {
                        var si = l.IndexOf(TitleSplit);
                        if (si > -1)
                        {
                            var up   = new UpdateModel();
                            up.Title = l.Substring(TitleSplit.Length, l.Length - TitleSplit.Length);
                            //tags
                            var tags = sr.ReadLine();
                            if (tags.IndexOf(TagsSplit) > -1)
                            {
                                up.Tags = tags.Substring(TagsSplit.Length, tags.Length - TagsSplit.Length);
                            }
                            //intro
                            var intro = sr.ReadLine();
                            if (intro.IndexOf(IntroSplit) > -1)
                            {
                                up.Intro = intro.Substring(IntroSplit.Length, intro.Length - IntroSplit.Length);
                            }
                            list.Add(up);
                            i++;
                            lblAnalyInfo.Text = string.Format("正在分析第{0}条记录", i);
                        }
                    }
                }
                btnAnalyze.Enabled = true;
                lblAnalyInfo.Text  = string.Format("分析结束,共发现{0}条待更新记录", list.Count);

                //在子线程中调用主线程invoke,解决GridView垂直下拉假死的问题
                this.Invoke(new Action(() => {
                    dataGridView1.DataSource = null;
                    dataGridView1.Columns.Clear();
                    dataGridView1.Rows.Clear();
                    BindGrid(list);
                    btnUpdate2.Visible        = true;
                    this.progressBar1.Visible = true;
                })
                            );
            });

            t.Start();

            //btnUpdate2.Visible = true;
            //
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            btnAnalyze.Enabled = false;
            lblAnalyInfo.Text = "请稍候,正在分析...";

            Thread t = new Thread(a => {
                var list = new List<UpdateModel>();
                //载入txt文件
                var fs = new FileInfo(openFileDialog1.FileName).OpenRead();
                StreamReader sr = new StreamReader(fs);
                var i = 0;
                while (sr.Peek() > -1)
                {
                    var l = sr.ReadLine();
                    if (!string.IsNullOrEmpty(l))
                    {
                        var si = l.IndexOf(TitleSplit);
                        if (si > -1)
                        {
                            var up = new UpdateModel();
                            up.Title = l.Substring(TitleSplit.Length, l.Length - TitleSplit.Length);
                            //tags
                            var tags = sr.ReadLine();
                            if (tags.IndexOf(TagsSplit) > -1)
                            {
                                up.Tags = tags.Substring(TagsSplit.Length, tags.Length - TagsSplit.Length);
                            }
                            //intro
                            var intro = sr.ReadLine();
                            if (intro.IndexOf(IntroSplit) > -1)
                            {
                                up.Intro = intro.Substring(IntroSplit.Length, intro.Length - IntroSplit.Length);
                            }
                            list.Add(up);
                            i++;
                            lblAnalyInfo.Text = string.Format("正在分析第{0}条记录",i);
                        }
                    }
                }
                btnAnalyze.Enabled = true;
                lblAnalyInfo.Text = string.Format("分析结束,共发现{0}条待更新记录", list.Count);

                //在子线程中调用主线程invoke,解决GridView垂直下拉假死的问题
                this.Invoke(new Action(() => {
                        dataGridView1.DataSource = null;
                        dataGridView1.Columns.Clear();
                        dataGridView1.Rows.Clear();
                        BindGrid(list);
                        btnUpdate2.Visible = true;
                        this.progressBar1.Visible = true;
                    })
                );
            });
            t.Start();

            //btnUpdate2.Visible = true;
            //
        }