Saturday, March 22, 2014

Crystal Reports in Visual Studio (C#,ASP.NET)

Crystal Reports  for Visual Studio 2010 is version 13
 and use version 10.5 for Visual Studio 2008

Getting Started with Crystal Reports for Visual Studio 2010

Tutorials for Crystal Reports for Visual Studio 2010 »
Service Pack 1:

Crystal Reports for Visual Studio .NET 2010 - Support Pack 1


Database Login Problem In Crystal Reports
http://www.google.co.in/search?q=database+login+in+crystal+report+viewer&hl=en-IN&gbv=2&oq=data+base+login+&gs_l=heirloom-serp.3.0.0i13j0i13i10j0i13l8.1246482.1250850.0.1252293.16.15.0.0.0.0.365.2823.5j2j5j3.15.0....0...1ac.1.34.heirloom-serp..9.7.820.-y8Y7o-j9iI

About Crystal Report Useful Link
http://1800thenerd.wordpress.com/2010/11/24/sap-crystal-reports-for-visual-studio-2010-files-needed-to-download/

Set Crystal Reports Location Dynamically

http://stackoverflow.com/questions/12002957/how-to-set-database-login-infos-connection-info-for-crystal-report


ConnectionInfo crconnectioninfo = new ConnectionInfo();
    ReportDocument cryrpt = new ReportDocument();
    TableLogOnInfos crtablelogoninfos = new TableLogOnInfos();
    TableLogOnInfo crtablelogoninfo = new TableLogOnInfo();

    Tables CrTables;

    crconnectioninfo.ServerName = "localhost";
    crconnectioninfo.DatabaseName = "dbclients";
    crconnectioninfo.UserID = "ssssssss";
    crconnectioninfo.Password = "xxxxxxx";  


  cryrpt.Load(Application.StartupPath + "\\rpts\\" + dealerInfo.ResourceName);

        CrTables = cryrpt.Database.Tables;

        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtablelogoninfo = CrTable.LogOnInfo;
            crtablelogoninfo.ConnectionInfo = crconnectioninfo;
            CrTable.ApplyLogOnInfo(crtablelogoninfo);
        }


        cryrpt.RecordSelectionFormula = getCustInfoRptSelection();
        cryrpt.Refresh();

        allReportViewer.ReportSource = cryrpt;

Thursday, March 20, 2014

Using SyndicationFeed to display RSS FEEDS in C# ASP.NET

 ASPX Code
 <asp:GridView runat="server" id="grid" AutoGenerateColumns="false">
        <Columns >
        <asp:BoundField  DataField="title" HeaderText="Titles"/>
        <asp:TemplateField>
        <ItemTemplate>
        <asp:Literal ID="ltSummary" Text='<%#Eval("Summary") %>' runat="server"></asp:Literal>
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>

C# Code:
XmlTextReader reader = new XmlTextReader("https://news.yahoo.com/rss/");

            DataTable dt=new DataTable();
            dt.Columns.Add("Title", typeof(string));
            dt.Columns.Add("Summary", typeof(string));
            DataRow dr=null;
      
        SyndicationFeed feed = SyndicationFeed.Load(reader);
        reader.Close();
        foreach (SyndicationItem item in feed.Items)
        {
            dr = dt.NewRow();
            String subject = item.Title.Text;   
            String summary = item.Summary.Text;
            dr["Title"] = subject;
            dr["Summary"] = summary;
            dt.Rows.Add(dr);

          
        }

        grid.DataSource = dt;
        grid.DataBind();

Thursday, March 6, 2014

LINQ


http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

Split Comma Separated String and Filter

if (Session["_sTagno"] != null)
                {
                    string ss = Session["_sTagno"].ToString();
                    var list = ss.Split(',').Where(s => !string.IsNullOrEmpty(s) && s != lblTagNo.Text).Distinct().ToArray();

                    string res = String.Join(",", list);

                    Session["_sTagno"] = res;

                }



ORM

http://codetunnel.com/blog/post/introduction-to-entity-framework-part-i-object-relational-mapping



passing multiple command Arguments To Obout Grid (Client Side)
 CommandArgument='<%# Container.DataItem["RefNo"]+","+ Container.DataItem["EntNo"] %>'


Find The button inside Template Obout Grid (Server Side)

 Button View = (Button)grdReqPurchaseHistory.Templates[0].Container.FindControl("View");


 Passing Arguments On Button Click (Client Side)
 onclick='<%# String.Format("setGridInEditMode({0});",  Container.DataItem["RefNo"]   ) %>'

   <script type="text/javascript">
        function setGridInEditMode(rec) {
            alert(rec);
        }
   
    </script>

 On Row Click Of Grid
 <OboutGrid:GridTemplate runat="server" ID="GtRow1">
<Template>
<table>
<tr onclick="RefreshDataGrid1(this)" id='<%#String.Format("{0},{1}",Container.DataItem["ItemTrnLineID"],Container.DataItem["OrderNo"]) %>'
 style="cursor: pointer">
<td>
<%# Container.DataItem["refNo"]%>
</td>
</tr>
</table>
</Template>
</OboutGrid:GridTemplate>

 <OboutGrid:Column DataField="refNo" HeaderAlign="left" Align="left" Width="10%" HeaderText="Ref Nos">
                                                    <TemplateSettings TemplateId="GtRow1" />
                                                </OboutGrid:Column>



java Script

 function RefreshDataGrid1(a) {

                document.getElementById("ctl00_contentHolder_hfItemTrans").value = a.id;
                $get('ctl00_contentHolder_btnEdit').click();

            }


   <div style="display: none">
                    <asp:Button runat="server" ID="btnEdit" OnClick="btnEdit_Click" />
                </div>

 protected void btnEdit_Click(object sender, EventArgs e)
    {
        str = hfItemTrans.Value.ToString().Split(',');
       // BindBrandGridView(Convert.ToInt32(str[0]), "", "", "", true, false);
   //BindGrid
    }

 Linq

Select Columns from DataTable in Linq

var query = DataTable_Name.AsEnumerable().Select
            (r => new
            {
                ColName1 = r.Field<string>("ColName1"),
                ColName2 = r.Field<int>("ColName2"),
                
            }).ToList();
  ddlRiskLevels.DataSource = query;
 ddlRiskLevels.DataBind();

Monday, March 3, 2014

OOP With C#


Polymorphism
http://msdn.microsoft.com/en-us/library/ms173152%28VS.80%29.aspx

Hosting .NET Windows Forms Controls in IE

http://www.codeguru.com/csharp/.net/net_general/internet/article.php/c19639/Hosting-NET-Windows-Forms-Controls-in-IE.htm

Sequence that events are raised for Pages, UserControls, MasterPages and HttpModules


Understanding the Page Life Cycle can be very important as you begin to build Pages with MasterPages and UserControls.
Does the Init event fire first for the Page, the MasterPage or the UserControl? 
What about the Load event?
If you make an incorrect assumption about the sequence that these events fire, then you may end up with a page that simply doesn't behave the way you had anticipated.
By running a simple test, we can see exactly when each event fires.  Our test setup is composed of a Page, MasterPage, UserControl, Nested UserControl and Button control as follows:
  • The Page is tied to the MasterPage
  • The UserControl is on the Page
  • The Nested UserControl is on the UserControl
  • The Button is on the Nested UserControl.
  • Clicking the Button calls the Page.DataBind method
Each event on these controls has been set to call Debug.WriteLine as each event is raised.  In addition to the events that get raised for regular pages, I've also set up an HttpModule and wired up all of those events as well. The results in the Debug output window of running this page and Clicking the Button are as follows:
BeginRequest - HttpModule
AuthenticateRequest - HttpModule
PostAuthenticateRequest - HttpModule
PostAuthorizeRequest - HttpModule
ResolveRequestCache - HttpModule
PostResolveRequestCache - HttpModule
PostMapRequestHandler - HttpModule
AcquireRequestState - HttpModule
PostAcquireRequestState - HttpModule
PreRequestHandlerExecute - HttpModule
PreInit - Page
Init - ChildUserControl
Init - UserControl
Init - MasterPage
Init - Page
InitComplete - Page
LoadPageStateFromPersistenceMedium - Page
ProcessPostData (first try) - Page
PreLoad - Page
Load - Page
Load - MasterPage
Load - UserControl
Load - ChildUserControl
ProcessPostData (second try) - Page
RaiseChangedEvents - Page
RaisePostBackEvent - Page
Click - Button - ChildUserControl
    DataBinding - Page
    DataBinding - MasterPage
    DataBinding - UserControl
    DataBinding - ChildUserControl
LoadComplete - Page
PreRender - Page
PreRender - MasterPage
PreRender - UserControl
PreRender - ChildUserControl
PreRenderComplete - Page
SaveViewState - Page
SavePageStateToPersistenceMedium - Page
SaveStateComplete - Page
Unload - ChildUserControl
Unload - UserControl
Unload - MasterPage
Unload - Page
PostRequestHandlerExecute - HttpModule
ReleaseRequestState - HttpModule
PostReleaseRequestState - HttpModule
UpdateRequestCache - HttpModule
PostUpdateRequestCache - HttpModule
EndRequest - HttpModule
PreSendRequestHeaders - HttpModule
PreSendRequestContent - HttpModule

Source:http://forums.asp.net/t/1191194.aspx

Saturday, January 25, 2014

Simple and Short (Managed Code , Unmanaged Code and Native Code)

Managed, Unmanaged, Native:

With the release of Visual Studio .NET 2003 (formerly known as Everett) on April 24th, many developers are now willing to consider using the new technology known as managed code. But especially for C++ developers, it can be a bit confusing. That's because C++, as I pointed out in my first column here, is special.

What Is Managed Code?

Managed Code is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer. The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code you've created. This assembly is the one-stop-shopping unit of deployment in the .NET world. You copy it to another server to deploy the assembly there—and often that copying is the only step required in the deployment.
Managed code runs in the Common Language Runtime. The runtime offers a wide variety of services to your running code. In the usual course of events, it first loads and verifies the assembly to make sure the IL is okay. Then, just in time, as methods are called, the runtime arranges for them to be compiled to machine code suitable for the machine the assembly is running on, and caches this machine code to be used the next time the method is called. (This is called Just In Time, or JIT compiling, or often just Jitting.)
As the assembly runs, the runtime continues to provide services such as security, memory management, threading, and the like. The application is managed by the runtime.
Visual Basic .NET and C# can produce only managed code. If you're working with those applications, you are making managed code. Visual C++ .NET can produce managed code if you like: When you create a project, select one of the application types whose name starts with .Managed., such as .Managed C++ application..

What Is Unmanaged Code?

Unmanaged code is what you use to make before Visual Studio .NET 2002 was released. Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler you may still have kicking around on your hard drive all produced unmanaged code. It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same. It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system. And importantly, it got them from the operating system explicitly, by asking for them, usually by calling an API provided in the Windows SDK. More recent unmanaged applications got operating system services through COM calls.
Unlike the other Microsoft languages in Visual Studio, Visual C++ can create unmanaged applications. When you create a project and select an application type whose name starts with MFC, ATL, or Win32, you're creating an unmanaged application.
This can lead to some confusion: When you create a .Managed C++ application., the build product is an assembly of IL with an .exe extension. When you create an MFC application, the build product is a Windows executable file of native code, also with an .exe extension. The internal layout of the two files is utterly different. You can use the Intermediate Language Disassembler, ildasm, to look inside an assembly and see the metadata and IL. Try pointing ildasm at an unmanaged exe and you'll be told it has no valid CLR (Common Language Runtime) header and can't be disassembled—Same extension, completely different files.

What about Native Code?

The phrase native code is used in two contexts. Many people use it as a synonym for unmanaged code: code built with an older tool, or deliberately chosen in Visual C++, that does not run in the runtime, but instead runs natively on the machine. This might be a complete application, or it might be a COM component or DLL that is being called from managed code using COM Interop or PInvoke, two powerful tools that make sure you can use your old code when you move to the new world. I prefer to say .unmanaged code. for this meaning, because it emphasizes that the code does not get the services of the runtime. For example, Code Access Security in managed code prevents code loaded from another server from performing certain destructive actions. If your application calls out to unmanaged code loaded from another server, you won't get that protection.
The other use of the phrase native code is to describe the output of the JIT compiler, the machine code that actually runs in the runtime. It's managed, but it's not IL, it's machine code. As a result, don't just assume that native = unmanaged.

Does Managed Code Mean Managed Data?

Again with Visual Basic and C#, life is simple because you get no choice. When you declare a class in those languages, instances of it are created on the managed heap, and the garbage collector takes care of lifetime issues. But in Visual C++, you get a choice. Even when you're creating a managed application, you decide class by class whether it's a managed type or an unmanaged type.
 This is an unmanaged type:

class Foo
{
private:
   int x;
public:
    Foo(): x(0){}
    Foo(int xx): x(xx) {}
};
 
 
This is a managed type:
__gc class Bar { private: int x; public: Bar(): x(0){} Bar(int xx): x(xx) {} }; 

The only difference is the __gc keyword on the definition of Bar. But it makes a huge difference.
Managed types are garbage collected. They must be created with new, never on the stack. So this line is fine:
Foo f;
But this line is not allowed:
Bar b;
If I do create an instance of Foo on the heap, I must remember to clean it up:
Foo* pf = new Foo(2);
// . . .
delete pf;
The C++ compiler actually uses two heaps, a managed an unmanaged one, and uses operator overloading on new to decide where to allocate memory when you create an instance with new.
If I create an instance of Bar on the heap, I can ignore it. The garbage collector will clean it up some after it becomes clear that no one is using it (no more pointers to it are in scope).
There are restrictions on managed types: They can't use multiple inheritance or inherit from unmanaged types, they can't allow private access with the friend keyword, and they can't implement a copy constructor, to name a few. So, you might not want your classes to be managed classes. But that doesn't mean you don't want your code to be managed code. In Visual C++, you get the choice.
 SOURCE:http://www.developer.com/net/cplus/print.php/2197621


Other Answers :
When you think of Unmanaged, think machine-specific, machine-level code. Like x86 assembly language. Unmanaged (native) code is compiled and linked to run directly on the processor it was designed for, excluding all the OS stuff for the moment. It's not portable, but it is fast. Very simple, stripped down code.


Managed code is everything from Java to old Interpretive BASIC, or anything that runs under .NET. Managed code typically is compiled to an intermediate level P-Code or byte code set of instructions. These are not machine-specific instructions, although they look similar to assembly language. Managed code insulates the program from the machine it's running on, and creates a secure boundary in which all memory is allocated indirectly, and generally speaking, you don't have direct access to machine resources like ports, memory address space, the stack, etc. The idea is to run in a more secure environment.

To convert from a managed variable, say, to an unmanaged one, you have to get to the actual object itself. It's probably wrapped or boxed in some additional packaging. UNmanaged variables (like an 'int', say) - on a 32 bit machine - takes exactly 4 bytes. There is no overhead or additional packaging. The process of going from managed to unmanaged code - and back again - is called "marshaling". It allows your programs to cross the boundary.


Other Answers :

Here is some other complimentary explication about Managed code:
  • Code that is executed by the CLR.
  • Code that targets the common language runtime, the foundation of the .NET Framework, is known as managed code.
  • Managed code supplies the metadata necessary for the CLR to provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on IL executes as managed code.
  • Code that executes under the CLI execution environment.
 Other Ansers:


 Other  Answers:
Marshaling between Managed and Unmanaged Code:
http://msdn.microsoft.com/en-us/magazine/cc164193.aspx