|
|
|
ผู้ที่มีความรู้ภาษา C# กรุณาให้คำแนะนำหรือชี้แนะเพิ่มเติมด้วยนะคะ กำลังฝึกหัดไม่ค่อยทราบเท่าไหร่ |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TourPlanLib;
public partial class sort : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Member"] == null)
{
Response.Redirect("login.aspx");
}
List<TourPlanLib.PlaceVO> places = (List<TourPlanLib.PlaceVO>)Session["plan_place"];
List<PassengerDTO> passengers = (List<PassengerDTO>)Session["plan_passengers"];
labelStart.Text = ((DateTime)Session["startDate"]).ToString("dd MMMM yyyy");
// labelEnd.Text = ((DateTime)Session["endDate"]).ToString("dd MMMM yyyy");
int kid=0;
int person = 0;
int foriogn = 0;
foreach (PassengerDTO pass in passengers)
{
if (pass.Nation != "Thai")
{
foriogn++;
continue;
}
else
{
if (pass.Age >= 15)
{
person++;
continue;
}
else
{
kid ++;
continue;
}
}
}
bool p = false;
decimal sum = 0;
foreach (PlaceVO place in places)
{
if (!p)
{
CenterPoint += String.Format(@"
var centerPoint= new GLatLng({0}, {1});
", place.Place.Lat, place.Place.Lon);
// BaseMarker += " baseMarker = new GMarker(centerPoint, {{ draggable: true }})";
p=true;
}
MyPlace += String.Format("myPoints.push(new GLatLng({0}, {1})); ", place.Place.Lat, place.Place.Lon);
#region row head
TableRow tr = new TableRow();
tr.CssClass = "even";
TableCell tc = new TableCell();
tc.CssClass = "table-col-0";
tc.Controls.Add(new LiteralControl(place.Place_name));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl("ราคา"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl("จำนวน"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl("รวม"));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
#endregion
#region row ผู้ใหญ่
tr = new TableRow();
tc = new TableCell();
tc.Controls.Add(new LiteralControl("ผู้ใหญ่"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl(place.Place.Place_fee.ToString("#,##0.## บาท")));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl(person.ToString()+ " คน" ));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl((person * place.Place.Place_fee).ToString("#,##0.## บาท")));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
#endregion
#region row เด็ก
tr = new TableRow();
tc = new TableCell();
tc.Controls.Add(new LiteralControl("เด็ก"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl(place.Place.Place_fee.ToString("#,##0.## บาท")));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl(kid.ToString() + " คน"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl((kid * place.Place.Place_fee).ToString("#,##0.## บาท")));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
#endregion
#region row ชาวต่างชาติ
tr = new TableRow();
tc = new TableCell();
tc.Controls.Add(new LiteralControl("ชาวต่างชาติ"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl(place.Place.Place_fee.ToString("#,##0.## บาท")));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl(foriogn.ToString() + " คน"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl((foriogn * place.Place.Place_fee).ToString("#,##0.## บาท")));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
#endregion
sum += passengers.Count * place.Place.Place_fee;
}
#region row สรุป
TableRow tr1 = new TableRow();
tr1.CssClass = "odd";
TableCell tc1 = new TableCell();
tc1.Controls.Add(new LiteralControl("รวม"));
tr1.Cells.Add(tc1);
tc1 = new TableCell();
tc1.Controls.Add(new LiteralControl(""));
tr1.Cells.Add(tc1);
tc1 = new TableCell();
tc1.Controls.Add(new LiteralControl(passengers.Count + " คน"));
tr1.Cells.Add(tc1);
tc1 = new TableCell();
tc1.Controls.Add(new LiteralControl(sum.ToString("#,##0.## บาท")));
tr1.Cells.Add(tc1);
Table1.Rows.Add(tr1);
#endregion
}
public String MyPlace
{
get;
set;
}
public String CenterPoint
{
get;
set;
}
//public String CenterPoint2
//{
// get;
// set;
//}
public String BaseMarker
{
get;
set;
}
protected void cbCalculateTime_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
{
}
protected void cbpCalculateTime_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
String[] param= e.Parameter.Split(new char[] { '/' });
String[] place = new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"};
String[] temp = param[0].Split(new char[] { ',' });
List<TourPlanLib.PlaceVO> places1 = (List<TourPlanLib.PlaceVO>)Session["plan_place"];
List<TourPlanLib.PlaceVO> placesSorted = new List<TourPlanLib.PlaceVO>();
String[] latLOns = param[1].Split(new char[] { ',' });
for (int ii = 0; ii < latLOns.Length; ii++)
{
if (latLOns[ii].Length == 0) continue;
String[] lat_Lon = latLOns[ii].Split(new char[] { '-' });
for (int j = 0;j < places1.Count; j++)
{
if (lat_Lon[0].Equals(places1[j].Place.Lat.ToString()) && lat_Lon[1].Equals(places1[j].Place.Lon.ToString()))
{
placesSorted.Add(places1[j]);
break;
}
}
}
DateTime startTime=(DateTime) Session["startTime"] ;
// int hour =int.Parse( ((decimal)Session["hour"]).ToString() );
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(new LiteralControl(startTime.ToString("HH:mm")));
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(new LiteralControl("ออกเดินทาง"));
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(new LiteralControl(""));
row.Cells.Add(cell);
TableTime.Rows.Add(row);
int i = 0;
//row 2 ที่แรก
row = new TableRow();
cell = new TableCell();
cell.Width = new Unit(100);
startTime = startTime.Add(new TimeSpan(1, 0, 0));
cell.Controls.Add(new LiteralControl(startTime.ToString("HH:mm")));
row.Cells.Add(cell);
cell = new TableCell();
cell.Width = new Unit(100);
cell.Controls.Add(new LiteralControl("ถึงสถานที่ " + placesSorted[i].Place_name));
row.Cells.Add(cell);
String old = startTime.ToString("HH:mm");
startTime = startTime.Add(new TimeSpan(placesSorted[i].Place.Hour, 0, 0));//เที่ยว
cell = new TableCell();
cell.Width = new Unit(200);
cell.Controls.Add(new LiteralControl(old + " - " + startTime.ToString("HH:mm")));
row.Cells.Add(cell);
cell = new TableCell();
cell.Width = new Unit(200);
cell.Controls.Add(new LiteralControl("เวลาที่อยู่ " + placesSorted[i].Place.Hour+" ชม."));
row.Cells.Add(cell);
TableTime.Rows.Add(row);
// startTime = startTime.Add(new TimeSpan(hour, 0, 0));//เที่ยว
i++;
foreach (String s in temp)
{
if (s.Length > 0)
{
row = new TableRow();
cell = new TableCell();
String[] temp2 = s.ToString().Split(new char[]{'.'});
String temp3 = temp2[1].Substring(0, 2);
startTime = startTime.Add(new TimeSpan(0,int.Parse(temp2[0]),
int.Parse(temp3)));
cell.Controls.Add(new LiteralControl(startTime.ToString("HH:mm")));
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(new LiteralControl("ถึงสถานที่ " + placesSorted[i].Place_name));
row.Cells.Add(cell);
old = startTime.ToString("HH:mm");
startTime = startTime.Add(new TimeSpan(placesSorted[i].Place.Hour, 0, 0));//เที่ยว
cell = new TableCell();
cell.Controls.Add(new LiteralControl(old+" - "+startTime.ToString("HH:mm")));
row.Cells.Add(cell);
cell = new TableCell();
cell.Width = new Unit(200);
cell.Controls.Add(new LiteralControl("เวลาที่อยู่ " + placesSorted[i].Place.Hour + " ชม."));
row.Cells.Add(cell);
i++;
TableTime.Rows.Add(row);
}
}
}
}
|
|
|
|
|
Date :
2011-03-18 16:21:40 |
By :
หมูแดง |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|