Laploy Web Board
Would you like to react to this message? Create an account in a few clicks or log in to continue.

กดเลือก datagridviewer โชว์รูปที่ Picturebox

2 posters

Go down

กดเลือก datagridviewer โชว์รูปที่ Picturebox Empty กดเลือก datagridviewer โชว์รูปที่ Picturebox

ตั้งหัวข้อ  rungsak 5th February 2011, 2:34 pm

if (txtSearch.Text.Trim() == "")
{
MessageBox.Show("กรุณาระบุรหัสหรือชื่อก่อน !!! ", "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

IHuman = from c in db.Humans
where c.IDCardName.Contains(txtSearch.Text.Trim())
|| c.FitstName.Contains(txtSearch.Text.Trim())
orderby c.FitstName
select c;

if (IHuman.Count() > 0)
{
tsEdit.Enabled = true;
dgvCustomerList.DataSource = IHuman.ToList();

}
else
{
ClearHuman();
dgvCustomerList.DataSource = null;
MessageBox.Show("เงื่อนไขที่คุณป้อน ไม่มีข้อมูลลูกค้า !!!", "ผลการค้นหา", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSearch.Focus();
txtSearch.SelectAll();
}
FormatDgvCustomerList();
}

private void FormatDgvCustomerList()
{
if (dgvCustomerList.RowCount > 0)
{
dgvCustomerList.Columns[0].HeaderText = "ระหัสบัตรประชาชน";
dgvCustomerList.Columns[1].HeaderText = "อำเภอ";

dgvCustomerList.Columns[0].Width = 180;

dgvCustomerList.Columns[1].Width = 235;

}
}
private void dgvCustomerList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1)
{
return;
}

mskIDCard.Text = dgvCustomerList.Rows[e.RowIndex].Cells["IDCardName"].Value.ToString();
txtAmphur.Text = dgvCustomerList.Rows[e.RowIndex].Cells["AmphurCard"].Value.ToString();

ตรงนี้คับ จะให้โชว์รูปที่ Picturebox ครับ โค้ดต้องเขียนยังไงคับ


private void picHumanPicture_Click(object sender, EventArgs e)
{
ofDlg.Title = "เลือกไฟล์รูปภาพ";
ofDlg.Filter = "Images(*.BMP;*.JPG;*.GIF;*.PNG) |*.BMP;*.JPG;*.GIF;*.PNG";

ofDlg.FileName = "";
ofDlg.Multiselect = false;
ofDlg.FilterIndex = 0;

if (ofDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{


FileTools ft = new FileTools(ofDlg.FileName);
imgExtension = ft.GetFileExtension();
picHumanPicture.Image = Image.FromFile(ofDlg.FileName);


}
else
{
imgExtension = "";
picHumanPicture.Image = null;
}
}
private void cmdDeletePicture_Click(object sender, EventArgs e)
{

imgExtension = "";
picHumanPicture.Image = null;
}

private void tsEdit_Click_1(object sender, EventArgs e)
{
if (mskIDCard.Text.Trim() == "")
{
MessageBox.Show("กรุณาป้อนรหัสบัตรประชาชนก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
mskIDCard.Focus();
return;
}

if (txtLastAccessByEdit.Text.Trim() == "")
{
MessageBox.Show("กรุณาป้อนชื่อผู้แก้ไขประวัติก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtLastAccessByEdit.Focus();
return;
}

if (MessageBox.Show("คุณต้องการแก้ไขประวัติผู้ต้องหา ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
tr = Conn.BeginTransaction();
try
{
sb.Remove(0, sb.Length);
sb.Append("UPDATE Human");
sb.Append(" SET AmphurCard=@AmphurCard");
sb.Append(" WHERE (IDCardName=@IDCardName)");
string sqlEdit;
sqlEdit = sb.ToString();

com.CommandText = sqlEdit;
com.CommandType = CommandType.Text;
com.Connection = Conn;
com.Transaction = tr;
com.Parameters.Clear();
com.Parameters.Add("@IDCardName", SqlDbType.NVarChar).Value = mskIDCard.Text.Trim();
com.Parameters.Add("@AmphurCard", SqlDbType.NVarChar).Value = txtAmphur.Text.Trim();


int result;
result = com.ExecuteNonQuery();
if (result == 0)
{
tr.Rollback();
MessageBox.Show("รหัสบัตรประชาชนที่คุณป้อน ไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
mskIDCard.SelectAll();
}
else
{
tr.Commit();
MessageBox.Show("แก้ไขประวัติเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);



ClearHuman();
this.Close();
frmMain f = new frmMain();
f.Show();

}
}
catch (Exception ex)
{
tr.Rollback();
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
mskIDCard.Focus();

}

rungsak

จำนวนข้อความ : 3
Join date : 05/02/2011

ขึ้นไปข้างบน Go down

กดเลือก datagridviewer โชว์รูปที่ Picturebox Empty สมมุตว่าชื่อไฟล์ตรง

ตั้งหัวข้อ  Admin 5th February 2011, 2:50 pm

mskIDCard.Text = dgvCustomerList.Rows[e.RowIndex].Cells["IDCardName"].Value.ToString();
txtAmphur.Text = dgvCustomerList.Rows[e.RowIndex].Cells["AmphurCard"].Value.ToString();

ใส่โค้ดที่นี่

สมมุตว่าชื่อไฟล์ตรงกับ IDCardName เก็บไว้ในโฟลเดอร์ c:\abc\

myPictureBox.image = new Bitmap( "c:\abc\" + IDCardName + ".jpg");

Admin
Admin

จำนวนข้อความ : 215
Join date : 17/12/2009

http://laploy.forumotion.com

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน

- Similar topics

 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ