In this step, you'll create your application and add folders to your application. You'll also add a database file and two code files to the folders.
To write code in C#
| C# |
Copy Code
|
|---|---|
using System.Collections.Generic;
using System.Linq;
using System.Web;
///<summary>
/// Summary description for Orders
/// </summary>
public class Orders
{
private double amount;
private string year,month,day;
public string Year
{
get
{
return year;
}
set
{
year = value;
}
}
public string Month
{
get
{
switch (month)
{
case "1": month = "Jan"; break;
case "2": month = "Feb"; break;
case "3": month = "Mar"; break;
case "4": month = "Apr"; break;
case "5": month = "May"; break;
case "6": month = "Jun"; break;
case "7": month = "Jul"; break;
case "8": month = "Aug"; break;
case "9": month = "Sep"; break;
case "10": month = "Oct"; break;
case "11": month = "Nov"; break;
case "12": month = "Dec"; break;
}
return month;
}
set
{
month = value;
}
}
public string Day
{
get
{
return day;
}
set
{
day = value;
}
}
public double OrderAmount
{
get
{
return amount;
}
set
{
amount = value;
}
}
}
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.OleDb;
using System.Web.Script.Services;
/// <summary>
/// Summary description for GetOrders
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class GetOrders : System.Web.Services.WebService {
public GetOrders () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Orders> GetDataOnLoad()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/OrdersDataBase.mdb"));
OleDbCommand cmd = new OleDbCommand("Select Year(OrderDate), Sum(OrderAmount) from OrdersByDate where Year(OrderDate) In (Select Distinct(Year(OrderDate)) from OrdersByDate) Group By Year(OrderDate)", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<Orders> orders = new List<Orders>();
for (int i = i < dt.Rows.Count; i++)
{
Orders od = new Orders();
od.Year = Convert.ToString(dt.Rows[i][0]);
od.OrderAmount = Convert.ToDouble(dt.Rows[i][1]);
orders.Add(od);
}
return orders;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Orders> GetOrderByMonth(string Year)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/OrdersDataBase.mdb"));
OleDbCommand cmd = new OleDbCommand("Select Month(OrderDate), Sum(OrderAmount) from OrdersByDate where Month(OrderDate) In (Select Distinct Month(OrderDate) from OrdersByDate) and Year(OrderDate)="+ Year + " Group By Month(OrderDate)", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dtMonths = new DataTable();
da.Fill(dtMonths);
List<Orders> orders = new List<Orders>();
for (int i = i < dtMonths.Rows.Count; i++)
{
Orders od = new Orders();
od.Month = Convert.ToString(dtMonths.Rows[i][0]);
od.OrderAmount = Convert.ToDouble(dtMonths.Rows[i][1]);
orders.Add(od);
}
return orders;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Orders> GetOrderByDay(string Month, string Year)
{
switch (Month)
{
case "Jan": Month = "1"; break;
case "Feb": Month = "2"; break;
case "Mar": Month = "3"; break;
case "Apr": Month = "4"; break;
case "May": Month = "5"; break;
case "Jun": Month = "6"; break;
case "Jul": Month = "7"; break;
case "Aug": Month = "8"; break;
case "Sep": Month = "9"; break;
case "Oct": Month = "10"; break;
case "Nov": Month = "11"; break;
case "Dec": Month = "12"; break;
}
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/OrdersDataBase.mdb"));
OleDbCommand cmd = new OleDbCommand("Select Day(OrderDate), Sum(OrderAmount) from OrdersByDate where Day(OrderDate) In (Select Distinct Day(OrderDate) from OrdersByDate) and Year(OrderDate)=" + Year + " and Month(OrderDate)="+Month+" Group By Day(OrderDate)", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dtDays = new DataTable();
da.Fill(dtDays);
List<Orders> orders = new List<Orders>();
for (int i = i < dtDays.Rows.Count; i++)
{
Orders od = new Orders();
od.Day = Convert.ToString(dtDays.Rows[i][0]);
od.OrderAmount = Convert.ToDouble(dtDays.Rows[i][1]);
orders.Add(od);
}
return orders;
}
}
|
|
To write code in Source View
<%http://helpcentral.componentone.com/nethelp/c1studioWeb%>