Exemplo n.º 1
0
    void SendResultInfoAsJson(GetNameFromVersionResponse res)
    {
        string strJson = JsonConvert.SerializeObject(res);

        Response.ContentType = "application/json; charset=utf-8";
        Response.Write(strJson);
        Response.End();
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        GetNameFromVersionResponse res = new GetNameFromVersionResponse();
        GetNameFromVersionRequest  req;

        res.error = String.Empty;

        // Need passed in store id and number of requested results.
        // 1. Deserialize the incoming Json.
        try
        {
            req = GetRequestInfo();
        }
        catch (Exception ex)
        {
            res.error = ex.Message.ToString();

            // Return the results as Json.
            SendResultInfoAsJson(res);

            return;
        }

        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        try
        {
            connection.Open();

            string         sql     = String.Format("select * from PKkeys where version='{0}'", req.version);
            SqlCommand     command = new SqlCommand(sql, connection);
            SqlDataReader  reader  = command.ExecuteReader();
            List <KeyInfo> list    = new List <KeyInfo>();
            while (reader.Read())
            {
//				res.name = Convert.ToString( reader["name"] );
//				list.Add( Convert.ToString( reader["name"] ) );
                KeyInfo ci = new KeyInfo();
                ci.name = Convert.ToString(reader["name"]);
                ci.kID  = Convert.ToInt32(reader["kID"]);
                list.Add(ci);
            }
            reader.Close();

            res.keysFound = list.ToArray();
        }
        catch (Exception ex)
        {
            res.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

        // Return the results as Json.
        SendResultInfoAsJson(res);
    }