Ejemplo n.º 1
0
        public static ObservableCollection <object> GetProductFromDBTwo(int catId = 0)
        {
            DataTable data     = null;
            var       products = new ObservableCollection <object>();

            data = QueryForSQLServer.GetProducts();
            foreach (DataRow row in data.Rows)
            {
                string kt = "";
                if ((int)row.ItemArray[4] <= 0)
                {
                    kt = "Hết hàng";
                }

                else if ((int)row.ItemArray[4] < 5)
                {
                    kt = "Sắp hết hàng";
                }
                else
                {
                    kt = "Còn hàng";
                }

                var product = new
                {
                    Id       = (int)row.ItemArray[0],
                    Name     = (string)row.ItemArray[2],
                    Price    = (Decimal)row.ItemArray[3],
                    Quantity = (int)row.ItemArray[4],
                    Status   = kt
                };
                products.Add(product);
            }
            return(products);
        }
Ejemplo n.º 2
0
        void getCustomer(string tel, bool uneditable = true)
        {
            if (tel != null)
            {
                var customerDt = QueryForSQLServer.GetCustomerByTel(tel);
                foreach (DataRow row in customerDt.Rows)
                {
                    customerDetail = new
                    {
                        Customer_Name    = row.ItemArray[0],
                        Tel              = row.ItemArray[1],
                        Customer_Address = row.ItemArray[2],
                        Customer_Email   = row.ItemArray[3]
                    };
                }
                CustomerStackPanel.DataContext = customerDetail;

                customerEmailTextBox.IsReadOnly   = uneditable;
                customerNameTextBox.IsReadOnly    = uneditable;
                customerAddressTextBox.IsReadOnly = uneditable;
            }
            else
            {
                CustomerStackPanel.DataContext = null;
            }
        }
Ejemplo n.º 3
0
        public ObservableCollection <Product> GetProductFromDb(int catId = 0)
        {
            DataTable data     = null;
            var       products = new ObservableCollection <Product>();


            data = QueryForSQLServer.GetProducts();
            foreach (DataRow row in data.Rows)
            {
                var product = new Product();
                product.Id             = (int)row.ItemArray[0];
                product.CatId          = (int)row.ItemArray[1];
                product.Name           = (string)row.ItemArray[2];
                product.Price          = (Decimal)row.ItemArray[3];
                product.Quantity       = (int)row.ItemArray[4];
                product.Description    = (string)row.ItemArray[5];
                product.Image          = (string)row.ItemArray[6];
                product.Author         = (string)row.ItemArray[7];
                product.Product_Images = new List <Product_Images>();
                products.Add(product);
            }
            if (catId != 0)
            {
                var productFillered = from product in products
                                      where product.CatId == catId
                                      select product;
                products = new ObservableCollection <Product>(productFillered);
            }

            return(products);
        }
Ejemplo n.º 4
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            var item = originalSource.DataContext as Product;

            QueryForSQLServer.DeleteProduct(item.Id);
            Refresh();
        }
Ejemplo n.º 5
0
        private void deletePurchase_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var Selecteditem = (sender as FrameworkElement).DataContext;
            int id           = (int)Selecteditem?.GetType().GetProperty("Purchase_ID")?.GetValue(Selecteditem, null);

            QueryForSQLServer.DeletePurchase(id);
            reLoadData();
        }
Ejemplo n.º 6
0
        private void cbbRemove_Click(object sender, RoutedEventArgs e)
        {
            var item = originalSource.DataContext as Category;

            QueryForSQLServer.DeleteCategory(item.Name);
            //reset cat

            Refresh();
        }
Ejemplo n.º 7
0
        private void purchaseDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                var test = (sender as DataGrid).SelectedItem;

                ObservableCollection <object> allPurchaseDetail = new ObservableCollection <object>();

                int?   id  = (int?)test?.GetType().GetProperty("Purchase_ID")?.GetValue(test, null);
                string tel = test?.GetType().GetProperty("Tel")?.GetValue(test, null).ToString();

                getCustomer(tel);

                #region PurchaseDetail
                DataGridDetailPurchase.Columns.Clear();
                DataGridDetailPurchase.AutoGenerateColumns = true;
                if (id != null)
                {
                    int index = (int)id;
                    var dt    = QueryForSQLServer.GetPurchaseDetail(index);
                    foreach (DataRow item in dt.Rows)
                    {
                        var _p = new
                        {
                            Name = item["Name"],
                            //Price = item["Price"],
                            Quantity = item["Quantity"],
                            Total    = item["Total"]
                        };
                        allPurchaseDetail.Add(_p);
                    }
                    DataGridDetailPurchase.ItemsSource = allPurchaseDetail;
                }
                else
                {
                    purchaseDataGrid.SelectedIndex = -1;
                    allPurchaseDetail.Clear();
                    DataGridDetailPurchase.ItemsSource = allPurchaseDetail;
                }
                #endregion

                btnAddItem.Visibility    = Visibility.Collapsed;
                btnDeleteItem.Visibility = Visibility.Collapsed;
                btnUpdate.Visibility     = Visibility.Collapsed;
                btnDone.Visibility       = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message.ToString());
            }
        }
Ejemplo n.º 8
0
        public static ObservableCollection <Category> GetCategoriesFromDb()
        {
            var       categoriesList = new ObservableCollection <Category>();
            DataTable q = QueryForSQLServer.GetCategory();

            foreach (DataRow row in q.Rows)
            {
                var category = new Category {
                    Id = (int)row.ItemArray[0], Name = (string)row.ItemArray[1]
                };
                categoriesList.Add(category);
            }
            return(categoriesList);
        }
Ejemplo n.º 9
0
        public PageCheckOut()
        {
            this.InitializeComponent();


            //date
            fromDatePicker.Date = DateTime.Today.AddDays(-3).Date;
            toDatePicker.Date   = DateTime.Today.Date;

            var _enumval = Enum.GetValues(typeof(PurchaseStatus)).Cast <PurchaseStatus>();

            purchaseStatesComboBox.ItemsSource   = _enumval.ToList();
            purchaseStatesComboBox.SelectedIndex = 4;

            reLoadData();
            productsListView.ItemsSource = QueryForSQLServer.GetProductFromDb();
        }
Ejemplo n.º 10
0
        private async void btnDone_Click(object sender, RoutedEventArgs e)
        {
            var messageDialog = new MessageDialog("Save your change ???");

            messageDialog.Commands.Add(new UICommand("Yes")
            {
                Id = 0
            });
            messageDialog.Commands.Add(new UICommand("No")
            {
                Id = 1
            });
            messageDialog.DefaultCommandIndex = 0;
            messageDialog.CancelCommandIndex  = 1;

            var result = await messageDialog.ShowAsync();

            if ((int)result.Id == 0)
            {
                Product.Price    = Decimal.Parse(addGia.Text);
                Product.Quantity = int.Parse(addSoLuong.Text);
                QueryForSQLServer.UpdateProduct(Product);

                //delete then insert
                QueryForSQLServer.DeleteProduct_Image(Product.Id);
                int id = 1;
                foreach (var item in Product.Product_Images)
                {
                    item.id        = id;
                    item.ProductId = Product.Id;
                    QueryForSQLServer.InsertProduct_Image(item);
                    id++;
                }
                Handler?.Invoke(Product);
                //e.Handled = true;
                //SystemNavigationManager manager = SystemNavigationManager.GetForCurrentView();
                //manager.BackRequested -= DetailPage_BackRequested;
                //manager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                this.Visibility = Visibility.Collapsed;
            }
            else
            {
                //this.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 11
0
        public void searchFillter(ObservableCollection <Product> products)
        {
            this.InitializeComponent();
            var       categoriesList = new ObservableCollection <Category>();
            DataTable q = QueryForSQLServer.GetCategory();

            foreach (DataRow row in q.Rows)
            {
                var category = new Category {
                    Id = (int)row.ItemArray[0], Name = (string)row.ItemArray[1]
                };
                categoriesList.Add(category);
            }

            ProductData = products;
            PagingPage();
            cbbListType.ItemsSource = categoriesList;
        }
Ejemplo n.º 12
0
        public UpdateUserControl(Product product)
        {
            this.InitializeComponent();
            Product = product;

            try
            {
                //Load Product_Images
                List <Product_Images> img    = new List <Product_Images>();
                DataTable             images = QueryForSQLServer.GetProducts_Image(Product.Id);

                foreach (DataRow item in images.Rows)
                {
                    var Product_Images = new Product_Images()
                    {
                        id        = (int)item.ItemArray[0],
                        ProductId = (int)item.ItemArray[1],
                        Name      = (string)item.ItemArray[2]
                    };
                    img.Add(Product_Images);
                }
                Product.Product_Images = img;
                lvManyImg.ItemsSource  = img;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ex: " + ex.Message);
            }



            this.DataContext = Product;
            var categoriesList = PageHome.GetCategoriesFromDb();

            cbbListType.ItemsSource   = categoriesList;
            cbbListType.SelectedIndex = (int)product.CatId - 1;


            //back
            SystemNavigationManager manager = SystemNavigationManager.GetForCurrentView();

            manager.BackRequested += DetailPage_BackRequested;
            manager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
        }
Ejemplo n.º 13
0
        private async void cbbEdit_Click(object sender, RoutedEventArgs e)
        {
            var       item  = originalSource.DataContext as Category;
            DataTable dt    = QueryForSQLServer.GetCategoryByName(item.Name);
            int       id    = (int)dt.Rows[0].ItemArray[0];
            TextBox   input = new TextBox()
            {
                Height          = (double)App.Current.Resources["TextControlThemeMinHeight"],
                PlaceholderText = "Display Text"
            };
            ContentDialog dialog = new ContentDialog()
            {
                Title               = "Change Category's Name",
                MaxWidth            = this.ActualWidth,
                PrimaryButtonText   = "OK",
                SecondaryButtonText = "Cancel",
                Content             = input
            };
            ContentDialogResult result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                input = (TextBox)dialog.Content;
                if (input.Text != "")
                {
                    var cat = new Category()
                    {
                        Id = item.Id, Name = input.Text
                    };
                    QueryForSQLServer.UpdateCategory(cat);
                    await new Windows.UI.Popups.MessageDialog("Updated!").ShowAsync();
                    Refresh();
                }
                else
                {
                    await new Windows.UI.Popups.MessageDialog("Nothing Change!").ShowAsync();
                }
            }
        }
Ejemplo n.º 14
0
        private async void btnDone_Click(object sender, RoutedEventArgs e)
        {
            var messageDialog = new MessageDialog("Add new produt", "Confirm");

            messageDialog.Commands.Add(new UICommand("Yes")
            {
                Id = 0
            });
            messageDialog.Commands.Add(new UICommand("No")
            {
                Id = 1
            });
            messageDialog.DefaultCommandIndex = 0;
            messageDialog.CancelCommandIndex  = 1;

            var result = await messageDialog.ShowAsync();

            if ((int)result.Id == 0)
            {
                Product.Price    = Decimal.Parse(addGia.Text);
                Product.Quantity = int.Parse(addSoLuong.Text);
                var productid = QueryForSQLServer.InsertProduct(Product);
                int id        = 1;
                foreach (var item in Product.Product_Images)
                {
                    item.id        = id;
                    item.ProductId = productid;
                    QueryForSQLServer.InsertProduct_Image(item);
                    id++;
                }
                Frame.GoBack();
            }
            else
            {
                Frame.GoBack();
            }
        }
Ejemplo n.º 15
0
        public DetailsUserControl(Product product)
        {
            if (product != null)
            {
                this.InitializeComponent();
                this.DataContext     = product;
                pageInfo.DataContext = "1";
                objProduct           = product;
                List <Product_Images> img    = new List <Product_Images>();
                DataTable             images = QueryForSQLServer.GetProducts_Image(product.Id);



                foreach (DataRow item in images.Rows)
                {
                    var Product_Images = new Product_Images()
                    {
                        id        = (int)item.ItemArray[0],
                        ProductId = (int)item.ItemArray[1],
                        Name      = (string)item.ItemArray[2]
                    };
                    img.Add(Product_Images);
                }

                lvManyImg.ItemsSource = img;

                //back
                SystemNavigationManager manager = SystemNavigationManager.GetForCurrentView();
                manager.BackRequested += DetailPage_BackRequested;
                manager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                this.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 16
0
        private async void addCat_Click(object sender, RoutedEventArgs e)
        {
            TextBox input = new TextBox()
            {
                Height          = (double)App.Current.Resources["TextControlThemeMinHeight"],
                PlaceholderText = "Display Text"
            };
            ContentDialog dialog = new ContentDialog()
            {
                Title               = "Change Category's Name",
                MaxWidth            = this.ActualWidth,
                PrimaryButtonText   = "OK",
                SecondaryButtonText = "Cancel",
                Content             = input
            };
            ContentDialogResult result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                input = (TextBox)dialog.Content;
                if (input.Text != "")
                {
                    var cat = new Category()
                    {
                        Name = input.Text
                    };
                    QueryForSQLServer.InsertCategory(cat);
                    await new Windows.UI.Popups.MessageDialog("Success!").ShowAsync();
                    Refresh();
                }
                else
                {
                    await new Windows.UI.Popups.MessageDialog("Noting change!").ShowAsync();
                }
            }
        }
Ejemplo n.º 17
0
        void reLoadData()
        {
            var dt = QueryForSQLServer.GetPurchase();

            allPurchase = new ObservableCollection <object>();
            //purchase
            foreach (DataRow item in dt.Rows)
            {
                string formatted = ((DateTime)item["Created_At"]).ToString();
                var    _p        = new
                {
                    Purchase_ID   = (int)item["Purchase_ID"],
                    Customer_Name = item["Customer_Name"] as string,
                    Tel           = item["Tel"] as string,
                    Total         = (decimal)item["Total"],
                    Created_At    = formatted,
                    Status        = (PurchaseStatus)(item["Status"])
                };
                allPurchase.Add(_p);
            }
            purchaseDataGrid.ItemsSource = allPurchase;
            PagingPage();
            //list_product.Clear();
        }
Ejemplo n.º 18
0
        private async void ImportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ExcelEngine excelEngine = new ExcelEngine();

                IApplication application = excelEngine.Excel;

                //Instantiates the File Picker.



                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                openPicker.FileTypeFilter.Add(".xlsx");
                openPicker.FileTypeFilter.Add(".xls");
                StorageFile openFile = await openPicker.PickSingleFileAsync();

                //Opens the workbook.
                IWorkbook workbook = await application.Workbooks.OpenAsync(openFile);

                //Access first worksheet from the workbook.
                var tabs = workbook.Worksheets;

                //Set Text in cell A3.


                //Sets workbook version.
                workbook.Version = ExcelVersion.Excel2016;

                //Initializes FileSavePicker.
                FileSavePicker savePicker = new FileSavePicker();

                List <Category> list = new List <Category>();

                foreach (var tab in tabs)
                {
                    Debug.WriteLine(tab.Name);
                    var row      = 3;
                    var category = new Category()
                    {
                        Name = tab.Name
                    };
                    category.Id = QueryForSQLServer.InsertCategory(category);

                    tab.UsedRangeIncludesFormatting = false;
                    var cell = tab.Range[$"C3"];

                    while (cell.Value != null && !cell.IsBlank)
                    {
                        var author      = tab.Range[$"J{row}"].Text;
                        var name        = tab.Range[$"C{row}"].Text;
                        var price       = Convert.ToDecimal(tab.Range[$"D{row}"].Number);
                        var quantity    = (int)(tab.Range[$"E{row}"].Number);
                        var description = tab.Range[$"F{row}"].Text;
                        var image       = tab.Range[$"I{row}"].Text;

                        var product = new Product()
                        {
                            Author      = author,
                            Name        = name,
                            CatId       = category.Id,
                            Price       = price,
                            Quantity    = quantity,
                            Description = description,
                            Image       = image
                        };

                        category.Products.Add(product);


                        Debug.WriteLine($"{author}{name}{price}{quantity}{description}");

                        // Đi qua dòng kế
                        row++;
                        cell = tab.Range[$"C{row}"];
                    }
                    list.Add(category);
                }
                var tes = list;

                workbook.Close();
                excelEngine.Dispose();

                var messageDialog = new MessageDialog("Import", "Confirm");

                messageDialog.Commands.Add(new UICommand("Yes")
                {
                    Id = 0
                });
                messageDialog.Commands.Add(new UICommand("No")
                {
                    Id = 1
                });
                messageDialog.DefaultCommandIndex = 0;
                messageDialog.CancelCommandIndex  = 1;

                var result = await messageDialog.ShowAsync();

                if ((int)result.Id == 0)
                {
                    foreach (var cat in list)
                    {
                        cat.Id = QueryForSQLServer.InsertCategory(cat);
                        foreach (var product in cat.Products)
                        {
                            var index = QueryForSQLServer.InsertProduct(product);
                        }
                    }
                    var messageDialog2 = await new MessageDialog("Success", "Confirm").ShowAsync();
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception: " + ex.Message);
            }
        }
Ejemplo n.º 19
0
        private async void Import_Detail_Images_Click(object sender, RoutedEventArgs e)
        {
            ExcelEngine excelEngine = new ExcelEngine();

            IApplication application = excelEngine.Excel;

            //Instantiates the File Picker.
            try
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                openPicker.FileTypeFilter.Add(".xlsx");
                openPicker.FileTypeFilter.Add(".xls");
                StorageFile openFile = await openPicker.PickSingleFileAsync();

                //Opens the workbook.
                IWorkbook workbook = await application.Workbooks.OpenAsync(openFile);

                //Access first worksheet from the workbook.
                var tabs = workbook.Worksheets;

                //Sets workbook version.
                workbook.Version = ExcelVersion.Excel2016;

                //Initializes FileSavePicker.
                FileSavePicker        savePicker = new FileSavePicker();
                List <Product_Images> list       = new List <Product_Images>();
                foreach (var tab in tabs)
                {
                    Debug.WriteLine(tab.Name);
                    var row     = 3;
                    var product = new Product()
                    {
                        Name = tab.Name
                    };

                    tab.UsedRangeIncludesFormatting = false;
                    var cell = tab.Range[$"C3"];

                    while (cell.Value != null && !cell.IsBlank)
                    {
                        var image = tab.Range[$"B{row}"].Text;
                        var name  = tab.Range[$"C{row}"].Text;

                        var ImageId = (int)QueryForSQLServer.GetProductsByImage(image).Rows[0].ItemArray[0];

                        var product_image = new Product_Images()
                        {
                            ProductId = ImageId,
                            Name      = name
                        };


                        Debug.WriteLine($"{image}{name}");
                        list.Add(product_image);
                        // Đi qua dòng kế
                        row++;
                        cell = tab.Range[$"C{row}"];
                    }
                }
                workbook.Close();
                excelEngine.Dispose();

                var messageDialog = new MessageDialog("Import", "Confirm");

                messageDialog.Commands.Add(new UICommand("Yes")
                {
                    Id = 0
                });
                messageDialog.Commands.Add(new UICommand("No")
                {
                    Id = 1
                });
                messageDialog.DefaultCommandIndex = 0;
                messageDialog.CancelCommandIndex  = 1;

                var result = await messageDialog.ShowAsync();

                if ((int)result.Id == 0)
                {
                    var i          = QueryForSQLServer.GetProducts_ImageMaxId(list[0].ProductId) + 1;
                    var preProduct = list[0].ProductId;
                    foreach (var img in list)
                    {
                        if (img.ProductId != preProduct)
                        {
                            i = QueryForSQLServer.GetProducts_ImageMaxId(img.ProductId) + 1;
                        }
                        img.id     = i;
                        preProduct = img.ProductId;
                        QueryForSQLServer.InsertProduct_Image(img);
                        Debug.WriteLine(img.id + img.Name + img.ProductId);
                        i++;
                    }
                    var messageDialog2 = await new  MessageDialog("Success", "Confirm").ShowAsync();
                }

                else
                {
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception: " + ex.Message);
            }
        }
Ejemplo n.º 20
0
        private async void addPurchaseButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Customer
                var dt = QueryForSQLServer.GetCustomerByTel(customerTelTextBox.Text.ToString());
                if (dt.Rows.Count == 0)
                {
                    var _newCustomer = new Customer
                    {
                        Tel           = customerTelTextBox.Text.ToString(),
                        Customer_Name = customerNameTextBox.Text.ToString()
                    };
                    QueryForSQLServer.InsertCustomer(_newCustomer);
                }
                else
                {
                    customerNameTextBox.Text = dt.Rows[0].ItemArray[0].ToString();
                }


                //Purchase
                var purchase = new Purchase()
                {
                    Created_At   = DateTime.Now,
                    Total        = list.Sum((dynamic p) => p.SubTotal as Nullable <decimal>),
                    Customer_Tel = customerTelTextBox.Text.ToString(),
                    Status       = (PurchaseStatus)(purchaseStatesComboBox.SelectedIndex + 1)
                };
                var p_id = QueryForSQLServer.InsertPurchase(purchase);

                //PurchaseDetail
                if (p_id == -1)
                {
                    var messageDialog = await new MessageDialog("Failed", "Confirm").ShowAsync();
                    return;
                }
                else
                {
                    foreach (dynamic item in list)
                    {
                        purchase.PurchaseDetails.Add(new PurchaseDetail()
                        {
                            Purchase_ID = p_id,
                            Product_ID  = item.Product_ID,
                            Price       = item.Unit_Price,
                            Quantity    = item.Quantity,
                            Total       = item.SubTotal
                        });
                    }
                    foreach (dynamic item in purchase.PurchaseDetails)
                    {
                        QueryForSQLServer.InsertPurchaseDetail(item);
                    }
                }


                var messageDialog2 = await new MessageDialog("Success", "Confirm").ShowAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Ejemplo n.º 21
0
        public PageAdmin()
        {
            InitializeComponent();
            //ngay thang nam
            fromDatePicker.Date = new DateTime(2021, 1, 1).Date;
            toDatePicker.Date   = new DateTime(2021, 12, 31).Date;

            data = new List <Tuple <int, decimal> >();
            data = QueryForSQLServer.GetTotalByMonth(2021);

            var dataSeller = QueryForSQLServer.GetListBestSellerPurchases();

            //string []Labels = new []{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug","Sep","Oct","Nov","Dec" };
            ////LineChartViewX.DataContext = Labels;
            //PieChartView.Series = new SeriesCollection();

            //foreach (var item in data)
            //{
            //    if (item.Item2 != 0)
            //        PieChartView.Series.Add(
            //        new PieSeries()
            //        {
            //            Values = new ChartValues<decimal> { item.Item2 },
            //            Title = item.Item1.ToString(),
            //            DataLabels = true,

            //        }
            //    ) ;
            //}
            //PieChartView.LegendLocation = LegendLocation.Bottom;
            //PieChartView.DataContext = this;

            var productdt = QueryForSQLServer.GetProductFromDBTwo();

            DataGridProduct.ItemsSource = productdt;

            //PieChartView.Series = new SeriesCollection();

            foreach (var item in dataSeller)
            {
                ColumChartView.Series.Add(
                    new ColumnSeries()
                {
                    Values = new ChartValues <decimal> {
                        item.Item2
                    },
                    Title      = item.Item1.ToString(),
                    DataLabels = true,
                }
                    );
            }

            ColumChartView.LegendLocation = LegendLocation.Bottom;
            ColumChartView.DataContext    = this;

            //var linedata = new List<decimal>();
            //foreach(var item in data)
            //{
            //    linedata.Add(item.Item2);
            //}
            //LineChartView.Series.Add(
            //    new LineSeries()

            //    {
            //        Values = new ChartValues<decimal> { linedata[0] },
            //        Title = "Doanh thu theo năm",
            //        LineSmoothness = 0, //0: straight lines, 1: really smooth lines
            //        DataLabels = true,


            //    }
            //);
            //for (int i = 1; i < linedata.Count(); i++)
            //{
            //    LineChartView.Series[0].Values.Add(linedata[i]);
            //}
            //LineChartView.LegendLocation = LegendLocation.Bottom;
            //LineChartView.AxisX.Add(
            //    new Axis
            //    {
            //        MinValue = 0,
            //        Labels = Labels
            //    }
            //    );
            //LineChartView.AxisY.Add(
            //    new Axis
            //    {
            //        MinValue = 0,
            //    }
            //    );
            //LineChartView.DataContext = this;
        }
Ejemplo n.º 22
0
        void FillByDate(DateTimeOffset?fromDate, DateTimeOffset?toDate)
        {
            data = new List <Tuple <int, decimal> >();
            data = QueryForSQLServer.GetTotalByMonth(2021);
            var list = data.ToList();

            if (fromDate != null && toDate != null)
            {
                data = new List <Tuple <int, decimal> >();
                for (int i = 0; i < list.Count(); i++)
                {
                    var Created_At    = list[i].Item1.ToString();
                    var dateMonth     = int.Parse(Created_At);
                    var fromDateMonth = int.Parse(fromDate?.ToString("MM"));
                    var toDateMonth   = int.Parse(toDate?.ToString("MM"));
                    if (fromDateMonth <= dateMonth && dateMonth <= toDateMonth)
                    {
                        data.Add(list[i]);
                    }
                }
                PieChartView.Series = new SeriesCollection();

                var enum2 = from num in data
                            orderby num.Item2 descending
                            select num;

                foreach (var item in enum2)
                {
                    if (item.Item2 != 0)
                    {
                        PieChartView.Series.Add(
                            new PieSeries()
                        {
                            Values = new ChartValues <decimal> {
                                item.Item2
                            },
                            Title      = item.Item1.ToString(),
                            DataLabels = true,
                        }
                            );
                    }
                }
                PieChartView.LegendLocation = LegendLocation.Bottom;
                PieChartView.DataContext    = this;

                LineChartView.Series = new SeriesCollection();
                var      linedata       = new List <decimal>();
                string[] Labels         = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                var      fromDateMonth2 = int.Parse(fromDate?.ToString("MM"));
                switch (fromDateMonth2)
                {
                case 1:
                    Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 2:
                    Labels = new[] { "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 3:
                    Labels = new[] { "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 4:
                    Labels = new[] { "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 5:
                    Labels = new[] { "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 6:

                    Labels = new[] { "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 7:
                    Labels = new[] { "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 8:
                    Labels = new[] { "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 9:
                    Labels = new[] { "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 10:
                    Labels = new[] { "Oct", "Nov", "Dec" };
                    break;

                case 11:
                    Labels = new[] { "Nov", "Dec" };
                    break;

                case 12:
                    Labels = new[] { "Dec" };
                    break;

                default:
                    break;
                }
                foreach (var item in data)
                {
                    linedata.Add(item.Item2);
                }
                LineChartView.Series.Add(
                    new LineSeries()

                {
                    Values = new ChartValues <decimal> {
                        linedata[0]
                    },
                    Title          = "Doanh thu theo năm",
                    LineSmoothness = 1,     //0: straight lines, 1: really smooth lines
                    DataLabels     = true,
                }
                    );
                for (int i = 1; i < linedata.Count(); i++)
                {
                    LineChartView.Series[0].Values.Add(linedata[i]);
                }
                LineChartView.LegendLocation = LegendLocation.Bottom;
                LineChartView.AxisX.Clear();
                LineChartView.AxisY.Clear();
                LineChartView.AxisX.Add(
                    new Axis
                {
                    MinValue = 0,
                    Labels   = Labels,
                }
                    );
                LineChartView.AxisY.Add(
                    new Axis
                {
                    MinValue = 0,
                }
                    );
                LineChartView.DataContext = this;
            }
        }
Ejemplo n.º 23
0
        private void editPurchase_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            btnAddItem.Visibility    = Visibility.Visible;
            btnDeleteItem.Visibility = Visibility.Visible;
            btnUpdate.Visibility     = Visibility.Visible;
            btnDone.Visibility       = Visibility.Visible;


            var Selecteditem = (sender as FrameworkElement).DataContext;

            current_id = (int)Selecteditem?.GetType().GetProperty("Purchase_ID")?.GetValue(Selecteditem, null);
            DataGridDetailPurchase.AutoGenerateColumns = false;

            var dt = QueryForSQLServer.GetPurchaseDetail(current_id);

            DataGridDetailPurchase.Columns.Clear();

            //customer
            string tel = Selecteditem?.GetType().GetProperty("Tel")?.GetValue(Selecteditem, null).ToString();

            getCustomer(tel, false);

            //DataGridDetailPurchase
            DataGridDetailPurchase.Columns.Add(new DataGridTextColumn()
            {
                Header  = dt.Columns[1].ColumnName,
                Binding = new Binding {
                    Path = new PropertyPath("Product_Name")
                }
            });

            DataGridDetailPurchase.Columns.Add(new DataGridTextColumn()
            {
                Header  = dt.Columns[2].ColumnName,
                Binding = new Binding
                {
                    Path = new PropertyPath("Quantity"),
                    Mode = BindingMode.TwoWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                }
            });
            DataGridDetailPurchase.Columns[1].IsReadOnly = false;


            DataGridDetailPurchase.Columns.Add(new DataGridTextColumn()
            {
                Header  = dt.Columns[4].ColumnName,
                Binding = new Binding {
                    Path = new PropertyPath("SubTotal")
                }
            });

            collection = new ObservableCollection <object>();


            foreach (DataRow row in dt.Rows)
            {
                //collection.Add(row.ItemArray);
                collection.Add(new
                {
                    Product_ID        = row.ItemArray[0],
                    Product_Name      = row.ItemArray[1],
                    Quantity          = row.ItemArray[2],
                    Unit_Price        = row.ItemArray[3],
                    SubTotal          = row.ItemArray[4],
                    PurchaseDetail_ID = row.ItemArray[5]
                });
            }
            DataGridDetailPurchase.ItemsSource = collection;
        }