public void Update(hospitalCenterTab hosp) { try { /*using (var db = new MedicalCenterDbEntities()) * { * var result = db.hospitalCenterTab.SingleOrDefault(b => b.hoId == hosp.hoId); * // var result = db.hospitalCenterTab.Find(hosp.hoId); * if (result == null) * { * db.hospitalCenterTab.Add(hosp); * } * else * { * // db.Entry(hosp).State=EntityState.Detached; * // db.hospitalCenterTab.Attach(hosp); * // db.Entry(hosp).State = EntityState.Modified; * db.SaveChanges(); * } * * * }*/ db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("ex", ex.Data.ToString()); } }
public void Add(hospitalCenterTab hosp) { try { db.hospitalCenterTab.Add(hosp); db.SaveChanges(); MessageBox.Show("تم اضاقة سجل مريض بنجاح!!", "عملية الاضافة", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Exception" + ex, ex.Data.ToString()); } }
private void btnEdit_Click(object sender, EventArgs e) { try { if (btnEdit.Text == "تعديل") { EnabledT(); btnEdit.Text = "تحديث"; return; } if (search.Text == "") { MessageBox.Show("يجب تحديد العنصر المراد تعديلة!!", "عملية التعديل", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information); return; } hospitalCenterTab hosp = new hospitalCenterTab(); hosp = db.hospitalCenterTab.Find(HoId); if (hosp != null) { hosp.hoId = HoId; hosp.hoCode = txtcode.Text; hosp.hoNameA = txtname.Text; hosp.hoNameE = txtlname.Text; hosp.hoAddressA = txtaddress1.Text; hosp.hoAddressE = txtaddress2.Text; if (txtmobile1.Text == "") { hosp.hoMobile1 = Convert.ToInt32(96700000000000); } else { hosp.hoMobile1 = Convert.ToInt32(txtmobile1.Text); } if (txtmobile2.Text == "") { hosp.hoMobile2 = Convert.ToInt32(0400000); } else { hosp.hoMobile2 = Convert.ToInt32(txtmobile2.Text); } if (txtfax.Text == "") { hosp.hoMobile1 = Convert.ToInt32(04000000); } else { hosp.hoFix = Convert.ToInt32(txtfax.Text); } hosp.hoNote = txtnote.Text; hosp.isDeleted = false; byte[] Picture; if (img.Image == null) { Picture = new byte[0]; } else { MemoryStream ms = new MemoryStream(); img.Image.Save(ms, img.Image.RawFormat); Picture = ms.ToArray(); } hosp.hoImg = Picture; } medicalcenter.Update(hosp); MessageBox.Show("تم عملية التعديل بنجاح!!", "عملية التعديل", MessageBoxButtons.OK, MessageBoxIcon.Information); clearText(); btnEdit.Enabled = false; } catch { throw; } }
private void simpleButton8_Click(object sender, EventArgs e) { hospitalCenterTab hosp = new hospitalCenterTab(); try { hosp.hoCode = txtcode.Text; hosp.hoNameA = txtname.Text; hosp.hoNameE = txtlname.Text; hosp.hoAddressA = txtaddress1.Text; hosp.hoAddressE = txtaddress2.Text; if (txtmobile1.Text == "") { hosp.hoMobile1 = Convert.ToInt32(96700000000000); } else { hosp.hoMobile1 = Convert.ToInt32(txtmobile1.Text); } if (txtmobile2.Text == "") { hosp.hoMobile2 = Convert.ToInt32(0400000); } else { hosp.hoMobile2 = Convert.ToInt32(txtmobile2.Text); } if (txtfax.Text == "") { hosp.hoMobile1 = Convert.ToInt32(04000000); } else { hosp.hoFix = Convert.ToInt32(txtfax.Text); } hosp.hoNote = txtnote.Text; hosp.isDeleted = false; byte[] Picture; if (img.Image == null) { Picture = new byte[0]; } else { MemoryStream ms = new MemoryStream(); img.Image.Save(ms, img.Image.RawFormat); Picture = ms.ToArray(); } hosp.hoImg = Picture; medicalcenter.Add(hosp); clearText(); } catch { return; } }