• 1405/04/20

تمرین جلسه 100 -پرکردن فیلد های فرم هنگام ویرایش :

سلام استاد خسته نباشید تمرینی که گفته بودید در جلسه 100 رو اینجوری تونستم انجامش بدم

using DataLayer.Context;
using DataLayer.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace Toplearn_School.People
{
    public partial class frmEditePersan : Form
    {
        int _pID;
        public frmEditePersan(int PersanId)
        {
            _pID = PersanId;
            InitializeComponent();
        }

        private void frmEditePersan_Load(object sender, EventArgs e)
        {
            using (TopLearn_DB_Context _Context = new TopLearn_DB_Context())
            {
                Person person = _Context.Persons.Find(_pID);
                txtName.Text = person.Name;
                txtFamily.Text = person.Family;
                txtMobile.Text = person.Mobile;
                txtEmail.Text = person.Email;
                if (person.IsTeacher == true)
                {
                    rbTeacher.Checked = true;
                }
                else
                {
                    rbStudent.Checked = true;
                }
            }
        }

        private void btnEdite_Click(object sender, EventArgs e)
        {
            using (TopLearn_DB_Context _Context = new TopLearn_DB_Context())
            {
                Person person = _Context.Persons.Find(_pID);
                person.Name = txtName.Text;
                person.Family= txtFamily.Text  ;
                person.Mobile= txtMobile.Text ;
                person.Email =txtEmail.Text;
                person.IsTeacher = false;
                if (rbTeacher.Checked)
                {
                    person.IsTeacher = true;
                }
                _Context.SaveChanges();
                DialogResult = DialogResult.OK;
            }
            MessageBox.Show($"اطلاعات [{txtName.Text}][{txtFamily.Text}] موفقیت ویرایش شد.","ویرایش",MessageBoxButtons.OK,MessageBoxIcon.Information);
           
            Close();
        }
    }
}

-عکس پروژه :

ممنون از تدریس عالیتون استاد

 

 

 

  • 1405/04/20
  • ساعت 20:29

عالی بود ، آفرین