Full Trust European Hosting

BLOG about Full Trust Hosting and Its Technology - Dedicated to European Windows Hosting Customer

AngularJS Hosting Europe - HostForLIFE :: Angular - Reactive Forms

clock September 8, 2021 08:32 by author Peter

Angular provides two approaches,
    Reactive-driven forms  
    Template-driven forms

Understanding the difference between template and reactive forms
    Template driven forms are asynchronous while, reactive forms are synchronous
    In the Reactive driven approach, most of the logic is from the components whereas, in the template-driven approach most of the logic resides in the template.

When to use template-driven approach
    When no complex validations are required in the form.
    When you migrate from angular js to angular 2+, it’s easier to consider this approach

When to use reactive driven approach
When form, becomes the key part of the app we must use a reactive-driven approach as it is predictable, reusable, testable.
How to build a reactive form in 4 steps

We need to import ReactiveFormMoudle in the root folder,
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }


Create form module in the component using - FormGroup, FormControl, and  FormArrays

In the reactive form, we will use FormGroup, FormControl, FormArray as they are the building block of an angular form.

First, let us try to understand what does those terminology means in simple words
     FormControl - It is a class that is used to get and set the value and validate the form control.
     FormGroup and FormArray - It represents the collections of form controls.

Now we need to go to app.compotents.ts and import FormGroup, FormControl & validator from the @angular/forms
import { FormGroup, FormControl, Validators } from '@angular/forms'

The next step is to create a FormGroup and Add FormControl inside the FormGroup.
schoolForm = new FormGroup({})

As you can see, we have an instance for form group and named it as schoolForm.

Under the schoolForm, we have three formControl instances representing the properties' first name, last name, country.
schoolForm = new FormGroup({
  firstname: new FormControl(),
  lastname: new FormControl(),
  country: new FormControl()
})


Building of HTML form
You would have noticed that we have enclosed it in a <form> and included three input felids first name, last name, country.
<form [formGroup]=" schoolForm "  (ngSubmit)="onSubmit()">
  <p>
    <label for="firstname">First Name </label>
    <input type="text" id="firstname" name="firstname" formControlName="firstname" >
  </p>
  <p>
    <label for="lastname">Last Name </label>
    <input type="text" id="lastname" name="lastname" formControlName=" lastname " >
  </p>
  <p>
    <label for="country">country </label>
    <input type="text" id=" country " name=" country " formControlName=" country " >
  </p>
  <p>
    <button type="submit">Submit</button>
  </p>
</form>


To connect the model and the template, add the following,
<form [formGroup]="schoolForm">

Next, we need to bind form fields to the FormControl models and use the formControlName directive.
<input type="text" id="firstname" name="firstname" formControlName="firstname" >

Lastly, we have to submit the form
(ngSubmit)="onSubmit()"

We have already got the submit button in our form. The ngSubmit binds itself to the click event of the submit button.

Get data in the Component class

To receive the form data in the component class. We have to create the onSubmit method in the component class.
onSubmit() {
  console.log(this. schoolForm.value);
}


We are using the,
console.log(this.contactForm.value)

To send the value of our form data to the console window.

I hope you understand about forms and how to use the reactive form in angular.



Crystal Report Hosting - HostForLIFE :: Alternate Row Color in Crystal Report

clock August 31, 2021 08:58 by author Peter

Most of the time while developing reports people wonder how to have alternating row colors in the report like below.


There is a cool trick to it.
 

Go to the format section of the Details. Click the Color Tab. Then click the button next to the Background Color CheckBox.

In the formula editor of background color, type the following:



if RecordNumber mod 2 = 0 then crSilver else crNoColor.

Save and close the editor.
 
And now when you run the report you will see alternate colors of silver and white in the details section.



European VB.NET Hosting - HostForLIFE :: Getting an External IP Address Locally using VB.Net

clock August 27, 2021 07:33 by author Peter

This short article shall address the easiest way possible to get your external IP address (and local/internal IP address). There is no particular magic to getting your external IP address; the easiest way I have found is to use the automation service provided by http://whatismyip.com/automation/n09230945.asp, the good folks at whatismyip.com are nice enough to provide a free service to return the external IP address. All that the ask in return is that you do not beat them up with too many requests; they suggest about one every five minutes as being within their comfort zone; however, they also offer to provide additional services upon request so if you need something more than that, give them a call and talk to them about it.

 
Now, if you have a public site and are interested in getting the user's IP address that is really not an issue. You can still just request the REMOTE_ADDR or HTTP_X_FORWARDED_FOR server variable to get that.
 
Code
There is not much code to address in this one. There are three examples to show: the local IP address, the external IP address (for when you might need to see that locally), and the remote IP address.
 
The first example shows how to collect the local IP address; here we use an instance of the IPHostEntry container class to capture the host entry and then we display the first item in the host entry's address list as the local IP address.

    ' Local IP Address (returns your internal IP address)  
    Dim hostName As String = System.Net.Dns.GetHostName()  
    Dim myIPs As IPHostEntry = Dns.GetHostEntry(hostName)  
    Response.Write("<em>Your Local IP Address is:  " & myIPs.AddressList(0).ToString() & "</em><br />")  
 

The next example uses the whatismyip.com automation service to capture the external IP address locally. This value is displayed as the external IP address. If you just need to find out your external IP address, you can use a browser to navigate to the whatismyip.com website and you will see your external IP address displayed on the page; alternatively, you can use another service such as IPChicken.com to perform the same function. If you want to pro-grammatically capture the external IP address locally, this code will do the job.

    ' External IP Address (get your external IP locally)  
    Dim utf8 As New UTF8Encoding()  
    Dim webClient As New WebClient()  
    Dim externalIp As String = _     utf8.GetString(webClient.DownloadData("http://whatismyip.com/automation/n09230945.asp"))  
    Response.Write("<h2>Your External IP Address is: " & externalIp & _  
    "</h2><br />")  

If you are working from a public website and you want to capture the user's IP address; the following code will do the job.
    ' Remote IP Address (useful for getting user's IP from public site; run locally it just returns localhost)  
    Dim remoteIpAddress As String = Request.ServerVariables("HTTP_X_FORWARDED_FOR")  
    If (String.IsNullOrEmpty(remoteIpAddress)) Then  
    remoteIpAddress = Request.ServerVariables("REMOTE_ADDR")  
    End If  
    Response.Write("<em>Your Remote IP Address is:  " + remoteIpAddress + "</em><br />")  

 
This article was intended to show some simple ways to capture IP address information under different circumstances. The three examples show demonstrate how to capture the local IP address, how to capture the external IP address locally, and how to capture the user's IP address from a public website.



Crystal Report Hosting - HostForLIFE :: How to Print a Crystal Report Programmatically in ASP.NET?

clock August 6, 2021 08:42 by author Peter

You can print a Crystal Report using the print option of Crystal Report Viewer. However, there are occasions when you want your application to print a report directly to the printer without viewing the report in Crystal Report Viewer.
 

The ReportDocument class provides PrintToPrinter method that may be used to print a CR direct to the printer. If no printer is selected, the default printer will be used to send the printing pages to.
 
The PrintToPrinter method takes four parameters.
 
nCopies : Indicates the number of copies to print.
collated : Indicates whether to collate the pages.
startPageN : Indicates the first page to print.
endPageN : Indicates the last page to print.
 
The following steps will guide you to achieve the same:
    Add a crystal report (.cr) file to your ASP.NET application.
    Add a report instance on the page level.
        Dim report As MyReport = New MyReport

    Populate reports data on Page_Init
        ' Get data in a DataSet or DataTable  
          
        Dim ds As DataSet = GetData()  
        ' Fill report with the data  
        report.SetDataSource(ds)

    Print Report
        report.PrintToPrinter(1, False, 0, 0)


If you wish to print a certain page range, change the last two parameters From To page number.
 
If you want to set page margins, you need to create a PageMargin object and set PrintOptions of the ReportDocument.
 
The following code sets page margins and printer name:
    Dim margins As PageMargins =  Report.PrintOptions.PageMargins  
       margins.bottomMargin = 200  
       margins.leftMargin = 200  
       margins.rightMargin = 50  
       margins.topMargin = 100  
       Report.PrintOptions.ApplyPageMargins(margins)  
       
       ' Select the printer name  
       Report.PrintOptions.PrinterName = printerName



Ajax Hosting UK - HostForLIFE :: Render API Using AJAX Call

clock August 3, 2021 07:57 by author Peter

In this article, we will discuss how to invoke API using the AJAX call. We use the AJAX call because it allows the user to update a web page without reloading the page, request data from a server after the page has loaded, receive data from a server after the page has loaded, and send the data to a server in the background.

 
The below HTTP verb is used to call a particular Web API call. Here is the mapping sequence.
    POST - Create
    GET - Read
    PUT - Update
    DELETE - delete

    var person = new Object();    
    person.name = $('#name').val();    
    person.surname = $('#surname').val();    
    $.ajax({    
        url: 'http://localhost:3413/api/person',    
        type: 'POST',    
        dataType: 'json',    
        data: person,    
        success: function (data, textStatus, xhr) {    
            console.log(data);    
        },    
        error: function (xhr, textStatus, errorThrown) {    
            console.log('Error in Operation');    
        }    
    });  


In the above code, we pass the person data to the API using the Post method.
 
You can call the API using the above code for different uses, like Delete record, Update record, and Get records using Get, Put, and Delete type keywords.

HostForLIFE.eu AJAX Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

 



AngularJS Hosting Europe - HostForLIFE :: Containerize An Angular Application

clock July 30, 2021 05:44 by author Peter

In this article, we are going to build an angular application using docker and host the production-ready environment in an NGINX container.


Let’s create an angular application.

Before creating an angular application, ensure that you have installed NodeJS and Angular CLI installed into your development environment.

Once the prerequisite is installed start executing the following command for creating an angular application.
ng new sample-app

Navigate to the project directory,
cd sample-app

Run the application by using the below command.
ng serve

Now your angular application starts running,

Let’s create a docker file and dockerizing the angular application.

Creating a Docker File

Docker file consists of the following stages,

    Building the Angular application into production-ready
    Serving the application using the NGINX server.

Let's discuss both the stages in detail and the command which we are going to use while creating a docker file.

Stage 1

FROM
Initializes a build stage, and gets the latest node image from the DOCKERHUB Registry as the base image from executing the instruction related to the angular application configuration. The stage is named build, which helps to reference this stage in the Nginx configuration stage.

WORKDIR
Sets the default directory in which instructions are executed, If the path is not found the directory will be created, In the above code path of usr/local/app is the directory where angular source code move into.

COPY
It copies the project source files from the project root directory into the host environment into the specified directory path on the container subsystem.

RUN
It compiles our application.

Stage 2
FROM

Initializes a build stage, and gets the latest Nginx image from the DOCKERHUB Registry as the base image from executing the instruction related to the Nginx configuration.

COPY
It copies the build output which is generated in STAGE 1(-FROM=build used to replace the default Nginx configuration).

EXPOSE

It informs the docker that the Nginx container listens on port 80, So exposing the specific port.

Docker File
# STAGE 1: Compile and Build angular application
#Using official node image as the base image
FROM node: latest as build
# Setting up the working directory
WORKDIR / usr / local / app
# Add the Source code to app
COPY. / /usr/local / app / # Install all dependencies
RUN npm install
# Generate the Build of the angular application
RUN npm run build
# STAGE 2: Serving the application using NGINX server
# Using official nginx image as the base image
FROM nginx: latest
# Copy compiled file from build stage
COPY– from = build / usr / local / app / dist / sample - app / usr / share / nginx / html
# Expose Port 80
EXPOSE 80

Let's RUN the DOCKER CONTAINER,

In order to run the docker container, open up the terminal or command prompt and navigate to the docker file into your project directory.
docker build -t sample-app:latest

Once the build is successful, execute the following command.
Docker image ls

The above command will list all images which are installed in our docker container.
Let’s run the image,
Docker run -d -p 8080:80 sample-app:latest

Here I am using -d its helps to detach the container and have it run in the background and the -p argument is used for port mapping which is port 80 of the docker container (as mentioned in the docker file), should expose port 8080 of the host machine.
docker ps

The above command displays the details of our running container.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13e5642e4s29 gurp13/sample-app:latest "/docker-entrypoint.…" 10 seconds ago Up 10 seconds 0.0.0.0:8080->80/tcp reen_khayyam

Now we can see that the container is up and running. Try to open localhost:8080, you can see your application running.

Application is running and working as expected now we can push out the image to an image repository, which helps to deploy our container to a cloud service, for that you need to create an account on the Docker hub.

Once you created an account on docker hub run the following command,
docker login -u <username> -p <password>
docker push sample-app:latest
    
Your image is successfully pushed to the Docker hub registry.



Europe SQL Hosting - HostForLIFEASP.NET :: Master Slave System Design

clock July 29, 2021 08:57 by author Peter

Master-Slave database design is usually designed to replicate to one or more database servers. In this scenario, we have a master/slave relationship between the original database and the copies of databases.

A master database only supports the write operations and the slave database only supports read operations. Basically, the master database will handle the insert, delete and update commands whereas the slave databases will handle the select command. 

The below image shows a master database with multiple slave databases.

 

 

Advantages of Master/Slave Design

    Availability
    We have replicated the master data across multiple locations. So in case, a slave database goes offline, then we have other slave databases to handle the read operations.

    Performance
    As the master/slave model has multiple slave database servers, more queries can be processed in parallel.

    Failover alleviating
    We can set up a master and a slave (or several slaves), and then write a script that monitors the master to check whether it is up. Then instruct our applications and the slaves to change master in case of failure.

Problem with Master/Slave Design


One of the major problems with this design is that if a user has changed his/her profile username. This request will go into the master database. It takes some time to replicate the change in the slave databases. In case the customer refreshes the profile, he/she will still see the old data because the changes have not yet synced from the Master to Slave.



Europe SQL Hosting - HostForLIFEASP.NET :: Add DBCC INPUTBUFFER to Your Performance Tuning Toolbox

clock July 15, 2021 08:09 by author Peter

A command I like to use when performance tuning is DBCC INPUTBUFFER. If you have ever run sp_whoisactive or sp_who2 to find out what sessions are executing when CPU is high for instance this can be a real quick lifesaver. At times, for me, those two options do not return enough information for what I’m looking for which is the associated stored procedure or object. Using this little helper along with the session id can easily get you that information.


Let’s take a look.

First, I will create a simple procedure to generate a workload.
CREATE OR ALTER PROCEDURE KeepRunning
AS
DECLARE @i INT=1
WHILE (@i <1000)
BEGIN
select @@servername
WAITFOR DELAY '00:00:30'
select @i=@i+1
END

Now I will execute the procedure and capture what it looks like using the first sp_who2 and then sp_whoisactive. Looking at the Sp_who2 screenshot all you can see is the session information including command and status that is being run but have no idea from what procedure it is being run from.

Exec KeepRunning

Now take it a step further and let’s run sp_whoisactive. Here we get more information such as the sql_text being run.

Take note of the session id, displayed with either tool, which in this case is 93. Now run DBCC INPUTBUFFER for that session.
DBCC INPUTBUFFER (93)

BINGO! We’ve now got what we needed which is the name of the store procedure that the statement is associated with.

Now let’s try one last thing. Remember I said sp_whoisactive does not give us the store procedure name, well that wasn’t 100% true. There are fantastic parameter options we can use that can get us even more information. Let’s run sp_whoisactive using the parameter @get_outer_command = 1. As shown in the screenshot you can see here is essentially the same thing as DBCC INPUTBUFFER giving you the sql_command i.e. the store procedure name.

Quickly knowing the stored procedure associated with the query that is causing issues allows us to easily follow the breadcrumbs to identify the root cause of an issue. If you cannot run third-party or community tools like sp_whoisactive, dbcc inputbuffer is an alternative for you. Therefore, I wanted to introduce DBCC INPUTBUFFER. Adding this little tidbit to your performance tuning toolbox can be a real-time saver,, you may have other useful ways to use it as well. Be sure to have a look.

 



AngularJS Hosting Europe - HostForLIFE.eu :: Custom Attribute Directive In Angular

clock July 6, 2021 07:14 by author Peter

In this article, we will learn about custom attribute directives in Angular. In this article, we will create some custom attributes directive and use in our components.
What is a directive?

Directives are classes that add additional behavior to elements in your Angular applications. With Angular's built-in directives, you can manage forms, lists, styles, and what users see.

The different types of Angular directives are as follows,
    Components - directives with a template. This type of directive is the most common directive type.
    Attribute directives - directives that change the appearance or behavior of an element, component, or another directive.
    Structural directives - directives that change the DOM layout by adding and removing DOM elements.

Create a new Angular project

Step 1
Open your folder where you want to save your project in Visual Studio Code or Command Prompt.

Step 2

Run the below command to create a new project. In this process, you will be asked some questions like add routing in your project and style sheet format, etc. You can add as per your requirements.
ng new custom-directives

JavaScript

As you see below, our project is created.Custom Attribute Directive In Angular
In this article, we will learn about custom attribute directives in Angular. In this article, we will create some custom attributes directive and use in our components.
What is a directive?

Directives are classes that add additional behavior to elements in your Angular applications. With Angular's built-in directives, you can manage forms, lists, styles, and what users see.

The different types of Angular directives are as follows,
    Components - directives with a template. This type of directive is the most common directive type.
    Attribute directives - directives that change the appearance or behavior of an element, component, or another directive.
    Structural directives - directives that change the DOM layout by adding and removing DOM elements.

Create a new Angular project

Step 1
Open your folder where you want to save your project in Visual Studio Code or Command Prompt.

Step 2
Run the below command to create a new project. In this process, you will be asked some questions like add routing in your project and style sheet format, etc. You can add as per your requirements.

ng new custom-directives

JavaScript
As you see below, our project is created.

Step 3
As you now open your app component you see a lot of code so we remove all the code and just add a simple h1 tag as you see below code.
<h1>This is Custom Attribute Directive Project</h1>

Markup

Step 4
Now run your project by a simple move to your project directory and then run the below command,
ng serve

JavaScript
After successfully running your project, you can see the output as below.



Built in Attributes Directives
Attribute directives listen to and modify the behavior of other HTML elements, attributes, properties, and components.

The most common attribute directives are as follows,
    NgClass - adds and removes a set of CSS classes.
    NgStyle - adds and removes a set of HTML styles.
    NgModel - adds two-way data binding to an HTML form element.

Create custom attributes directive

Step 1
Create a new folder in your project’s app folder called directives to simplify project structure.

Step 2
Run the below command to create a new custom attribute directive. Here error is the name of our directive and directives is a folder name that we create.
ng g directive directives/error

JavaScript
After executing the above command, it will generate the following two files.

And it also adds our directive in-app module file’s declaration section.

Step 3
Now we implement logic in this directive that if the user uses this directive in any element, the element color will become red. For that add the below code in your file.
import { Directive, ElementRef } from '@angular/core';


@Directive({
  selector: '[appError]'
})

export class ErrorDirective {
  constructor(el:ElementRef) {
    el.nativeElement.style.color="red";
   }
}

Explanation
    In the above code first, we add the ElementRef type parameter in the constructor. It will get that element on which we use our custom attribute directive
    Then by using this el parameter we change color from style to red.

Implement custom attributes directive in our components

To add our custom attribute directive we need to add attributes In our element. As you see in your directive file you see a selector in our case our selector name is appError, by using appError in our element we can change the style.

Add this attribute in your element as shown below image,

Now refresh your page in the browser and you can see out like below image,

So as you see that we can create custom attribute directives easily. You can implement it as your requirement. In the future, we will create some other custom directives that will be useful in our day-to-day projects. If you like this article kindly share it with your friends and if you have any doubt let me know in the comments.



Europe SQL Hosting - HostForLIFEASP.NET :: How To Update Tables With Joins In SQL?

clock June 30, 2021 08:53 by author Peter

In this blog, we will see how to update tables with joins in SQL.

When we are dealing with the data we need to store that data in the database like MySQL, Oracle, etc. In daily practice, we need to create tables, and account for alterations that may be lead us to update the table's data.

We can use iteration While loop or a Cursor for the same purpose but in this blog, we will be updating tables with joins in SQL.

Let's start.
First of all, we need a database (example: TestingDatabase) with two tables (example: Countries and second one States) schema as shown below,

Table: Countries 

Table: States

Now we have two tables with a common countries id column, we added a column named Countrysortname in the states table using an alter command,
ALTER TABLE STATES ADD countrysortname NVARCHAR(5)

SQL

We can apply inner join on country_id.
Table schema after adding a column.

Table: States

Now, we are ready to update the table States using INNER JOIN.

We need to write a select command first to verify what we are going to update as shown below,

Syntax
SELECT [L.column_name],
               [R.column_name]
FROM   table_name1 L
       JOIN table_name2 R
         ON L.column_name = R.column_name

UPDATE L
SET    [L.Column_name] = [R.Column_name]
FROM   table_name1 L
       JOIN table_name2 R
                    ON L.column_name = R.column_name

Example

SELECT ct.id,ct.name,ct.sortname,st.id,  st.countrysortname
FROM   states st
INNER JOIN countries ct
ON ct.id = st.country_id

Update Command

UPDATE st
SET    st.countrysortname = ct.sortname
FROM   states st
INNER JOIN countries ct
ON ct.id = st.country_id

With Subquery

SELECT l.id,
       r.id,
       l.countrysortname,
       r.sortname

FROM   states l
       INNER JOIN (SELECT st.id,
                          ct.sortname
                   FROM   states st
                          INNER JOIN countries ct
                                  ON ct.id = st.country_id)r ON l.id = r.id


Update Command


UPDATE l
SET    l.countrysortname = r.sortname
FROM   states l
       INNER JOIN (SELECT st.id,
                          ct.sortname
                   FROM   states st
                          INNER JOIN countries ct
                                  ON ct.id = st.country_id)r
               ON l.id = r.id
WHERE  l.id = r.id


Hope this will help you.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Tag cloud

Sign in