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

{

}

}

}

}

相关推荐
m0_6312704023 分钟前
标准C++(二)
开发语言·c++·算法
Zhen (Evan) Wang23 分钟前
What is the new in C#11?
开发语言·c#
0224号比邻星29 分钟前
[C语言]第十节 函数栈帧的创建和销毁一基础知识到高级技巧的全景探索
c语言·开发语言
martian6651 小时前
学懂C++(六十):C++ 11、C++ 14、C++ 17、C++ 20新特性大总结(万字详解大全)
开发语言·c++·c++20
zhangbin_2371 小时前
【Python机器学习】NLP信息提取——命名实体与关系
开发语言·人工智能·python·深度学习·机器学习·自然语言处理
Kerwin要坚持日更3 小时前
Java小白一文讲清Java中集合相关的知识点(九)
java·开发语言
IT规划师4 小时前
C#|.net core 基础 - 值传递 vs 引用传递
c#·.netcore·值传递·引用传递
WZF-Sang4 小时前
Linux权限理解【Shell的理解】【linux权限的概念、管理、切换】【粘滞位理解】
linux·运维·服务器·开发语言·学习
_Power_Y4 小时前
JavaSE:11、内部类
java·开发语言
你可以自己看5 小时前
python的基础语法
开发语言·python