コード例 #1
0
 public Product GetProduct(int id)
 {
     using (ProductsDataContext db = new ProductsDataContext())
     {
         return(db.Product.FirstOrDefault(p => p.ProductId == id));
     }
 }
コード例 #2
0
        public List <ProductResult> getResultsByCategory(string category)
        {
            ProductsDataContext db = new ProductsDataContext();

            var query = from p in db.Products
                        where p.Category == category
                        select new { p.Category, p.Description, p.Id, p.ImageUrl, p.Name, p.Price, p.Stock };

            var results = new List <ProductResult>();

            foreach (var q in query)
            {
                var result = new ProductResult
                {
                    Name        = q.Name,
                    Category    = q.Category,
                    Price       = (double)q.Price,
                    ImageUrl    = q.ImageUrl,
                    Description = q.Description,
                    Stock       = q.Stock,
                    Id          = q.Id
                };

                results.Add(result);
            }
            return(results);
        }
コード例 #3
0
 //private List<Product> _Products = new List<Product>() {
 //    new Product {ProductId =1,ProductName ="Product 1", Price = 10.00 },
 //         new Product {ProductId =2,ProductName ="Product 2", Price = 10.00 } ,
 //              new Product {ProductId =3,ProductName ="Product 3", Price = 10.00 }
 //};
 public List <Product> GetProducts()
 {
     using (ProductsDataContext db = new ProductsDataContext())
     {
         return(db.Product.ToList());
     }
 }
コード例 #4
0
ファイル: Products.cs プロジェクト: vijaydairyf/BillingApp
        //Update
        public static int UpdateClientProductInfo(int _ClientProductsID, decimal _SalesPrice, string _IncludeOnInvoice, string _ImportsAtBaseOrSales)
        {
            int  includeoninvoice;
            bool importsatbaseorsales;

            switch (_IncludeOnInvoice)
            {
            case "Always": includeoninvoice = 0;
                break;

            case "Non-Zero": includeoninvoice = 1;
                break;

            case "Never": includeoninvoice = 2;
                break;

            default: includeoninvoice = 1;
                break;
            }

            if (_ImportsAtBaseOrSales == "Yes")
            {
                importsatbaseorsales = false;
            }
            else
            {
                importsatbaseorsales = true;
            }

            var dc     = new ProductsDataContext();
            int result = dc.S1_Products_UpdateClientProductsInfo(_ClientProductsID, _SalesPrice, includeoninvoice, importsatbaseorsales);

            return(result);
        }
コード例 #5
0
ファイル: Products.cs プロジェクト: vijaydairyf/BillingApp
        //INSERT
        public static int InsertClientProduct(int _ClientID, int _ProductID, int _VendorID)
        {
            var dc     = new ProductsDataContext();
            int result = dc.S1_Products_InsertClientProduct(_ClientID, _ProductID, _VendorID);

            return(result);
        }
コード例 #6
0
ファイル: Products.cs プロジェクト: vijaydairyf/BillingApp
        public static int CreateProduct(ViewModels.ViewModelProducts p)
        {
            var dc = new ProductsDataContext();

            var result = dc.S1_Products_AddProduct(p.ProductCode, p.ProductName, Convert.ToDecimal(p.BaseCost), Convert.ToDecimal(p.BaseCommission), Convert.ToByte(p.IncludeOnInvoice), Convert.ToDecimal(p.Employment), Convert.ToDecimal(p.Tenant), Convert.ToDecimal(p.Business), Convert.ToDecimal(p.Volunteer), Convert.ToDecimal(p.Other)).SingleOrDefault();

            return(Convert.ToInt32(result.productID));
        }
コード例 #7
0
    //查询数据库数据
    protected IQueryable <Products> GetQuery(decimal basePrice)
    {
        pdc = new ProductsDataContext();
        var query = from product in pdc.Products
                    where product.UnitPrice > 50
                    select product;

        return(query);
    }
コード例 #8
0
ファイル: ProductDAO.cs プロジェクト: jannunzi/dev
 public ProductDAO()
 {
     using (var db = new ProductsDataContext())
     {
         var products = db.Products.Take(100);
         foreach (var p in products)
             Console.WriteLine(p.name);
     }
 }
コード例 #9
0
ファイル: ProductDAO.cs プロジェクト: gillismr/dev
 public ProductDAO()
 {
     using (var db = new ProductsDataContext())
     {
         var products = db.Products.Take(100);
         foreach (var p in products)
         {
             Console.WriteLine(p.name);
         }
     }
 }
コード例 #10
0
        public static void Initialize()
        {
            using (var dc = new ProductsDataContext(ProductsDataContext.ConnectionString))
            {
                //dc.DeleteDatabase();
                if (dc.DatabaseExists() == false)
                {
                    dc.CreateDatabase();

                    dc.SubmitChanges();
                }
            }
        }
コード例 #11
0
ファイル: Products.cs プロジェクト: vijaydairyf/BillingApp
        //Returns a list of all products
        public static List <Product> GetProductsFromClient(int _ClientID)
        {
            List <Product> products = new List <Product>();

            ProductsDataContext dc = new ProductsDataContext();
            var result             = dc.S1_Products_GetProductListFromClient(_ClientID);

            foreach (var item in result)
            {
                Product newItem = new Product(0, Convert.ToInt32(item.ClientProductsID), item.ProductCode, item.ProductName, Convert.ToInt32(item.IncludeOnInvoice), Convert.ToDecimal(item.SalesPrice), Convert.ToInt32(item.ImportsAtBaseOrSales), item.VendorName, Convert.ToInt32(item.VendorID));

                products.Add(newItem);
            }

            return(products);
        }
コード例 #12
0
ファイル: Products.cs プロジェクト: vijaydairyf/BillingApp
        //Returns a list of all products
        public static List <Product> GetProducts()
        {
            List <Product> products = new List <Product>();

            ProductsDataContext dc = new ProductsDataContext();
            var result             = dc.S1_Products_GetProductList();

            foreach (var item in result)
            {
                Product newItem = new Product(item.ProductID, 0, "", item.ProductName, 0, 0, 0, "", 0);

                products.Add(newItem);
            }

            return(products);
        }
コード例 #13
0
 protected void Button4_Click(object sender, EventArgs e)
 {
     pdc = new ProductsDataContext();
     IEnumerable<Products> query = from product in pdc.Products
                                  where product.ProductID == 79
                                  select product;
     //可以使用DeleteOnSubmit一次删除一条记录
     //foreach (Products prod in query)
     //{
     //    pdc.Products.DeleteOnSubmit(prod);
     //}
     //也可以使用DeleteAllOnSubmit一次删除一批记录
     pdc.Products.DeleteAllOnSubmit(query);
     pdc.SubmitChanges();
     //再次绑定
     GridView1.DataSource = GetQuery(50);
     GridView1.DataBind();
 }
コード例 #14
0
ファイル: Products.cs プロジェクト: vijaydairyf/BillingApp
        //Returns a list of all products for use in a dropdown
        public static List <SelectListItem> GetProductList()
        {
            List <SelectListItem> productList = new List <SelectListItem>();

            ProductsDataContext dc = new ProductsDataContext();
            var result             = dc.S1_Products_GetProductList();

            foreach (var item in result)
            {
                SelectListItem newItem = new SelectListItem();
                newItem.Value = item.ProductID.ToString();
                newItem.Text  = item.ProductName;

                productList.Add(newItem);
            }

            return(productList);
        }
コード例 #15
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     pdc = new ProductsDataContext();
     Products newprod = new Products();
     newprod.ProductName = "新添加的一项产品";
     newprod.SupplierID = 13;
     newprod.CategoryID = 5;
     newprod.UnitPrice = 57;
     newprod.UnitsInStock = 13;
     newprod.ReorderLevel = 15;
     //这里使用InsertOnSubmit将新创建的对象添插入到集合中。
     pdc.Products.InsertOnSubmit(newprod);
     //向数据库提交更改
     pdc.SubmitChanges();
     //再次绑定
     GridView1.DataSource = GetQuery(50);
     GridView1.DataBind();
 }
コード例 #16
0
    protected void Button4_Click(object sender, EventArgs e)
    {
        pdc = new ProductsDataContext();
        IEnumerable <Products> query = from product in pdc.Products
                                       where product.ProductID == 79
                                       select product;

        //可以使用DeleteOnSubmit一次删除一条记录
        //foreach (Products prod in query)
        //{
        //    pdc.Products.DeleteOnSubmit(prod);
        //}
        //也可以使用DeleteAllOnSubmit一次删除一批记录
        pdc.Products.DeleteAllOnSubmit(query);
        pdc.SubmitChanges();
        //再次绑定
        GridView1.DataSource = GetQuery(50);
        GridView1.DataBind();
    }
コード例 #17
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        pdc = new ProductsDataContext();
        Products newprod = new Products();

        newprod.ProductName  = "新添加的一项产品";
        newprod.SupplierID   = 13;
        newprod.CategoryID   = 5;
        newprod.UnitPrice    = 57;
        newprod.UnitsInStock = 13;
        newprod.ReorderLevel = 15;
        //这里使用InsertOnSubmit将新创建的对象添插入到集合中。
        pdc.Products.InsertOnSubmit(newprod);
        //向数据库提交更改
        pdc.SubmitChanges();
        //再次绑定
        GridView1.DataSource = GetQuery(50);
        GridView1.DataBind();
    }
コード例 #18
0
        private ProductResult getDetailsFromId(int id)
        {
            ProductsDataContext db = new ProductsDataContext();
            var query = from p in db.Products
                        where p.Id == id
                        select new { p.Category, p.Description, p.Id, p.ImageUrl, p.Name, p.Price, p.Stock };

            var result = new ProductResult
            {
                Name        = query.First().Name,
                Category    = query.First().Category,
                Price       = (double)query.First().Price,
                ImageUrl    = query.First().ImageUrl,
                Description = query.First().Description,
                Stock       = query.First().Stock,
                Id          = query.First().Id
            };

            return(result);
        }
コード例 #19
0
        public bool Create(Product product)
        {
            //int maxId = _Products.Max(p => p.ProductId);
            // product.ProductId = maxId++;
            bool success = false;

            try
            {
                using (ProductsDataContext db = new ProductsDataContext())
                {
                    db.Product.Add(product);
                    db.SaveChanges();
                    success = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(success);
        }
コード例 #20
0
 public ProductRepository(ProductsDataContext context)
 {
     _context = context;
 }
コード例 #21
0
 //调用存储过程方法
 public IEnumerable<CustOrdersDetailResult> GetCustOrdersDetails(int OrderID)
 {
     ProductsDataContext pdc = new ProductsDataContext();
     return pdc.CustOrdersDetail(OrderID);
 }
コード例 #22
0
 //查询数据库数据
 protected IQueryable<Products> GetQuery(decimal basePrice)
 {
     pdc = new ProductsDataContext();
     var query = from product in pdc.Products
                 where product.UnitPrice > 50
                 select product;
     return query;
 }
コード例 #23
0
    //调用存储过程方法
    public IEnumerable <CustOrdersDetailResult> GetCustOrdersDetails(int OrderID)
    {
        ProductsDataContext pdc = new ProductsDataContext();

        return(pdc.CustOrdersDetail(OrderID));
    }
コード例 #24
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //BOLEntityKeywords EntityKeywordsBOL = new BOLEntityKeywords();

            //ReqUtils Utils = new ReqUtils();
            //ContentsDataContext dc = new ContentsDataContext();
            //var ContentList = dc.Contents;
            //foreach (var item in ContentList)
            //{
            //    try
            //    {
            //        string CurDesc = item.ContentText;
            //        CurDesc = Utils.RemoveTags(CurDesc);
            //        CurDesc = Tools.PersianTextCorrection(CurDesc);
            //        ExtractKeywords(CurDesc);
            //        string KeywordCodeList = Tools.GetkeywordCodes2(AdvertiseKeyword);
            //        EntityKeywordsBOL.SaveKeywordList(item.Code, KeywordCodeList, 4);
            //    }
            //    catch
            //    {
            //    }

            //}

            //BOLEntityKeywords EntityKeywordsBOL = new BOLEntityKeywords();
            //TabirDataContext dc = new TabirDataContext();

            //ReqUtils Utils = new ReqUtils();
            //var TabirList = dc.Tabirs;
            //foreach (var item in TabirList)
            //{
            //    try
            //    {
            //        string CurDesc = item.Meaning;
            //        CurDesc = Utils.RemoveTags(CurDesc);
            //        CurDesc = Tools.PersianTextCorrection(CurDesc);
            //        ExtractKeywords(CurDesc);
            //        string KeywordCodeList = Tools.GetkeywordCodes2(AdvertiseKeyword);
            //        EntityKeywordsBOL.SaveKeywordList(item.Code, KeywordCodeList, 5);
            //    }
            //    catch
            //    {
            //    }

            //}

            BOLEntityKeywords   EntityKeywordsBOL = new BOLEntityKeywords();
            ProductsDataContext dc = new ProductsDataContext();

            ReqUtils Utils       = new ReqUtils();
            var      ProductList = dc.Products;

            foreach (var item in ProductList)
            {
                try
                {
                    string CurDesc = item.Description;
                    CurDesc = Utils.RemoveTags(CurDesc);
                    CurDesc = Tools.PersianTextCorrection(CurDesc);
                    ExtractKeywords(CurDesc);
                    string KeywordCodeList = Tools.GetkeywordCodes2(AdvertiseKeyword);
                    EntityKeywordsBOL.SaveKeywordList(item.Code, KeywordCodeList, 6);
                }
                catch
                {
                }
            }
        }
コード例 #25
0
 public BaseBOLProducts()
 {
     dataContext = new ProductsDataContext();
 }