Posts

Showing posts from 2016

Passing values betwwen Windows Forms in Realtime - Using Delegates and Events

Image
Hi all, in this post I'll explain how to use delegates to pass value to another form. To demonstrate this I'll use windows forms. Task: 1. There is a Windows form called Tool. And there is another Windows form called Register. 2. We need to get the name of the user from the Register form to the Tool form. I have created a Windows form project and named it as BaseNumbers. You can use any number as you like. Then I have designed the 2 forms as bellow. To make the things work we have to use delegates and events. Register Form namespace BaseNumbers { public delegate void RegisterUser(string name); public partial class Register : Form { public event RegisterUser registerUser; public Register() { InitializeComponent(); } private void btnRegister_Click(object sender, EventArgs e) { if (txtUsername.Text != "") { if (registerUser != null)

ASP.Net Multi-Tier Architecture : With Product sample

Image
In this post I'll explain how to manage a much more better structure in your web applications with Multi-Tier architectures. In this post we are going to experience the Three-Tier architecture. Even-though we name this as a Three-Tier architecture we can divide it into more levels to manage the complexity of the project. This is the architecture we are going to implement in this post.   Responsibilities of each layers: 1. Application Layer - This is the top level and the layer which the end user getting access to. Which simply means this is the web site interface which include all the aspx files, css files and other scripts. 2. Business Layer - This is the main layer of the application which holds the business logic. I have divide this layer in to 2 layers. Business Logic Layer - This layer holds the pure business logic itself. Business Domain Layer - This holds the domain objects of the solution which require in the business logic. (Ex: Product, User) 3. Database L

Decompiling and debugging .Net dll files

Image
Hi All, when you are working with some third party tools there are some times those third party throws errors. As example when you are developing ASP.Net Web Applications with CMS (Content Management System) like SItecore, it throws errors. In these situations we have to check where the error is getting throwing. But the problem is most of the third party tools have assembly (.dll) files which we cannot decompile. Why we cannot debug them ? Because, it is a end product and they don't include the .pdb files that need to debug their libraries. What is a .pdb file ? A program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program. A PDB file is created when you build with  /debug  (Visual Basic/C#). You can build Visual Basic and Visual C# applications with  /debug:full  or  /debug:pdbonly . Building with  /debug:full  generates debuggable code.  - msdn.microsoft.com Read more about PDB files

Asp.Net MVC: With Product example 1

Web.config  - Add the connection string <connectionStrings>     <add name="ProductDBConnectionString" connectionString="Data Source=LK-PRK\SQL2012DEV;Initial Catalog=ProductDB;Integrated Security=True"         providerName="System.Data.SqlClient" />   </connectionStrings> Connections.cs - in Model section using System.Configuration; using System.Data.SqlClient; namespace TestStock.Models {     public class Connection     {         public static SqlConnection GetConnection()         {             var conn = ConfigurationManager.ConnectionStrings["ProductDBConnectionString"].ConnectionString;             return new SqlConnection(conn);         }     } } Products.cs  - in Models section namespace TestStock.Models {     public class Product     {         public int Id { get; set; }         public string Name { get; set; }         public double Price { get; set; }     } } ProductHelper.cs - in M

.Net Better structure : With Product sample - Insert Data from JavaScript (3)

In this post we are going to call C# function using jQuery Ajax. jQuery Ajax help to send client side request without doing a post back. This allow to trigger an asynchronous (you can do synchronous as well, but what is the point ?) Add the jQuery libry to your page header. Find this from Google or Microsoft CDN. I'll take from Google CDN. https://developers.google.com/speed/libraries/#jquery Create a JavaScript file under folder called Scripts and name that file as Script.js. Add the following script to that file. Using this script file we are going to call a server side method which is written in C#. Script.js function AddProduct() {     var name = document.getElementById('txtProductName').value;     var price = document.getElementById('txtProductPrice').value;     if (name == "") {         alert("Enter product name !");     }else if (price == "") {         alert("Enter product price !");     }else if

.Net Better structure : With Product sample - Insert Data from C# (2)

Hi all, this is the 2nd post of this series. In this post I'll try to explain how to insert data to a database while keeping a better structure in your Visual Studio ASP.Net application. First lets create this (or similar to this) Stored Procedure in your database to add products. AddProducts Stored Procedure SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE AddProducts @name varchar(50), @price decimal(8,2) AS BEGIN SET NOCOUNT ON; INSERT INTO Products VALUES (@name, @price); END GO Inside the Domain folder of your project, create the following class. Product.cs namespace TestWeb.Domains {     public class Product     {         public int Id { get; set; }         public string Name { get; set; }         public double Price { get; set; }     } } Under the DomainHelpers folder, inside ProductHelper class add this code. ProductHelper.cs public string AddProduct(Product product)         {             string message;        

.Net Better structure : With Product sample - Get Data (1)

Hi all, in this series of blog posts I'll explain how to create ASP.Net web applications using a better structure. This is the part 1 of this blog series, so in this post I'll try to explain how to retrieve data from database. First go tot the Visual Studio and create a ASP.Net Empty Web Application project. Give a suitable name (I'll be using TestWeb). Create database and tables with some sample data. Now lets connect to that database using a connection string. Web.config <?xml version="1.0"?> <!--   For more information on how to configure your ASP.NET application, please visit   http://go.microsoft.com/fwlink/?LinkId=169433   --> <configuration>     <connectionStrings>         <add name="ProductDBConnectionString" connectionString="Data Source=LK-PRK\SQL2012DEV;Initial Catalog=ProductDB;Integrated Security=True"             providerName="System.Data.SqlClient" />     </connection