|
 |
|
C# WinForm ต้องการสร้างหลายเงื่อนไขให้กับ Checkbox |
|
 |
|
|
 |
 |
|
เป็น WinForm C# มี checkbox 4 ตัว ต้องการให้กดตัวใดตัวหนึ่งแล้วโชว์ข้อมูล หรือ กดพร้อมกันหลายๆตัว แล้วให้ข้อมูลในแต่ละ checkbox แสดงรวมทั้งหมดอะคะ
แต่ที่แสดงอยู่ คือ พอกดหลายๆตัว กลับแสดงข้อมูลแค่ checkbox เดียว
เช่น
1. checkbox ขาดงาน
2. checkbox ลากิจ
พอกดเลือก ' checkbox ขาดงาน ' ก็จะแสดงข้อมูลของคนที่ขาดงานมา แล้วถ้าเรากดปุ่ม ' checkbox ลากิจ' ด้วย
จะต้องมีทั้งข้อมูล คนขาดงานและคนที่ลากิจ แต่พอกดปุ่ม ลากิจ มันโชว์แต่ข้อมูลลากิจ แต่ไม่โชว์คนที่ขาดงานเข้ามาด้วย
รบกวนดู Code ให้ทีนะคะ ต้องเขียนเงื่อนไขยังไง ถึงจะแสดงแบบที่กล่าวไว้ข้างต้นได้
Code (C#)
public void missShw()
{
SqlConnection conn = new SqlConnection(appConn);
string sql = "SELECT [filesTA].EmpNo,[Employee].Title + ' ' + [Employee].[First Name] + ' ' + [Employee].[Last Name] as 'FullName',[filesTA].ChkDate"
+ ",Convert(nvarchar(5),[filesTA].ChkIn,108) as 'ChkIn',Convert(nvarchar(5),[filesTA].ChkOut,108) as 'ChkOut"
+ ",[filesTA].LateMin"
+ " From [WebSP].[dbo].[filesTA] inner join [WebSP].[dbo].[Employee] on [Employee].EmployeeNo=[filesTA].EmpNo INNER JOIN [WebSP].[dbo].[CompanyData] On [CompanyData].Company = [Employee].Company"
+ " WHERE [filesTA].ChkDate ='" + dateTimePicker.Value.ToString("yyyy-MM-dd") + "'"
+ " and [Employee].Section = '" + cbSection.SelectedValue + "'"
+ " and [Employee].Team = '" + cbTeam.SelectedValue + "'"
+ " and [filesTA].ErrorCode = '2'";
da = new SqlDataAdapter(sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
dgvShow.DataSource = ds.Tables[0];
}
public void leaveFull()
{
SqlConnection conn = new SqlConnection(appConn);
string sql = "SELECT [filesTA].EmpNo,[Employee].Title + ' ' + [Employee].[First Name] + ' ' + [Employee].[Last Name] as 'FullName',[filesTA].ChkDate"
+ ",Convert(nvarchar(5),[filesTA].ChkIn,108) as 'ChkIn',Convert(nvarchar(5),[filesTA].ChkOut,108) as 'ChkOut"
+ ",[filesTA].LateMin"
+ " From [WebSP].[dbo].[filesTA] inner join [WebSP].[dbo].[Employee] on [Employee].EmployeeNo=[filesTA].EmpNo INNER JOIN [WebSP].[dbo].[CompanyData] On [CompanyData].Company = [Employee].Company"
+ " WHERE [filesTA].ChkDate ='" + dateTimePicker.Value.ToString("yyyy-MM-dd") + "'"
+ " and [Employee].Section = '" + cbSection.SelectedValue + "'"
+ " and [Employee].Team = '" + cbTeam.SelectedValue + "'"
+ " and [filesTA].ErrorCode = '3'";
da = new SqlDataAdapter(sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
dgvShow.DataSource = ds.Tables[0];
}
//ขาดงาน
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (checkBox4.Checked == true)
{
missShw();
}
}
//ลากิจ
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (checkBox3.Checked == true)
{
leaveFull();
}
}
ขอบคุณล่วงหน้ามากๆๆจ้า
Tag : .NET, Ms SQL Server 2008, Win (Windows App), C#, VS 2008 (.NET 3.x), Windows

|
|
 |
 |
 |
 |
Date :
2012-11-19 12:53:44 |
By :
porn_toon |
View :
1222 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 05
|