📄 leaveform.cs
字号:
//文件名:LeaveForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MyPersonnel
{
public partial class LeaveForm : Form
{
public LeaveForm()
{
InitializeComponent();
}
private void 离职管理BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.离职管理BindingSource.EndEdit();
this.离职管理TableAdapter.Update(this.myPersonnelDataSet.离职管理);
}
private void LeaveForm_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“myPersonnelDataSet.离职管理”中。您可以根据需要移动或移除它。
this.离职管理TableAdapter.Fill(this.myPersonnelDataSet.离职管理);
}
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
//自动计算离职管理自编号
String MySQLConnectionString = global::MyPersonnel.Properties.Settings.Default.MyPersonnelConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = "Select max(自编号) 最大编号 From 离职管理";
object MyResult = MyCommand.ExecuteScalar();
Int64 MyID = 1;
if (MyResult != System.DBNull.Value)
{
String MyMaxID = MyResult.ToString().Trim();
MyMaxID = MyMaxID.Substring(2, MyMaxID.Length - 2);
MyID = Convert.ToInt64(MyMaxID) + 1;
}
int MyLength = MyID.ToString().Length;
string MyNewID = "";
switch (MyLength)
{
case 1:
MyNewID = "LZ0000000" + MyID.ToString();
break;
case 2:
MyNewID = "LZ000000" + MyID.ToString();
break;
case 3:
MyNewID = "LZ00000" + MyID.ToString();
break;
case 4:
MyNewID = "LZ0000" + MyID.ToString();
break;
case 5:
MyNewID = "LZ000" + MyID.ToString();
break;
case 6:
MyNewID = "LZ00" + MyID.ToString();
break;
case 7:
MyNewID = "LZ0" + MyID.ToString();
break;
}
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
this.自编号TextBox.Text = MyNewID;
}
private void 查询ToolStripButton_Click(object sender, EventArgs e)
{
String MySQLConnectionString = global::MyPersonnel.Properties.Settings.Default.MyPersonnelConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
string MySQL = "Select * From 基本档案 Where 姓名 LIKE '" + this.员工姓名ToolStripTextBox.Text + "' AND (员工编号 NOT IN(SELECT 员工编号 FROM 离职管理))";
DataTable MyPersonnelTable = new DataTable();
SqlDataAdapter MyDataAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyDataAdapter.Fill(MyPersonnelTable);
this.基本档案DataGridView.DataSource = MyPersonnelTable;
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
private void 基本档案DataGridView_Click(object sender, EventArgs e)
{
this.员工编号TextBox.Text = this.基本档案DataGridView.CurrentRow.Cells[1].Value.ToString();
this.员工姓名TextBox.Text = this.基本档案DataGridView.CurrentRow.Cells[3].Value.ToString();
}
private void 基本档案DataGridView_SelectionChanged(object sender, EventArgs e)
{
string My员工姓名 = this.基本档案DataGridView.CurrentRow.Cells[3].Value.ToString();
try
{
this.离职管理TableAdapter.FillBy(this.myPersonnelDataSet.离职管理, My员工姓名);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -