Tuesday 19 September 2017

Ionic 3 Login Screen and Validations


Login Screen with validations


In this article, we will discuss Ionic3 and angular 2 validations. How we can display validation messages.

Let's create a new login page in the application. You can either add all the pages (.ts .html and .scss file manually) or you can create by running the command mention below.

ionic generate page Login.

it will automatically add a page in your application as shown in below snapshot.



Login.ts


1) Open Login.ts file and import form builder, form group and validators

import { FormBuilder, FormGroup, Validators } from '@angular/forms';



2) In Constructor, add form builder as a parameter as shown in below snapshot.
3) Declare account as any object and add 2 properties "email" and "password"
4) For Email, compose validators (Required and Email type) as shown below.


 export class LoginPage {
  account:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public alertCtrl: AlertController, formBuilder: FormBuilder) {

   this.account = formBuilder.group({   
   email: ['', Validators.compose([Validators.required,Validators.email])],     
   password: ['',Validators.compose([Validators.required,Validators.maxLength(5)])]
    }); 
  }
 }



5) For Password, we have set required and max length 5.


Construct HTML Form


1) Open Login.html file, pass account model in formGroup
2) formControlName to textbox
3) [class.invalid], if you want to give a red border on validation. This is custom class mention below
4) With the help of hasError property, you can check the exact error.
5) Disable login button, if page is not valid [disabled]="!account.valid"


account.controls.email.hasError('required') 
account.controls.email.hasError('email') 
account.controls.email.hasError('maxlength') 
account.controls.email.hasError('minlength') 
account.controls.email.hasError('pattern') 


<form  [formGroup]="account" (submit)="doLogin()">
    <ion-list>
      <ion-item>
        <ion-label floating>Email</ion-label>
        <ion-input type="text" formControlName="email"      
        [class.invalid]="!account.controls.email.valid  && account.controls.email.dirty">   
       </ion-input>      
      </ion-item>
     
    <p class="errorMessage" *ngIf="!account.controls.email.hasError('required')          && account.controls.email.hasError('email')  && account.controls.email.dirty)">
    Please enter a valid email.
    </p>

    <p class="errorMessage" *ngIf="account.controls.email.hasError('required') 
    && (account.controls.email.dirty )">Please enter email
    </p>     
  
   <ion-item>
    <ion-label floating>Password</ion-label>
    <ion-input type="password" formControlName="password"                 [class.invalid]="!account.controls.password.valid && account.controls.password.dirty">
    </ion-input>
   </ion-item>
   
  <p class="errorMessage" *ngIf="!account.controls.password.hasError('required')       && account.controls.password.hasError('maxlength') 
    && (account.controls.password.dirty)">Max length should be 5.
   </p>
    
    <p class="errorMessage" *ngIf="account.controls.password.hasError('required')       && (account.controls.password.dirty)">
    Please enter password
    </p>     
  
    <div padding>
        <button ion-button color="dark" block type="submit"  [disabled]="!account.valid">Login</button>
    </div>
    </ion-list>
  </form>


Styling the Form


1) Open Login.scss file.

page-login {
    .invalid {
    border-bottom: 1px solid #FF6153;
    }
    .errorMessage
    {
        color: red;
        font-size: 10px;
        margin-left: 20px;
    }
}



Submit Button Functionality


Login button functionality, I've checked with static email and password.
If both are matched then redirect to Next Page otherwise show an alert message.
Open Login.ts file and paste the below method in it.

doLogin() {     
      if(this.account.value.email =="test@gmail.com" && this.account.value.password=="test")
        {
           this.navCtrl.push(TabsPage);
        }
       else{
          let alert = this.alertCtrl.create({
            title: 'Message',
            subTitle:'Invalid Login',
            buttons: ['OK']
          });
          alert.present();
          }
   }



For alert, you need to import Alert Controller on top of the page.
For navigation, we need the Nav Controller.

import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AlertController } from 'ionic-angular';


We've already passed the alert and navigation controller in constructor as shown in first snapshot.


The Output would be like below screenshot.




Button will be enabled only, if we will input valid text in the textbox.

That's all about the article. Thanks for reading. If you have any question related to this article. you can mention in comments box below.


Friday 9 June 2017

SSRS - Switch Statement

Problem: Display month (1,2,3 to January, February and March)

Right click on the expression, it will open popup and paste the below expression there.
In below expression, MonthNumber is the column name, if column value is 1 then change to January and so on with the help of switch statement.

=switch(
Fields!MonthNumber.Value=1,"January",
Fields!MonthNumber.Value=2,"February",
Fields!MonthNumber.Value=3,"March",
Fields!MonthNumber.Value=4,"April",
Fields!MonthNumber.Value=5,"May",
Fields!MonthNumber.Value=6,"June",
Fields!MonthNumber.Value=7,"July",
Fields!MonthNumber.Value=8,"August",
Fields!MonthNumber.Value=9,"September",
Fields!MonthNumber.Value=10,"October",
Fields!MonthNumber.Value=11,"November",
Fields!MonthNumber.Value=12,"December"
)



Thursday 11 May 2017

SSRS - The report definition has an invalid target namespace Error

This error normally occurred when you created a report on one SQL version and deploying/opening on another SQL version.

I've created my SSRS report on SQL 2016 and I'm trying to open it on SQL 2014 Report Builder. I'm getting below error.

The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition' which cannot be upgraded.


The solution of this problem is, just open the report in XML format and changed the following lines.





<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition">


to 


<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">



 Just change 2016 version as shown above and remove below lines


Search "ReportParametersLayout" in the code and remove the whole block. This code is only for SQL 2016.

 <ReportParametersLayout>
    <GridLayoutDefinition>
      <NumberOfColumns>2</NumberOfColumns>
      <NumberOfRows>2</NumberOfRows>
      <CellDefinitions>
        <CellDefinition>
          <ColumnIndex>0</ColumnIndex>
          <RowIndex>0</RowIndex>
          <ParameterName>EndDate</ParameterName>
        </CellDefinition>
        <CellDefinition>
          <ColumnIndex>1</ColumnIndex>
          <RowIndex>0</RowIndex>
          <ParameterName>EntityId</ParameterName>
        </CellDefinition>
        <CellDefinition>
          <ColumnIndex>0</ColumnIndex>
          <RowIndex>1</RowIndex>
          <ParameterName>StartDate</ParameterName>
        </CellDefinition>
      </CellDefinitions>
    </GridLayoutDefinition>
  </ReportParametersLayout>

After then, you can see your report will open properly in SQL 2014

Wednesday 10 May 2017

SSRS - Remove decimals If result is whole number


Remove decimals If value is whole number.

Example: If value is 28.00 then report should show 28 and If value is 28.25 then report should show 28.25

How we can achieve this.

Add expression in this report and add below lines.


=Replace(Round(Fields!HourPerWeek.Value,2),".00","")

or

=CDec(Replace(Fields!HoursPerWeek.Value,".00",""))

Thursday 20 April 2017

Copy data from one sheet to another conditionally in Excel VBA



In my excel sheet, I've 2 sheets.

1. Name as "Master Sheet"
2. Q1

In this article we will copy only those rows to sheet "Q1" where Quarter column contains text Q1.
So to copy those rows

Follow the below steps.

1. Open your excel file.
2. Press Alt + F11 to open VBA Editor
3. Insert the module as shown in snapshot below



 

4. Create the function in the module.


Sub Quarter()
   
    Dim xRg As Range
    Dim xCell As Range
    Dim i As Long
    Dim Q1Count As Long
   
    i = Worksheets("Master Sheet").UsedRange.Rows.Count
    Q1Count = 1
   
    Set xRg = Worksheets("Master Sheet").Range("D1:D" & i)
    On Error Resume Next
    Application.ScreenUpdating = False
    For Each xCell In xRg
   
        If CStr(xCell.Value) = "Q1" Then
            xCell.EntireRow.Copy Destination:=Worksheets("Q1").Range("A" & Q1Count + 1)
            Q1Count = Q1Count + 1
        End If
     
    Next
    Application.ScreenUpdating = True
   
End Sub


In this function I've implemented foreach, If cell contains text Q1, then that row will be copied to Destination file.

5.  Save the file as macro enabled workbook. (save as .xlsm format)
6. Press F5 to run the function.


If you want your rows to copy automatically when you press Ctrl + S then implement below code in workbook file. Make sure you are not writing this code on Module.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 
  Quarter
End Sub



Once you press save or Ctrl + S, your rows will copy automatically.


If you want your rows to copy automatically when you change anything in excel then implement below code.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Quarter
End Sub


If you want your rows to copy on button click then add button on your excel file.

To add the button, go to Developer menu, Press Insert and select button from Form controls as shown in snapshot below and draw rectangle on page where you want button.




   You can see button in below snapshot.



You can change the button text by pressing right click on the button and you can also give the button Ids as well.
Now we need to add click event of button.

Implement below code in workbook file. Make sure you are not writing this code in Module file.

Private Sub Button2_Click()
  Quarter
End Sub


Once you press button, it will copy the excel file rows to sheet Q1.


If you want to delete all the content of sheet Q1 before copy anything then call below method before calling Quarter method.


Sub DeleteRecords()
      Sheets("Q1").Cells.Delete    
End Sub

This method will delete all the content of sheet Q1.


That's all about the copy and paste. If you have any question you can write on the blog.

How to find the reason of HTTP Error 500.30 - ASP.NET Core app failed to start in Azure App Service

HTTP Error 500.30 - The ASP.NET Core app failed to start If your web app is throwing an error HTTP error 500.30 then how to find the root ca...