diff --git a/TCSetup/TCSetup.vdproj b/TCSetup/TCSetup.vdproj index d23f4a5..91f4db3 100644 --- a/TCSetup/TCSetup.vdproj +++ b/TCSetup/TCSetup.vdproj @@ -146,7 +146,7 @@ } "{3C67513D-01DD-4637-8A68-80971EB9504F}:_57FF55C0487B4507A7ADC64F8E5966A5" { - "DefaultLocation" = "8:[ProgramFilesFolder][Manufacturer]\\[ProductName]" + "DefaultLocation" = "8:[ProgramFiles64Folder][Manufacturer]\\[ProductName]" "Name" = "8:#1925" "AlwaysCreate" = "11:FALSE" "Condition" = "8:" @@ -183,15 +183,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:TimeControl" - "ProductCode" = "8:{232A368F-8E6F-4FBB-B176-718FE5FE9F46}" - "PackageCode" = "8:{9FEA6838-90F7-4F96-9D10-00374CF5ABA5}" + "ProductCode" = "8:{BB3E5E5C-6F52-48B4-893C-57EB236F23D6}" + "PackageCode" = "8:{65B804AE-9561-4656-8793-2FB8B8BEBCDF}" "UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}" "AspNetVersion" = "8:4.0.30319.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:3.1.0" + "ProductVersion" = "8:3.1.1" "Manufacturer" = "8:SamHou" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" @@ -199,13 +199,13 @@ "Subject" = "8:" "ARPCONTACT" = "8:SamHou" "Keywords" = "8:" - "ARPCOMMENTS" = "8:" + "ARPCOMMENTS" = "8:TimeControl安装程序" "ARPURLINFOABOUT" = "8:" "ARPPRODUCTICON" = "8:" "ARPIconIndex" = "3:0" "SearchPath" = "8:" "UseSystemSearchPath" = "11:TRUE" - "TargetPlatform" = "3:0" + "TargetPlatform" = "3:1" "PreBuildEvent" = "8:" "PostBuildEvent" = "8:" "RunPostBuildEvent" = "3:0" @@ -797,7 +797,7 @@ { "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF" { - "SourcePath" = "8:..\\TimeControlConsole\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe" + "SourcePath" = "8:..\\TimeControlConsole\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" @@ -825,7 +825,7 @@ } "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7" { - "SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows\\apphost.exe" + "SourcePath" = "8:..\\TimeControl\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" diff --git a/TimeControl/App.cs b/TimeControl/App.cs index 4f79f1f..78d21be 100644 --- a/TimeControl/App.cs +++ b/TimeControl/App.cs @@ -6,14 +6,17 @@ namespace TimeControl { - internal class App + public class App { private string name; private string location; public string Name { get { return name; }} - private int time; - - public string ReportApp() + internal int time; + /// + /// 返回进程的简要概述 + /// + /// 进程的简要概述 + public override string ToString() { return Name + " 已使用 " + time+" 秒!"; } @@ -21,11 +24,21 @@ public App(string name, string location) { this.name = name; this.location = location; - time = 0; + Reset(); } - public void Run() + /// + /// 运行一次(一秒) + /// + public virtual void Run() { time++; } + /// + /// 重设时间 + /// + public void Reset() + { + time = 0; + } } } diff --git a/TimeControl/ControlPanel.Designer.cs b/TimeControl/ControlPanel.Designer.cs index ba58d0e..a9ee2b8 100644 --- a/TimeControl/ControlPanel.Designer.cs +++ b/TimeControl/ControlPanel.Designer.cs @@ -36,8 +36,8 @@ private void InitializeComponent() this.controlTab = new System.Windows.Forms.TabControl(); this.startNow = new System.Windows.Forms.TabPage(); this.processMonitor = new System.Windows.Forms.TabPage(); - this.processNameBox = new System.Windows.Forms.TextBox(); this.refreshButton = new System.Windows.Forms.Button(); + this.processNameBox = new System.Windows.Forms.TextBox(); this.removeButton = new System.Windows.Forms.Button(); this.appAddButton = new System.Windows.Forms.Button(); this.usageBox = new System.Windows.Forms.ListBox(); @@ -45,7 +45,7 @@ private void InitializeComponent() this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.label3 = new System.Windows.Forms.Label(); this.tabPage1 = new System.Windows.Forms.TabPage(); - this.unloackPassWordSetButton = new System.Windows.Forms.Button(); + this.unloackPasswordSetButton = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.unlockPasswordBox = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); @@ -53,6 +53,7 @@ private void InitializeComponent() this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.ExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.processMonitorTimer = new System.Windows.Forms.Timer(this.components); + this.autoRefreshBox = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.timeBox)).BeginInit(); this.controlTab.SuspendLayout(); this.startNow.SuspendLayout(); @@ -120,8 +121,9 @@ private void InitializeComponent() // // processMonitor // - this.processMonitor.Controls.Add(this.processNameBox); + this.processMonitor.Controls.Add(this.autoRefreshBox); this.processMonitor.Controls.Add(this.refreshButton); + this.processMonitor.Controls.Add(this.processNameBox); this.processMonitor.Controls.Add(this.removeButton); this.processMonitor.Controls.Add(this.appAddButton); this.processMonitor.Controls.Add(this.usageBox); @@ -133,23 +135,23 @@ private void InitializeComponent() this.processMonitor.Text = "进程计时"; this.processMonitor.UseVisualStyleBackColor = true; // - // processNameBox - // - this.processNameBox.Location = new System.Drawing.Point(528, 274); - this.processNameBox.Name = "processNameBox"; - this.processNameBox.Size = new System.Drawing.Size(143, 27); - this.processNameBox.TabIndex = 4; - // // refreshButton // - this.refreshButton.Location = new System.Drawing.Point(528, 205); + this.refreshButton.Location = new System.Drawing.Point(528, 156); this.refreshButton.Name = "refreshButton"; - this.refreshButton.Size = new System.Drawing.Size(143, 47); - this.refreshButton.TabIndex = 3; + this.refreshButton.Size = new System.Drawing.Size(143, 51); + this.refreshButton.TabIndex = 5; this.refreshButton.Text = "刷新"; this.refreshButton.UseVisualStyleBackColor = true; this.refreshButton.Click += new System.EventHandler(this.RefreshButton_Click); // + // processNameBox + // + this.processNameBox.Location = new System.Drawing.Point(528, 213); + this.processNameBox.Name = "processNameBox"; + this.processNameBox.Size = new System.Drawing.Size(143, 27); + this.processNameBox.TabIndex = 4; + // // removeButton // this.removeButton.Location = new System.Drawing.Point(528, 108); @@ -162,7 +164,7 @@ private void InitializeComponent() // // appAddButton // - this.appAddButton.Location = new System.Drawing.Point(528, 307); + this.appAddButton.Location = new System.Drawing.Point(528, 246); this.appAddButton.Name = "appAddButton"; this.appAddButton.Size = new System.Drawing.Size(143, 66); this.appAddButton.TabIndex = 1; @@ -213,7 +215,7 @@ private void InitializeComponent() // // tabPage1 // - this.tabPage1.Controls.Add(this.unloackPassWordSetButton); + this.tabPage1.Controls.Add(this.unloackPasswordSetButton); this.tabPage1.Controls.Add(this.label2); this.tabPage1.Controls.Add(this.unlockPasswordBox); this.tabPage1.Controls.Add(this.label1); @@ -225,15 +227,15 @@ private void InitializeComponent() this.tabPage1.Text = "程序保护"; this.tabPage1.UseVisualStyleBackColor = true; // - // unloackPassWordSetButton + // unloackPasswordSetButton // - this.unloackPassWordSetButton.Location = new System.Drawing.Point(6, 39); - this.unloackPassWordSetButton.Name = "unloackPassWordSetButton"; - this.unloackPassWordSetButton.Size = new System.Drawing.Size(120, 44); - this.unloackPassWordSetButton.TabIndex = 7; - this.unloackPassWordSetButton.Text = "设置"; - this.unloackPassWordSetButton.UseVisualStyleBackColor = true; - this.unloackPassWordSetButton.Click += new System.EventHandler(this.unloackPassWordSetButton_Click); + this.unloackPasswordSetButton.Location = new System.Drawing.Point(6, 39); + this.unloackPasswordSetButton.Name = "unloackPasswordSetButton"; + this.unloackPasswordSetButton.Size = new System.Drawing.Size(120, 44); + this.unloackPasswordSetButton.TabIndex = 7; + this.unloackPasswordSetButton.Text = "设置"; + this.unloackPasswordSetButton.UseVisualStyleBackColor = true; + this.unloackPasswordSetButton.Click += new System.EventHandler(this.UnloackPasswordSetButton_Click); // // label2 // @@ -290,6 +292,16 @@ private void InitializeComponent() this.processMonitorTimer.Interval = 1000; this.processMonitorTimer.Tick += new System.EventHandler(this.ProcessMonitorTimer_Tick); // + // autoRefreshBox + // + this.autoRefreshBox.AutoSize = true; + this.autoRefreshBox.Location = new System.Drawing.Point(557, 78); + this.autoRefreshBox.Name = "autoRefreshBox"; + this.autoRefreshBox.Size = new System.Drawing.Size(91, 24); + this.autoRefreshBox.TabIndex = 6; + this.autoRefreshBox.Text = "自动刷新"; + this.autoRefreshBox.UseVisualStyleBackColor = true; + // // ControlPanel // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); @@ -334,13 +346,14 @@ private void InitializeComponent() private System.Windows.Forms.ListBox usageBox; private System.Windows.Forms.Button appAddButton; private System.Windows.Forms.Button removeButton; - private System.Windows.Forms.Button refreshButton; private System.Windows.Forms.Timer processMonitorTimer; private System.Windows.Forms.TabPage tabPage1; - private System.Windows.Forms.Button unloackPassWordSetButton; + private System.Windows.Forms.Button unloackPasswordSetButton; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox unlockPasswordBox; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox processNameBox; + private System.Windows.Forms.Button refreshButton; + private System.Windows.Forms.CheckBox autoRefreshBox; } } \ No newline at end of file diff --git a/TimeControl/ControlPanel.cs b/TimeControl/ControlPanel.cs index eacfa0b..3ac9d65 100644 --- a/TimeControl/ControlPanel.cs +++ b/TimeControl/ControlPanel.cs @@ -18,8 +18,8 @@ public partial class ControlPanel : Form { private bool hide = false;//指示启动后是否需要隐藏 private bool isClosable = false;//指示当前是否可以关闭 - List appList = new();//所有监控软件列表 private int unlockPasswordHash = 0;//密码哈希值,用作比对 + private ListController controller;//列表、计时控制器 public ControlPanel(bool hide) { InitializeComponent(); @@ -27,7 +27,9 @@ public ControlPanel(bool hide) if (File.Exists(PasswordFile.tcPassLocation))//加载密码哈希值 { unlockPasswordHash = Convert.ToInt32(File.ReadAllText(PasswordFile.tcPassLocation)); + PasswordSet(); } + controller = new(usageBox, processMonitorTimer); } private void StartButton_Click(object sender, EventArgs e)//启动屏保程序 @@ -86,41 +88,38 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs private void AppAddButton_Click(object sender, EventArgs e)//添加打开的窗口 { - processMonitorTimer.Stop(); - Process[] processes=Process.GetProcessesByName(processNameBox.Text); - try + if (processNameBox.Text.ToLower() == "timecontrol" || + processNameBox.Text.ToLower() == "timecontrolconsole") { - foreach (Process process in processes) - { - appList.Add(new App(process.ProcessName, process.MainModule.FileName)); - } - } - catch (Exception ex) - { - MessageBox.Show("错误",ex.Message,MessageBoxButtons.OK,MessageBoxIcon.Error); + return; } - CalculateTime(); + TimeInput timeInput = new(controller, processNameBox.Text); + timeInput.ShowDialog(); } private void RemoveButton_Click(object sender, EventArgs e)//移除所有的已添加窗口 { - if (usageBox.SelectedIndex >=0) - appList.RemoveAt(usageBox.SelectedIndex); - CalculateTime(); + //检测密码设置 + if (unlockPasswordHash != 0) + { + PasswordInput passwordInput = new(unlockPasswordHash); + if (passwordInput.ShowDialog() == DialogResult.OK) + controller.Remove(); + } + else + controller.Remove(); } private void RefreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间 { - CalculateTime(); + controller.Refresh(); } private void ProcessMonitorTimer_Tick(object sender, EventArgs e) { - foreach (App app in appList)//计算进程时间 - { - if (Process.GetProcessesByName(app.Name).Length != 0) - { app.Run(); } - } + controller.Run(); + if (autoRefreshBox.Checked) + controller.Refresh(); if (Process.GetProcessesByName("TimeControlConsole").Length == 0)//检查保护程序状态 { ProcessStartInfo process = new(); @@ -128,12 +127,6 @@ private void ProcessMonitorTimer_Tick(object sender, EventArgs e) Process.Start(process); } } - private void CalculateTime()//将进程时间推送到ListBox控件 - { - processMonitorTimer.Stop(); - ListBoxController.Refresh(usageBox, appList); - processMonitorTimer.Start(); - } private void ForceClose()//可以正常关闭 { isClosable = true; @@ -148,13 +141,17 @@ private void ControlPanel_Shown(object sender, EventArgs e)//启动隐藏参数 processMonitorTimer.Start(); } - private void unloackPassWordSetButton_Click(object sender, EventArgs e)//保存密码 + private void UnloackPasswordSetButton_Click(object sender, EventArgs e)//保存密码 { unlockPasswordHash = unlockPasswordBox.Text.GetHashCode();//保存哈希值 + PasswordSet(); + File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件 + } + private void PasswordSet()//密码设置后调用 + { unlockPasswordBox.Text = ""; unlockPasswordBox.Enabled = false; - unloackPassWordSetButton.Enabled = false; - File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件 + unloackPasswordSetButton.Enabled = false; } } } diff --git a/TimeControl/LimitWarningWindow.Designer.cs b/TimeControl/LimitWarningWindow.Designer.cs new file mode 100644 index 0000000..5c0be9f --- /dev/null +++ b/TimeControl/LimitWarningWindow.Designer.cs @@ -0,0 +1,74 @@ +namespace TimeControl +{ + partial class LimitWarningWindow + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.displayLabel = new System.Windows.Forms.Label(); + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.closeButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // displayLabel + // + this.displayLabel.Location = new System.Drawing.Point(12, 9); + this.displayLabel.Name = "displayLabel"; + this.displayLabel.Size = new System.Drawing.Size(523, 89); + this.displayLabel.TabIndex = 0; + this.displayLabel.Text = "应用 即将达到时间限制,请保存所有工作,然后提前关闭进程"; + // + // closeButton + // + this.closeButton.Location = new System.Drawing.Point(109, 126); + this.closeButton.Name = "closeButton"; + this.closeButton.Size = new System.Drawing.Size(305, 68); + this.closeButton.TabIndex = 1; + this.closeButton.Text = "立即强制关闭(请确保已保存任何文件)"; + this.closeButton.UseVisualStyleBackColor = true; + this.closeButton.Click += new System.EventHandler(this.closeButton_Click); + // + // LimitWarningWindow + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(547, 224); + this.Controls.Add(this.closeButton); + this.Controls.Add(this.displayLabel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "LimitWarningWindow"; + this.Text = "应用即将达到时间限制"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label displayLabel; + private System.ComponentModel.BackgroundWorker backgroundWorker1; + private System.Windows.Forms.Button closeButton; + } +} \ No newline at end of file diff --git a/TimeControl/LimitWarningWindow.cs b/TimeControl/LimitWarningWindow.cs new file mode 100644 index 0000000..f83a31d --- /dev/null +++ b/TimeControl/LimitWarningWindow.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TimeControl +{ + public partial class LimitWarningWindow : Form + { + LimitedApp warningApp; + public LimitWarningWindow(LimitedApp warningApp) + { + InitializeComponent(); + displayLabel.Text = $"应用{warningApp.Name}即将达到时间限制,请保存所有工作,然后提前关闭进程"; + this.warningApp = warningApp; + } + + private void closeButton_Click(object sender, EventArgs e) + { + warningApp.Ban();//禁用掉app + Close(); + } + } +} diff --git a/TimeControl/LimitWarningWindow.resx b/TimeControl/LimitWarningWindow.resx new file mode 100644 index 0000000..8453790 --- /dev/null +++ b/TimeControl/LimitWarningWindow.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/TimeControl/LimitedApp.cs b/TimeControl/LimitedApp.cs new file mode 100644 index 0000000..dcb72e3 --- /dev/null +++ b/TimeControl/LimitedApp.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Diagnostics; +using System.Windows.Forms; + +namespace TimeControl +{ + public class LimitedApp : App + { + private int timeLimit; + public LimitedApp(string name, string location,int timeLimit) : base(name, location) + { + this.timeLimit = timeLimit; + } + /// + /// 运行一次(一秒),并根据情况显示警告或关闭进程 + /// + public override void Run() + { + base.Run(); + if (time == timeLimit - 30) + { + LimitWarningWindow warningWindow = new(this); + warningWindow.Show(); + } + if (time>=timeLimit) + { + Ban(); + } + } + /// + /// 返回时间受限进程的简要概述 + /// + /// 时间受限进程的简要概述 + public override string ToString() + { + return base.ToString() + "进程时间限制为:" + timeLimit + "秒"; + } + /// + /// 禁用掉该程序 + /// + public void Ban() + { + Process[] processes = Process.GetProcessesByName(Name); + foreach (Process process in processes) + { + process.Kill(); + } + time = timeLimit; + } + } +} diff --git a/TimeControl/ListBoxController.cs b/TimeControl/ListBoxController.cs deleted file mode 100644 index 1d5f32f..0000000 --- a/TimeControl/ListBoxController.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace TimeControl -{ - static internal class ListBoxController - { - public static void Refresh(ListBox listBox,List apps) - { - listBox.Items.Clear(); - foreach (App app in apps) - { - listBox.Items.Add(app.ReportApp()); - } - } - } -} diff --git a/TimeControl/ListController.cs b/TimeControl/ListController.cs new file mode 100644 index 0000000..a8fea5a --- /dev/null +++ b/TimeControl/ListController.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TimeControl +{ + public class ListController + { + private ListBox listBox; + private List apps; + private Timer timer; + + public ListController(ListBox listBox,Timer timer) + { + this.listBox = listBox; + apps = new List(); + this.timer = timer; + } + + /// + /// 刷新列表显示 + /// + public void Refresh() + { + timer.Stop(); + listBox.Items.Clear(); + foreach (App app in apps) + { + listBox.Items.Add(app.ToString()); + } + timer.Start(); + } + /// + /// 根据名称添加进程 + /// + /// 要添加的进程名称 + public void AddByName(string name) + { + timer.Stop(); + Process[] processes = Process.GetProcessesByName(name); + try + { + foreach (Process process in processes) + { + apps.Add(new App(process.ProcessName, process.MainModule.FileName)); + } + } + catch (Exception ex) + { + MessageBox.Show("错误", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + this.Refresh(); + } + /// + /// 根据名称添加时间受限的进程 + /// + /// 进程名称 + /// 限制时长(秒) + public void AddByName(string name,int limitTime) + { + timer.Stop(); + Process[] processes = Process.GetProcessesByName(name); + try + { + foreach (Process process in processes) + { + apps.Add(new LimitedApp(process.ProcessName, process.MainModule.FileName,limitTime)); + } + } + catch (Exception ex) + { + MessageBox.Show("错误", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + this.Refresh(); + } + /// + /// 跟踪所有进程,增加一秒 + /// + public void Run() + { + foreach (App app in apps)//计算进程时间 + { + if (Process.GetProcessesByName(app.Name).Length != 0) + { + if (app is LimitedApp) + { + LimitedApp limitedApp=app as LimitedApp; + limitedApp.Run(); + } + else + app.Run(); + } + } + } + /// + /// 移除所列表所选的进程 + /// + public void Remove() + { + timer.Stop(); + if (listBox.SelectedIndex >= 0) + apps.RemoveAt(listBox.SelectedIndex); + Refresh(); + } + } +} diff --git a/TimeControl/TimeControl.csproj b/TimeControl/TimeControl.csproj index 0451842..7f10d86 100644 --- a/TimeControl/TimeControl.csproj +++ b/TimeControl/TimeControl.csproj @@ -2,21 +2,31 @@ WinExe - net6.0-windows + net6.0-windows10.0.22000.0 true SamHou - 3.1.0 + 3.1.1 TimeControl.Program False icons8_sand_watch.ico AnyCPU + 7.0 + AnyCPU;x64;x86 Auto + + Auto + + + + Auto + + diff --git a/TimeControl/TimeInput.Designer.cs b/TimeControl/TimeInput.Designer.cs new file mode 100644 index 0000000..b064ead --- /dev/null +++ b/TimeControl/TimeInput.Designer.cs @@ -0,0 +1,91 @@ +namespace TimeControl +{ + partial class TimeInput + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.okButton = new System.Windows.Forms.Button(); + this.timeBox = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.timeBox)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(68, 35); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(288, 20); + this.label1.TabIndex = 0; + this.label1.Text = "输入进程限时,0则表示不限制时间(秒)"; + // + // okButton + // + this.okButton.Location = new System.Drawing.Point(139, 140); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(110, 53); + this.okButton.TabIndex = 1; + this.okButton.Text = "确定"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // timeBox + // + this.timeBox.Location = new System.Drawing.Point(120, 87); + this.timeBox.Maximum = new decimal(new int[] { + 200000, + 0, + 0, + 0}); + this.timeBox.Name = "timeBox"; + this.timeBox.Size = new System.Drawing.Size(150, 27); + this.timeBox.TabIndex = 2; + // + // TimeInput + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 218); + this.Controls.Add(this.timeBox); + this.Controls.Add(this.okButton); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "TimeInput"; + this.Text = "TimeInput"; + ((System.ComponentModel.ISupportInitialize)(this.timeBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.NumericUpDown timeBox; + } +} \ No newline at end of file diff --git a/TimeControl/TimeInput.cs b/TimeControl/TimeInput.cs new file mode 100644 index 0000000..1f208d5 --- /dev/null +++ b/TimeControl/TimeInput.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TimeControl +{ + public partial class TimeInput : Form + { + private ListController listController; + private string appName; + public TimeInput(ListController listController,string appName) + { + InitializeComponent(); + this.listController = listController; + this.appName = appName; + } + + private void okButton_Click(object sender, EventArgs e) + { + if (timeBox.Value==0) + { + listController.AddByName(appName); + } + else + { + listController.AddByName(appName,Convert.ToInt32( timeBox.Value)); + } + Close(); + } + } +} diff --git a/TimeControl/TimeInput.resx b/TimeControl/TimeInput.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/TimeControl/TimeInput.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TimeControlConsole/TimeControlConsole.csproj b/TimeControlConsole/TimeControlConsole.csproj index 7899140..8f34354 100644 --- a/TimeControlConsole/TimeControlConsole.csproj +++ b/TimeControlConsole/TimeControlConsole.csproj @@ -8,6 +8,7 @@ 7.0 ..\TimeControl\bin AnyCPU + AnyCPU;x64;x86 diff --git "a/\346\227\266\346\216\247.sln" "b/\346\227\266\346\216\247.sln" index 6b6c025..13f60f5 100644 --- "a/\346\227\266\346\216\247.sln" +++ "b/\346\227\266\346\216\247.sln" @@ -7,37 +7,50 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimeControl", "TimeControl\ EndProject Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "TCSetup", "TCSetup\TCSetup.vdproj", "{36173DC9-6785-40FF-A995-0E2A85487285}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeControlConsole", "TimeControlConsole\TimeControlConsole.csproj", "{3F10963C-5471-4A63-9BA2-8D422B121006}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimeControlConsole", "TimeControlConsole\TimeControlConsole.csproj", "{3F10963C-5471-4A63-9BA2-8D422B121006}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|x64.ActiveCfg = Debug|Any CPU {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|x86.ActiveCfg = Debug|Any CPU {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|x86.Build.0 = Debug|Any CPU {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|Any CPU.ActiveCfg = Release|Any CPU {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|Any CPU.Build.0 = Release|Any CPU - {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.ActiveCfg = Release|Any CPU - {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.Build.0 = Release|Any CPU + {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x64.ActiveCfg = Release|x64 + {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x64.Build.0 = Release|x64 + {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.ActiveCfg = Release|x86 + {DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.Build.0 = Release|x86 {36173DC9-6785-40FF-A995-0E2A85487285}.Debug|Any CPU.ActiveCfg = Debug + {36173DC9-6785-40FF-A995-0E2A85487285}.Debug|x64.ActiveCfg = Debug + {36173DC9-6785-40FF-A995-0E2A85487285}.Debug|x64.Build.0 = Debug {36173DC9-6785-40FF-A995-0E2A85487285}.Debug|x86.ActiveCfg = Debug {36173DC9-6785-40FF-A995-0E2A85487285}.Release|Any CPU.ActiveCfg = Release {36173DC9-6785-40FF-A995-0E2A85487285}.Release|Any CPU.Build.0 = Release + {36173DC9-6785-40FF-A995-0E2A85487285}.Release|x64.ActiveCfg = Release + {36173DC9-6785-40FF-A995-0E2A85487285}.Release|x64.Build.0 = Release {36173DC9-6785-40FF-A995-0E2A85487285}.Release|x86.ActiveCfg = Release {3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x64.ActiveCfg = Debug|x64 + {3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x64.Build.0 = Debug|x64 {3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x86.ActiveCfg = Debug|Any CPU {3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x86.Build.0 = Debug|Any CPU {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|Any CPU.ActiveCfg = Release|Any CPU {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|Any CPU.Build.0 = Release|Any CPU - {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.ActiveCfg = Release|Any CPU - {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.Build.0 = Release|Any CPU + {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x64.ActiveCfg = Release|x64 + {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x64.Build.0 = Release|x64 + {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.ActiveCfg = Release|x86 + {3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE