private void dgvShenasnamehMashinAlat_Click(object sender, EventArgs e) { if (dgvShenasnamehMashinAlat.CurrentRow != null) { if (dgvShenasnamehMashinAlat.CurrentRow.Index != -1) { model.ID = Convert.ToInt64(dgvShenasnamehMashinAlat.CurrentRow.Cells["ID"].Value); dbs_CMMSEntities1 _db = new dbs_CMMSEntities1(); model = _db.tbl_UsableMaterialsGhaleb.Where(x => x.ID == model.ID).FirstOrDefault(); } } }
private void btnSave_Click(object sender, EventArgs e) { try { dbs_CMMSEntities1 obj = new dbs_CMMSEntities1(); tbl_UsableMaterialsGhaleb tbl = new tbl_UsableMaterialsGhaleb(); tbl.IDGhaleb = PropIDGhaleb; tbl.Caption = txtCaption.Text; tbl.Type = cmbType.Text; tbl.TimeServices = txtTimeServices.Text; tbl.UsableGhataatYadaki = txtUsableGhataatYadaki.Text; tbl.UsableMaterials = txtUsableMaterials.Text; tbl.Peryod = txtperyod.Text; obj.tbl_UsableMaterialsGhaleb.Add(tbl); obj.SaveChanges(); MessageBox.Show("اطلاعات با موفقیت ذخیره گردید", "ثبت اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطای رخ داده است", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }