using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; //connect to database using System.Data.SqlClient; using System.Data; using System.Configuration; using System.Collections; //to use string ehhehee using System.Text; using System.IO; //message box public partial class Pre_Owned_customasp_searchcarcontrol : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { Get_CarDetail(); } protected void Link_Click(object sender, EventArgs e) { Session["year"] = "0"; Session["model"] = (sender as LinkButton).Text; // Session["model"] = "0"; Session["location"] = "0"; Session["counter"] = "1"; //Response.Redirect("~/searchlist.aspx?currentvalue=1" + "&var1=" + (string)(Session["year"]) + "&var2=" + (string)(Session["model"]) +"&var3="+(string)(Session["location"])); Response.Redirect("~/searchlist.aspx?currentvalue=1"); } protected void Get_CarDetail() { SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString); try { DataSet dq = new DataSet(); DataTable dt = new DataTable(); dq.Tables.Add(dt); SqlCommand cmd = new SqlCommand(); cmd.Connection = myConnection; // cmd.CommandType = CommandType.StoredProcedure; //cmd.CommandText = "SELECT TOP 6 car_model,car_year,car_price,car_location,car_plate,car_status,status_date FROM(SELECT * FROM cardatabase WHERE car_approve = 'Approved' AND car_status = 'Available' UNION ALL SELECT * FROM cardatabase where car_approve = 'Approved' AND car_status = 'Booked' AND status_date Between DateAdd(DD,-7,GETDATE() ) and GETDATE() UNION ALL SELECT * FROM cardatabase where car_approve = 'Approved' AND car_status = 'Sold' AND status_date Between DateAdd(DD,-14,GETDATE() ) and GETDATE()) AS a ORDER BY car_year DESC, car_price ASC"; cmd.CommandText = "SELECT TOP 6 car_model,car_year,car_price,car_location,car_plate,car_status,status_date FROM cardatabase WHERE car_approve = 'Approved' AND (car_status = 'Available' OR (car_status = 'Booked' AND status_date Between DateAdd(DD,-7,GETDATE() ) and GETDATE()) OR (car_status = 'Sold' AND status_date Between DateAdd(DD,-14,GETDATE() ) and GETDATE()) ) ORDER BY car_year DESC, car_price ASC"; //cmd.CommandText = "SELECT car_model,car_year,car_price,car_location,car_plate,car_status FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY car_year DESC) as row FROM cardatabase WHERE car_approve = 'Approved') a WHERE row >0 AND row <= 6"; myConnection.Open(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(dt); string[] myallsearch = new string[dt.Rows.Count]; string[] myyear = new string[dt.Rows.Count]; string[] mymodel = new string[dt.Rows.Count]; string[] imgplate = new string[dt.Rows.Count]; string[] myprice = new string[dt.Rows.Count]; string[] mylocation = new string[dt.Rows.Count]; string[] myplate = new string[dt.Rows.Count]; string[] mystatus = new string[dt.Rows.Count]; int[] whyohwhy = new int[dt.Rows.Count]; StringBuilder sb = new StringBuilder(); for (int i = 0; i <= dt.Rows.Count - 1; i++) { mymodel[i] = dt.Rows[i][0].ToString(); myyear[i] = dt.Rows[i][1].ToString(); whyohwhy[i]=Convert.ToInt32(dt.Rows[i][2]); myprice[i] = string.Format("{0:#,###0}",whyohwhy[i]); mylocation[i] = dt.Rows[i][3].ToString(); myplate[i] = Uri.EscapeDataString(dt.Rows[i][4].ToString()); imgplate[i] = myplate[i].Replace("%20", "_"); mystatus[i] = dt.Rows[i][5].ToString(); if ( mystatus[i] == "Sold") { myallsearch[i] = "

" + mymodel[i] + " " + myyear[i] + "RM" + myprice[i] + "

"; } else if ( mystatus[i] == "Booked") { myallsearch[i] = "

" + mymodel[i] + " " + myyear[i] + "RM" + myprice[i] + "

"; } else { myallsearch[i] = "

" + mymodel[i] + " " + myyear[i] + "RM" + myprice[i] + "

"; } //myallsearch[i] = "
"; sb.Append(myallsearch[i]); carplaceholder.InnerHtml = "
" + sb.ToString(); } } catch (Exception f) { Console.WriteLine(f.ToString()); } finally { // Close Connection myConnection.Close(); //valuecheck.Text = dt.Rows[4][0].ToString(); //valuecheck.Text = "ahahhahahahahahsduajancan198237172412542174192"; } } }