/// <summary>
        /// 绑定正则表达式列表,根据网站
        /// </summary>
        /// <param name="site"></param>
        public void BindRegularList(Site site)
        {
            using (RegularDAL dal = new RegularDAL())
            {
                regularList = dal.GetRegularList(site);
            }

            //清理原来数据
            lv_ExpressionList.Items.Clear();
            lv_ExpressionList.Columns.Clear();

            //初始化listview的列头
            UIHelper.InitListView(lv_ExpressionList, "正则表达式", "文章类型");

            try
            {
                foreach (var item in regularList)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = item.Name;
                    lvi.SubItems.Add(item.Type.Name);
                    lvi.Name = item.ID.ToString();

                    lv_ExpressionList.Items.Add(lvi);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #2
0
        private bool disposedValue = false; // 要检测冗余调用

        #endregion Fields

        #region Methods

        /// <summary>
        /// 添加一个新网站
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public bool AddSite(Site site)
        {
            try
            {
                using (ACSDbContext db = new ACSDbContext())
                {
                    db.Sites.Attach(site);
                    db.Sites.Add(site);
                    db.SaveChanges();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
예제 #3
0
        /// <summary>
        /// 初始化数据库数据
        /// </summary>
        public ACSDbContext()
        {
            if (!this.Database.Exists())
            {
                this.Database.Create();

                Site site = new Site()
                {
                    ID = Guid.NewGuid(),
                    Address = "http://www.jrkz.com",
                    Name = "金融客栈"
                };

                this.Sites.Add(site);

                Type type = new Type() {
                    ID = Guid.NewGuid(),
                    Name = "时事"
                };

                this.Articles.Add(new Article()
                {
                    ID = Guid.NewGuid(),
                    Title = "hehe",
                    Time = DateTime.Now,
                    Site = site,
                    Content = "hehehee",
                    Type = type
                });

                this.Regulars.Add(new Regular
                {
                    ID = Guid.NewGuid(),
                    Name = @"<h1[\s\S]*?</h1>",
                    Site = site,
                    Type = type
                });

                // 记住要保存
                this.SaveChanges();
            }
        }
        private void btn_SiteAdd_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txt_NewSiteName.Text) && !String.IsNullOrEmpty(txt_NewSiteAddress.Text))
            {
                using (SiteDAL dal = new SiteDAL())
                {
                    if (dal.GetSite(txt_NewSiteName.Text)==null)
                    {
                        Site site = new Entities.Site()
                        {
                            ID = Guid.NewGuid(),
                            Address = txt_NewSiteAddress.Text.Trim(),
                            Name = txt_NewSiteName.Text
                        };

                        if (dal.AddSite(site))
                        {
                            siteList.Add(site);
                            BindSiteList();
                            MessageBox.Show("添加网站成功!");
                        }
                        else
                        {
                            MessageBox.Show("添加失败!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("此网站已存在!");
                    }
                }
            }
            else
            {
                MessageBox.Show("请添加完整信息!");
            }
        }
예제 #5
0
        /// <summary>
        /// 更新网站地址
        /// </summary>
        /// <param name="site"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        public bool UpdateSiteAddress(Site site, string address)
        {
            try
            {
                site.Address = address;
                // 这种更新数据的方法不用先查询,直接修改
                using (ACSDbContext db = new ACSDbContext())
                {
                    DbEntityEntry<Site> entry = db.Entry<Site>(site);

                    entry.State = EntityState.Unchanged;
                    entry.Property("Address").IsModified = true;

                    db.SaveChanges();
                }
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }