예제 #1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            MobileManager _mobileManager = new MobileManager();
            Mobile        _mobile        = new Mobile();

            try
            {
                //Mandetory
                _mobile.Name = nameTextBox.Text;
                if (string.IsNullOrEmpty(_mobile.Name))
                {
                    MessageBox.Show("Empty name not possible!!");
                    return;
                }

                //Mandetory
                _mobile.IMEI = imeiTextBox.Text;
                if (string.IsNullOrEmpty(_mobile.IMEI))
                {
                    MessageBox.Show("Empty IMEI not possible!!");
                    return;
                }

                if (_mobile.IMEI.Length != 15)
                {
                    MessageBox.Show("Please enter 15 digit !!");
                    return;
                }
                //Unique
                if (_mobileManager.IsEMEIExist(_mobile))
                {
                    MessageBox.Show(_mobile.IMEI + "Already Exist !!!");
                    return;
                }

                //Mandetory
                _mobile.Price = Convert.ToInt32(priceTextBox.Text);

                if (string.IsNullOrEmpty(priceTextBox.Text))
                {
                    MessageBox.Show("Empty Price not possible!!");
                    return;
                }

                if (_mobileManager.Add(_mobile))
                {
                    MessageBox.Show("Saved");
                }

                nameTextBox.Clear();
                imeiTextBox.Clear();
                priceTextBox.Clear();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
예제 #2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            Mobile mobile = new Mobile();

            if (String.IsNullOrEmpty(modelNameTextBox.Text))
            {
                MessageBox.Show("Enter Model name");
                return;
            }

            if (String.IsNullOrEmpty(imeiTextBox.Text))
            {
                MessageBox.Show("Enter IMEI");
                return;
            }
            if (imeiTextBox.TextLength != 15)
            {
                MessageBox.Show("IMEI Must be 15 char");
                return;
            }

            mobile.ModelName = modelNameTextBox.Text;
            mobile.IMEI      = imeiTextBox.Text;
            if (_mobileManager.IsImeiExist(mobile))
            {
                MessageBox.Show("This IMEI exist");
                return;
            }
            if (String.IsNullOrEmpty(priceTextBox.Text))
            {
                MessageBox.Show("Enter price");
                return;
            }
            if (!Regex.IsMatch(priceTextBox.Text, @"\d"))
            {
                MessageBox.Show("Price Must be number");
                return;
            }

            mobile.Price = Convert.ToDouble(priceTextBox.Text);
            if (_mobileManager.Add(mobile))
            {
                MessageBox.Show("Mobile added");
                return;
            }
            else
            {
                MessageBox.Show("Cannot Added");
                return;
            }
        }