📄 wagesrecord.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace PM
{
/// <summary>
/// WagesRecord 的摘要说明。
/// </summary>
public class WagesRecord : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox No_cb;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox Name_txt;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox WagesId_txt;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.DateTimePicker Time_dtp;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private DataTable dt = new DataTable();
private System.Windows.Forms.TextBox Exp1_txt;
private System.Windows.Forms.TextBox Exp2_txt;
private System.Windows.Forms.TextBox Exp3_txt;
private System.Windows.Forms.TextBox Exp4_txt;
private System.Windows.Forms.TextBox Exp5_txt;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox Exp_txt;
private string ID = string.Empty;
public WagesRecord()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WagesRecord));
this.label1 = new System.Windows.Forms.Label();
this.No_cb = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.Name_txt = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.WagesId_txt = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.Time_dtp = new System.Windows.Forms.DateTimePicker();
this.label5 = new System.Windows.Forms.Label();
this.Exp1_txt = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.Exp2_txt = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.Exp3_txt = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.Exp4_txt = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.Exp5_txt = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label10 = new System.Windows.Forms.Label();
this.Exp_txt = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 0;
this.label1.Text = "员工编号";
//
// No_cb
//
this.No_cb.Location = new System.Drawing.Point(72, 8);
this.No_cb.Name = "No_cb";
this.No_cb.Size = new System.Drawing.Size(100, 20);
this.No_cb.TabIndex = 1;
this.No_cb.SelectedIndexChanged += new System.EventHandler(this.No_cb_SelectedIndexChanged);
//
// label2
//
this.label2.Location = new System.Drawing.Point(200, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 2;
this.label2.Text = "员工姓名";
//
// Name_txt
//
this.Name_txt.Location = new System.Drawing.Point(256, 8);
this.Name_txt.Name = "Name_txt";
this.Name_txt.TabIndex = 3;
this.Name_txt.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 56);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 16);
this.label3.TabIndex = 4;
this.label3.Text = "工资号";
//
// WagesId_txt
//
this.WagesId_txt.Location = new System.Drawing.Point(72, 48);
this.WagesId_txt.Name = "WagesId_txt";
this.WagesId_txt.TabIndex = 5;
this.WagesId_txt.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(200, 56);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 16);
this.label4.TabIndex = 6;
this.label4.Text = "发放时间";
//
// Time_dtp
//
this.Time_dtp.Format = System.Windows.Forms.DateTimePickerFormat.Short;
this.Time_dtp.Location = new System.Drawing.Point(256, 48);
this.Time_dtp.Name = "Time_dtp";
this.Time_dtp.Size = new System.Drawing.Size(100, 21);
this.Time_dtp.TabIndex = 7;
//
// label5
//
this.label5.Location = new System.Drawing.Point(200, 96);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 16);
this.label5.TabIndex = 8;
this.label5.Text = "水电费";
//
// Exp1_txt
//
this.Exp1_txt.Location = new System.Drawing.Point(256, 88);
this.Exp1_txt.Name = "Exp1_txt";
this.Exp1_txt.TabIndex = 9;
this.Exp1_txt.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(16, 128);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(56, 16);
this.label6.TabIndex = 10;
this.label6.Text = "其他费用";
//
// Exp2_txt
//
this.Exp2_txt.Location = new System.Drawing.Point(72, 120);
this.Exp2_txt.Name = "Exp2_txt";
this.Exp2_txt.TabIndex = 11;
this.Exp2_txt.Text = "";
//
// label7
//
this.label7.Location = new System.Drawing.Point(216, 128);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(32, 16);
this.label7.TabIndex = 12;
this.label7.Text = "补贴";
//
// Exp3_txt
//
this.Exp3_txt.Location = new System.Drawing.Point(256, 120);
this.Exp3_txt.Name = "Exp3_txt";
this.Exp3_txt.TabIndex = 13;
this.Exp3_txt.Text = "";
//
// label8
//
this.label8.Location = new System.Drawing.Point(32, 168);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(32, 16);
this.label8.TabIndex = 14;
this.label8.Text = "奖金";
//
// Exp4_txt
//
this.Exp4_txt.Location = new System.Drawing.Point(72, 160);
this.Exp4_txt.Name = "Exp4_txt";
this.Exp4_txt.TabIndex = 15;
this.Exp4_txt.Text = "";
//
// label9
//
this.label9.Location = new System.Drawing.Point(200, 168);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(56, 16);
this.label9.TabIndex = 16;
this.label9.Text = "实发工资";
//
// Exp5_txt
//
this.Exp5_txt.Location = new System.Drawing.Point(256, 160);
this.Exp5_txt.Name = "Exp5_txt";
this.Exp5_txt.TabIndex = 17;
this.Exp5_txt.Text = "";
this.Exp5_txt.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Exp5_txt_MouseDown);
this.Exp5_txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Exp5_txt_KeyPress);
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 200);
this.button1.Name = "button1";
this.button1.TabIndex = 18;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(256, 200);
this.button2.Name = "button2";
this.button2.TabIndex = 18;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label10
//
this.label10.Location = new System.Drawing.Point(24, 88);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(32, 16);
this.label10.TabIndex = 19;
this.label10.Text = "工资";
//
// Exp_txt
//
this.Exp_txt.Location = new System.Drawing.Point(72, 88);
this.Exp_txt.Name = "Exp_txt";
this.Exp_txt.TabIndex = 20;
this.Exp_txt.Text = "";
//
// WagesRecord
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(376, 245);
this.Controls.Add(this.Exp_txt);
this.Controls.Add(this.Exp5_txt);
this.Controls.Add(this.Exp4_txt);
this.Controls.Add(this.Exp3_txt);
this.Controls.Add(this.Exp2_txt);
this.Controls.Add(this.Exp1_txt);
this.Controls.Add(this.WagesId_txt);
this.Controls.Add(this.Name_txt);
this.Controls.Add(this.label10);
this.Controls.Add(this.button1);
this.Controls.Add(this.label9);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.Time_dtp);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.No_cb);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "WagesRecord";
this.Closing += new System.ComponentModel.CancelEventHandler(this.WagesRecord_Closing);
this.Load += new System.EventHandler(this.WagesRecord_Load);
this.ResumeLayout(false);
}
#endregion
private void WagesRecord_Load(object sender, System.EventArgs e)
{
if(WagesInfoForm.wwID == "insert")
{
DBNo_cb();
this.WagesId_txt.Enabled = false;
}
if(WagesInfoForm.wwID == "update")
{
string []ss = WagesInfoForm.wiff.sb.ToString().Split('#');
this.No_cb.DropDownStyle = ComboBoxStyle.Simple;
this.No_cb.Enabled = false;
this.ID = ss[0];
this.No_cb.Text = ss[1];
this.Name_txt.Text = ss[2];
this.WagesId_txt.Text = ss[3];
this.Time_dtp.Text = ss[4];
this.Exp_txt.Text = ss[5];
this.Exp1_txt.Text = ss[6];
this.Exp2_txt.Text = ss[7];
this.Exp3_txt.Text = ss[8];
this.Exp4_txt.Text = ss[9];
}
}
private void DBNo_cb()
{
string s = "select EmployInfo.*,WagesInfo.* from EmployInfo,WagesInfo where WagesInfo.waId=EmployInfo.waId order by eId asc";
Base b = new Base();
this.dt = b.ExeSQLdt(s);
for(int i = 0 ; i < this.dt.Rows.Count ; i ++)
{
this.No_cb.Items.Add(this.dt.Rows[i]["eId"].ToString());
}
}
private void No_cb_SelectedIndexChanged(object sender, System.EventArgs e)
{
for(int i = 0 ; i < this.dt.Rows.Count ; i ++)
{
if(this.dt.Rows[i]["eId"].ToString() == this.No_cb.Text)
{
this.Name_txt.Text = this.dt.Rows[i]["eName"].ToString();
this.WagesId_txt.Text = this.dt.Rows[i]["Id"].ToString();
break;
}
}
}
//确定
private void button1_Click(object sender, System.EventArgs e)
{
if(WagesInfoForm.wwID == "insert")
{
string s = "insert into WagesInfo (waId,Id,enDate,enMonney,enMonney1,enMonney2,enMonney3,enMonney4,enMonney5) values (";
s += int.Parse(this.No_cb.Text.Trim()) + "," + int.Parse(this.WagesId_txt.Text.Trim()) + ",'" + this.Time_dtp.Value.ToShortDateString();
s += "'," + Convert.ToDecimal(this.Exp_txt.Text.Trim()) + "," + Convert.ToDecimal(this.Exp1_txt.Text.Trim()) + "," + Convert.ToDecimal(this.Exp2_txt.Text.Trim());
s += "," + Convert.ToDecimal(this.Exp3_txt.Text.Trim()) + "," + Convert.ToDecimal(this.Exp4_txt.Text.Trim()) + "," + Convert.ToDecimal(this.Exp5_txt.Text.Trim()) +")";
Base b = new Base();
b.ExeSQL(s);
MessageBox.Show("添加成功!");
}
if(WagesInfoForm.wwID == "update")
{
string s = "update WagesInfo set Id=" + int.Parse(this.WagesId_txt.Text.Trim()) + ",enDate='" + this.Time_dtp.Value.ToShortDateString() + "',enMonney=";
s += Convert.ToDecimal(this.Exp_txt.Text.Trim()) + ",enMonney1=" + Convert.ToDecimal(this.Exp1_txt.Text.Trim()) + ",enMonney2=";
s += Convert.ToDecimal(this.Exp2_txt.Text.Trim()) + ",enMonney3=" + Convert.ToDecimal(this.Exp3_txt.Text.Trim());
s += ",enMonney4=" + Convert.ToDecimal(this.Exp4_txt.Text.Trim()) + ",enMonney5=" + Convert.ToDecimal(this.Exp5_txt.Text.Trim());
s += " where wwwaId=" + int.Parse(this.ID);
Base b = new Base();
b.ExeSQL(s);
MessageBox.Show("修改成功!");
}
this.Close();
}
private void WagesRecord_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
WagesInfoForm.wiff.Enabled = true;
WagesInfoForm.wiff.DBDataGrid();
}
//取消
private void button2_Click(object sender, System.EventArgs e)
{
WagesInfoForm.wiff.Enabled = true;
WagesInfoForm.wiff.DBDataGrid();
this.Close();
}
//当实发工资的文本框获得焦点时,自动算出实发工资
private void Exp5_txt_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
//把字符串格式转化成货币格式
string exp = String.Format("{0:c}",this.Exp_txt.Text.Trim());
string exp1 = String.Format("{0:c}",this.Exp1_txt.Text.Trim());
string exp2 = String.Format("{0:c}",this.Exp2_txt.Text.Trim());
string exp3 = String.Format("{0:c}",this.Exp3_txt.Text.Trim());
string exp4 = String.Format("{0:c}",this.Exp4_txt.Text.Trim());
this.Exp5_txt.Text = Convert.ToString(double.Parse(exp) - double.Parse(exp1) - double.Parse(exp2) + double.Parse(exp3) + double.Parse(exp4));
}
catch
{
MessageBox.Show("货币格式错误!");
}
}
private void Exp5_txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)13)
{
this.button1_Click(sender,e);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -