Sunday, September 12, 2010

Charts in Silverlight

hi,
I have been searching for a different types of charts in silverlight .I found a open source control called Visifire that supports WPF and Silverlight with the option of 3D View.
Here is the link to draw the chart control.

http://visifire.codeplex.com/

Wcf Data Service

Hi
I have created a basic WCF Dataservices using ADO.net entity framework in silverlight. When i about to create method and access it i m getting error as bad request,Error in query syntax.

I have created Wcf Dataservice as
public static void InitializeService(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

config.UseVerboseErrors = true;
}

[WebGet]
public string GetUsers(string userId)
{
return "my data";
}

my browser uri is
http://localhost:50449/DataService.svc/GetUsers?userId='1'


And here is the Code from Client:
public void LoadData(string userId)
{
var qry = ctx.CreateQuery("GetUsers").AddQueryOption("UserId", string.Format(@"'{0}'", userId));

qry.BeginExecute(new AsyncCallback(OnLoadComplete), qry);

}
When i execute via browser uri i m getting the result. Not by accessing via method in SL.
I found in SL it adds () in browser URI as like this
http://localhost:50449/DataService.svc/GetUsers()?userId='1'

After a long search we can execute the method as mentioned below which solve me the problem.

ctx.BeginExecute(new Uri(string.Format("{0}GetUsers?UserId={1}", smileEntites.BaseUri, "'1' "), UriKind.RelativeOrAbsolute), OnLoadComplete, null);

void OnLoadComplete(IAsyncResult result)
{

try
{
// Get the results and add them to the collection
IQueryable queryResults = smileEntites.EndExecute(result).AsQueryable();
foreach (var coursw in queryResults)
{
}


}
catch (Exception ex)
{
if (HtmlPage.IsEnabled)
{
HtmlPage.Window.Alert("Failed to retrieve data: " + ex.ToString());
}
}
}

Wednesday, April 21, 2010

Bypassing the Image Cache

Hi,
By default Silverlight will not download an image more than once if is contained within the image cache. That is, as long as the URI remains the same it will reference the image from the cache.
So what if the image changed on the server even though it has the same URI? Your application can force an update by setting the property IgnoreImageCache to true.
Example:
Image img = new Image();

Uri uri = new Uri("http://YourServer.com/MyImage.png", UriKind.Absolute);
BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(uri);
bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
img.Source = bi;
LayoutRoot.Children.Add(img);

Monday, November 30, 2009

Paging in wrapPanel

Here is the paging Functionality in Wrap Panel
I have added Wrap panel using the namespace system.windows.Controls.toolkit as shown in the image



Do not set width on wrap panel. Wrap panel loads image based on main page size changes
I have loaded images from xml and when the main window is resized paging changes based on that

public MainPage()
{
InitializeComponent();
this.SizeChanged += new SizeChangedEventHandler(MainPage_SizeChanged);
webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(new Uri("Application.xml", UriKind.RelativeOrAbsolute));
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}

void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
{
Paging();
}
private void Paging()
{
appHeight = this.ActualHeight;
appWidth = this.ActualWidth;
pageSize = Convert.ToInt32(Math.Floor(((this.ActualHeight) - 216) / 38));
if (pageSize != 0.0)
{
pagecount = Convert.ToInt32(Math.Ceiling(totalSize / pageSize));
PageStackPanel.Children.Clear();
myWrapPanel.Children.Clear();
if (pagecount != 1)
{
for (int i = 0; i <= pagecount; i++) {
HyperlinkButton href = new HyperlinkButton();
href.Content = i + 1;
href.Click += new RoutedEventHandler(href_Click);
PageStackPanel.Children.Add(href);
}
}
}
GetInteractivity(1);
}

void href_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton hf = sender as HyperlinkButton; GetInteractivity(Convert.ToInt32(hf.Content));
}
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try
{
xmlParser = new XMLParser(e.Result);
BindXML(); webClient.OpenReadCompleted -= new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
totalSize = interactivityList.Count; Paging();
GetInteractivity(1);
}
catch (Exception ex) { }
}
private void GetInteractivity(double pgSize)
{
myWrapPanel.Children.Clear();
int startVal = Convert.ToInt32((pgSize - 1) * pageSize);
int endVal = Convert.ToInt32((pgSize) * pageSize);
endVal = endVal > Convert.ToInt32(totalSize) ? Convert.ToInt32(totalSize) : endVal;
for (int i = startVal; i <=endVal;i++)

{
Image img = new Image();
img.Width = 160;
img.Height = 160;
string imgpath = interactivityList[i].imagePath.ToString();
Uri uri = new Uri(imgpath, UriKind.Relative);
ImageSource src = new BitmapImage(uri);
img.Source = src;
img.Tag = interactivityList[i].xapfilePath;
img.MouseLeftButtonDown += new MouseButtonEventHandler(image1_MouseLeftButtonDown);
Rectangle rect = new Rectangle();
rect.Width = 100;
rect.Height = 100;
myWrapPanel.Children.Add(img);
myWrapPanel.Children.Add(rect);
}
}
private void BindXML()
{
List elements = xmlParser.GetElements("Application");
if (elements.Count > 0)
{
for (int i = 0; i <= elements.Count; i++)

{
Interactivity interactivity = new Interactivity();
imageElement = elements[i].Element("ImagePath");
interactivity.imagePath = imageElement.Value.ToString();
xapElement = elements[i].Element("xapFilePath");
interactivity.xapfilePath = xapElement.Value.ToString();
interactivityList.Add(interactivity);
}
}
} public class Interactivity
{
public string imagePath { get; set; }
public string xapfilePath { get; set; }
}


NOTE:

Replace <= with <

LoadXap File Dynamically through HTML page

How to load xap file dynamically in silverlight?
We can use xap loader class method or else u can load xap file via html Page.Here is my example to load the xap file dynamically
Lets Create a sample application and bind the image in tat application .I have created the project in the name of sampleapplication .


Now i have created the other project name loadXAP to load sampleapplication XAP file.I have added MyPage.htm Page in the web project,and add the following code as in the image


and add div with the Id 'silverlightControlHost' in the body tag .Now place the sample application Xap file in the ClientBin folder of loadXap Application.Now i have place thumbnail of image and when i click on the image it redirects to MyPage.htm file with the XAP filename as Query string .Here is the screen shot of the application


Thursday, October 22, 2009

Accordian Control Problem in Blend

Hi ,
When the Accordian Control is added in silverlight. When you open in Blend You could not able to find the control in Expression Blend.

To View in the Blend You should add reference System.Windows.Controls.Layout.Toolkit. and System.Windows.Controls.Toolkit

Wednesday, October 14, 2009

ErrorCode:4001 ErrorType:MediaError AG_E_NETWORK_ERROR

Hi all,

ErrorCode:4001 ErrorType:MediaError AG_E_NETWORK_ERROR

I get the above error when i play a media file. It ruins my whole day.
At last i found by adding the media file in the Bin Debug/Release folder and in the web i have added in the client bin folder. It solve my issue

Wednesday, September 2, 2009

Search Query in sql

Hi ,I have the table name stipr and category with the following fields as follows
iprdate
iprno
deliveredto
classification
requiredfor
stcategoryID
mainstatus
and category table with the field of
stcategoryID
Now my requirement is i have to write the query with the different combination as followsfor ex:
declare @IPRdate datetime,@IPRNo nvarchar(50),@DeliveredTo nvarchar(50),@Classification nvarchar(50),@RequiredFor nvarchar(50),@STCategoryID nvarchar(50),@MainStatus nvarchar(50)
Begin
if @IPRdate !=null and @IPRNo=null and @DeliveredTo = null AND @Classification = null AND @RequiredFor = null AND @STCategoryID = null AND @MainStatus = nullBeginselect * from Store.STIPR,Store.STCategory where IPRdate=@IPRdateEndelse if @IPRdate !=null and @IPRNo !=null and @DeliveredTo = null AND @Classification = null AND @RequiredFor = null AND @STCategoryID = null AND @MainStatus = null
Begin
select * from Store.STIPR,Store.STCategory where IPRdate=@IPRdate and IPRNo=@IPRNo
End
End

After a long search i found the query using case then

select * from Store.STIPR,Store.STCategory where
iprdate = (case when @IPRdate is null then iprdate else @IPRdate end) and
iprno = (case when @IPRNo is null then iprno else @IPRNo end) and
deliveredto = (case when @DeliveredTo is null then deliveredto else @DeliveredTo end) and
classification = (case when @Classification is null then classification else @Classification end) and
requiredfor = (case when @RequiredFor is null then requiredfor else @RequiredFor end) and
stcategoryID = (case when @STCategoryID is null then stcategoryID else @STCategoryID end) and
mainstatus = (case when @MainStatus is null then mainstatus else @MainStatus end)




Friday, July 31, 2009

SilverLight Interview Questions

What are the types of containers in silver light?
dock panel-dock panel is used to arrange a set of objects around the edges of panel. Dock Panel’s Dock property enables you to specify the location of objects inside Dock Panel. If you set the LastChild Fill property to true (the default value) and the last element is allowed to resize, the last element added to the panel will resize to fill the remaining space. If the last element is set to a specific size, the last element will be set to the specified size and positioned in the middle of the remaining space. The order in which elements are added to the dock panel is important.
Wrap Panel-Wrap panel is used to wrap the content in the next line.

What is silverlight .js file?
silverlight.js is a helper file is used when adding a silverlight application to a web page via javascript .It contains more helper method like get silverlight,ongetsilverlight,etc.We can add silverlight application to a web page by an alternate way asusing objecttag in html element

Does Silverlight support ADO.NET? and How to load the data to Silverlight from database?
It Does not support ado.net .have to use via WCF service,

How to use the styles in Silverlight? Can we load the external CSS file into Silverlight?
NO, it is not possibel to load external css in silverlight.We can use setter property to in app.xaml to apply the style.
For ex:
In app.xaml
style x:Key="titleBorder" TargetType="Border"
setter property="Background" value="#ff0000"
Style
if we r using brush then use Setter.value under setter.property
To use in the page
border style="{staticresource TitleBorder}>
textBlock text="GetData" style="{staticresource titleborder}"
border

can we use more than one xaml file in same project? explain?
yes we can use.To redirect from one xaml to other xaml
App app = (App)Application.Current;
app.UserName = txtUser.Text;
App.GoToPage(new Page2());

public static void GoToPage(UserControl nextPg)
{
App app = (App)Application.Current;
// Remove the displayed page
app.mainUI.Children.Clear();
// Show the next page
app.mainUI.Children.Add(nextPg);
}
to pass the parameter u can created property class and assign the value before passing parameter



Monday, June 22, 2009

Reset Identity column value in sql

Syntax:
DBCC CHECKIDENT
( 'table'
[ , { NORESEED | { RESEED [ , new_reseed_value ] } } ]
) [WITH NO_INFOMSGS]

Key:
NORESEED - The current identity value should not be changed.
RESEED - Change the identity value.
new_reseed_value - The new seed value to be used for the identity column.
WITH NO_INFOMSGS - Suppresses all information messages.

DBCC CHECKIDENT ('Employee', RESEED, 0)

Friday, June 19, 2009

Update Dynamic Values in App.Config

Hi,
Here is the code to update the dynamic values in app.config


Wednesday, June 17, 2009

Day Pilot Calendar Div problem in IE7 Browsers

Day Pilot Calendar Div problem in IE7 Browsers


Calendar does not set in the IE7 Where as It Works fine in Firefox. In Ie7 It get blocked. it ruins the whole day and at last i found the solution by


Set the parent div to position: relative

Read Me and License Agreement While Creating Window Setup

Here is the instruction to add readme and license agreement while creating Windows Setup:

1) Select File->New->Project.

2) In the project panes, select Setup and deployment projects. In the templates pane, select setup project.

3) Select File->Add project->Existing Project. And add your project

4) Select the "File System on Target Machine" in the File system editor.

5) To add the output, select View->Custom ActionàAdd Custom Action->project output. Select "Project" from the drop down-list. Select primary output from the output list.

6) Click the ok button.

7) To create a shortcut on the desktop, in the details pane select primary output from sample. Select action->create shortcut to primary output. Change the shortcut name. Drag the shortcut to the user's Desktop node in the left pane.

8) Right Click on the User Desktop Select Properties Window and Change the Condition Property to SHORTCUTDEMO

9) To add Read Me and License file follow the procedure

10) Create ReadMe.Rtf File and License.Rtf File and add it in the application folder in the file system editor Note: If the Content is not displayed in read me and license then there is a problem in rtf format file.

11) Select View à User Interface Editor and right click on start under install category and click Add Dialog menu.

12) In the Add Dialog box, select the Checkboxes (A), License Agreement, Read Me, and Splash dialog boxes, and then add them to the Start sequence.

13) Drag and drop the dialog boxes into the proper sequence


14) Select the License Agreement dialog box and view its properties window. Change the License File property to license.rtf.

15) Select the Read Me dialog box and select View | Properties Window to bring up its properties window. Change the Readme File property to readme.rtf.

16) To have the developer.com logo display on all of these additional default dialogs, set the Banner Bitmap property to developer.gif.

17) Use the Checkboxes (A) dialog box to ask the user whether the demo shortcut you placed in the User's Desktop folder should be installed or not. Modify the properties of this dialog box to match the Figure 5 screenshot.

18) Remember to set the CheckBox1Property to SHORTCUTDEMO. This value is the same as the Condition property that you set for the User's Desktop folder in the File System Editor. If the user selects this checkbox during installation, the value of the SHORTCUTDEMO condition is set to true. As a result, the shortcut installs on the user's desktop. If the user does not select this checkbox, the SHORTCUTDEMO condition is set to false and the shortcut does not install.

Wednesday, May 20, 2009

SqlQuery To Export Data from Excel to Sql

Hi,
Here is the query to export the data from Excel to sqlserver

CREATE TABLE [dbo].[Addresses_Temp] (
[FirstName] VARCHAR(20),
[LastName] VARCHAR(20),
[Address] VARCHAR(50),
[City] VARCHAR(30),
[State] VARCHAR(2),
[ZIP] VARCHAR(10)
)
GO

INSERT INTO [dbo].[Address_Temp] ( [FirstName], [LastName], [Address], [City], [State], [ZIP] )
SELECT [FirstName], [LastName], [Address], [City], [State], [ZIP]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
'SELECT * FROM [Sheet1$]')

To Access the function such as OPENROWSET Go to
MicroSoftSqlServer2005--->ConfigurationTools--->
SqlSurfaceAreaConfiguration

Click on Surface Area Configuration For features
and Enable OPENROWSET and OPENDATASOURCE support

Sunday, May 10, 2009

WildCharacters in Sql

Hi,
Here are the query results using Wild card Character.Consider below table
Student:

Now Consider the Query

Select * from student Where Name like ‘John%’.

It return results as name starts with john . You will get the result as



Select * from student Where Name like ‘%John’. It results as



Select * from student Where Name like ‘%John%’. It results as



Select * from student Where Class like ‘Fo_r’. '_' matches single character and replace it


Friday, May 8, 2009

What is a flat file?

A flat file is the name given to text, which can be read or written only sequentially.

Calculate Age from the DateOfBirth

Hi,
Here is the program with the three line to calculate the age from the DOB

long yrs = 0;
DateTime bdayDate = new DateTime(2010, 07, 17);
TimeSpan ts = DateTime.Now.Subtract(bdayDate);
yrs = ts.Days / 365;
Response.Write(yrs);

Saturday, April 25, 2009

Difference Between .net FrameWork 1.1,2.0,3.0,3.5

2.0 has some extendable features when compared to 1.1

1).net 2.0 supports web Request, web Response and web client classes

2).net 2.0 added the features of generic classes
3).net 2.0 added the feature of MultipleActiveResultSet,UserDefinedDataTypes,xmlDataTypes
4).net 2.0 UTF8Encoding is more faster than 1.1
5)When the file attachment u s

To read more Detail click the following link
http://msdn.microsoft.com/en-us/library/t357fb32.aspx

Difference between 2.0 and 3.0 is
WCF,WPF,WWF,WindowsCardSpace

3.0 and 3.5 is similar, with the additional features of enhanced WCF Control,ASp.net with Ajax , LinQ

Monday, February 2, 2009

Unsafe code may only appear if compiling with /unsafe in VisualStudio 2005

Hi,
Here is the error which i got when using unsafe code
Unsafe code may only appear if compiling with /unsafe
Here is the solution for the above error
Add the following line under system.codedom /compilers
compiler language="C#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" compilerOptions="/unsafe" /

UnSafe Code in C#

Hi,
Here is some details about Unsafe in C#
Unsafe code is code which does not executed under full control of CLR. It can cause some problems therefore each use must be marked as "unsafe".
...
unsafe
{
...
// unsafe context: can use pointers here
...
}
...
Generally speaking when you write any program in C# you create managed code. Managed code is executed under the control of Common Language Runtime (CLR). CRL causes that programmer do not need to manage memory and take care about memory's allocation and deallocation. CLR also allows you to write what is called 'unsafe code'.

Advantages:

  • Performance and flexibility, by using pointer you can access data and manipulate it in the most efficient way possible.
  • Compatibility, in most cases we still need to use old windows APIs, which use pointers extensively. Or third parties may supply DLLs that some of it’s functions need pointer parameters. Although this can be done by using DLLImport and System.IntPtr class, but in some cases it’s just much simpler to use pointer.
  • Memory Addresses, there is no way to know the memory address of some data without using pointers.

Disadvantages:

  • Complex syntax, to use pointers you need to go throw more complex syntax than we used to experience in C#.
  • Harder to use, you need be more careful and logical while using pointers, miss using pointer might lead to the following:
    • Overwrite other variables.
    • Stack overflow.
    • Access areas of memory that doesn’t contain any data as they do.
    • Overwrite some information of the code for the .net runtime, which will surely lead you application to crash.
  • Type-safety, using pointers will cause the code to fail in the .net type-safety checks, and of course if your Security policy don’t allow non type-safety code, then the .net framework will refuse to execute it.