2.3.1 员工报班
员工报班主要的功能是新增报班,报废报班,查询报班,左边DGV显示的是员工的信息,右边DGV显示的是员工报班的信息,左边选择一个员工右边出显示出报班信息
2.3.1(图1)
从界面上可以看到我们这里用到的控件有
控件名称 |
说明 |
文字(Label) |
控件可以在工具箱直接拖动至窗体,拖至窗体后右击属性可以修改控件的样式和各种属性,还可以编辑事件。右击控件选择属性,在跳出框里面选择带有雷电的图标,在里面可以选择属性 |
下拉框(ComboBox) | |
文本(TextBox) | |
按钮(Button) | |
表格(DataGridView) | |
容器(Panel) | |
日期控件(DateTimePicker) |
数据库
1、表与关系
2.3.1(图2)
表1.员工表(dbo.StaffList)
列名 |
数据类型 |
主键/外键 |
说明 |
StaffID |
int |
主键 |
员工ID |
StaffNumber |
char (100) |
|
员工编号 |
StaffName |
char (100) |
|
员工姓名 |
Sex |
char (100) |
|
性别 |
IdentityCardNumber |
char (100) |
|
身份证号 |
HomeLocation |
char (100) |
|
家庭地址 |
Phone |
char (100) |
|
电话 |
StaffTypeID |
int |
外键 |
员工类型表.员工类型ID |
OrganizationID |
int |
外键 |
机构表.机构ID |
StationID |
int |
外键 |
站点表.站点ID |
Remarks |
char (100) |
|
备注 |
LeaveOfficeNo |
bit |
|
离职否 |
InvokingNo |
bit |
|
调用否 |
Date |
datetime |
|
日期 |
Photo |
nvarchar (3000) |
|
相片 |
表2.站点表(dbo.StationList)
列名 |
数据类型 |
主键/外键 |
说明 |
StationID |
int |
主键 |
站点ID |
StationNumber |
char (100) |
|
站点编号 |
StationName |
char (100) |
|
站点名称 |
StopNo |
bit |
|
停用否 |
表3.员工类型表(StaffTypeList)
列名 |
数据类型 |
主键/外键 |
说明 |
StaffTypeID |
int |
主键 |
员工类型ID |
StaffTypeName |
char (100) |
|
员工类型名称 |
StaffTypeNumber |
char (100) |
|
员工类型编号 |
StaffTypeDoral |
char (100) |
|
员工类型工价 |
表4..机构表(OrganizationList)
列名 |
数据类型 |
主键/外键 |
说明 |
OrganizationID |
int |
主键 |
机构ID |
OrganizationName |
char (100) |
|
机构名称 |
表5.报班表(ReportClassList)
列名 |
数据类型 |
主键/外键 |
说明 |
ReportClassID |
int |
主键 |
报班ID |
ReportClassTime |
datetime |
|
报班时间 |
LateReachNo |
bit |
|
晚到否 |
ReachNo |
bit |
|
到否 |
StaffID |
int |
外键 |
员工ID |
NullifyNo |
bit |
|
作废否 |
1.DGV员工信息的绑定
2.3.1(图2)
第一步:数据库的存储过程
IF @Type='frmReport_SelectStaffInformation'--dgv绑定员工信息
BEGIN
SELECT StaffList.StaffID,LTRIM(RTRIM(StaffList.StaffNumber))AS StaffNumber,LTRIM(RTRIM(StaffList.StaffName))AS StaffName,
LTRIM(RTRIM(StaffList.Sex))AS Sex,LTRIM(RTRIM(StaffTypeList.StaffTypeName))AS StaffTypeName,
LTRIM(RTRIM(OrganizationList.OrganizationName))AS OrganizationName,
LTRIM(RTRIM(StationList.StationName))AS StationName,StaffList.LeaveOfficeNo
FROM StaffList INNER JOIN
StaffTypeList ON StaffList.StaffTypeID = StaffTypeList.StaffTypeID INNER JOIN
OrganizationList ON StaffList.OrganizationID = OrganizationList.OrganizationID INNER JOIN
StationList ON StaffList.StationID = StationList.StationID
WHERE StaffList.LeaveOfficeNo=0--员工是否离职为否
END
第二步:逻辑层(BLL)代码
[OperationContract]
public DataSet frmReport_SelectStaffInformation()//dgv绑定员工信息
{
SqlParameter[] mySqlParameter = { new SqlParameter("@Type", SqlDbType.Char) };
mySqlParameter[0].Value = "frmReport_SelectStaffInformation";
DataTable myDataTable = myDALMethod.QueryDataTable("ReportStatistics_frmReport", mySqlParameter);
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add(myDataTable);
return myDataSet;
}
第三步:界面层(UIL)代码
Load事件的代码:
DataTable dtReportClass = myfrmReportClassClient.frmReport_SelectReport().Tables[0];
dgvReportClassNews.DataSource = dtReportClass;
2.查询报班
第一步:数据库的存储过程
IF @Type='frmReport_SelectReport'--查询报班
BEGIN
SELECT ReportClassID,ReportClassTime,LateReachNo,ReachNo,NullifyNo
FROM ReportClassList
END
第二步:逻辑层(BLL)代码
[OperationContract]
public DataSet frmReport_SelectReport()//查询报班
{
SqlParameter[] mySqlParameter = { new SqlParameter("@Type", SqlDbType.Char) };
mySqlParameter[0].Value = "frmReport_SelectReport";
DataTable myDataTable = myDALMethod.QueryDataTable("ReportStatistics_frmReport", mySqlParameter);
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add(myDataTable);
return myDataSet;
}
第三步:界面层(UIL)代码
private void btnDemandAll_Click(object sender, EventArgs e)//直接查询
{
DataTable dtReportClass = myfrmReportClassClient.frmReport_SelectReport().Tables[0];
DateTime ReportClassTimeOne = Convert.ToDateTime(dtpDateOne.Text);
DateTime ReportClassTimeTwo = Convert.ToDateTime(dtpDateTwo.Text);//获取控件的数据
if (dtpDateOne.Text != "")
{
DataView dgv1 = new DataView(dtReportClass);//声明一个DataView
dgv1.RowFilter = "(ReportClassTime>='" + ReportClassTimeOne + "'AND ReportClassTime<='" + ReportClassTimeTwo + "')";//根据文本控件查询,查询的条件
dtReportClass = dgv1.ToTable();
dgvReportClassNews.DataSource = dtReportClass;//给dgv绑定数据
}
}
private void btnDemand_Click(object sender, EventArgs e)//根据员工来查询
{
PublicStaticObject.StaffReportClassID = (int)dgvStaffNews.CurrentRow.Cells["StaffID"].Value;
DataTable dtReportClass = myfrmReportClassClient.frmReport_SelectReport().Tables[0];
DateTime ReportClassTimeOne = Convert.ToDateTime(dtpDateOne.Text);
DateTime ReportClassTimeTwo = Convert.ToDateTime(dtpDateTwo.Text);
if (dtpDateOne.Text != "")
{
DataView dgv1 = new DataView(dtReportClass);
dgv1.RowFilter = "(ReportClassTime>='" + ReportClassTimeOne + "'AND ReportClassTime<='" + ReportClassTimeTwo + "')";//根据文本控件查询
dtReportClass = dgv1.ToTable();
dgvReportClassNews.DataSource = dtReportClass;
}
}
3.报班的实现和报废报班的实现
2.3.1(图3)
第一步:数据库的存储过程
@Type Char(100)='',
@StaffID Int=0,
@ReportClassID Int=0,
@ReportClassTime Datetime='',
@LateReachNo Bit=0,
@ReachNo Bit=0,
@NullifyNo Bit=0
IF @Type='frmReport_InsertReport'--新增报班 BEGIN
INSERT INTO ReportClassList
(ReportClassTime,LateReachNo,ReachNo,NullifyNo,StaffID)
VALUES (@ReportClassTime,@LateReachNo,@ReachNo,@NullifyNo,@StaffID)
END
IF @Type='frmReport_DeleteReport'--报废报班 BEGIN
UPDATE ReportClassList
SET ReportClassList.NullifyNo=1--修改报班表报班报废否为否
WHERE ReportClassList.ReportClassID=@ReportClassID
END
第二步:逻辑层(BLL)代码
[OperationContract]//新增报班
public int frmReport_InsertReport(DateTime dtpReportClassTime, bool boolLateReachNo, bool boolReachNo, bool boolNullifyNo, int intStaffID)
{
SqlParameter[] mySqlParameter = { new SqlParameter("@Type", SqlDbType.Char),
new SqlParameter("@ReportClassTime", SqlDbType.DateTime),
new SqlParameter("@LateReachNo", SqlDbType.Bit),
new SqlParameter("@ReachNo", SqlDbType.Bit),
new SqlParameter("@NullifyNo", SqlDbType.Bit),
new SqlParameter("@StaffID", SqlDbType.Int)};
mySqlParameter[0].Value = "frmReport_InsertReport";
mySqlParameter[1].Value = dtpReportClassTime;
mySqlParameter[2].Value = boolLateReachNo;
mySqlParameter[3].Value = boolReachNo;
mySqlParameter[4].Value = boolNullifyNo;
mySqlParameter[5].Value = intStaffID;
return myDALMethod.UpdateData("ReportStatistics_frmReport", mySqlParameter);
}
[OperationContract]
public int frmReport_DeleteReport(int intReportClassID)//作废报班
{
SqlParameter[] mySqlParameter = { new SqlParameter("@Type", SqlDbType.Char),
new SqlParameter("@ReportClassID", SqlDbType.Char)};
mySqlParameter[0].Value = "frmReport_DeleteReport";
mySqlParameter[1].Value = intReportClassID;
return myDALMethod.UpdateData("ReportStatistics_frmReport", mySqlParameter);
}
第三步:界面层(UIL)代码
private void btnDemand_Click(object sender, EventArgse)//根据员工来查询
{
PublicStaticObject.StaffReportClassID= (int)dgvStaffNews.CurrentRow.Cells["StaffID"].Value;
DataTabledtReportClass = myfrmReportClassClient.frmReport_SelectReport().Tables[0];
DateTimeReportClassTimeOne = Convert.ToDateTime(dtpDateOne.Text);
DateTimeReportClassTimeTwo = Convert.ToDateTime(dtpDateTwo.Text);
if(dtpDateOne.Text != "")
{
DataViewdgv1 = new DataView(dtReportClass);
dgv1.RowFilter = "(ReportClassTime>='" +ReportClassTimeOne + "'ANDReportClassTime<='" + ReportClassTimeTwo + "')";//根据文本控件查询
dtReportClass = dgv1.ToTable();
dgvReportClassNews.DataSource =dtReportClass;
}
}
private void btnCancel_Click(objectsender, EventArgs e)//作废报班
{
if(MessageBox.Show("是否作废该报班???", "操作提示", MessageBoxButtons.OKCancel,MessageBoxIcon.Asterisk) == DialogResult.OK)//显示提示框
{
intinNullifyReportClassID = myfrmReportClassClient.frmReport_DeleteReport(PublicStaticObject.intReportClassID);
if(inNullifyReportClassID > 0)
{
MessageBox.Show("已作废!");
DataTabledtReportClass = myfrmReportClassClient.frmReport_SelectReport().Tables[0];
dgvReportClassNews.DataSource = dtReportClass;
}
else
{
MessageBox.Show("操作错误!");
}
}
}
仅供学习,禁止用于商业用途