public UserDataGridFormatConfigurationViewModel(string dataGridName) { _dataGridName = dataGridName; _service = new DataGridManagementService(); InitData(); InitCommand(); }
public BaseViewModel() { CommonService = new CommonService(); Menu = MemoryCache.Default["PageCache"] as MainMenuModel; User = (MemoryCache.Default["UserCache"] as UserCacheModel).User; HostName = Dns.GetHostName(); DataGridId = Menu == null ? 0: Menu.ID * 10000 + 1; ComboBoxSearchService = new ComboBoxSearchService(); ExportHelper = new DataTableImportExportHelper(); DataGridManagementService = new DataGridManagementService(); UserDataId = CommonService.GetUserDataId(User, Menu == null ? 0 :Menu.ID); PrintConfiguration = new BarTenderPrintConfigModelXX(); }
private void InitCommand() { PrintConfigurationSaveBaseCommand = new DelegateCommand((obj) => { string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration); if (string.IsNullOrEmpty(msg)) { int id = CommonService.SaveBarTenderPrintConfigXX(PrintConfiguration); if (id > 0) { PrintConfiguration.Id = id; MessageBox.Show("保存成功"); } else { MessageBox.Show("保存失败,请联系管理员"); } } else { MessageBox.Show(msg); } }); TemplateSelectBaseCommand = new DelegateCommand((obj) => { System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { PirntTemplates = PrintHelper.GetTenderPrintA4Templates(fbd.SelectedPath); } }); DirectorySelectBaseCommand = new DelegateCommand((obj) => { // 导出目录选择 System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { HostConfig.HostValue = fbd.SelectedPath; var result = CommonService.SaveHostConfig(HostConfig); if (result) { HostConfig = CommonService.GetHostConfig(DataGridId, HostName, User.ID); } } }); ExportBaseCommand = new DelegateCommand((obj) => { if (Directory.Exists(HostConfig.HostValue)) { ExportView view = new ExportView(DataGridId, 1); (view.DataContext as ExportViewModel).Export((type, outputEntity, checkBoxValue, orderedColumns) => { view.Close(); if (type == 1) { DataTable datatable = new DataTable(); if (outputEntity == 1) { datatable = _service.GetExportData1("DGPrintA4", User.ID, CommonService.GetSqlWhereString(QueryParameter)); ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(QueryParameter)); MessageBox.Show("导出成功"); } //else if (outputEntity == 2) //{ // datatable = _shippingService.GetShippingBillExprotDataTable2(UserDataId); // new Helper.DataTableImportExportHelper().ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption); // MessageBox.Show("导出成功"); //} //else if (outputEntity == 3) //{ // datatable = _shippingService.GetShippingBillExprotDataTable3(UserDataId, string.Join(",", orderedColumns)); // new Helper.DataTableImportExportHelper().ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption, checkBoxValue, 1, orderedColumns); // MessageBox.Show("导出成功"); //} } }); view.ShowDialog(); } else { MessageBox.Show("目录不存在,请先选择导出的目录"); DirectorySelectBaseCommand.Execute(null); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "ExportBaseCommand", ActionDesc = HostConfig.TypeDesciption + HostConfig.TypeId.ToString(), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); DataGridSaveCommand = new DelegateCommand((obj) => { DataGridManagementService.SaveColumnConfigurationInUserInterface(obj as DataGrid, User.ID); MessageBox.Show("参数保存成功"); }); PrintBaseCommand = new DelegateCommand((obj) => { string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration); if (string.IsNullOrEmpty(msg)) { var selectedLists = ((obj as DataGrid).SelectedItems).Cast <LabelPrintHistoryModel>().ToList(); if (selectedLists.Count > 0) { string result = _print.BarTenderPrintA4(selectedLists, PrintConfiguration, selectedLists.Sum(x => x.PrintCount)); MessageBox.Show(result); QueryCommand.Execute(null); } else { MessageBox.Show("先选择行数据,【CTRL】或【SHFIT】 多选行"); } } else { MessageBox.Show(msg); } }); QueryCommand = new DelegateCommand((obj) => { PrintHistoryLists.Clear(); _service.GetHistoryLists(CommonService.GetSqlWhereString(QueryParameter)).ForEach(x => PrintHistoryLists.Add(x)); }); DataGridManageCommand = new DelegateCommand((obj) => { var grid = obj as DataGrid; UserDataGridFormatConfigurationView view = new UserDataGridFormatConfigurationView("DGPrintA4"); (view.DataContext as UserDataGridFormatConfigurationViewModel).WithParam(null, (type, outputEntity) => { view.Close(); if (type == 1) { // 重新加载DataGrid格式 grid.Columns.Clear(); CommonService.GetUserDataGridColumn(User.ID, grid, 0); } }); view.ShowDialog(); }); }
public DataGridManagementViewModel() { _service = new DataGridManagementService(); InitData(); InitCommand(); }
private void InitCommand() { #region 打印参数 PrintConfigurationSaveBaseCommand = new DelegateCommand((obj) => { string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration); if (string.IsNullOrEmpty(msg)) { int id = CommonService.SaveBarTenderPrintConfigXX(PrintConfiguration); if (id > 0) { PrintConfiguration.Id = id; MessageBox.Show("保存成功"); } else { MessageBox.Show("保存失败,请联系管理员"); } } else { MessageBox.Show(msg); } }); TemplateSelectBaseCommand = new DelegateCommand((obj) => { System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { PirntTemplates = PrintHelper.GetTenderPrintTemplates(fbd.SelectedPath); } }); #endregion #region 导出 //DirectorySelectBaseCommand = new DelegateCommand((obj) => //{ // // 导出目录选择 // System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); // if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) // { // HostConfig.HostValue = fbd.SelectedPath; // var result = CommonService.SaveHostConfig(HostConfig); // if (result) // { // HostConfig = CommonService.GetHostConfig(DataGridId, HostName, User.ID); // } // } //}); //ExportBaseCommand = new DelegateCommand((obj) => //{ // if (Directory.Exists(HostConfig.HostValue)) // { // ExportView view = new ExportView(DataGridId); // (view.DataContext as ExportViewModel).Export(1, (type, outputEntity, checkBoxValue, orderedColumns) => // { // view.Close(); // if (type == 1) // { // DataTable datatable = new DataTable(); // if (outputEntity == 1) // { // datatable = _service.GetExportData1("DGPrintA4", User.ID, CommonService.GetSqlWhereString(QueryParameter)); // ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(QueryParameter)); // MessageBox.Show("导出成功"); // } // //else if (outputEntity == 2) // //{ // // datatable = _shippingService.GetShippingBillExprotDataTable2(UserDataId); // // new Helper.DataTableImportExportHelper().ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption); // // MessageBox.Show("导出成功"); // //} // //else if (outputEntity == 3) // //{ // // datatable = _shippingService.GetShippingBillExprotDataTable3(UserDataId, string.Join(",", orderedColumns)); // // new Helper.DataTableImportExportHelper().ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption, checkBoxValue, 1, orderedColumns); // // MessageBox.Show("导出成功"); // //} // } // }); // view.ShowDialog(); // } // else // { // MessageBox.Show("目录不存在,请先选择导出的目录"); // DirectorySelectBaseCommand.Execute(null); // } // CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "ExportBaseCommand", ActionDesc = HostConfig.TypeDesciption + HostConfig.TypeId.ToString(), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); //}); #endregion #region 保存表格 DataGridManageBaseCommand = new DelegateCommand((obj) => { var grid = obj as DataGrid; UserDataGridFormatConfigurationView view = new UserDataGridFormatConfigurationView("DGPrintLS"); (view.DataContext as UserDataGridFormatConfigurationViewModel).WithParam(null, (type, outputEntity) => { view.Close(); if (type == 1) { // 重新加载DataGrid格式 grid.Columns.Clear(); CommonService.GetUserDataGridColumn(User.ID, grid, 0); } }); view.ShowDialog(); }); DataGridSaveBaseCommand = new DelegateCommand((obj) => { DataGridManagementService.SaveColumnConfigurationInUserInterface(obj as DataGrid, User.ID); MessageBox.Show("表格格式保存成功"); }); #endregion #region 其他 PrintBaseCommand = new DelegateCommand((obj) => { string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration); if (string.IsNullOrEmpty(msg)) { if (BarcodeTypeSelectedItem.ItemSeq == 1) { MessageBox.Show("工单不能打印,请选择其他类别"); return; } var selectedLists = ((obj as DataGrid).SelectedItems).Cast <LabelPrintLSModel>().ToList(); if (selectedLists.Count > 0) { string result = _print.BarTenderPrintLS(selectedLists, PrintConfiguration); // 将标签插入PDM系统 //string hids = string.Join(",", selectedLists.Select(x => x.HistoryId)); //var PdmLists = new PrintLSService().GetPdmBarCodeLists(ProductionDate, hids); var PdmLists = selectedLists.Select(x => new LabelInsertDataModel { BarCode = x.BarCode, Inventory_Id = x.FNumber, JarmodelId = x.BucketNumber, Unit_weight = x.NetWeight, ProjectBatch = x.HistoryBatchNo , BoxCode = "1", Nbox = "1", CreateDate = DateTime.Now.Date.ToString("yyyy-MM-dd") }); foreach (var item in PdmLists) { CommonHelper.InsertBarCode(item); } MessageBox.Show(result); QueryBaseCommand.Execute(null); } else { MessageBox.Show("先选择行数据,【CTRL】或【SHFIT】 多选行"); } } else { MessageBox.Show(msg); } }); QueryBaseCommand = new DelegateCommand((obj) => { PrintLSLists.Clear(); _service.GetLists(ProductionDate, BarcodeTypeSelectedItem.ItemSeq).ForEach(x => PrintLSLists.Add(x)); }); #endregion GenerationNewDataCommand = new DelegateCommand((obj) => { //if (_service.ExistsPrintData(ProductionDate)) //{ // //提示是否清理 // MessageBoxResult result = MessageBox.Show("当天已经有数据,重新生成会将打印记录清除", "温馨提示", MessageBoxButton.YesNo); // if (result == MessageBoxResult.Yes) // { // _service.GenerationPrintData(ProductionDate); // } //} //else //{ _service.GenerationPrintData(ProductionDate); //} QueryBaseCommand.Execute(null); }); }