
武魂分为两大类,一
类是器武魂,一类是兽
武魂。顾名思义,以器具
为武魂者,就是器武魂,
以动物为武魂
者,就是
兽武魂。
相对来说,器
武魂包含范围更
大,大多数人也都是
器武魂,而器武魂中
无法修炼的武魂也要比兽武魂的比例更大。
1.先说跳转到网页,c#中是如何实现的。写一句代码就可以了:
system.diagnostics.process.start(yoururladdrstr)
如果指定使用ie打开的话,可以写成:
system.diagnostics.process.start("iexplore.exe",
yoururladdrstr)
所以,明白了这个,就是在你的菜单栏对应的选项中的click事件中,添加上面的代码,即可。
其中yoururladdrstr设置你自己所需的url地址;
详情和原理,可以参考我的帖子:
【已解决】c#中调用资源管理器(explorer.exe)打开指定文件夹
+
并选中指定文件
+
调用(系统默认的播放类)软件(如wmp)打开(播放歌曲等)文件
(这里不给贴地址,所以请自己用google搜标题,即可找到帖子地址)
题目中说明中的第一步:偶数*2,奇数*1 但是示例中的员工等级是偶数单乘的是1,我的代码中员工等级的处理方式和员工号一致,如果需要调整,在Calc(string xx)方法中注释的else位置修改。
图片中是窗口截图。代码如下:
namespace Calc
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose()
}
base.Dispose(disposing)
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtNumber = new System.Windows.Forms.TextBox()
this.txtPwd = new System.Windows.Forms.TextBox()
this.txtLevel = new System.Windows.Forms.TextBox()
this.txtValCode = new System.Windows.Forms.TextBox()
this.label1 = new System.Windows.Forms.Label()
this.label2 = new System.Windows.Forms.Label()
this.label3 = new System.Windows.Forms.Label()
this.label4 = new System.Windows.Forms.Label()
this.label5 = new System.Windows.Forms.Label()
this.txtInput = new System.Windows.Forms.TextBox()
this.SuspendLayout()
//
// txtNumber
//
this.txtNumber.Location = new System.Drawing.Point(102, 68)
this.txtNumber.Name = "txtNumber"
this.txtNumber.ReadOnly = true
this.txtNumber.Size = new System.Drawing.Size(126, 21)
this.txtNumber.TabIndex = 0
//
// txtPwd
//
this.txtPwd.Location = new System.Drawing.Point(102, 105)
this.txtPwd.Name = "txtPwd"
this.txtPwd.PasswordChar = '*'
this.txtPwd.ReadOnly = true
this.txtPwd.Size = new System.Drawing.Size(126, 21)
this.txtPwd.TabIndex = 0
//
// txtLevel
//
this.txtLevel.Location = new System.Drawing.Point(102, 136)
this.txtLevel.Name = "txtLevel"
this.txtLevel.ReadOnly = true
this.txtLevel.Size = new System.Drawing.Size(126, 21)
this.txtLevel.TabIndex = 0
//
// txtValCode
//
this.txtValCode.Location = new System.Drawing.Point(102, 173)
this.txtValCode.Name = "txtValCode"
this.txtValCode.ReadOnly = true
this.txtValCode.Size = new System.Drawing.Size(126, 21)
this.txtValCode.TabIndex = 0
//
// label1
//
this.label1.AutoSize = true
this.label1.Location = new System.Drawing.Point(55, 71)
this.label1.Name = "label1"
this.label1.Size = new System.Drawing.Size(29, 12)
this.label1.TabIndex = 4
this.label1.Text = "工号"
//
// label2
//
this.label2.AutoSize = true
this.label2.Location = new System.Drawing.Point(55, 108)
this.label2.Name = "label2"
this.label2.Size = new System.Drawing.Size(29, 12)
this.label2.TabIndex = 5
this.label2.Text = "密码"
//
// label3
//
this.label3.AutoSize = true
this.label3.Location = new System.Drawing.Point(55, 139)
this.label3.Name = "label3"
this.label3.Size = new System.Drawing.Size(29, 12)
this.label3.TabIndex = 6
this.label3.Text = "级别"
//
// label4
//
this.label4.AutoSize = true
this.label4.Location = new System.Drawing.Point(55, 176)
this.label4.Name = "label4"
this.label4.Size = new System.Drawing.Size(41, 12)
this.label4.TabIndex = 7
this.label4.Text = "验证码"
//
// label5
//
this.label5.AutoSize = true
this.label5.Location = new System.Drawing.Point(55, 31)
this.label5.Name = "label5"
this.label5.Size = new System.Drawing.Size(29, 12)
this.label5.TabIndex = 8
this.label5.Text = "工号"
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(102, 28)
this.txtInput.Name = "txtInput"
this.txtInput.Size = new System.Drawing.Size(126, 21)
this.txtInput.TabIndex = 1
this.txtInput.Leave += new System.EventHandler(this.txtInput_Leave)
this.txtInput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtInput_KeyPress)
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F)
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
this.ClientSize = new System.Drawing.Size(263, 241)
this.Controls.Add(this.txtInput)
this.Controls.Add(this.label5)
this.Controls.Add(this.label4)
this.Controls.Add(this.label3)
this.Controls.Add(this.label2)
this.Controls.Add(this.label1)
this.Controls.Add(this.txtValCode)
this.Controls.Add(this.txtLevel)
this.Controls.Add(this.txtPwd)
this.Controls.Add(this.txtNumber)
this.Name = "Form1"
this.Text = "Form1"
this.ResumeLayout(false)
this.PerformLayout()
}
#endregion
private System.Windows.Forms.TextBox txtNumber
private System.Windows.Forms.TextBox txtPwd
private System.Windows.Forms.TextBox txtValCode
private System.Windows.Forms.Label label1
private System.Windows.Forms.Label label2
private System.Windows.Forms.Label label3
private System.Windows.Forms.Label label4
private System.Windows.Forms.TextBox txtLevel
private System.Windows.Forms.Label label5
private System.Windows.Forms.TextBox txtInput
}
}
using System
using System.Collections.Generic
using System.ComponentModel
using System.Data
using System.Drawing
using System.Linq
using System.Text
using System.Windows.Forms
namespace Calc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
txtInput.Focus()
}
private void txtInput_Leave(object sender, EventArgs e)
{
string content = txtInput.Text.Trim()
Calc(content)
}
private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
{
int charInt = (int)e.KeyChar
if (charInt == 8 || charInt ==13)
{
string content = txtInput.Text.Trim()
Calc(content)
}
}
private void Calc(string content)
{
if (string.IsNullOrEmpty(content))
{
MessageBox.Show("请输入工号。")
txtInput.SelectAll()
return
}
if (content.Length < 11)
{
MessageBox.Show("输入的工号格式不正确。")
txtInput.SelectAll()
return
}
string number = content.Substring(0, 6)
string pwd = content.Substring(7, 4)
string level = content[10].ToString()
txtNumber.Text = number
txtPwd.Text = pwd
txtLevel.Text = level
//计算验证码
char[] numberChar = number.ToCharArray()
int result = 0
for (int i = 0 i < numberChar.Length + 1 i++)
{
if (i < numberChar.Length)
{
int calcNumber = int.Parse(numberChar[i] + "")
int element = (calcNumber) % 2 == 0 ? calcNumber * 2 : calcNumber
if (element > 10)
element = int.Parse(element.ToString()[1] + "") + 1
result += element
}
else //级别校验,级别值为1 2 3 4 9按照规则计算结果不会超过10
{
int levelInt = int.Parse(level)
result += levelInt % 2 == 0 ? levelInt * 2 : levelInt
}
}
result = CalcUntilSingleNumber(result)
txtValCode.Text = result + ""
}
private int CalcUntilSingleNumber(int number)
{
int result = 0
string resultString = number.ToString()
if (resultString.Length > 1)
{
char[] stringChar = resultString.ToCharArray()
foreach (char item in stringChar)
{
result += int.Parse(item + "")
}
if (result >= 10)
result = CalcUntilSingleNumber(result)
}
else
{
result = number
}
return result
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)