13-04-19, 03:28 AM
(آخر تعديل لهذه المشاركة : 13-04-19, 03:30 AM {2} بواسطة ابراهيم ايبو.)
السلام عليكم اخوتي الكرام
اخي وحبيبي Elgokr تحية لك من القلب
انا لم الحظ ردك لانني عكفت على كتابة الحل وبتوفيق من الله تمكنت من ذلك
حيث قمت بتعديل كود الحذف وعرفت متغير يحمل قيمة حقل الترقيم ووضعت بعد كود حذف السجل استدعاء الداتا ثم كود حذف الصورة
وعدلت كود Dgv_VF_SelectionChanged
يحيث استدعيت الصورة وحولتها الى مصفوفة ووضعتها في FileStream ثم حملتها في مربع الصورة
ووضعت الحل ليستفيد منه الجميع
كود :
private void Btn_Delete_Click(object sender, EventArgs e)
{
int EmpNum = int.Parse(Txt_VegFruit_Id.Text);
try
{
if (MessageBox.Show("هل انت متأكد من حذف السجل؟", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Delete_VegFruits(Convert.ToInt32(Txt_VegFruit_Id.Text));
// تمت اضافة هذا السطر
SelectAll_VegFruits(); // اعادة تحميل الداتا قبل حذف الصورة
File.Delete("image\\" + EmpNum + ".jpg");
}
else
{
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Cleardata_VegFruits();
SelectAll_VegFruits();
}
private void Btn_New_Click(object sender, EventArgs e)
{
Cleardata_VegFruits();
}
private void Dgv_VF_SelectionChanged(object sender, EventArgs e)
{
try
{
Txt_VegFruit_Id.Text = Dgv_VF.CurrentRow.Cells[0].Value.ToString();
Txt_VegFruit_Name.Text = Dgv_VF.CurrentRow.Cells[1].Value.ToString();
Cmb_VegFruit_Type.Text = Dgv_VF.CurrentRow.Cells[2].Value.ToString();
Txt_VegFruit_About.Text = Dgv_VF.CurrentRow.Cells[3].Value.ToString();
Txt_Notes.Text = Dgv_VF.CurrentRow.Cells[4].Value.ToString();
Txt_ImgePath.Text = "image\\" + Txt_VegFruit_Id.Text + ".jpg";
//Pb_VegFruit_Pic.Image = Image.FromFile("image\\" + Txt_VegFruit_Id.Text + ".jpg");
// ثم تحميلها في مربع الصورة (fs) هنا جلب الصورة وتحويلها الى بايت مصفوفة ثم وضعها في
FileStream fs = new FileStream(Txt_ImgePath.Text, FileMode.Open, FileAccess.Read);
byte[] filebytes = new byte[fs.Length];
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
Pb_VegFruit_Pic.Image = Image.FromStream(new System.IO.MemoryStream(filebytes));
fs.Close();
fs = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}وسادرس كودك اخي الجوكر لاني دائما بحاجة لافكار خلاقة مثل افكارك دمت لنا بعد الله عونا وسلمت يداك تقبل احترامي
اعمل الخير وأجرك لا تنتظره فالله خير من إليك يرده
البرمجة ليست مجرد كود بل هي منهج تفكير منطقي لحل المشكلات
