Tuesday, May 27, 2008

Sort ascending or descending dynamics

You 2 Ways to sort ascending or descending dynamics depends on variable:
First way:
SELECT [Id]
,[Last_Update_Dt]
FROM [Tellas_PhotoGallery].[dbo].[IMAGE]
order by CAST([Last_Update_Dt] AS INT)*-1

SELECT [Id]
,[Last_Update_Dt]
FROM [Tellas_PhotoGallery].[dbo].[IMAGE]order by [Last_Update_Dt] DESC
This technique of multiplying either 1(ASC) or -1(DESC), can be used in many queries, and of course is not limited to datetimes.
Second way
DECLARE @SortOrder int
SET @SortOrder = 1
SELECT [Id]
,[Last_Update_Dt]
FROM [Tellas_PhotoGallery].[dbo].[IMAGE]
ORDER BY
CASE
WHEN @SortOrder = 1 THEN (RANK() OVER (ORDER BY [Last_Update_Dt] ASC))
WHEN @SortOrder = 2 THEN (RANK() OVER (ORDER BY [Last_Update_Dt] DESC))
END

Article below gives you ideas to create dynamic query Sorting and Where Clause without conactenate string:
http://www.sqlteam.com/article/dynamic-order-by

Friday, May 23, 2008

How can we Send SMS?

Before we talk about sending SMS we need to tell you some definitions:

SMSC (Short Message Service Centre):
is a network element in the mobile telephone network which delivers SMS messages.
When a user sends a text message (SMS message) to another user, the message gets stored in the SMSC which delivers it to the destination user when they are available. This is a store and forward op

SMS Gateway:
Average rate of sending SMS for each short number account is 1 message/sec, If you sumbit messages with high rates all messages will failed. SMS gateway application to facilitate the SMS traffic between businesses and mobile subscribers.

Protocols: The
Value-added service provider (VASP) providing the content submits the message to the mobile operator's SMSC(s) using a TCP/IP protocol such as the short message peer-to-peer protocol (SMPP) or the External Machine Interface (EMI). The SMSC delivers the text using the normal Mobile Terminated delivery procedure. The subscribers are charged extra for receiving this premium content, and the amount is typically divided between the mobile network operator and the VASP either through revenue share or a fixed transport fee.

Nokia PC Suite:
is a software package used to establish an interface between Nokia mobile devices and computers that run Microsoft Windows operating system. It can be used to transfer music, photos and applications. It can also be used to send Short Message Service (SMS) messages or act as a modem to connect the computer to the Internet. A mobile phone can be connected by USB, Bluetooth, or infrared.

If you have Application and want to add SMS service to your application, You can send this message by 4 ways:
1. Use Nokia PC Suite to send Short Message Service (SMS) messages from your computer using your SIM card.

2. Use any third party which made applications to send bulk SMS,
This way needn't any knowledge of connection of the operator, It only needs to learn how can you deal with its API.
example of this third party:
http://www.clickatel.com/

3. Use a gateway to connect to SMSC Operators and use its API to send your message.
To use this gateway:
a. Make a deal with operatot to send your SMS through his SMSC.
b. You must have knowledge of mobile network Protocols to configure connection of smsc.
example of this third party:
http://www.kannel.org/ (Free)
http://www.nowsms.com/

4. Use SDK from Third Party to connect to the operator, You will use this SDK to build your gateway application.
Your application Functions:
1. Connect to SMSC
2. Manage rates of sending messages.
3. Send/Receive Message.
4. Logs any actions (Sending/Receive/Notifications/Failure/Succeed)
example of this third party:
http://www.derdack.com/
http://www.devshock.com/ (Free but only for SMPP Protocol)

Notes:
Alias:
UCP Protocol allow you to set alias per each message, While SMPP needs your operator set this alias and will be constant for all messages.

Message Message size:
The maximum single text message size is either 160 7-bit characters, 140 8-bit characters, or 70 16-bit characters. Characters in languages such as Arabic, Chinese, Korean, Japanese or Slavic languages (e.g., Russian) must be encoded using the 16-bit UCS-2 character encoding (see Unicode).Larger content (Concatenated SMS, multipart or segmented SMS or "long sms") can be sent using multiple messages, in which case each message will start with a user data header (UDH) containing segmentation information. Since UDH is inside the payload, the number of characters per segment is lower: 153 for 7-bit encoding, 134 for 8-bit encoding and 67 for 16-bit encoding. The receiving handset is then responsible for reassembling the message and presenting it to the user as one long message. While the standard theoretically permits up to 255 segments, 6 to 8 segment messages are the practical maximum, and long messages are often billed as equivalent to multiple SMS messages.

Saturday, May 17, 2008

Creating a DSL Designer: HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND

When try to create DSL Designer in Vistual Sudio 2008, I found Error:
Creating a DSL Designer: HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND
and didn't create correct Project.

I install Visual studio 2007 again(Repair), and VS 2008 SDK and problem have been solved. But after I Opened DSL Project created with VS 2005. I faced this problem again. And repairing again didn't solve this problem.

I Found solution removing all database connection from Server Explorer of Visual Studio.

Thursday, May 8, 2008

Ajax getLocation Problem

When I developed a solution using ASPNET and ajax, I faced problem with AJAX
When I used any control used getLocation function and page is scrolled.
For example when I used popup extender and onmousehover popup extender appears shiffted. This problem is occured only in IE.
To Solve this problem I did these steps:
1. I Added ScriptReference to script manager to customize MicrosoftAjax.js
<asp:ScriptManager ID="ScriptManager1" runat="server"
ScriptMode="Release"
EnableScriptLocalization="false">
<Scripts>
<asp:ScriptReference Name="MicrosoftAjax.js"
Path="~/AjaxFramework/MicrosoftAjax.js" />
</Scripts>
</asp:ScriptManager>

2. Customized MicrosoftAjax.js
a. Added these functions to javascript file After line of code Function.__class=true;
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return [curleft,curtop];
}
function f_scrollLeft() {
return f_filterResults (
window.pageXOffset ? window.pageXOffset : 0,
document.documentElement ? document.documentElement.scrollLeft : 0,
document.body ? document.body.scrollLeft : 0
);
}
function f_scrollTop() {
return 0;
return f_filterResults (
window.pageYOffset ? window.pageYOffset : 0,
document.documentElement ? document.documentElement.scrollTop : 0,
document.body ? document.body.scrollTop : 0
);
}
function f_filterResults(n_win, n_docel, n_body) {
var n_result = n_win ? n_win : 0;
if (n_docel && (!n_result (n_result > n_docel)))
n_result = n_docel;
return n_body && (!n_result (n_result > n_body)) ? n_body : n_result;
}
function getScrollXY() {
var scrOfX = 0, scrOfY = 0;
if( typeof( window.pageYOffset ) == 'number' ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft document.body.scrollTop ) ) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if( document.documentElement && ( document.documentElement.scrollLeft document.documentElement.scrollTop ) ) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}

return [ scrOfX, scrOfY ];
}

b. search for (Sys.Browser.agent){case Sys.Browser.InternetExplorer:...break;
replace code in this switch case with Code Below:
case Sys.Browser.InternetExplorer:
Sys.UI.DomElement.getLocation = function(element) {
k = findPos(element);
if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) { p = getScrollXY(); offsetX = k[0]+p[0]; offsetY = k[1]+p[1]; return new Sys.UI.Point(offsetX, offsetY); } offsetX = k[0]+f_scrollLeft(); offsetY = k[1]+f_scrollTop(); return new Sys.UI.Point(offsetX, offsetY); }
break;
Note: You can do this change using microsoftAjax.debug.js and use debug Mode (It is easier to edit), But You will find debug file size 250 KB, and 179 KB after you converted it to relase.
It is better to do this change direct to released file because it's size 89 KB.