Пример #1
0
        public ProductObservableCollection <Product> Build()
        {
            ProductObservableCollection <Product> products = new ProductObservableCollection <Product>();

            var filePath = String.Format("{0}{1}\\ProductModel.xml", AppDomain.CurrentDomain.BaseDirectory,
                                         DBUtility.FilePath);

            List <ProductModel> list = null;

            if (this.checkFileFirst)
            {
                if (!File.Exists(filePath))
                {
                    list = DBUtility.CreateFile <ProductModel>(DBUtility.MockProductModel());
                }
                else
                {
                    list = DBUtility.DeserializeParamsListOf <ProductModel>(filePath);
                }
            }

            if (list != null)
            {
                foreach (ProductModel sp in list)
                {
                    products.Add(sp.ProductModel2Product());
                }
            }


            return(products);
        }
Пример #2
0
        public ProductObservableCollection <Product> GetProducts()
        {
            hasError = false;
            ProductObservableCollection <Product> products = new ProductObservableCollection <Product>();

            try
            {
                LinqDataContext dc    = new LinqDataContext();
                var             query = from q in dc.LinqProducts
                                        select new ProductModel
                {
                    ProductId    = q.ProductID,
                    ModelNumber  = q.ModelNumber,
                    ModelName    = q.ModelName,
                    UnitCost     = (decimal)q.UnitCost,
                    Description  = q.Description,
                    CategoryName = q.LinqCategory.CategoryName
                };
                foreach (ProductModel sp in query)
                {
                    products.Add(sp.ProductModel2Product());
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError     = true;
            }

            return(products);
        } //GetProducts()
Пример #3
0
        public ProductSelectionModel()
        {
            dataItems = new ProductObservableCollection <Product>();

            //DataItems = App.StoreDB.GetProducts();
            DataItems = App.StoreDB.GetProductsByXML();

            listBoxCommand = new RelayCommand(() => SelectionHasChanged());
            App.Messenger.Register("ProductCleared", (Action)(() => SelectedProduct = null));
            App.Messenger.Register("GetProducts", (Action)(() => GetProducts()));
            App.Messenger.Register("UpdateProduct", (Action <Product>)(param => UpdateProduct(param)));
            App.Messenger.Register("DeleteProduct", (Action)(() => DeleteProduct()));
            App.Messenger.Register("AddProduct", (Action <Product>)(param => AddProduct(param)));
            //By XML
            App.Messenger.Register("GetProductsByXML", (Action)(() => GetProductsByXML()));
        }
Пример #4
0
        public ProductObservableCollection <Product> GetProductsByXML()
        {
            hasError = false;
            ProductObservableCollection <Product> products = new ProductObservableCollection <Product>();

            try
            {
                //True: Check if File Exist
                products = new ProductModel().WhitCheckFileFirst(true);
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError     = true;
            }

            return(products);
        }