//Customer Add Database//
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (_isUpdate)
            {
                DialogResult r = MessageBox.Show("Əminsinizmi.?", "Yenilemeye", MessageBoxButtons.YesNo);
                if (r == DialogResult.Yes)
                {
                    _customer.Name           = TxtName.Text;
                    _customer.Surname        = TxtSuranme.Text;
                    _customer.Email          = TxtEmail.Text;
                    _customer.Phone          = TxtPhone.Text;
                    _customer.IdentityNumber = TxtIdentify.Text;
                    MessageBox.Show("Melumat yenilendi");
                    _customerDal.Update(_customer);
                    AddCustomer?.Invoke(_customer, new EventArgs());
                }
            }
            else
            {
                if (!this.CheckInput())
                {
                    MessageBox.Show("Zehmet olmasa xanalari doldurun !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (!TxtEmail.Text.IsEmail())
                {
                    MessageBox.Show("Emaili duzgun qeyd edin !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (!TxtPhone.Text.IsNumber())
                {
                    MessageBox.Show("Nomreni duzgun qeyd edin !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (!TxtIdentify.Text.IsNumber() || TxtIdentify.Text.Length != 8)
                {
                    MessageBox.Show("En azi 8 eded olmalidir !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                List <Customer> customers = _customerDal.GetAll();
                foreach (Customer item in customers)
                {
                    if (item.IdentityNumber == TxtIdentify.Text)
                    {
                        MessageBox.Show(" Bele Kimlik nomresi Qeyd edilibdir !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                //if ( _customerDal.GetByIdentifyNumber(TxtIdentify.Text))
                //{
                //    MessageBox.Show(" Bele Kimlik nomresi Qeyd edilibdir !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    return;
                //}

                if (_customerDal.GetAll().Any(m => m.Email == TxtEmail.Text))
                {
                    MessageBox.Show("Bu email artiq movcuddur !", "Xəbərdarlıq", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                Customer customer = new Customer
                {
                    Name           = TxtName.Text,
                    Surname        = TxtSuranme.Text,
                    Email          = TxtEmail.Text,
                    Phone          = TxtPhone.Text,
                    IdentityNumber = TxtIdentify.Text
                };
                MessageBox.Show("Musteri elave edildi");
                _customerDal.Create(customer);
                AddCustomer?.Invoke(customer, new EventArgs());
            }


            this.Close();
        }
Ejemplo n.º 2
0
 internal bool Create(Customer customer)
 {
     _status = _customerDal.Create(customer);
     return(_status);
 }