|
|
|
ให้แสดงผล เช็คบ็อกคะ ช่วยหน่อยนะคะ ด่วนนนนนนนนนนะคะ ขอบคุณก่อนล่วงหน้าคะ |
|
|
|
|
|
|
|
Code (C#)
private void txtSearchReceive_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (txtSearchReceive.Text.Trim() == "")
{
return;
}
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("SELECT ");
sb.Append("RECEIVE_HEAD.ReceiveHeadId, ");
sb.Append("RECEIVE_HEAD.ReceiveHeadDate, ");
sb.Append("SHIPPER.ShipperName, ");
sb.Append("SUPPLIER.SupplierName, ");
sb.Append("PRODUCT.ProductId, ");
sb.Append("PRODUCT.ProductName, ");
sb.Append("RECEIVE_DETAIL.AmountProduct, ");
sb.Append("UNITPACK.UnitPackName, ");
sb.Append("RECEIVE_DETAIL.ReceiveDetailQuantity, ");
sb.Append("UNITSALE.UnitSaleName, ");
sb.Append("RECEIVE_DETAIL.ReceiveDetailPriceUnit, ");
sb.Append("EMPLOYER.EmployerName ");
sb.Append("FROM RECEIVE_HEAD INNER JOIN ");
sb.Append("RECEIVE_DETAIL ON ");
sb.Append("RECEIVE_HEAD.ReceiveHeadId = RECEIVE_DETAIL.ReceiveHeadId ");
sb.Append("INNER JOIN PRODUCT ON ");
sb.Append("RECEIVE_DETAIL.ProductId = PRODUCT.ProductId ");
sb.Append("INNER JOIN SHIPPER ON ");
sb.Append("RECEIVE_HEAD.ShipperId = SHIPPER.ShipperId ");
sb.Append("INNER JOIN SUPPLIER ON ");
sb.Append("RECEIVE_DETAIL.SupplierId = SUPPLIER.SupplierId ");
sb.Append("INNER JOIN EMPLOYER ON ");
sb.Append("RECEIVE_HEAD.EmployerId = EMPLOYER.EmployerId ");
sb.Append("INNER JOIN UNITSALE ON ");
sb.Append("PRODUCT.UnitSaleId = UNITSALE.UnitSaleId ");
sb.Append("INNER JOIN UNITPACK ON ");
sb.Append("PRODUCT.UnitPackId = UNITPACK.UnitPackId ");
if (cboSearch_DataReceive.SelectedIndex == 0)
{
sb.Append(" WHERE (RECEIVE_HEAD.ReceiveHeadId=@ReceiveId)");
}
else if (cboSearch_DataReceive.SelectedIndex == 1)
{
sb.Append(" WHERE (SHIPPER.ShipperName LIKE @ShipperName)");
}
if (cboSearch_DataReceive.SelectedIndex == 2)
{
sb.Append(" WHERE (PRODUCT.ProductId=@ProductId)");
}
else if (cboSearch_DataReceive.SelectedIndex == 3)
{
sb.Append(" WHERE (PRODUCT.ProductName LIKE @ProductName)");
}
if (cboSearch_DataReceive.SelectedIndex == 4)
{
sb.Append(" WHERE (RECEIVE_HEAD.DrawId=@DrawId)");
}
sb.Append(" ORDER BY RECEIVE_HEAD.ReceiveHeadId ");
if (chkDateTime.Checked)
{
sb.Append("SELECT ");
sb.Append("RECEIVE_HEAD.ReceiveHeadId, ");
sb.Append("RECEIVE_HEAD.ReceiveHeadDate, ");
sb.Append("SHIPPER.ShipperName, ");
sb.Append("SUPPLIER.SupplierName, ");
sb.Append("PRODUCT.ProductId, ");
sb.Append("PRODUCT.ProductName, ");
sb.Append("RECEIVE_DETAIL.AmountProduct, ");
sb.Append("UNITPACK.UnitPackName, ");
sb.Append("RECEIVE_DETAIL.ReceiveDetailQuantity, ");
sb.Append("UNITSALE.UnitSaleName, ");
sb.Append("RECEIVE_DETAIL.ReceiveDetailPriceUnit, ");
sb.Append("EMPLOYER.EmployerName ");
sb.Append("FROM RECEIVE_HEAD INNER JOIN ");
sb.Append("RECEIVE_DETAIL ON ");
sb.Append("RECEIVE_HEAD.ReceiveHeadId = RECEIVE_DETAIL.ReceiveHeadId ");
sb.Append("INNER JOIN PRODUCT ON ");
sb.Append("RECEIVE_DETAIL.ProductId = PRODUCT.ProductId ");
sb.Append("INNER JOIN SHIPPER ON ");
sb.Append("RECEIVE_HEAD.ShipperId = SHIPPER.ShipperId ");
sb.Append("INNER JOIN SUPPLIER ON ");
sb.Append("RECEIVE_DETAIL.SupplierId = SUPPLIER.SupplierId ");
sb.Append("INNER JOIN EMPLOYER ON ");
sb.Append("RECEIVE_HEAD.EmployerId = EMPLOYER.EmployerId ");
sb.Append("INNER JOIN UNITSALE ON ");
sb.Append("PRODUCT.UnitSaleId = UNITSALE.UnitSaleId ");
sb.Append("INNER JOIN UNITPACK ON ");
sb.Append("PRODUCT.UnitPackId = UNITPACK.UnitPackId ");
sb.Append(" WHERE (RECEIVE_HEAD.ReceiveHeadDate BETWEEN @StartDateTime AND @EndDateTime) ");
MessageBox.Show("แสดง");
}
string sqlSearch;
sqlSearch = sb.ToString();
dt = new DataTable();
com = new SqlCommand();
com.Parameters.Clear();
com.Parameters.Add("@StartDateTime", SqlDbType.DateTime).Value = dtStart.Value.ToString("dd/MM/yyyy");
com.Parameters.Add("@EndDateTime", SqlDbType.DateTime).Value = dtEnd.Value.ToString("dd/MM/yyyy");
if (cboSearch_DataReceive.SelectedIndex == 0)
{
com.Parameters.Add("@ReceiveId", SqlDbType.NVarChar).Value = txtSearchReceive.Text.Trim();
}
else if (cboSearch_DataReceive.SelectedIndex == 1)
{
com.Parameters.Add("@ShipperName", SqlDbType.NVarChar).Value = "%" + txtSearchReceive.Text.Trim() + "%";
}
else if (cboSearch_DataReceive.SelectedIndex == 2)
{
com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = txtSearchReceive.Text.Trim();
}
else if (cboSearch_DataReceive.SelectedIndex == 3)
{
com.Parameters.Add("@ProductName", SqlDbType.NVarChar).Value = "%" + txtSearchReceive.Text.Trim() + "%";
}
else if (cboSearch_DataReceive.SelectedIndex == 4)
{
com.Parameters.Add("@DrawId", SqlDbType.NVarChar).Value = txtSearchReceive.Text.Trim();
}
com.CommandText = sqlSearch;
com.CommandType = CommandType.Text;
com.Connection = Conn;
dr = com.ExecuteReader();
if (dr.HasRows)
{
dt.Load(dr); // ให้ dt โหลดข้อมูลออกมา
CheckResult = dt.Rows.Count;
dgvReceiveHistoryMain.DataSource = dt; // แสดงรายชื่อ ลงไปยัง dgv unit ( Datagrid view)
FormatDgvReceiveHistoryMain();
}
else
{
CheckResult = 0;
dgvReceiveHistoryMain.DataSource = null; // ล้างข้อมูลออก
}
txtSearchReceive.Focus();
txtSearchReceive.SelectAll();
lblReceiveHistoryMain.Text = "พบ : " + CheckResult.ToString() + " รายการ จากการค้นหาคำว่า " + txtSearchReceive.Text + "";
dr.Close();
}
}
Tag : C#
|
|
|
|
|
|
Date :
2011-02-14 10:10:31 |
By :
ทวิตตี้ |
View :
879 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พี่ๆๆๆๆๆๆๆๆๆคะ ช่วยหน่อยนะคร้า
|
|
|
|
|
Date :
2011-02-14 11:01:03 |
By :
ทวิตตี้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|