• 1405/05/03

تمرین جلسه 97ام (اعتبار سنجی فیلد های اجباری) :

namespace TopLearn_School.People
{

    public partial class frmAddPerson : Form
    {
        TopLearn_School_DB _context = new TopLearn_School_DB();
        public frmAddPerson()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //نمایش ستاره قرمز کنار فیلد های اجباری
        void showStarLabel()
        {
            lblRedStar1.Visible = true;
            lblRedStar2.Visible = true;
            lblRedStar3.Visible = true;
        }

        //ثبت اطلاعات شخص جدید در بانک
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if ((txtName.Text != "") && (txtFamily.Text != "") && (txtMobile.Text != ""))
            {
                Person person = new Person()
                {
                    Name = txtName.Text,
                    Family = txtFamily.Text,
                    Mobile = txtMobile.Text,
                    Email = txtEmail.Text,
                    CreateDate = DateTime.Now,
                    IsTeacher = (rbTeacher.Checked == true) ? true : false
                };
                _context.People.Add(person);
                _context.SaveChanges();
                //DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("لطفا فیلد های ستاره دار پر شود!","توجه",MessageBoxButtons.OK);
                showStarLabel();
            }


        }
    }
}
  • 1405/05/04
  • ساعت 00:52

عالی بود