コード例 #1
0
ファイル: BrandProviderTests.cs プロジェクト: qgate/CMS
        public void Test_Add_QueryById_Update_Delete_BrandProvider()
        {
            var brand = new Brand
            {
                Name            = "secondBrand",
                Description     = "Hello description!",
                UtcCreationDate = DateTime.UtcNow,
                UtcUpdateDate   = DateTime.UtcNow
            };

            //Add brand
            provider.Add(brand);
            Console.WriteLine("Add OK!");

            //QueryBy
            var brandQueryBy = provider.QueryById(brand.Id);

            Assert.IsNotNull(brandQueryBy);
            Console.WriteLine("QueryBy OK!");

            //update
            brand.Description = "New description";
            provider.Update(brand);
            var brandUpdate = provider.QueryById(brand.Id);

            Assert.AreEqual("New description", brandUpdate.Description);
            Console.WriteLine("Update OK!");

            //Delete
            provider.Delete(brand);
            var brandDelete = provider.QueryById(brand.Id);

            Assert.IsNull(brandDelete);
            Console.WriteLine("Delete OK!");
        }
コード例 #2
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int rowIndex = e.RowIndex;

            Brand brand = new Brand();

            brand.Brand_id = Convert.ToInt32(this.GridView1.DataKeys[rowIndex].Value);

            BrandProvider provider = new BrandProvider();

            if (provider.Delete(brand))
            {
                this.Alert("删除成功!!!");

                if (this.txt_Name.Text == "")
                {
                    this.ListPager1.RecordCount = this.ListPager1.RecordCount - 1;
                    this.BindSource(null);
                }
                else
                {
                    this.ListPager1.RecordCount = this.ListPager1.RecordCount - 1;
                    this.BindSource("%" + this.txt_Name.Text + "%");
                }
            }
        }