using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Xml.Linq;
using System.Reflection;
using Action = System.Action;
using System.Data.SqlClient;
using System.Drawing;
using System.Data.OleDb;
using WPFWindow = System.Windows;
using System.Data;
using DataTable = System.Data.DataTable;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.Win32;
using System.Collections.ObjectModel;
using System.Reflection.Emit;
namespace WpfApp1
{
///
/// Interaction logic for Window033.xaml
///
public partial class Window033 : WPFWindow.Window
{
public Window033()
{
InitializeComponent();
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
}
class ProductPriceViewModel : INotifyPropertyChanged
{
public ProductPriceViewModel()
{
//DataTableCollection = ExcelUtlity.ReadExcelFile(excelpath);
command = new RelayCommand(Execute);
}
public DataTable DataTableCollection { get; set; }
public List MainProductCategory
{
get => new List() {"PrintProduct","RetroPrint","PrintWithFrame","Calendar","Collage",
"CollagePoster","SingleSidePhoto","PassportPhoto","IDPhotoCard","GadgetProduct","GreetingCard"};
}
public List ProductName
{
get => new List() {
"10x10","10x15","10x8","10x20","13x18","13x13","15x20","15x23","20x25","20x30","Sticker","Metallic","Perfo" };
}
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler? CanExecuteChanged;
public void OnPropertyChanged([CallerMemberName] String info = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
private bool Filter(object item)
{
Product p = item as Product;
if (p == null) return true;
var ret = true;
if (!String.IsNullOrEmpty(MainProductSearch))
ret = ret && p.Mainproduct.IndexOf(MainProductSearch, StringComparison.OrdinalIgnoreCase) >= 0 ||
p.Name.IndexOf(MainProductSearch, StringComparison.OrdinalIgnoreCase) >= 0;
if (!String.IsNullOrEmpty(SizeSearch))
ret = ret && p.Name.IndexOf(SizeSearch, StringComparison.OrdinalIgnoreCase) >= 0;
if (!String.IsNullOrEmpty(MediaType))
ret = ret && p.Name.IndexOf(MediaType, StringComparison.OrdinalIgnoreCase) >= 0;
if (Visible.HasValue)
ret = ret && p.Visible.IndexOf(Visible.Value.ToString(), StringComparison.OrdinalIgnoreCase) >= 0;
return ret;
}
private ICollectionView cvs;
public ICollectionView View
{
get { return cvs; }
set
{
cvs = value;
OnPropertyChanged("View");
}
}
private readonly ICommand command;
public ICommand Command
{
get
{
return command;
}
}
//private CollectionViewSource cvs = new CollectionViewSource();
// public ICollectionView View { get; set; }
//public ICollectionView View
//{
// get
// {
// if (cvs.Source == null)
// {
// cvs.Source = GetProductsPriceListXML();// GetProductsPriceListXML();GetProductsListPriceExcel();
// cvs.View.Filter = Filter;
// }
// return this.cvs.View;
// }
//}
//public Product SelectedProduct { get; set; }
private Product selectedProduct;
public Product SelectedProduct
{
get { return selectedProduct; }
set
{
selectedProduct = value;
OnPropertyChanged("SelectedProduct");
}
}
private string _MainProductSearch;
public string MainProductSearch
{
get { return _MainProductSearch; }
set
{
_MainProductSearch = value;
OnPropertyChanged();
View.Refresh();
}
}
private string _SizeSearch;
public string SizeSearch
{
get { return _SizeSearch; }
set
{
_SizeSearch = value;
OnPropertyChanged();
View.Refresh();
}
}
private string _MediaType;
public string MediaType
{
get { return _MediaType; }
set
{
_MediaType = value;
OnPropertyChanged();
View.Refresh();
}
}
private bool? _Visible;
public bool? Visible
{
get { return this._Visible; }
set
{
this._Visible = value;
OnPropertyChanged();
View.Refresh();
}
}
public static DataTable ConvertToDataTable(IList data)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
System.Data.DataTable table = new System.Data.DataTable();
foreach (PropertyDescriptor prop in properties)
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
foreach (T item in data)
{
DataRow row = table.NewRow();
foreach (PropertyDescriptor prop in properties)
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
table.Rows.Add(row);
}
return table;
}
//EEPlus parsing excel to list of objects
//https://github.com/ducklmg/ExcelToObject
public ICommand MyCommand { get => new RelayCommand(executemethod, canexecutemethod); }
public ICommand ReadCommand { get => new RelayCommand(Execute, canexecutemethod); }
//https://gist.github.com/kzelda/2facdff2d924349fe96c37eab0e9ee47 readwrite excel openxml
string excelpath = @"C:\Users\krangaraj.KONICAFR\Desktop\Price_202301111303.xlsx";
string pricinglocalfile = @"C:\xmltest\Prices_2022_12_15_All_CM_V4.txt";
public ObservableCollection Items { get; set; }
private void Execute(object parm)
{
//Items = GetProductsPriceListXML();
//View = CollectionViewSource.GetDefaultView(Items);
//View.Filter = Filter;
//View.Refresh();
}
private void executemethod(object parameter)
{
switch (parameter.ToString())
{
case "ExcelExport":
ExcelUtlity obj = new ExcelUtlity();
System.Data.DataTable dt = ConvertToDataTable(GetProductsPriceListXML());
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "Price_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx";
obj.WriteDataTableToExcel(dt, path);
System.Windows.MessageBox.Show("Excel Pricing File created on the desktop");
return;
case "ReadExcel":
//DataTableCollection = GetDataTable();
// System.Data.DataTable dtexcel = ExcelUtlity.ReadExcelSheet(excelpath, false);
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
fileDialog.FilterIndex = 1;
fileDialog.Multiselect = false;
dynamic result = fileDialog.ShowDialog();
if (result == true)
{
string excelfilepath = fileDialog.FileName;
DataTableCollection = ExcelUtlity.ReadExcelFile(excelfilepath);
ObservableCollection