/// <summary> /// 模型数据改变 /// </summary> /// <param name="obj"></param> private void dataChanged(EquipmentTypeModel equipmentTypeModel) { getPageData(pageRepuestParams.PageIndex, pageRepuestParams.PageSize); var tmpModel = EquipmentTypeInfoList.FirstOrDefault(a => a.Id == equipmentTypeModel.Id); this.EquipmentTypeInfo = EquipmentTypeInfoList.FirstOrDefault(); }
public override void OnParamterChanged(object parameter) { this.EquipmentModel = parameter as EquipmentInfoModel; this.EntDepartmentInfo = EntDepartmentInfoList.Where(x => x.Id == Guid.Parse(EquipmentModel.DepartmentInfo_Id)).FirstOrDefault(); this.EquFactoryInfo = EquFactoryInfoList.Where(x => x.Id == Guid.Parse(EquipmentModel.EquFactoryInfo_Id)).FirstOrDefault(); this.EquipmentTypeModel = EquipmentTypeInfoList.Where(x => x.Id == EquipmentModel.EquipmentType_Id).FirstOrDefault(); }
/// <summary> /// 是否可以执行打印命令 /// </summary> /// <returns></returns> private bool OnCanExecutePrintCommand() { if (Equals(EquipmentTypeInfoList, null) || !EquipmentTypeInfoList.Any()) { return(false); } else { return(true); } }
/// <summary> /// 取得分页数据 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> private void getPageData(int pageIndex, int pageSize) { #if DEBUG System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); #endif pageRepuestParams.SortField = GlobalData.SortField; pageRepuestParams.SortOrder = GlobalData.SortOrder; pageRepuestParams.PageIndex = pageIndex; pageRepuestParams.PageSize = pageSize; var result = Utility.Http.HttpClientHelper.PostResponse <OperationResult <PageResult <EquipmentTypeModel> > >(GlobalData.ServerRootUri + "EquipmentTypeInfo/PageData", Utility.JsonHelper.ToJson(pageRepuestParams)); #if DEBUG stopwatch.Stop(); Utility.LogHelper.Info("获取设备信息用时(毫秒):" + stopwatch.ElapsedMilliseconds); Utility.LogHelper.Info("设备信息内容:" + Utility.JsonHelper.ToJson(result)); #endif if (!Equals(result, null) && result.Successed) { UiMessage = result?.Message; LogHelper.Info(UiMessage.ToString()); if (result.Data.Data.Any()) { EquipmentTypeInfoList = new ObservableCollection <EquipmentTypeModel>(result.Data.Data); TotalCounts = result.Data.Total; } else { EquipmentTypeInfoList?.Clear(); TotalCounts = 0; UiMessage = "未找到数据"; } } else { //操作失败,显示错误信息 EquipmentTypeInfoList = new ObservableCollection <EquipmentTypeModel>(); UiMessage = result?.Message ?? "查询设备信息失败,请联系管理员!"; } }
/// <summary> /// 执行导出命令 /// </summary> private async void OnExecuteExportCommand() { var window = (MetroWindow)Application.Current.MainWindow; var dialogResult = await window.ShowMessageAsync("数据导出" , "确定要从磁盘中导出企业信息数据吗?" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "是", NegativeButtonText = "否" }); if (dialogResult == MessageDialogResult.Affirmative) { string filePath = ""; System.Windows.Forms.SaveFileDialog openFileDialog = new System.Windows.Forms.SaveFileDialog(); openFileDialog.FileName = "设备类型信息" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + ".xls"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)//注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性 { filePath = openFileDialog.FileName; } if (string.IsNullOrEmpty(filePath)) { await window.ShowMessageAsync("数据导出" , "数据导出失败,选择存储路径为空!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); return; } if (EquipmentTypeInfoList.Any()) { try { EquipmentTypeModel model = new EquipmentTypeModel(); List <string> displayNameList = model.GetDisplayName(); DataTable dataTable = EquipmentTypeInfoList.ToDataTable <EquipmentTypeModel>(displayNameList); NPOIHelper.Export(dataTable, "企业信息", filePath); } catch (Exception ex) { await window.ShowMessageAsync("数据导出" , "数据导出失败!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } if (File.Exists(filePath)) { await window.ShowMessageAsync("数据导出" , "数据导出已完成!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } else { await window.ShowMessageAsync("数据导出" , "数据导出失败!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } } else { await window.ShowMessageAsync("数据导出" , "数据导出失败,无数据!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } } }
/// <summary> /// 执行导入命令 /// </summary> private async void OnExecuteImportCommand() { var window = (MetroWindow)System.Windows.Application.Current.MainWindow; var dialogResult = await window.ShowMessageAsync("数据导入" , "确定要导入企业信息数据到磁盘中吗?将会删除磁盘中原有数据" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "是", NegativeButtonText = "否" }); if (dialogResult == MessageDialogResult.Affirmative) { string filePath = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK)//注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性 { filePath = openFileDialog.FileName; } if (string.IsNullOrEmpty(filePath)) { UiMessage = "数据导入失败,选择存储路径为空!"; return; } if (EquipmentTypeInfoList.Any()) { try { EquipmentTypeModel model = new EquipmentTypeModel(); Dictionary <String, Type> filedNameDc = model.GetFiledNameAndType(); DataTable dt = NPOIHelper.Import(filePath); DataTable dtNew = new DataTable(); foreach (var kvp in filedNameDc) { dtNew.Columns.Add(kvp.Key, kvp.Value); } object[] values = new object[filedNameDc.Count]; foreach (DataRow row in dt.Rows) { for (int i = 0; i < dtNew.Columns.Count; i++) { values[i] = row[i]; } dtNew.Rows.Add(values); } List <EquipmentTypeModel> enterpriseModels = dtNew.DataTableToList <EquipmentTypeModel>(); getPageData(pageRepuestParams.PageIndex, pageRepuestParams.PageSize); var result = Utility.Http.HttpClientHelper.PostResponse <OperationResult>(GlobalData.ServerRootUri + "EquipmentTypeInfo/Remove", Utility.JsonHelper.ToJson(EquipmentTypeInfoList.Select(x => x.Id).ToList())); if (!Equals(result, null) && result.Successed) { var addResult = Utility.Http.HttpClientHelper.PostResponse <OperationResult>(GlobalData.ServerRootUri + "EquipmentTypeInfo/Add", Utility.JsonHelper.ToJson(enterpriseModels)); await window.ShowMessageAsync("数据导入" , "数据导入已完成!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); getPageData(pageRepuestParams.PageIndex, pageRepuestParams.PageSize); EquipmentTypeInfo = null; } else { //操作失败,显示错误信息 UiMessage = "数据删除失败,请联系管理员!"; } } catch (Exception ex) { await window.ShowMessageAsync("数据导入" , "数据导入失败!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } //if (File.Exists(filePath)) //{ // await window.ShowMessageAsync("数据导入" // , "数据导入已完成!" // , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); //} //else //{ // await window.ShowMessageAsync("数据导入" // , "数据导入失败!" // , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); //} } else { await window.ShowMessageAsync("数据导入" , "数据导入失败,无数据!" , MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } } }