package main import ( "github.com/lxn/walk" . "github.com/lxn/walk/declarative" "github.com/lxn/win" "log" "os" ) // 初始始化窗体 func GetWindows() error { icon, _ := walk.NewIconFromResourceId(3) err := MainWindow{ Visible: false, AssignTo: &app.mw, Title: app.title, Size: Size{Width: 500, Height: 360}, Font: Font{Family: "微软雅黑", PointSize: 9}, Icon: icon, Layout: VBox{}, MenuItems: []MenuItem{ Menu{ Text: "&编辑", Items: []MenuItem{ Separator{}, Action{ Text: "清除缓存", OnTriggered: clearAll, }, Action{ Text: "重构索引", OnTriggered: reDbIndex, }, Action{ Text: "数据备份", OnTriggered: dbBak, }, Action{ Text: "数据还原", OnTriggered: reDbBak, }, Action{ Text: "退出", OnTriggered: func() { OnExit() }, }, }, }, Menu{ Text: "&设置", Items: []MenuItem{ Separator{}, Action{ Text: "设置数据库内存", OnTriggered: setDbSize, }, Action{ Text: "设置应用内存", OnTriggered: setServerSize, }, }, }, Menu{ Text: "&表册", // Image: "./image/shezhi.png", Items: []MenuItem{ Separator{}, Action{ // Image: "./image/shujuku.png", Text: "按照职务输出生成(可能人员重复)", OnTriggered: getMcByA0281, }, Action{ // Image: "./image/yingyong.png", Text: "按照主职务生成(可能人员丢失)", OnTriggered: getMcByA0279, }, }, }, Menu{ Text: "&帮助", Items: []MenuItem{ Action{ Text: "关于", OnTriggered: app.aboutactionTriggered, }, /*Action{ Text: "要求", OnTriggered: app.aboutactionTriggered, },*/ }, }, }, Children: []Widget{GroupBox{ Title: "基础服务状态", Layout: Grid{Columns: 3}, Children: []Widget{ Label{Text: service1.text, MinSize: Size{Width: 220, Height: 30}, TextColor: walk.RGB(255, 255, 0)}, Label{AssignTo: &service1.labelState, Text: "正在运行", MinSize: Size{Width: 80, Height: 30}}, Composite{ Layout: HBox{}, MaxSize: Size{Width: 198, Height: 30}, Children: []Widget{ PushButton{ AssignTo: &service1.btnRegister, MaxSize: Size{Width: 60, Height: 30}, Text: "注册表", }, PushButton{ AssignTo: &service1.btnStop, MaxSize: Size{Width: 60, Height: 30}, Text: "停止", }, PushButton{ AssignTo: &service1.btnStart, MaxSize: Size{Width: 60, Height: 30}, Text: "启动", }, }, }, }, }, GroupBox{ Title: "业务服务状态", Layout: Grid{Columns: 3}, Children: []Widget{ Label{Text: service3.text, MinSize: Size{Width: 220, Height: 30}}, Label{AssignTo: &service3.labelState, Text: "正在运行", MinSize: Size{Width: 80, Height: 30}}, Composite{ Layout: HBox{}, MaxSize: Size{Width: 198, Height: 30}, Children: []Widget{ PushButton{ AssignTo: &service3.btnRegister, MaxSize: Size{Width: 60, Height: 30}, Text: "注册表", }, PushButton{ AssignTo: &service3.btnStop, MaxSize: Size{Width: 60, Height: 30}, Text: "停止", }, PushButton{ AssignTo: &service3.btnStart, MaxSize: Size{Width: 60, Height: 30}, Text: "启动", }, }, }, }, }, TextEdit{AssignTo: &app.msg, VScroll: true, ReadOnly: true}, Composite{ Layout: HBox{}, Children: []Widget{ PushButton{ MinSize: Size{Width: 200, Height: 30}, Text: "打开windows服务管理程序", OnClicked: openServices, }, HSpacer{}, PushButton{ MinSize: Size{Width: 140, Height: 30}, Text: "关闭本监控窗口", OnClicked: func() { OnExit() }, }, }, }}, OnSizeChanged: func() { _ = app.mw.SetSize(walk.Size(Size{Width: 500, Height: 360})) }, }.Create() winLong := win.GetWindowLong(app.mw.Handle(), win.GWL_STYLE) // 不能调整窗口大小,禁用最大化按钮 win.SetWindowLong(app.mw.Handle(), win.GWL_STYLE, winLong & ^win.WS_SIZEBOX & ^win.WS_MAXIMIZEBOX & ^win.WS_SIZEBOX) // 设置窗体生成在屏幕的正中间,并处理高分屏的情况 // 窗体横坐标 = ( 屏幕宽度 - 窗体宽度 ) / 2 // 窗体纵坐标 = ( 屏幕高度 - 窗体高度 ) / 2 _ = app.mw.SetX((int(win.GetSystemMetrics(0)) - app.mw.Width()) / 2 / app.mw.DPI() * 96) _ = app.mw.SetY((int(win.GetSystemMetrics(1)) - app.mw.Height()) / 2 / app.mw.DPI() * 96) return err } //数据库配置结构 type DbSetings struct { InnodbBufferPoolSize int // 数据库缓存大小 } // 运行 数据库设置 Dialog func (mw *myApp) RunDbSetingDialog(owner walk.Form, confirmCall func(*DbSetings)) { var seting *DbSetings var dlg *walk.Dialog var db *walk.DataBinder var acceptPB, cancelPB *walk.PushButton seting = new(DbSetings) // 设置预定值 seting.InnodbBufferPoolSize = 512 _, _ = Dialog{ AssignTo: &dlg, Title: "数据源内存设置", Font: Font{Family: "微软雅黑", PointSize: 9}, DefaultButton: &acceptPB, CancelButton: &cancelPB, DataBinder: DataBinder{ AssignTo: &db, Name: "setings", DataSource: seting, ErrorPresenter: ToolTipErrorPresenter{}, }, MinSize: Size{Width: 450, Height: 160}, Layout: VBox{}, Children: []Widget{ Composite{ Layout: Grid{Columns: 2}, Children: []Widget{ Label{Text: `      数据库内存:`}, NumberEdit{Value: Bind("InnodbBufferPoolSize", Range{Min: 64, Max: 10240}), Suffix: " M", Decimals: 0}, }, }, Composite{ Layout: HBox{}, Children: []Widget{ HSpacer{}, PushButton{ AssignTo: &acceptPB, Text: "保存", OnClicked: func() { if err := db.Submit(); err != nil { showMsg("【异常】处理设置数据库内存时,发生异常!") log.Fatal(err) return } // 关闭页面 dlg.Cancel() // 应用 回调函数 confirmCall(seting) }, }, PushButton{ AssignTo: &cancelPB, Text: "取消", OnClicked: func() { dlg.Cancel() }, }, }, }, }, }.Run(owner) } //应用配置结构 type AppSetings struct { PermSize int // 非堆区初始内存分配大小 MaxPermSize int // 非堆区分配的内存的最大上限 Xms int // 堆区内存初始内存分配的大小 Xmx int // 堆区内存可被分配的最大上限 } // 运行 应用设置 Dialog func (mw *myApp) RunAppSetingDialog(owner walk.Form, confirmCall func(*AppSetings)) { var seting *AppSetings var dlg *walk.Dialog var db *walk.DataBinder var acceptPB, cancelPB *walk.PushButton seting = new(AppSetings) // 设置预定值 seting.PermSize = 128 seting.MaxPermSize = 256 seting.Xmx = 512 seting.Xms = 512 _, _ = Dialog{ AssignTo: &dlg, Title: "应用内存设置", Font: Font{Family: "微软雅黑", PointSize: 9}, DefaultButton: &acceptPB, CancelButton: &cancelPB, DataBinder: DataBinder{ AssignTo: &db, Name: "setings", DataSource: seting, ErrorPresenter: ToolTipErrorPresenter{}, }, MinSize: Size{Width: 450, Height: 270}, Layout: VBox{}, Children: []Widget{ Composite{ Layout: Grid{Columns: 2}, Children: []Widget{ Label{Text: `  PermSize(非堆区)初始内存分配大小:`}, NumberEdit{Value: Bind("PermSize", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, Label{Text: `MaxPermSize(非堆区)最大内存分配上限:`}, NumberEdit{Value: Bind("MaxPermSize", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, Label{Text: `      Xms(堆区)初始内存分配大小:`}, NumberEdit{Value: Bind("Xms", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, Label{Text: `      Xmx(堆区)最大内存分配上限:`}, NumberEdit{Value: Bind("Xmx", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, }, }, Composite{ Layout: HBox{}, Children: []Widget{ HSpacer{}, PushButton{ AssignTo: &acceptPB, Text: "保存", OnClicked: func() { if err := db.Submit(); err != nil { showMsg("【异常】处理设置数据库内存时,发生异常!") log.Fatal(err) return } // 关闭页面 dlg.Cancel() // DB 回调函数 confirmCall(seting) }, }, PushButton{ AssignTo: &cancelPB, Text: "取消", OnClicked: func() { dlg.Cancel() }, }, }, }, }, }.Run(owner) } //数据还原设置 type DbBakSetings struct { fileEdit *walk.TextEdit fileName string } // 运行 数据还原设置 Dialog func (mw *myApp) RunDbBakSetingDialog(owner walk.Form, confirmCall func(*DbBakSetings)) { var seting *DbBakSetings var dlg *walk.Dialog var db *walk.DataBinder var acceptPB, cancelPB *walk.PushButton seting = new(DbBakSetings) seting.fileName = "" _, _ = Dialog{ AssignTo: &dlg, Title: "数据还原设置", Font: Font{Family: "微软雅黑", PointSize: 9}, DefaultButton: &acceptPB, CancelButton: &cancelPB, DataBinder: DataBinder{ AssignTo: &db, Name: "setings", DataSource: seting, ErrorPresenter: ToolTipErrorPresenter{}, }, MinSize: Size{Width: 450, Height: 220}, Layout: VBox{}, Children: []Widget{ GroupBox{ Layout: HBox{}, Children: []Widget{ Label{Text: `请输入还原文件名称(如:2022122235133):`}, TextEdit{AssignTo: &seting.fileEdit}, }, }, GroupBox{ Layout: HBox{}, Children: []Widget{ Label{Text: `说明: 1. 需要您选择还原的文件,并且在触发“恢复”时,先提示是否进行备份(选择是/否),按照选择文件进行解压覆盖; 2. 请自行检查备份包的大小是否正常,通常包大于400M; 3. 备份时,请确保服务正常启动!`}, }, }, Composite{ Layout: HBox{}, Children: []Widget{ HSpacer{}, PushButton{ AssignTo: &acceptPB, Text: "恢复", OnClicked: func() { if err := db.Submit(); err != nil { showMsg("【异常】选择恢复文件时,发生异常!") log.Fatal(err) return } Info.Println(path + `\` + seting.fileEdit.Text() + `.gz`) _, err := os.OpenFile(path+`\`+seting.fileEdit.Text()+`.gz`, os.O_RDWR, 0666) if err != nil { walk.MsgBox(app.mw, "错误", "无法打开文件。", walk.MsgBoxIconWarning) return } seting.fileName = seting.fileEdit.Text() // 关闭页面 dlg.Cancel() // DB 回调函数 confirmCall(seting) }, }, PushButton{ AssignTo: &cancelPB, Text: "取消", OnClicked: func() { dlg.Cancel() }, }, }, }, }, }.Run(owner) }