Friday, December 27, 2013

Top jQuery Plugins

1, https://github.com/peachananr/autofix_anything
2, http://lirancohen.github.io/stickUp/#installation
3, http://codegeekz.com/top-jquery-plugins/

4, http://thedesignblitz.com/best-jquery-plugins-september-2013/
5, http://craigsworks.com/projects/qtip/docs/tutorials
6, http://fnagel.github.io/MultiDialog/demos/index.html
7, http://swaydeng.github.io/imgcolr/   (https://github.com/swaydeng/imgcolr)
8,http://owlgraphic.com/owlcarousel/#demo
9, http://jquery-plugins.net/
10, http://www.htmldrive.net/


Sunday, December 15, 2013


Trong quá trình làm việc với ASP.NET và JQUERY, tôi phát hiện ra rằng có 5 chức năng khác nhau có thể được dùng để gọi Ajax đến một trang khác và lấy dữ liệu từ trang đó. Tôi sẽ trình bày từng chức năng một.

Sau đây là danh sách các chức năng có sẵn trong thư viện JQuery để thực hiện cuộc gọi Ajax:
  1. Load
  2. getJson
  3. GET
  4. POST
  5. Ajax
Load:
Phương thức gọi Ajax đến trang và hỗ trợ gửi sử dụng phương thức khác là Get hoặc Post.

var loadUrl = "TestPage.htm";$(document).ready(function () {$("#load_basic").click(function () {$("#result").html(ajax_load).load(loadUrl, function (response, status, xhr) {if (status == "error") {var msg = "Sorry but there was an error: ";$("#dvError").html(msg + xhr.status + " " + xhr.statusText);}});return false;});
Như bạn có thể nhìn thấy trong đoạn mã trên, bạn có thể dễ dàng thực hiện gọi đến bất kỳ trang nào bằng cách di chuyển qua nó một Url cố định. Chức năng Call Back cung cấp Control nhiều hơn và cho phép xử lý   lỗi bất kỳ bằng cách sử dụng giá trị trạng thái.

Một trong những điều quan trọng về phương pháp tải là nó cho phép tải một phần của một trang chứ không phải là toàn bộ trang. Vì vậy, để thu hồi một phần duy nhất của trang, cuộc gọi vẫn giữ nguyên nhưng url là:
var loadUrl = "TestPage.htm # dvContainer";
Vì vậy, bằng việc thông qua địa chỉ trên phương thức tải nó chỉ tải các nội dung của thẻ div có id=dvContainer. Kiểm tra đoạn code sau:


Firebug cho thấy response được trả lại khi chúng ta gọi trang theo phương thức tải.

Tính năng quan trọng:
  • Cho phép thực hiện gọi với cả hai Request Get và Post
  • Cho phép tải các phần của trang.
getJSON

Một phương thức cho phép thu hồi các dữ liệu JSON bằng cách thực hiện gọi Ajax đến trang. Phương thức này chỉ cho phép di chuyển các tham số bằng cách sử dụng phương thức được đăng tải tham số là không được phép. Một điều nữa là phương thức này cung cấp phản ứng bằng cách sử dụng định dạng JSON.

var jsonUrl = "Json.htm";$("#btnJson").click(function () {$("#dvJson").html(ajax_load);$.getJSON(jsonUrl, function (json) {var result = json.name;$("#dvJson").html(result);});return false;});

Đoạn mã trên làm cho việc sử dụng các chức năng getJSON và hiển thị dữ liệu json lấy từ trang. Sau đây là dữ liệu json trả về bởi các tập tin Json.htm.
{"name": "Hemang Vyas","age" : "32","sex": "Male"}
Bên dưới là hình ảnh hiển thị dữ liệu json được trả về như response:


Tình năng quan trọng:
- Chỉ gửi dữ liệu sử dụng phương thức Get; không chấp nhận phương thức Post.
- Trả lại Response data.

Get
Cho phép chấp nhận gửi một yêu cầu Ajax với phương thức Get. Xử lý các phản ứng trong nhiều định dạng bao gồm xml, html, Text, script, json, và jonsp.

var getUrl = "GETAndPostRequest.aspx";$("#btnGet").click(functi on () {$("#dvGet").html(ajax_load);$.get(getUrl, { Name: "Pranay" }, function (result) {$("#dvGet").html(result);});return false;});
Trong mã tôi di chuyển qua các tham số Name và các trang bằng cách sử dụng yêu cầu có được. Về phía server, bạn có thể nhận được giá trị của tham số Name trong một đối tượng request querycollection.

if (Request.QueryString["Name"]!=null){txtName.Text = Request.QueryString["Name"].ToString();}
Firebug cho thấy các tham số thông qua yêu cầu Get và giá trị của tham số này pranay.


Tính năng quan trọng:
- Có thẻ xử lý bất kỳ loại dữ liệu Response.
- Gửi dữ liệu bằng cách sử dụng phương thức duy nhất là get

Post

Cho phép thực hiện một yêu cầu Ajax với phương thức post. Xử lý các phản ứng trong nhiều định dạng bao gồm xml, html, Text, script, json, và jonsp. (Post) giống như nhận được nhưng chỉ gửi dữ liệu bằng cách sử dụng các phương thức Post.

var postUrl = "GETAndPostRequest.aspx";$("#btnPost").click(funct ion () {$("#dvPost").html(ajax_load);$.post(postUrl, { Name: "Hanika" }, function (result) {$("#dvPost").html(result);});return false;});
Trong mã tôi di chuyển qua các tham số Name và các trang bằng cách sử dụng Request Post.

Về phía server, bạn có thể nhận được giá trị của tham số Name trong đối tượng response formcollection.

if (Request.Form["Name"] != null){ txtName.Text = Request.Form["Name"].ToString();} Firebug cho thấy các tham số thông qua yêu cầu Get và giá trị của tham số này là Hanika.


Tính năng quan trọng:
- Có thể xử lý bất lỳ loại dữ liệu.
- Gửi dữ liệu bằng cách sử dụng phương thức duy nhất là Post

Ajax

Cho phép thực hiện cuộc gọi Ajax. Phương thức này cung cấp kiểm soát nhiều hơn tất cả các phương thức khác mà chúng ta đã thấy. Bạn có thể tìm ra sự khác biệt bằng cách kiểm tra danh sách các tham số.

var ajaxUrl = "Json.htm";$("#btnAjax").click(function () {$("#dvAjax").html(ajax_load);$.ajax({type: "GET", //GET or POST or PUT or DELETE verburl: ajaxUrl, // Location of the servicedata: "", //Data sent to servercontentType: "", // content type sent to serverdataType: "json", //Expected data format from serverprocessdata: true, //True or Falsesuccess: function (json) {//On Successfull service callvar result = json.name;$("#dvAjax").html(result);},error: ServiceFailed// When Service call fails});return false;});
Trong đoạn mã trên, bạn có thể nhìn thấy tất cả các thông số và chú thích dành cho mỗi tham số bằng việc mô tả mục đích.

Firebug hiển thị trang trở lại gọi dữ liệu json và chức năng Ajax xử lý các respose như JSON bởi vì trong mã kiểu dữ liệu = json.


Tính năng quan trọng:
- Cung cấp kiểm soát nhiều hơn việc gửi dữ liệu và yêu cầu dữ liệu.
- Cho phép xử lý lỗi xảy ra trong suốt quá trình call.
- Cho phép xử lý dữ liệu nếu gọi đến trang thành công

Tóm tắt:
Mỗi phương thức của Jquery là khác nhau. Vì vậy, việc sử dụng cho từng mục đích cũng khác nhau.
Nguồn bài viết: Dngaz.com

Monday, December 9, 2013

Posted by Max on Wednesday, September 01, 2010 6:50 AM
If you need to get the identity value from a query, you can use SCOPE_IDENTITY().

In your stored procedure add:

SET @id=SCOPE_IDENTITY()
RETURN @id

and when you create the procedure, declare:

@id int output

-Example-

In this example we create a Stored Procedure to add a new category (idcategory,categoryname). The procedure return the identity value, in this case the id of the category:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[anm_InsertCategory] (
@categoryname nvarchar(256),
@idcategory int output
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [anm_Categories] ([category]) VALUES (@categoryname)
SET @idcategory=SCOPE_IDENTITY()
RETURN @idcategory
END

In this way we use the stored procedure in C#:

string strConn = ConfigurationManager.ConnectionStrings["csname"].ToString();
SqlConnection conn = new SqlConnection(strConn);
SqlCommand command = new SqlCommand("anm_InsertCategory", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@categoryname", SqlDbType.NVarChar).Value = cat_name;
command.Parameters.Add("@idcategory", SqlDbType.Int).Direction = ParameterDirection.Output;
conn.Open();
command.ExecuteNonQuery();
string idcat = command.Parameters["@idcategory"].Value.ToString();


Now the value of the string idcat is the identity value of the new category just added and you can use this value in another query.

Friday, September 6, 2013

Copy and paste this code into proxy.ashx.cs. using System; using System.IO; using System.Net; using System.Web; namespace WebApplication1 { public class proxy : IHttpHandler { public void ProcessRequest(HttpContext context) { HttpResponse response = context.Response; // Check for query string string uri = Uri.UnescapeDataString(context.Request.QueryString.ToString()); if (string.IsNullOrWhiteSpace(uri)) { response.StatusCode = 403; response.End(); return; } // Filter requests if (!uri.ToLowerInvariant().Contains("wikimedia.org")) { response.StatusCode = 403; response.End(); return; } // Create web request WebRequest webRequest = WebRequest.Create(new Uri(uri)); webRequest.Method = context.Request.HttpMethod; // Send the request to the server WebResponse serverResponse = null; try { serverResponse = webRequest.GetResponse(); } catch (WebException webExc) { response.StatusCode = 500; response.StatusDescription = webExc.Status.ToString(); response.Write(webExc.Response); response.End(); return; } // Exit if invalid response if (serverResponse == null) { response.End(); return; } // Configure reponse response.ContentType = serverResponse.ContentType; Stream stream = serverResponse.GetResponseStream(); byte[] buffer = new byte[32768]; int read = 0; int chunk; while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0) { read += chunk; if (read != buffer.Length) { continue; } int nextByte = stream.ReadByte(); if (nextByte == -1) { break; } // Resize the buffer byte[] newBuffer = new byte[buffer.Length * 2]; Array.Copy(buffer, newBuffer, buffer.Length); newBuffer[read] = (byte)nextByte; buffer = newBuffer; read++; } // Buffer is now too big. Shrink it. byte[] ret = new byte[read]; Array.Copy(buffer, ret, read); response.OutputStream.Write(ret, 0, ret.Length); serverResponse.Close(); stream.Close(); response.End(); } public bool IsReusable { get { return false; } } } } Without closing the web browser, append the name of the proxy service and the web resource (highlighted below) that you need access to. For example: http://localhost:51220/proxy.ashx?http://upload.wikimedia.org/wikipedia/en/f/f0/New-esri-logo.jpg

Wednesday, September 4, 2013

Cách làm như sau: Cách 1: chuột phải vào biểu tượng Computer chọn properties hoặc gõ lện chuột trái Computer và gõ lệnh Control PanelAll Control Panel ItemsSystem một của sổ hiện ra ở dòng cuối cùng có chữ change product key màu xanh hiện ra bạn clik chuột vào đó cửa sổ mới mở ra sẽ có chỗ nhập key mới bạn nhập key và chọn next chờ một lúc để active key mơi thế là xong nhớ là máy tính phải nối mạng! Cách 2: Vì không biết win7 của bro active kiểu gì nên không đưa ra được phương án chính xác. Bạn thử thay đổi Key bằng command line xem. Vào Start gõ cmd rồi chuột phải lên cmd chọn Run as Administrator Gõ lệnh : slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX rồi enter Trong đó XXXXX-XXXXX-XXXXX-XXXXX-XXXXX là key của bạn. Để Actived Windows sau khi thay đổi Key gõ tiếp: slmgr.vbs -ato Enter Nếu nó successfully thì OK Cách 3: 1.Slmgr.vbs –ipk (cài đặt, xác nhận và thay đổi K.@.y) VD: slmgr.vbs -ipk 22TKD-F8XX6-YG69F-9M66D-PMJBM 2.Slmgr.vbs -upk (gở bỏ K.@.y đã cài đặt) 3.Slmgr.vbs -ato (kiểm tra sự hoạt động của windows) 4.Slmgr.vbs -dli (hiện thông tin license – chứng nhận) 5.Slmgr.vbs -dlv (hiện full thông tin license) 6.Slmgr.vbs -xpr (hiện ngày hết hạn Expiration) 7.Slmgr.vbs -cpky (làm sạch các product K.@.y trong regedit) 8.Slmgr.vbs -ilc (xác nhận, cài đặt file license) VD: slmgr.vbs -ilc HPQOEMSLIC-MPC.XRM-MS 9.Slmgr.vbs -rilc (gỡ bỏ cài đặt file license) run và gỏ những lệnh cần chạy những lệnh này sẽ giúp bạn kích hoạt key mới . Nếu chắc cú key bạn có là key xịn HERE ARE THE CODES Windows® 7 Ultimate Product Key: FJGCP-4DFJD-GJY49-VJBQ7-HYRR2 342DG-6YJR8-X92GV-V7DCV-P4K27 Windows® 7 Professional Product Key: YKHFT-KW986-GK4PY-FDWYH-7TP9F VTDC3-WM7HP-XMPMX-K4YQ2-WYGJ8 32KD2-K9CTF-M3DJT-4J3WC-733WD 6RQ9V-6GCG4-8WV2H-966GF-DQ4DW Windows® 7 Home Premium Product Key: 7JQWQ-K6KWQ-BJD6C-K3YVH-DVQJG RHPQ2-RMFJH-74XYM-BH4JX-XM76F 2QDBX-9T8HR-2QWT6-HCQ XJ-9YQTR 6RBBT-F8VPQ-QCPVQ-KHR B8-RMV82 C6MHH-TRRPT-74TDC- FHRMV-XB88W 27GBM-Y4QQC-JKHXW-D 9W83-FJQKD 38GRR-KMG3D-BTP99-TC9G4 -BBDJJ CQBVJ-9J697-PWB9R- 4K7W4-2BT4J HWDFB-YVFG4-3TJ7F- Q3WMT-7B6PH Home Basic = MD83G-H98CG-DXPYQ-Q8GCR-HM8X2 Server Home Standard = MCQYD-2TJYQ-JP7KR-7GYYF-YGPXQ Professional = 3YHKG-DVQ27-RYRBX-JMPVM-WG38T Home Premium = RHPQ2-RMFJH-74XYM-BH4JX-XM76F Enterprise = H7X92-3VPBB-Q799D-Y6JJ3-86WC6 Ultimate = D4F6K-QK3RD-TMVMJ-BBMRX-3MBMV

see more here http://dotnetcluster.blogspot.com/2011/06/auto-refresh-div-using-ajax.html

Friday, June 21, 2013

Introduction
This article explains how to export an aspx page to a PDF file.
Requirement
The only requirement is to add the DLL of "ITextSharp" to the application.
Code
In the code behind add the following namespaces:
using iTextSharp.text;
using iTextSharp.text.pdf;
using
iTextSharp.text.html;
using
iTextSharp.text.html.simpleparser;
using
System.Drawing;
Design a page.
Place the following code on the button click event to convert the aspx page into PDF:
protected void Button1_Click(object sender, EventArgs e)
{
       
string attachment = "attachment; filename=" + "abc" + ".pdf";
        Response.ClearContent();

        Response.AddHeader(
"content-disposition", attachment);
        Response.ContentType =
"application/pdf";
       
StringWriter s_tw = new StringWriter();
       
HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
        h_textw.AddStyleAttribute(
"font-size", "7pt");
        h_textw.AddStyleAttribute(
"color", "Black");
        Panel1.RenderControl(h_textw);
//Name of the Panel
       
Document doc = new Document();
        doc =
new Document(PageSize.A4, 5, 5, 15, 5);
       
FontFactory.GetFont("Verdana", 80, iTextSharp.text.Color.RED);
       
PdfWriter.GetInstance(doc, Response.OutputStream);
        doc.Open();

       
StringReader s_tr = new StringReader(s_tw.ToString());
       
HTMLWorker html_worker = new HTMLWorker(doc);
        html_worker.Parse(s_tr);

        doc.Close();
        Response.Write(doc);

   }
public override void VerifyRenderingInServerForm(Control control)
{
}

Saturday, June 15, 2013

This is my version of a class that displays a check box in a DataGridView Header cell.
This is based on the code from http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/827907ea-c529-4254-9b15-2e6d571f5c5b

It assumes that the check box is located in the first DataGridView column. It allows for column caption and provides built-in check/uncheck functionality. Play with x and y parameters to place the checkbox where you want in the header cell.

Here is a usage example:


DataGridViewColumn column = new DataGridViewCheckBoxColumn();
CheckBox ckBoxMaster = CheckBoxInHeader.CreateCheckBoxInHeader(column, 12, 4, "     Select All");
DataGridView1.Controls.Add(ckBoxMaster);


The class listing:

  class CheckBoxInHeader
    {
    public static CheckBox CreateCheckBoxInHeader(DataGridViewColumn column, int x, int y, string caption)
    {
        CheckBoxInHeader cbInHeader = new CheckBoxInHeader();
        CheckBox ckBox = cbInHeader.CreateCheckBox(column, x, y, caption);
        ckBox.CheckedChanged += new EventHandler(cbInHeader.ckBox_CheckedChanged);
        return ckBox;
    }
    private CheckBox CreateCheckBox(DataGridViewColumn column, int x, int y, string caption)
    {
        CheckBox ckBox = new CheckBox();
        //Get the column header cell bounds          
        Rectangle rect = column.DataGridView.GetCellDisplayRectangle(0, -1, true);
        ckBox.Size = new Size(18, 18);
        //play with check box position
        rect.Offset(x, y);
        //Change the location of the CheckBox to make it stay on the header
        ckBox.Location = rect.Location;
        column.Name = caption;
        return ckBox;
    }
    private void ckBox_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox cb = sender as CheckBox;
        DataGridView dgv = (DataGridView)cb.Parent;
        foreach (DataGridViewRow row in dgv.Rows)
        {
            row.Cells[0].Value = cb.Checked;
        }
    }
    }

Saturday, June 8, 2013

1) Open Notepad

2) Paste below code
Call LogEntry()

Sub LogEntry()
On Error Resume Next
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XMLHTTP")
URL = "http://www.YourDomain.com/track.aspx"
objRequest.open "POST", URL , false
objRequest.Send
Set objRequest = Nothing
End Sub

3) Save page as *.vbs

4) Schedule this task using Windows Task Scheduler

Start-> All Programs-> Accessories-> System Tools-> Scheduled Tasks.

To schedule a new task:

1. Double-click Add Scheduled Task to start the Scheduled Task Wizard, and then click Next in the first dialog box.
2. The next dialog box displays a list of programs that are installed on your computer, either as part of the Windows XP operating system, or as a result of software installation.

Use one of the following procedures:
* If the program that you want to run is listed, click the program, and then click Next.
* If you want to run a program, script, or document that is not listed, click Browse, click the folder and file that you want to schedule, and then click Open.
3. Type a name for the task, and then choose one of the following options:
* Daily
* Weekly
* Monthly
* One time only
* When my computer starts (before a user logs on)
* When I log on (only after the current user logs on)

4. Click Next, specify the information about the day and time to run the task, and then click Next.

Note that the information about the day and time to run the task vary depending on the selection that you made in the previous wizard dialog box. For example, if you chose Weekly, you must indicate the day of the week, the time, and if the task should run every week, every 2 weeks, every 3 weeks, and so on.
5. Type the name and password of the user who is associated with this task. Make sure that you choose a user with sufficient permissions to run the program. By default, the wizard selects the name of the user who is currently logged on.
6. Click Next, and then click Finish after you verify the choices that you have made.

Using Advanced Options in Scheduled Tasks
If you want to change the configuration of the task, click Open in the advanced properties for the task before you click Finish. After you click Finish, the Properties dialog box opens for the task.

On the Schedule tab, you can change any of the scheduling options that you chose in the wizard, and you can also change the task configuration so that the task does not run too long, does not run if the computer is running on batteries (for laptops), and to specify whether or not the computer should be idle for the task to run.

NOTE: You can open the Properties dialog box for the task at any time if you open Scheduled Tasks, right-click the task, and then click Properties.

You cannot schedule a task so that it repeats in an interval less than one day; however, you can do this in the Properties dialog box:

1. Click the Schedule tab, and then click Advanced.
2. Click to select the Repeat task check box, and then specify the number of minutes or hours in which you want the task to be repeated.

The following is how you can schedule a windows task that can call an ASP.NET web page. Usually we want to schedule task from Windows. I have seen lots of questions regarding this in the past.

The cool thing about Windows task is that you can execute custom jobs to be executed in the server without the need of a user to be logged in.

The following code can be used to call ASPX web pages to run a specific job that needs to execute some sort of logic. The script is written in VB.NET, but the web page can be written with C# as the vbscript only is used to create the call from the server to the page.

The steps are as follow:


  • Write the Script (VB in this case)
  • Create an ASP.NET page 
  • Schedule the task through the VBS Script
1- Write the script

Call LogEntry()

Sub LogEntry()


        On Error Resume Next

        'variables
        Dim objRequest
        Dim URL

        Set objRequest = CreateObject("Microsoft.XMLHTTP")

        'URL link 
        URL = "http://www.YourDomain.com/MyWebPage.aspx

        'Open the HTTP request and pass the URL 
        objRequest.open "POST", URL , false

        'Send the HTML Request
        objRequest.Send

        'Set the object to nothing
        Set objRequest = Nothing

End Sub

2- Create an ASP.NET page

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="tracklog.aspx.vb" Inherits="Tracklog" %>



    Log Page







Code behind (Here we are presenting an example that returns a page object with the message MyWebPage.aspx was called)


Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Partial Class MyWebPageLog

    Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       Response.write(“MyWebPage.aspx was called:” & System.DateTime.Now())

       End Sub

End Class
3- Scedule a windows task:

NOTE : All the information below has been copied and pasted here from here http://support.microsoft.com/default.aspx?scid=kb;en-us;308569&sd=tech

With Scheduled Tasks, you can schedule any script, program, or document to run at a time that is most convenient for you. Scheduled Tasks starts every time that you start Windows XP and runs in the background, and it starts each task that you schedule at the time that you specify when you create the task.Using Scheduled Tasks
To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Scheduled Tasks.

To schedule a new task:
  1. Double-click Add Scheduled Task to start the Scheduled Task Wizard, and then click Next in the first dialog box.
  2. The next dialog box displays a list of programs that are installed on your computer, either as part of the Windows XP operating system, or as a result of software installation.

    Use one of the following procedures:
    • If the program that you want to run is listed, click the program, and then click Next.
    • If you want to run a program, script, or document that is not listed, click Browse, click the folder and file that you want to schedule, and then click Open.
  3. Type a name for the task, and then choose one of the following options:
    • Daily
    • Weekly
    • Monthly
    • One time only
    • When my computer starts (before a user logs on)
    • When I log on (only after the current user logs on)
  4. Click Next, specify the information about the day and time to run the task, and then click Next.

    Note that the information about the day and time to run the task vary depending on the selection that you made in the previous wizard dialog box. For example, if you chose Weekly, you must indicate the day of the week, the time, and if the task should run every week, every 2 weeks, every 3 weeks, and so on.
  5. Type the name and password of the user who is associated with this task. Make sure that you choose a user with sufficient permissions to run the program. By default, the wizard selects the name of the user who is currently logged on.
  6. Click Next, and then click Finish after you verify the choices that you have made.

Using Advanced Options in Scheduled Tasks

If you want to change the configuration of the task, click Open in the advanced properties for the task before you click Finish. After you click Finish, the Properties dialog box opens for the task.

On the Schedule tab, you can change any of the scheduling options that you chose in the wizard, and you can also change the task configuration so that the task does not run too long, does not run if the computer is running on batteries (for laptops), and to specify whether or not the computer should be idle for the task to run.

NOTE: You can open the Properties dialog box for the task at any time if you open Scheduled Tasks, right-click the task, and then click Properties.

You cannot schedule a task so that it repeats in an interval less than one day; however, you can do this in the Properties dialog box:
  1. Click the Schedule tab, and then click Advanced.
  2. Click to select the Repeat task check box, and then specify the number of minutes or hours in which you want the task to be repeated.

I hope you can find this useful.

Friday, May 17, 2013

I decided to write this post because I have not found a simple and clear description for installing PHP on Windows, and setting this not very common combination to work with MS SQL 2008.
We are currently working on porting the largest system ever created in Deep Shift Labs from Windows 2000 and MS SQL 2000 to Windows 2008 and MS SQL 2008. I want to speak briefly about the history of this system and why we actually needed to install PHP on Windows. The system is about 800K lines of PHP code and it has been helping people to solve their business needs for the last 10 years. This system is designed for one of our customers. The first few years, the system worked on FreeBSD, Apache and PostgreSQL. Then the client’s company went public, and they needed to switch to commercial software. Sometime in 2004, we have been able, thanks to the fact that we originally used ADODB, to move, with a little effort, from FreeBSD/Apache to Windows 2000/IIS 5 (PHP runs as an ISAPI module). Finally, in 2006 we moved the then small database, both in structure and in size, to MS SQL 2000 from PostgreSQL.
The most difficult part in the distant 2006 was to find a driver which is bug free with MS SQL. We had tried everything supported by ADODB back then, and, in the end, we decided in favor of php_dblib.dll suggested and maintained by Frank Kromann. Frank was maintaining MS SQL extensions in PHP project and helped us immensely. The php_mssql.dll driver was using ntwdblib.dll from Microsoft, that does not work with dates and long texts properly. php_dblib.dll used dblib.dll from FreeTDS and we have not found any problems in it and started using it.

And now came the moment when the customer wants to move to the operating system and database that have Microsoft support (Windows 2000 and MS SQL 2000 are not supported anymore) and such a move, in general, is a common requirement in large enterprises.
Naturally, in the ADODB 4.93 we have been using since 2006, there is no mssqlnative driver support and so the challenge was set as follows:
- Move the database from MS SQL 2000 to MS SQL 2008
- Move the web server from Windows 2000 and IIS 5 (ISAPI) on Windows 2008 and IIS 7 (FastCGI)
- Upgrade PHP 5.1.6 to PHP 5.4.6
- Upgrade ADODB from 4.93 to 5.17 with transition to the new driver ‘mssqlnative’
- To test the system, including the two replications processes to our database from servers running MS SQL 2000 and MS SQL 2005.
This is one of the installation methods (obviously the one we used).
1. Create C:\PHP and C:\tmp folders
2. Load non thread safe PHP version recommended for use here and here. The file will contain _nts_ in the name, for example – php-5.4.6-nts-Win32-VC9-x86.zip (latest version available at the time of writing this post) from the site http://windows.php.net/download/.
3. Unpack it in C:\PHP
4. Load latest drivers from MS SQL Microsoft (file SQLSRV30) and extract it to C:\PHP\ext
5. Download the PHP web installer from Microsoft. They offer two versions and I used the latter one available with PHP 5.3.13. Install it.
You can ask a reasonable question why we install 5.3.13 to switch to 5.4.6. There are two reasons. First – I did not manage to set PHP 5.4.6 and manually configure IIS. Despite my attempts to let PHP see its php.ini file inside the C:\PHP I failed to do so. According to all the manuals you need to create a variable PHPRC assigning the path to php.ini, but in my case, someone has done something wrong.
PHPRC did not work for me
Since PHP couldn’t see the configuration file, MS SQL driver was not loaded. Being stuck at this point for a couple of hours I asked for help in the forum and started looking for alternatives, waiting until America wakes up and sees my ‘SOS’ message in the forum. It was then that I accidentally came across a site where I found the alternative I was looking for. Maybe I would not have started using the installer if it had not offered to set this magical and wonderful PHP Manager I could not resist at the thought of trying. In the end I found that the PHP Manager allows adding PHP 5.4.6, making its php.ini file perfectly visible.
Microsoft PHP web installer
It installs all the necessary components as well. It took some 10 years for Microsoft to add some really cool things to run PHP on Windows – here you have MS SQL driver and the installer which adds a special PHP Manager inside IIS, and even Windows Cache PHP accelerator for IIS.
PHP Manager
After installation, we have PHP 5.3.13 installed in the Program Files and PHP Manager inside IIS.
PHP Manager dashboard
As you can see from the PHP Manager, you can control the configuration parameters from php.ini, and the extensions are shown in a separate page. Also here we see what php.ini file is being used and where the error logs are written. There is quick access to the FastCGI handler created by the installer. It is possible to add other versions of PHP and switch between them. We have not tested if it is possible to use PHP Manager to set different PHP versions on different virtual hosts. I think this and much more, such as to use different php.ini files for different virtual hosts can be done manually using the excellent article by Ruslan Yakushev from Microsoft. We just needed to add PHP version 5.4.6 to “live happily ever after”.
Adding PHP 5.4.6
Now we can add PHP 5.4.6, which we put into in C:\PHP. After adding, we see that IIS now uses a new version of PHP, and that PHP Manager created a new handler, which is used (we do not see it here), but we can check with phpinfo(), which PHP manager can dynamically generate for us (how-cool-it-is!).
PHP 5.4.6 can see php.ini now
Now it is time to look at PHP extensions (modules). I removed mysql and added both versions of the MS SQL driver sqlsrv and pdo_sqlsrv. I forgot to check if IIS sees our changes immediately. I am used to executing “iisreset” after changing configuration.
PHP Manager extensions UI
PHP Manager offers two pre-defined configuration options for error handling for development and production.
PHP Manager error reporting UI
When I changed the path to the error log, PHP Manager did not see my changes, and I had to restart the IIS. I really got used to the old fashioned way for a folder for uploaded files, session and logs and store them in PHP C:\tmp. No wonder our periodic scripts are in C:\etc. Options ‘Configure error reporting’ and ‘Set runtime limits’ are kept separately in PHP Manager for convenience only, as they all (except for the extension modules) are available from the ‘Manage all settings’ panel.
PHP Manager points to a wrong location after PHP version switch
If you need to parse HTML files with PHP – create one more mapping by looking at parameters of existing PHP mapping you already have.
Setting PHP to handle HTML files (if needed)
Now we can try to connect to MS SQL with the driver only and via ADODB. First you need to make sure the server is configured to allow TCP/IP as well as port 1433 is open on the Windows firewall.
Checking SQL Server networking
In my case it was not so. If you cannot connect from PHP, it is recommended to install SQLCMD and use it for testing. For example, here we will find the required version of SQLCMD.
I want to draw your attention to the fact that the new Microsoft driver returns datetime as PHP DateTime:: object. But we use ADODB, which does this little trick converting this object into a string on line 794 of adodb-mssqlnative.inc.php file:

$this->fields[$key] = $value->format("Y-m-d\TH:i:s\Z");
Thus, returning us the string ’2012-08-22T23:42:22Z ‘instead of the usual ’2012-08-22 23:42:22′ and so for backward compatibility, you can correct adodb-mssqlnative.inc.php this way:
if(is_array($this->fields)) {
    foreach($this->fields as $key=>$value) {
        if (is_object($value) && method_exists($value, 'format')) {//is DateTime object
     //$this->fields[$key] = $value->format("Y-m-d\TH:i:s\Z");
            //DSL DateTime output format fix
            $this->fields[$key] = $value->format("Y-m-d H:i:s");
 }
    }
}
Here is an example, where you can find connection and query snippets which use Microsoft driver directly and via ADODB.

echo "Direct driver connection
";
$connectionInfo = array(
      "UID"=>'aws_user',
      "PWD"=>'Q1w2e3r4t5',
      "Database"=>"AWS_Database"
);
 
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect('192.168.3.86, 1433', $connectionInfo);
if( $conn === false )
{
   echo "Unable to connect.";
   die( print_r( sqlsrv_errors(), true));
}
 
 
$tsql = "SELECT GETDATE() AS today";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
   echo "Error in executing query.";
   die( print_r( sqlsrv_errors(), true));
}
 
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
echo "Today is ".$row['today']->format('Y-m-d H:i:s')."";
 
 
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
 
ini_set( "include_path", ini_get( "include_path" ) . ";" . $_SERVER["DOCUMENT_ROOT"] . "/include" );
require_once("adodb5\adodb.inc.php");
$user     = "aws_user";
$password = "Q1w2e3r4t5";
$server="192.168.3.86, 1433";
$database = "AWS_Database";
 
echo "ADODB MSSQL Native connection
";
$adoConnection = ADONewConnection('mssqlnative');
//$adoConnection->debug = true;
$adoConnection->Connect($server, $user, $password, $database);
 
 
$rs = $adoConnection->Execute($tsql);
 
echo "Today is ".$rs->fields['today']."";
$adoConnection->Close();
?>
In conclusion, we want to say that the Microsoft site provides a lot of useful information for running PHP on IIS and using Microsoft drivers to connect to MS SQL. For example, here you will find the entry to the forum PHP/IIS, and other useful links. Forums dedicated to PHP driver for MS SQL databases are located here. I used them more-than-once. They are active and guys helped me a lot.
Finally a couple of handy articles on how to configure PHP on IIS:
- Enable Per-Site PHP Configuration on IIS 7 and IIS 6.0
- Using FastCGI to Host PHP Applications on IIS
- Using FastCGI to Host PHP Applications on IIS 6.0

see more here http://www.deepshiftlabs.com/dev_blog/?p=1880&lang=en-us

Tuesday, February 26, 2013

see this link http://clarkupdike.blogspot.com/2009/03/basic-example-of-jquerys-uidialog.html

I have looked at many examples of inserting an iframe into a jQuery UI dialog and have had little success. Then I came across this blog post describing a method that works… function showDialog(){ $("#divId").html('

Facebook

JQuery

jQuery(function($) {
    $(document).ready(function() {
        $('#panelHandle').hover(function() {
            $('#sidePanel').stop(true, false).animate({
                'left': '0px'
            }, 900);
        }, function() {
            jQuery.noConflict();
        });

        jQuery('#sidePanel').hover(function() {
            // Do nothing
        }, function() {

            jQuery.noConflict();
            jQuery('#sidePanel').animate({
                left: '-201px'
            }, 800);

        });
    });
});
 
demo here http://jsfiddle.net/nirajmchauhan/GPdFk/ 

Open command prompts and run these commands one by one on command prompt

  • cd /d C:\Windows\Microsoft.NET\Framework\v4.0.30319
  • iisreset /stop
  • aspnet_regiis -i
  • iisreset /start
  • %systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /[path='%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll'].allowed:True 
  • %systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /[path='%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll'].allowed:True

In this post, I will show you how to get the QueryString variable value using jQuery. I have created a function which returns value of any querystring variable.

//Code Starts
function GetQueryStringParams(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}​
//Code Ends 
 
And this is how you can use this function assuming the URL is,

 "http://phattrienweb.com/?technology=jquery&blog=jquerybyexample". 
 
//
var tech = GetQueryStringParams('technology');
var blog = GetQueryStringParams('blog');
//
 
OR....
 
 // Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
 


 var first = getUrlVars()["qid"];


http://phattrienweb.com/