using Admin.Core.IService; using Admin.Core.Model.Sys; using Admin.Core.Model; using Admin.Core.Service; using Admin.Core.Wpf.Models; using Admin.Core.Wpf.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using log4net; using MaterialDesignThemes.Wpf; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.Metrics; using System.Drawing.Imaging; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using Admin.Core.Common; using Admin.Core.IRepository; using StackExchange.Profiling.Internal; /* * 首页信息 * */ namespace Admin.Core.Wpf.ViewModels { public partial class IndexPageViewModel : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); protected readonly IBaseOrderInfoServices? _baseOrderInfoServices; public IndexPageViewModel() { _baseOrderInfoServices = App.ServiceProvider.GetService(); _=LoadData(); } #region 加载DataGrid数据 private async Task LoadData() { Datalist.Clear(); var list= await _baseOrderInfoServices.QueryPrintInfo(); foreach(var item in list) { Datalist.Add(new OrderInfo() { created_time = item.CreateTime.ToString(), order_code = item.OrderCode, product_code = item.ProductCode, product_name = item.ProductName, plan_amount = item.PlanAmount, complete_amount = item.CompleteAmount.ToString() == "" ? 0 : item.CompleteAmount, material_code = item.MaterialCode, material_name = item.MaterialName, standard_amount = item.StandardAmount, ErrorNum = item.ErrorAmount, LinerCodeNum = item.LinerAmount, BoxCodeNum = item.BoxAmount }); } } #endregion #region 查询按钮 /// /// 查询 /// [RelayCommand] private void QueryString(string queryStr) { System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { if (!string.IsNullOrEmpty(queryStr)) { Datalist.Clear(); //Expression> whereExpression = x => (bool)x.DelFlag == false; //if (queryStr.IsNotEmptyOrNull()) //{ // whereExpression = whereExpression.And(x => x.PLAN_CODE.Contains(queryStr)); //} var list = await _baseOrderInfoServices.QueryPrintInfo(); //list.Where(d => d.MaterialName.Contains("U壳") || d.MaterialName.Contains("内胆")); var orderList = list.Where(d => d.OrderCode.Contains(queryStr) || d.ProductCode.Contains(queryStr) || d.ProductName.Contains(queryStr) || d.MaterialCode.Contains(queryStr) || d.MaterialName.Contains(queryStr)); foreach (var item in orderList) { Datalist.Add(new OrderInfo() { created_time = item.CreateTime.ToString(), order_code = item.OrderCode, product_code = item.ProductCode, product_name = item.ProductName, plan_amount = item.PlanAmount, complete_amount = item.CompleteAmount.ToString() == "" ? 0 : item.CompleteAmount, material_code = item.MaterialCode, material_name = item.MaterialName, standard_amount = item.StandardAmount, ErrorNum = item.ErrorAmount, LinerCodeNum = item.LinerAmount, BoxCodeNum = item.BoxAmount }); } } else { Datalist.Clear(); _ = LoadData(); } //Datalist.Insert(0, Datalist[Datalist.Count - 1]); //Datalist.RemoveAt(Datalist.Count - 1); })); } #endregion #region radio查询按钮 /// /// 查询 /// [RelayCommand] private async Task RadioQuery(string query) { try { string materialName= string.Empty; //if (string.IsNullOrEmpty(query)) materialName = "内胆"; //if (query == "Liner") materialName = "内胆"; //if (query== "UShell") materialName = "U壳"; Datalist.Clear(); var list = await _baseOrderInfoServices.QueryPrintInfo(); var orderList = list.Where(d => d.MaterialName.Contains(query) ); foreach (var item in orderList) { Datalist.Add(new OrderInfo() { created_time = item.CreateTime.ToString(), order_code = item.OrderCode, product_code = item.ProductCode, product_name = item.ProductName, plan_amount = item.PlanAmount, complete_amount = item.CompleteAmount.ToString() == "" ? 0 : item.CompleteAmount, material_code = item.MaterialCode, material_name = item.MaterialName, standard_amount = item.StandardAmount, ErrorNum = item.ErrorAmount, LinerCodeNum = item.LinerAmount, BoxCodeNum = item.BoxAmount }); } } catch (Exception ex) { log.Error("查询数据异常", ex); } } #endregion #region 打印 /// /// 打印 /// [RelayCommand] private void Print(string obj) { if (string.IsNullOrEmpty(obj)) { MessageBox.Show("请选中一行!","系统提醒"); return; } string order_code = SelectedCells.product_code; string product_code = SelectedCells.product_code; string product_name = SelectedCells.product_name; string material_code = SelectedCells.material_code; string material_name = SelectedCells.material_name; int standard_amount = SelectedCells.standard_amount; PrintToDevView printToDev= new PrintToDevView(product_code, material_code, material_name, standard_amount); printToDev.ShowDialog(); } #endregion #region 补打 /// ///补打 /// [RelayCommand] private void SupplementPrint(string obj) { if (string.IsNullOrEmpty(obj)) { MessageBox.Show("请选中要补打的数据!", "系统提醒"); return; } string order_code = SelectedCells.order_code; string product_code = SelectedCells.product_code; string product_name = SelectedCells.product_name; string material_code = SelectedCells.material_code; string material_name = SelectedCells.material_name; int standard_amount = SelectedCells.standard_amount; SupplementPrintPageView printToDev = new SupplementPrintPageView(order_code,product_code, material_code, material_name); printToDev.ShowDialog(); } #endregion #region 续打 /// ///续打 /// [RelayCommand] private void ContinuedPrint() { MessageBox.Show("续打"); // OrderInfo info = new OrderInfo(); } #endregion #region 初始化datagrid private ObservableCollection datalist = new ObservableCollection(); public ObservableCollection Datalist { get { return datalist; } set { datalist = value; OnPropertyChanged();//属性通知 } } #endregion #region 获取当前行数据 赋值到textbox private OrderInfo selectedCells; public OrderInfo SelectedCells { get { return selectedCells; } set { selectedCells = value; SetProperty(ref selectedCells, value); } } #endregion } }