Tuesday, 8 August 2017

How to use data-balloon in angular 2?

Today we are going to discuss that how to use data-balloon in the angular 2/4 application. You must know that why we are using data-balloon in our application and what kind of features it is going to provide to us. For this click on this link and check out its features

It is easy to use in simple HTML application, but we have a problem to use this in the angular 2/4 application. In the angular 2/4 we can't use this as it is as shown in the above article. For this, we need to create a directive and use that under our application. I am going to explain, how to create directive and how to use this in the application.
Step by step information:

1. Create a new TS file or use an existing file to create the directive and copy the below code. In this code, you will find that we are going to set only two properties as dynamic, following the same method you can add other properties and make it more styling.
// This directive is to use to add the hover message using data-balloon
@Directive({
selector: '[dataBalloon]'
})
export class DataBalloonDirective implements OnChanges {
@Input('databalloonProperty') tooltipText: any;
@Input('databalloonpos') position: any;
constructor(private el: ElementRef) {
}
ngOnChanges(changes) {
if (this.tooltipText) {
$(this.el.nativeElement).attr({
"data-balloon": this.tooltipText,
"data-balloon-pos": this.position,
"data-balloon-length":"fit"
});
}
}
}
2. Add that directive in your app-common module or on your page where you want to use this. 
3.  <span class="text-capitalize"  
dataBalloon databalloonProperty="{{username}}" databalloonpos="up"> 



4.Run the application and check the results. 


Enjoy it !!!!

Saturday, 1 October 2016

Compare Id from a Comma separated value in Sql Server

I have a column in which UserIds are stored in a comma separated form (as shown below). Now I have a problem that I need to check whether the current user is available in that list or not. 

I was using split function for this but that was taking too much time. As we need to perform this action on millions of records and table is having 20 other columns which we need to returns. 

Id     UserId 
--  ---------------
1    10,11,12,13    
2    10,13,15,4 

I was using split function for this but that was taking too much time. As we need to perform this action on millions of records and table is having 20 other columns which we need to returns.

Then I found the below solution of my problem. 

SELECT * FROM dbo.History 
WHERE (','+ RTRIM(ShareWith)+',') LIKE '%,'+CAST(@UserId AS VARCHAR)+',%')



Wednesday, 13 April 2016

Another Form of Ternary Operator In AngularJS

Once I was working on an AngularJS application. I have a requirement that under ng-repeat I need one object value with comma separated but ‘.’ in last. We can achieve this with the help of ternary operator very easily, but I found something different. This is like 

{{ !$last && ', ' || '.'}}


The above solution resolved the problem also, but the interesting thing is that who it is working. It creates a confusion in my mind. Now I started to find out the best answer for this. In-order to this I created a question on stackoverflow and got many answers all are same. Every explain that it is working as a Ternary operator. 

The best answer that I found is as given below.


It is a form of ternary operator. && returns first operand if it is a falsy value and second operand if first operand is truthy e.g. 1 && 3 will return 3 but 0 && 3 will return 0. Second operator is not evaluated if first is falsy. || is similar but returns first operand if it is truthy and second operand if first is falsy.


So basically cond && val1 || val2 is equivalend to cond ? val1 : val2 under condition that val1 is truthy value. If this is not the case e.g. cond && 0 || 1 this will always return last value 1 in this case.
For readability reasons you should always prefer ternary operator ?: than Boolean shortcircuting operators.

Saturday, 28 November 2015

Could not load file or assembly 'Telerik.Reporting, Version=9.2.15.1105, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies.

I am working on Telerik Reports. The application is working fine on local system or in debugging mode, but it gives an error (Could not load file or assembly 'Telerik.Reporting, Version=9.2.15.1105, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies) when I am trying to deploy the application. In order to resolve this issue we just need to copy the specified dll from "C:\Program Files (x86)\Telerik\Reporting Q3 2015\Bin". 

Follow the below steps and see how I resolved this error.

Step 1: Deploy the application on the server where you want to deploy. 

Step 2: Open server using any of the FTP tool and upload an error showing dll from location "C:\Program Files (x86)\Telerik\Reporting Q3 2015\Bin" under bin folder of the deployed application. 


PS: Every time when you will update the Telerik Reporting tool and deploying your application again then you will face the same error, because of version change. This time you need to follow the same steps and upload the latest file.

Tuesday, 22 September 2015

Copy Screens In LightSwitch using XML Editor

I was working on LightSwitch application and came across with an issue to copy screen. Then I tried a way to copy the screen using XML Editor. As LightSwitch screens can be edited in XML only. Here are the steps that we can follow and copy screens easily.  

Step 1: Create a with extension Copy of your screen. (e.g you want to copy Home.lsml screen then create new screen with name HomeCopy.lsml) It does not matter which template you are using. 

Step 2: Open the Home.lsml screen in XML Editor and copy all content. 

Step 3: Use the same way to open the HomeCopy.lsml screen in XML Editor and paste all the content form Home Screen. Then find and replace Home with HomeCopy keyword. 

Step 4: Apply the same way to copy the CS file code for corresponding file. CS file can be open as it is and copy the content from Home.lsml.cs to HomeCopy.lsml.cs and replace the name of all screen methods with HomeCopy. 

Thanks........

Saturday, 11 April 2015

Could not load file or assembly 'C1.Silverlight.5'

While working on the Lightswitch Using C1 component, I was facing an issue that application is running in Debug mode but it was not working in Release mode. Whenever I try to run a lightswitch application in Release mode then I was facing the below issue. 

Could not load file or assembly  'C1.Silverlight.5, VersiĆ³n 5.0.20142.419, Culture=neutral, PublicToken=2aa4ec5576d6c3ce’ or one of its dependencies. The system cannot find the file specified.


After debugging this issue and find the solution from Richa's reply. It is occurring due to the C1 dll files are not loading in release mode in lightswitch. That's why it is giving this error. To resolve this issue please follow the below step.

Open the .csproj file for the desktop client project in notepad and remove the occurrence of the below lines. 

<ExtensionReferenceType>DebugOnly</ExtensionReferenceType>

Now open project in VS and rebuild and run the application.

Wednesday, 4 March 2015

Link server under Server Objects in Sql server

While working on the different applications. Some times we need to link other servers with our local server so that we can execute some queries. We can link any online server with our local sql server or one VPS to another VPS. Even with this we can link Azure Sql server to any one.
Here are the queries which will help us to link the Server. 


EXEC sp_addlinkedserver
@server='NameOfServer',  
@srvproduct='',
@provider='sqlncli',
@datasrc='Server e.g 192.168.1.1,1433',
@location='',
@provstr='',
@catalog='Database Name'

EXEC sp_addlinkedsrvlogin
@rmtsrvname=' NameOfServer ',
@useself='false',
@rmtuser='User Name',
@rmtpassword='Password'

EXEC sp_serveroption ' NameOfServer ', 'Collation Compatible', true;

The above queries will help to link the server and linked server will be showing under Server Object of your sql server.

 

For executing the queries you can use the simple query method, but if your tables having foreign key relation then you have to execute you query as given below. 

declare @sql as nvarchar(max) =  'SET IDENTITY_INSERT info ON ' +
'INSERT into info ([Id], [FirstName], [LastName], [Description], [Note]) VALUES (2, N''Harsh'', N''Gupta'', NULL, N''Test1'') ' +
'SET IDENTITY_INSERT info Off'
EXEC [ServerName].DatabaseName.dbo.sp_executesql @sql
 
We have to create a simple string of all the queries and then we have to execute with the help of sp_executesql on linked server.