Exemple #1
0
        public CustomerData getCustomerDetails(String customerID)
        {
            CustomerData customerData = new CustomerData();

            try
            {
                String query = "SELECT * from customer where ID = '" + customerID + "'";
                conn = new SqlConnection(connectionString);
                SqlCommand comm = new SqlCommand(query, conn);
                conn.Open();
                reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    customerData.setFirstName(reader.GetString(1));
                    customerData.setLastName(reader.GetString(2));
                    customerData.setAddress(reader.GetString(3));
                    customerData.setEmail(reader.GetString(4));
                    customerData.setMobileNumer(reader.GetInt32(5));
                    customerData.setFixedNumber(reader.GetInt32(6));
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(customerData);
        }
Exemple #2
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(addressLine3) || val.isEmpty(email) || val.isEmpty(mobileNumber.ToString()) || val.isEmpty(FixedLine.ToString()))
            {
                await this.ShowMessageAsync("Error", "Input Data Cannot Be Empty", MessageDialogStyle.Affirmative);
            }
            else if (val.isNumeric(mobileNumber.ToString()) || val.isNumeric(FixedLine.ToString()))
            {
                await this.ShowMessageAsync("Error", "Contact Numbers Should Be Numeric", MessageDialogStyle.Affirmative);
            }
            else
            {
                int affectedLines = 0;
                customerData = new CustomerData();

                customerData.setFirstName(firstName);
                customerData.setLastName(lastName);
                customerData.setAddress(addressLine1, addressLine2, addressLine3);
                customerData.setEmail(email);
                customerData.setMobileNumer(mobileNumber);
                customerData.setFixedNumber(fixedNumber);

                try
                {
                    handleDatabase = new HandleDatabase();
                    affectedLines  = handleDatabase.executeCustomerEntry(customerData);

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

                        FirstName.Text = "";
                        LastName.Text  = "";
                        Address1.Text  = "";
                        Address2.Text  = "";
                        Address3.Text  = "";
                        Email.Text     = "";
                        FixedLine.Text = "";
                        Mobile.Text    = "";
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "Sorry Can not Create the Profile, Please Try again", MessageDialogStyle.Affirmative);
                    }
                }
                catch (SqlException sqlException)
                {
                    Console.WriteLine(sqlException);
                }
            }
        }
        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(addressLine3) || val.isEmpty(email) || val.isEmpty(mobileContact.ToString()) || val.isEmpty(homeContact.ToString()))
            {
                await this.ShowMessageAsync("Error", "Input Data Cannot Be Empty", MessageDialogStyle.Affirmative);
            }
            else
            {
                int affectedLines = 0;
                customer = new CustomerData();

                customer.setFirstName(FirstName.Text);
                customer.setLastName(LastName.Text);
                customer.setAddress(Address1.Text + ' ' + Address2.Text + ' ' + Address3.Text);
                customer.setEmail(Email.Text);
                customer.setMobileNumer(Convert.ToInt32(MobileContact.Text));
                customer.setFixedNumber(Convert.ToInt32(HomeContact.Text));
                try
                {
                    handleDatabase = new HandleDatabase();
                    affectedLines  = handleDatabase.executeCustomerUpdate(customer, customerID);

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

                        ViewCustomers view = new ViewCustomers();
                        view.Show();
                        this.Close();
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "Sorry Can not Update, Please Try again", MessageDialogStyle.Affirmative);

                        ViewCustomers view = new ViewCustomers();
                        view.Show();
                        this.Close();
                    }
                }
                catch (SqlException sqlException)
                {
                    Console.WriteLine(sqlException);
                }
            }
        }