示例#1
0
 public void AddedMushteri(Mushteri msht)
 {
     FillMushteri();
     CmbPerson.Items.Add(msht.Name + "," + msht.Surname + "," + msht.Phone);
 }
示例#2
0
        private void btnAddPerson_Click(object sender, EventArgs e)
        {
            int errCount = 0;

            if (string.IsNullOrEmpty(txtName.Text))
            {
                errCount++;
                lblMName.ForeColor = Color.DarkRed;
            }
            else
            {
                errCount--;
                lblMName.ForeColor = SystemColors.ControlText;
            }

            //////////////////////////////////////////////////

            if (string.IsNullOrEmpty(txtSurname.Text))
            {
                errCount++;
                lblMSurname.ForeColor = Color.DarkRed;
            }
            else
            {
                errCount--;
                lblMSurname.ForeColor = SystemColors.ControlText;
            }

            ///////////////////////////////////////////////////////

            if (string.IsNullOrEmpty(txtPhone.Text))
            {
                errCount++;
                lblMPhone.ForeColor = Color.DarkRed;
            }
            else
            {
                errCount--;
                lblMPhone.ForeColor = SystemColors.ControlText;
            }

            if (errCount > 0)
            {
                return;
            }

            if (db.Mushteris.FirstOrDefault(m => m.Phone == txtPhone.Text) == null)
            {
                Mushteri msht = new Mushteri
                {
                    Name    = txtName.Text,
                    Surname = txtSurname.Text,
                    Phone   = txtPhone.Text
                };
                db.Mushteris.Add(msht);
                db.SaveChanges();
                HomeForm.AddedMushteri(msht);
            }

            else
            {
                Mushteri msht = db.Mushteris.FirstOrDefault(m => m.Phone == txtPhone.Text);

                HomeForm.AddedMushteri(msht);
            }

            this.Close();
        }