Thứ Tư, 11 tháng 1, 2012

SQL Service Brokers

SQL Service Brokers
http://blog.sqlauthority.com/2009/09/21/sql-server-intorduction-to-service-broker-and-sample-script/


ervice Broker in Microsoft SQL Server 2005 is a new technology that provides messaging and queuing functions between instances. The basic functions of sending and receiving messages forms a part of a “conversation.” Each conversation is considered to be a complete channel of communication. Each Service Broker conversation is considered to be a dialog where two participants are involved.
Service broker find applications when single or multiple SQL server instances are used. This functionality helps in sending messages to remote databases on different servers and processing of the messages within a single database. In order to send messages between the instances, the Service Broker uses TCP/IP.
This transaction message queuing system enables the developers to build secure and reliable applications, which are scalable. The developers can design applications from independent components known as “services.” If the applications need to avail the functionality of these services, then it sends message to the particular “service.”
Loosely coupled applications (programs that exchange messages independently) are supported by the Service broker. The three components of the Service broker are as follows: conversation components (which consist of the conversation groups, conversations and messages); service definition components (which define the conversations); and networking and security components (defines the infrastructure used for exchanging messages between instances)
The maintenance of Service Broker is easy and it is a part of the routine database administration procedure. This is because this functionality forms a part of the Database Engine. Service Broker also provides security by preventing unauthorized access from networks and by message encryption.
Let us understand Service Broker with simple script. Script contains necessary comments to explain what exactly script is doing.
---------------------------- Service Broker -----------------------
-- In this exercise we will learn how to cofigure Servie Broker and send and recieve messages.
-------------------------------------------------------------------
CREATE DATABASE ServiceBrokerTest
GO
USE ServiceBrokerTest
GO
-- Enable Service BrokerALTER DATABASE ServiceBrokerTest SET ENABLE_BROKER
GO
-- Create Message TypeCREATE MESSAGE TYPE SBMessage
VALIDATION 
NONE
GO
-- Create ContractCREATE CONTRACT SBContract(SBMessage SENT BY INITIATOR)GO-- Create Send QueueCREATE QUEUE SBSendQueue
GO
-- Create Receive QueueCREATE QUEUE SBReceiveQueue
GO
-- Create Send Service on Send QueueCREATE SERVICE SBSendServiceON QUEUE SBSendQueue (SBContract)GO-- Create Receive Service on Recieve QueueCREATE SERVICE SBReceiveServiceON QUEUE SBReceiveQueue (SBContract)GO-- Begin Dialog using service on contractDECLARE @SBDialog uniqueidentifierDECLARE @Message NVARCHAR(128)BEGIN DIALOG CONVERSATION @SBDialogFROM SERVICE SBSendServiceTO SERVICE 'SBReceiveService'ON CONTRACT SBContractWITH ENCRYPTION = OFF-- Send messages on DialogSET @Message N'Very First Message';SEND ON CONVERSATION @SBDialogMESSAGE TYPE SBMessage (@Message)SET @Message N'Second Message';SEND ON CONVERSATION @SBDialogMESSAGE TYPE SBMessage (@Message)SET @Message N'Third Message';SEND ON CONVERSATION @SBDialogMESSAGE TYPE SBMessage (@Message)GO-- View messages from Receive QueueSELECT CONVERT(NVARCHAR(MAX), message_bodyAS MessageFROM SBReceiveQueue
GO
-- Receive messages from Receive QueueRECEIVE TOP(1CONVERT(NVARCHAR(MAX), message_bodyAS MessageFROM SBReceiveQueue
GO
-- Receive messages from Receive QueueRECEIVE CONVERT(NVARCHAR(MAX), message_bodyAS MessageFROM SBReceiveQueue
GO
-- Clean UpUSE master
GO
DROP DATABASE ServiceBrokerTest
GO
You can download the above script from here.
Let me know what do you think of this script and how simply one can configure service broker.
Reference : Pinal Dave (http://blog.sqlauthority.com)

Thứ Ba, 10 tháng 1, 2012

Phần mêm quản lý kho thuốc thú y

Giới thiệu tính năng phần mềm quản lý kho thuốc thú y:

1/ Quản lý danh mục khách hàng
2/ Quản lý danh mục sản phẩm
3/ Quản lý danh mục nhà cung cấp
4/ Quản lý bán hàng
5/ Quản lý xuất/nhập hàng
6/ Quản lý công nợ khách hàng
7/ Thống kê hàng tồn
8/ In hóa đơn bán hàng, hóa đơn hàng tồn, ...
9/ Tìm kiếm hết sức tiện lợi, nhanh chóng
10/ Phân quyền truy cập cho từng người dùng

Dưới đây là một số hình ảnh minh họa:
Hình 1 - Cửa sổ bán hàng

Hình 2 - Cửa sổ In hóa đơn

Hình 3 - Quản lý công nợ

Hình 4 - Theo dõi hóa đơn bán hàng
Hình 5 - Quản lý hàng

GridView All Rows in Edit Mode

Introduction:
http://highoncoding.com/Articles/219_GridView_All_Rows_in_Edit_Mode.aspx
http://aspadvice.com/blogs/azamsharp/archive/2006/12/18/GridView-Update-All-Rows-At-Once.aspx

GridView provides a very easy way to edit the data by using the in-place editing feature. Although the feature is great but sometimes we want to view the complete GridView in the edit mode and quickly edit multiple records without having to click the edit button on each row. In this article I will demonstrate how to convert the whole GridView in edit mode with a click of a button.

Database Design:

In this article I will be using a custom database called School which consists of a single table called “Users”. The Users table contains only three columns namely FirstName, LastName and UserID.

Displaying Data in the GridView Control:

The first task is to display the data in the GridView control. Take a look at the method below which is used to populate the GridView control.

private void BindData()

{

string connectionString = "Server=localhost;Database=School;Trusted_Connection=true";

SqlConnection myConnection = new SqlConnection(connectionString);

SqlDataAdapter ad = new SqlDataAdapter("SELECT UserID, FirstName, LastName FROM Users", myConnection);

DataSet ds = new DataSet();

ad.Fill(ds);
gvUsers.DataSource = ds;
gvUsers.DataBind();

}

Depending on the data in the database your GridView will be populated.

GridView HTML Code:

The HTML code of the GridView is where all the magic happens. Let’s first take a look at the code.












































Now, check out the section where all the TemplateFields exists. The section contains the Label as well as the TextBox. The visibility of the Label and the TextBox depends on the IsInEditMode property which, is a public property defined in the code behind. You can think of it as a switch meaning that when the Labels are displayed then the TextBoxes are not displayed and when the TextBoxes are displayed then the Labels will not be displayed.

IsInEditMode Property:

This is a simple property that returns the Boolean value of true or false.

private bool isEditMode = false;

protected bool IsInEditMode

{

get { return this.isEditMode; }

set { this.isEditMode = value; }

}


I have used a simple ASP.NET Button control to change the GridView to edit mode. Check out the code below:



// This method will put the GridView in the edit mode

protected void Button1_Click(object sender, EventArgs e)

{

isEditMode = true;

BindData();

}


Yup! That is all you need to change the GridView to edit mode. The isEditMode variable is set to true and it will make TextBoxes visible and the Labels invisible.