| | |
| | | using HMI.MenuManage.Entity; |
| | | using HMI.MenuManage.Model; |
| | | using HMI.UI.Util; |
| | | using HMI.Util; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | { |
| | | Model.LoadData(); |
| | | this.Loaded -= UserManage_Loaded; |
| | | } |
| | | |
| | | public override void DoClose(object sender, EventArgs e) |
| | | { |
| | | try |
| | | { |
| | | Model?.sqliteHelper?.Close(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Warn("Do Close Failed.", ex); |
| | | } |
| | | } |
| | | |
| | | private void Button_Click(object sender, RoutedEventArgs e) |
| | |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.SaveFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | else if (btn.Name == "exportBtn") |
| | | { |
| | | ExportToExcel(); |
| | | } |
| | | else if (btn.Name == "importBtn") |
| | | { |
| | | ImportFromExcel(); |
| | | } |
| | | } |
| | | |
| | | public void ExportToExcel() |
| | | { |
| | | try |
| | | { |
| | | if (Model.DataSource == null || Model.DataSource.Count <= 0) |
| | | { |
| | | ToastHelper.Warning(this.lang("App.NoExportData")); |
| | | return; |
| | | } |
| | | System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog(); |
| | | |
| | | string fname = string.Empty; |
| | | sfd.Filter = ""; |
| | | sfd.DefaultExt = "xls"; |
| | | sfd.FileName = this.lang("HMI.User.Title"); |
| | | if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
| | | { |
| | | fname = sfd.FileName; |
| | | ExcelHelper.ExportExcel(fname, Model.DataSource); |
| | | ToastHelper.Success(this.lang("App.ExportSuccess")); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("Export User Data Failed.", ex); |
| | | ToastHelper.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public void ImportFromExcel() |
| | | { |
| | | try |
| | | { |
| | | System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); |
| | | openDialog.Filter = "execl(*.xlsx;*.xls)|*.xlsx;*.xls"; |
| | | if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
| | | { |
| | | List<UserData> users = ExcelHelper.ReadFromExcel<UserData>(openDialog.FileName); |
| | | if (users == null || users.Count <= 0) |
| | | { |
| | | ToastHelper.Warning(this.lang("App.NoImportData")); |
| | | return; |
| | | } |
| | | Model.ImportUser(users); |
| | | Model.LoadData(); |
| | | ToastHelper.Success(this.lang("App.ImportSuccess")); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("AlarmText Import Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{this.lang("App.ImportFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | | } |