Пример #1
0
        public void GetMyTool(String UserID)
        {
            JavaScriptSerializer ser = new JavaScriptSerializer();

            ToolListing[] ToolData = null;
            int           HasTool  = 0;

            Array[] tab = null;
            try
            {
                using (SqlConnection connextion = new SqlConnection(DBConnection.ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("SELECT * FROM Tools where UserID=@UserID");
                    cmd.CommandType = CommandType.Text;

                    cmd.Connection = connextion;
                    cmd.Parameters.AddWithValue("@UserID", UserID);

                    connextion.Open();
                    SqlDataAdapter adpt      = new SqlDataAdapter(cmd);
                    DataTable      datatable = new DataTable();
                    adpt.Fill(datatable);
                    ToolData = new ToolListing[datatable.Rows.Count];

                    for (int i = 0; i < datatable.Rows.Count; i++)
                    {
                        ToolData[i]           = new ToolListing();
                        ToolData[i].ToolID    = Convert.ToString(datatable.Rows[i]["ToolID"]);
                        ToolData[i].ToolName  = Convert.ToString(datatable.Rows[i]["ToolName"]);
                        ToolData[i].ToolDes   = Convert.ToString(datatable.Rows[i]["ToolDes"]);
                        ToolData[i].ToolPrice = Convert.ToString(datatable.Rows[i]["ToolPrice"]);
                        ToolData[i].DateAdd   = Convert.ToString(datatable.Rows[i]["DateAdd"]);

                        // get tool image


                        ToolData[i].PictureLink = PicLink(ToolData[i].ToolID);
                    }



                    if (datatable.Rows.Count > 0)
                    {
                        HasTool = 1;
                        datatable.Clear();
                        connextion.Close();
                    }
                }
            }
            catch (Exception e)
            {
            }
            var jsonData = new
            {
                HasTool  = HasTool,
                ToolData = ToolData
            };

            HttpContext.Current.Response.Write(ser.Serialize(jsonData));
        }
Пример #2
0
        public void GetToolListing(String UserID, String Distance, String From, String to, String ToolTypeID, String ToolID, String q)
        {
            if (q.Equals("@"))
            {
                q = "%";
            }
            else
            {
                q = "%" + q + "%";
            }
            JavaScriptSerializer ser = new JavaScriptSerializer();

            ToolListing[] ToolData = null;
            int           HasTool  = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(DBConnection.ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "ToolListing";
                    cmd.Connection  = connection;
                    cmd.Parameters.AddWithValue("@UserID", UserID);
                    cmd.Parameters.AddWithValue("@Distance", Distance);
                    cmd.Parameters.AddWithValue("@From", From);
                    cmd.Parameters.AddWithValue("@to", to);
                    cmd.Parameters.AddWithValue("@ToolTypeID", ToolTypeID);
                    cmd.Parameters.AddWithValue("@q", q);
                    cmd.Parameters.AddWithValue("@ToolID", ToolID);
                    connection.Open();
                    SqlDataAdapter adpt      = new SqlDataAdapter(cmd);
                    DataTable      dataTable = new DataTable();
                    adpt.Fill(dataTable);
                    ToolData = new ToolListing[dataTable.Rows.Count];

                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        ToolData[i]             = new ToolListing();
                        ToolData[i].ToolID      = Convert.ToString(dataTable.Rows[i]["ToolID"]);
                        ToolData[i].ToolName    = Convert.ToString(dataTable.Rows[i]["ToolName"]);
                        ToolData[i].ToolDes     = Convert.ToString(dataTable.Rows[i]["ToolDes"]);
                        ToolData[i].ToolPrice   = Convert.ToString(dataTable.Rows[i]["ToolPrice"]);
                        ToolData[i].DateAdd     = Convert.ToString(dataTable.Rows[i]["DateAdd"]);
                        ToolData[i].PictureLink = Convert.ToString(dataTable.Rows[i]["PictureLink"]);
                    }
                    if (dataTable.Rows.Count > 0)
                    {
                        HasTool = 1;
                        dataTable.Clear();
                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            var jsonData = new
            {
                ToolData = ToolData,
                HasTool  = HasTool
            };

            HttpContext.Current.Response.Write(ser.Serialize(jsonData));
        }