Ejemplo n.º 1
0
        private async void saveButton_Click(object sender, RoutedEventArgs e)
        {
            val = new Validation();
            if (val.isEmpty(firstName) || val.isEmpty(lastName) || val.isEmpty(addressLine1) || val.isEmpty(addressLine2) ||
                val.isEmpty(sellingCenter) || val.isEmpty(nic) || val.isEmpty(mobileNumber.ToString()) || val.isEmpty(homeContact.ToString()))
            {
                await this.ShowMessageAsync("Error", "Data Cannot be Empty", MessageDialogStyle.Affirmative);
            }
            else if (val.isNumeric(mobileNumber.ToString()) || val.isNumeric(homeContact.ToString()))
            {
                await this.ShowMessageAsync("Error", "Contact Numbers Should be Numeric", MessageDialogStyle.Affirmative);
            }
            else
            {
                int affectedLines = 0;
                driver.FirstName   = FirstName.Text;
                driver.LastName    = LastName.Text;
                driver.Address     = Address1.Text + ' ' + Address2.Text + ' ' + Address3.Text;
                driver.NIC         = NIC.Text;
                driver.Mobile      = Convert.ToInt32(Mobile.Text);
                driver.HomeContact = Convert.ToInt32(HomeContact.Text);
                driver.SalesCenter = SellingCenter.SelectedValue.ToString();
                try
                {
                    handleDatabase = new HandleDatabase();
                    affectedLines  = handleDatabase.executeDriverEntry(driver);

                    if (affectedLines > 0)
                    {
                        await this.ShowMessageAsync("Successfull", "New Entry have been Successfully Registered", MessageDialogStyle.Affirmative);

                        FirstName.Text   = "";
                        LastName.Text    = "";
                        Address1.Text    = "";
                        Address2.Text    = "";
                        Address3.Text    = "";
                        NIC.Text         = "";
                        Mobile.Text      = "";
                        HomeContact.Text = "";
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "Sorry Can not Proceed, Please Try again", MessageDialogStyle.Affirmative);
                    }
                    clearFields();
                }
                catch (SqlException sqlException)
                {
                    Console.WriteLine(sqlException);
                }
            }
        }