c# mainwindows

using HZH_Controls.Forms;

using Microsoft.Win32;

using NPOI.SS.UserModel;

using Serilog;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Deployment.Application;

using System.Diagnostics;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace MIAS_DigitalTool_Platform

{

public partial class MainWindow : Form

{

//MainWindow frm = new MainWindow();

public MainWindow()

{

InitializeComponent();

指定前景色,这里使用蓝色作为示例

//System.Drawing.Color foreColor = System.Drawing.Color.White;

// 指定背景色,这里使用透明色作为示例

//System.Drawing.Color backColor = System.Drawing.Color.Transparent;

//this.menu1ToolStripMenuItem.Image = HZH_Controls.FontImages.GetImage(HZH_Controls.FontIcons.A_fa_eye, 32, foreColor, backColor);

//this.submenu1ToolStripMenuItem.Image = HZH_Controls.FontImages.GetImage(HZH_Controls.FontIcons.A_fa_eye, 32, foreColor, backColor);

this.menuStrip1.BackColor = Color.FromArgb(255, 84, 92, 100);

this.menuStrip1.ForeColor = Color.White;

string fullPath = Path.Combine(Application.StartupPath, StaticClass.global.leftcornerPic);

this.Icon = new Icon(fullPath);

this.Text = StaticClass.global.resourceManager.GetString("title");

this.menu1ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1");

this.versionToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("versionmanage");

this.helpToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("help");

this.submenu1ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1_sub1");

this.label_rights.Text = StaticClass.global.resourceManager.GetString("rights");

this.label_user.Text = StaticClass.global.account;

this.label_authority.Text = StaticClass.global.authority;

this.label_version.Text = StaticClass.global.globalVersion;

this.engineer1_1ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1_sub1_sub1");

this.database1_2ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1_sub1_sub2");

this.helpdocToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("helpdoc");

this.suggestToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("userfeedback");

this.fullfillToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("userfullfill");

this.submenu2ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1_sub2");

this.sub21ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1_sub2_sub1");

this.sub22ToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("menu1_sub2_sub2");

this.versionLogToolStripMenuItem.Text = StaticClass.global.resourceManager.GetString("versionmanage_sub1");

//权限管理

if (StaticClass.global.authority == "1")

{

this.menu1ToolStripMenuItem.Enabled = true;

this.database1_2ToolStripMenuItem.Enabled = false;

this.suggestToolStripMenuItem.Enabled = true;

this.helpToolStripMenuItem.Enabled = true;

this.sub21ToolStripMenuItem.Enabled=true;

this.versionToolStripMenuItem.Enabled=true;

this.versionLogToolStripMenuItem.Enabled = true;

this.portalIntegrateToolStripMenuItem.Enabled = true;

this.portalToolStripMenuItem.Enabled = true;

this.parametersDevToolStripMenuItem.Enabled = true;

this.zwcadsecToolStripMenuItem.Enabled = true;

this.cadfolderreadToolStripMenuItem.Enabled = true;

this.knowledgeToolStripMenuItem.Enabled = true;

}

else if(StaticClass.global.authority == "2")

{

this.menu1ToolStripMenuItem.Enabled = true;

this.database1_2ToolStripMenuItem.Enabled = false;

this.suggestToolStripMenuItem.Enabled = true;

this.database1_2ToolStripMenuItem.Enabled=true;

this.helpToolStripMenuItem.Enabled = true;

this.sub21ToolStripMenuItem.Enabled = true;

this.sub22ToolStripMenuItem.Enabled = true;

this.versionToolStripMenuItem.Enabled = true;

this.versionLogToolStripMenuItem.Enabled = true;

this.portalIntegrateToolStripMenuItem.Enabled = true;

this.portalToolStripMenuItem.Enabled = true;

this.knowledgeToolStripMenuItem.Enabled = true;

this.parametersDevToolStripMenuItem.Enabled = true;

this.zwcadsecToolStripMenuItem.Enabled = true;

this.cadfolderreadToolStripMenuItem.Enabled = true;

}

else if (StaticClass.global.authority == "3")

{

this.menu1ToolStripMenuItem.Enabled = true;

this.database1_2ToolStripMenuItem.Enabled = false;

this.suggestToolStripMenuItem.Enabled = true;

this.database1_2ToolStripMenuItem.Enabled = true;

this.helpToolStripMenuItem.Enabled = true;

this.sub21ToolStripMenuItem.Enabled = true;

this.sub22ToolStripMenuItem.Enabled = true;

this.versionToolStripMenuItem.Enabled = true;

this.versionLogToolStripMenuItem.Enabled = true;

this.portalIntegrateToolStripMenuItem.Enabled = true;

this.portalToolStripMenuItem.Enabled = true;

this.parametersDevToolStripMenuItem.Enabled = true;

this.knowledgeToolStripMenuItem.Enabled = true;

this.zwcadsecToolStripMenuItem.Enabled = true;

this.cadfolderreadToolStripMenuItem.Enabled = true;

}

}

private void submenu1ToolStripMenuItem_Click(object sender, EventArgs e)

{

}

//private void btForm1_Click(object sender, EventArgs e)

//{

// OpenForm(typeof(Forms.SelfCheckTool.LengthCal));

//}

private void OpenForm(Type t)

{

foreach (var c in panel1.Controls)

{

if (c is Form form)

{

form.Close();

form.Dispose();

}

}

Form f = (Form)Activator.CreateInstance(t);

f.FormBorderStyle = FormBorderStyle.None;

f.TopLevel = false;

f.Parent = panel1;

//f.WindowState = FormWindowState.Maximized;

f.Dock = DockStyle.Fill;

f.Show();

// 主窗体大小改变时,子窗体会自动调整大小

// 如果需要在主窗体大小改变时执行其他操作,可以添加如下事件处理器

//this.Resize += (sender, e) => {

// // 主窗体大小改变时的逻辑

//};

GC.Collect();

}

//private void submenu1ToolStripMenuItem_Click_1(object sender, EventArgs e)

//{

// OpenForm(typeof(Forms.SelfCheckTool.LengthCal));

//}

private void menu1ToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void engineer1_1ToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.SelfCheckTool.BOM.EngineerInspect));

}

private void database1_2ToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.SelfCheckTool.BOM.Database));

}

private void helpdocToolStripMenuItem_Click(object sender, EventArgs e)

{

// 共享盘上的 Word 文档路径

string documentPath = @"\\SRV-CNACDATA\internal_software\Documents\MIAS_Toolkit_Instruction.docx";

// 确保路径是可访问的

if (!File.Exists(documentPath))

{

MessageBox.Show("The document does not exist.");

return;

}

// 使用 Word 打开文档

try

{

// 启动 Word 应用程序并打开文档

Process.Start("WINWORD.EXE", documentPath);

}

catch (Exception ex)

{

Log.Information(ex.Message);

// 处理异常,例如 Word 未安装

MessageBox.Show("An error occurred: " + ex.Message);

}

}

private void timer1_Tick(object sender, EventArgs e)

{

// 调用ExecuteScalar方法的示例

string queryString = "select version from dbo.1version where ID = 1"; // 这里是一个没有参数的SQL查询

object result = SqlhelperClass.sqlHelper.ExecuteScalar(queryString, CommandType.Text);

try

{

// 尝试连接到SQL Server并执行操作

// 检查result是否为null(如果查询没有返回任何行)

if (result != null)

{

// 将结果转换为期望的类型,例如int、decimal等

string count = result.ToString().Trim();

if (count != this.label_version.Text)

{

this.label_versionalarm.Text = StaticClass.global.resourceManager.GetString("versionalarm");

this.label_versionalarm.Visible = true;

this.label_versionalarm.ForeColor = Color.Red;

FrmTips.ShowTips(this, StaticClass.global.resourceManager.GetString("versionalarm"), 10000, true, ContentAlignment.MiddleCenter, null, TipsSizeMode.Medium, new Size(300, 50), TipsState.Warning);

}

else

{

this.label_versionalarm.Visible = false;

}

}

else

{

}

}

catch (SqlException ex)

{

Log.Information(ex.Message);

// 检查SqlException的Number属性以获取错误代码

Console.WriteLine("SQL Error: " + ex.Number + " - " + ex.Message);

this.label_versionalarm.Text = "Network SQL Error:" + ex.Number + "-" + ex.Message;

// 可以根据错误代码采取特定的恢复措施

}

catch (Exception ex)

{

Log.Information(ex.Message);

// 处理其他类型的异常

Console.WriteLine("General Error: " + ex.Message);

this.label_versionalarm.Text = "General Error:" + ex.Message;

}

}

private void fullfillToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.Feedback.Feedback));

}

private void sub21ToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.SelfCheckTool.Flychain.Flychaincal));

}

private void versionLogToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.VersionLog.VersionTimeLine));

}

private void portalToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.Portal.Portal));

}

private void 参数化设计开发ToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void sW二开ToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void pDM二开ToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.Secdev.PDMdev));

}

private void testbuttonToolStripMenuItem_Click(object sender, EventArgs e)

{

模拟按下Ctrl+Q

//SendKeys.Send("^q");

等待一段时间,以便按键被处理

//System.Threading.Thread.Sleep(1000);

//MessageBox.Show("Q");

}

private void zWCAD二开ToolStripMenuItem_Click(object sender, EventArgs e)

{

//OpenForm(typeof(Forms.Secdev.ZWCAD));

}

private void cadfolderreadToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.Secdev.ZWCADData));

}

private void singlecadToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.Secdev.ZWCAD));

}

private void questionSubmitToolStripMenuItem_Click(object sender, EventArgs e)

{

OpenForm(typeof(Forms.Knowledge.knowledgeShare));

}

private void swtableDataToolStripMenuItem_Click(object sender, EventArgs e)

{

try

{

using (Forms.Secdev.SWdev childForm = new Forms.Secdev.SWdev())

{

childForm.ShowDialog();

}

}

catch (Exception ex)

{

Serilog.Log.Information(ex.Message);

}

finally

{

}

}

}

}

相关推荐
朝朝辞暮i3 小时前
C++ 第 23 课:class —— 开始真正进入面向对象
开发语言·c++·算法
小师兄吃牛肉4 小时前
C语言篇:宏
c语言·开发语言
郑同学的笔记4 小时前
【c++随笔28】strcmp 和 memcmp对比
开发语言·c++
未来之窗软件服务5 小时前
C# 截图源码支持自动保存-东方仙盟
c#·仙盟创梦ide·东方仙盟·电脑工具
言乐65 小时前
Python根据无法识别搜索词找出可能输入内容模型
开发语言·python·django·virtualenv·pygame
weixin_307779135 小时前
有限产能智能排产与动态重排智能体:从需求解构到技术实现
开发语言·人工智能·算法·架构
kakakahahahaha5 小时前
Windows C盘临时文件清理:%temp%、Windows Temp、Prefetch、Windows.old与hiberfil.sys处理指南
c语言·开发语言·windows
朝朝辞暮i5 小时前
C++ 第 27 课:智能指针 shared_ptr
开发语言·c++·算法
朝朝辞暮i6 小时前
C++ 第 29 课:回调函数 Callback
开发语言·c++·算法
笨笨饿6 小时前
140_AI新手村MCP与Skills是干嘛的
开发语言·人工智能·python·stm32·单片机·嵌入式硬件·物联网