コード例 #1
0
ファイル: ValidateText.cs プロジェクト: Hanif6731/Phonebook
        public static bool DoesStringContainsDigit(string str)
        {
            try
            {
                foreach (char item in str)
                {
                    if (ValidateText.IsNumber(item.ToString()))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return(false);
        }
コード例 #2
0
 private void BtnSave_Click(object sender, EventArgs e)
 {
     if (ValidateText.Text(this.txtPhone.Text))
     {
         if (ValidateText.IsNumber(this.txtPhone.Text))
         {
             string sql;
             if (this.Phone == null)
             {
                 sql = "insert into id_phone values (" + this.Id + ", '" + this.txtPhone.Text + "');";
             }
             else
             {
                 sql = "update id_phone set phone='" + this.txtPhone.Text + "' where id=" + this.Id + " and phone = '" + this.Phone + "';";
             }
             try
             {
                 DataAccess.ExecuteUpdateQuery(sql);
                 MessageBox.Show("Saved!!");
                 if (this.Phone != null)
                 {
                     sql = @"select * from id_phone where id=" + this.Id + ";";
                     this.CI.PopulateData(sql);
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString());
             }
             finally
             {
                 this.Dispose();
             }
         }
         else
         {
             MessageBox.Show("Not a valid Phone no");
         }
     }
 }
コード例 #3
0
        private bool Validation()
        {
            bool flag = false;

            try
            {
                if (ValidateText.Text(this.txtPhone1.Text))
                {
                    if (ValidateText.IsNumber(this.txtPhone1.Text))
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                        MessageBox.Show("Number Cannot contain alphabets", "Warning!!!");
                    }
                }
                if (ValidateText.Text(this.txtPhone2.Text))
                {
                    if (ValidateText.IsNumber(this.txtPhone2.Text))
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                        MessageBox.Show("Number Cannot contain alphabets", "Warning!!!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(flag);
        }
コード例 #4
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            string sql;

            this.FirstName = this.txtFirstName.Text;
            this.LastName  = this.txtLastName.Text;
            this.Email     = this.txtEmail.Text;
            this.phone[0]  = this.txtPhone1.Text;
            this.phone[1]  = this.txtPhone2.Text;
            if (PhoneBook.ValidateText.Text(this.Email) == false)
            {
                this.Email = "-";
            }
            else
            {
                if (PhoneBook.ValidateText.ValidEmail(this.Email))
                {
                }
                else
                {
                    MessageBox.Show("Email is not Valid!");
                    return;
                }
            }
            if (PhoneBook.ValidateText.Text(this.FirstName + this.LastName, this.txtPhone1.Text))
            {
                if (this.Validation())
                {
                    if (this.Id > DataAccess.SearchMaxID())
                    {
                        try
                        {
                            sql = @"insert into contacts values(" + this.Id + ",'" + this.FirstName + " " + this.LastName + "','" + this.Email + "');";
                            DataAccess.ExecuteUpdateQuery(sql);
                            sql = @"insert into id_phone values(" + this.Id + ",'" + this.phone[0] + "');";
                            DataAccess.ExecuteUpdateQuery(sql);
                            if (ValidateText.Text(this.txtPhone2.Text))
                            {
                                sql = @"insert into id_phone values(" + this.Id + ",'" + this.phone[1] + "');";
                                DataAccess.ExecuteUpdateQuery(sql);
                            }
                            DataAccess.ID++;
                            MessageBox.Show("Contact Saved!", "Saved!");
                            this.back();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    else
                    {
                        try
                        {
                            sql = @"update contacts set name='" + this.FirstName + " " + this.LastName + "',email='" + this.Email + "'where id=" + this.Id + ";";
                            DataAccess.ExecuteUpdateQuery(sql);
                            sql = @"update id_phone set phone='" + this.phone[0] + "' where id = " + this.Id + " and phone='" + this.OldNumbers[0] + "';";
                            DataAccess.ExecuteUpdateQuery(sql);
                            if (ValidateText.Text(this.txtPhone2.Text))
                            {
                                if (this.OldNumbers[1] == null)
                                {
                                    sql = @"insert into id_phone values(" + this.Id + ",'" + this.phone[1] + "');";
                                    DataAccess.ExecuteUpdateQuery(sql);
                                }
                                else
                                {
                                    sql = @"update id_phone set phone='" + this.phone[1] + "' where id = " + this.Id + " and phone='" + this.OldNumbers[1] + "';";
                                    DataAccess.ExecuteUpdateQuery(sql);
                                }
                            }
                            DataAccess.ID++;
                            MessageBox.Show("Contact Updated!", "Updated!");
                            this.back();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("You might have missed the name or phone box.\nWould you mind, checking the name or phone box, please?\nYou have to insert your name and at least one phone number.", "Warning!!");
            }
        }