protected void Page_Load(object sender, EventArgs e)
    {
        // Get the JSON input object from a client.
        Hashtable jsonInput = JSONUtil.GetJSONObject(Request);

        // Read input data from jsonInput: customer ID
        // If you want to know the format of the input and output data,
        // go to the description of function checkIfCustomerExists()
        // in Ex11_CheckIfCustomerExists_Client.js.
        Dictionary <string, object> jsonContent
            = (Dictionary <string, object>)jsonInput["content"];
        string customerId
            = Convert.ToString(jsonContent["customer_id"]);

        // Check if the customer exists in the database.
        HomeShoppingDataManager dataManager = HomeShoppingDataManager.getInstance();
        bool ifCustomerExists = dataManager.checkIfCustomerExists(customerId);

        // Create output JSON object.
        Hashtable jsonOutput        = new Hashtable();
        Hashtable jsonOutputHeader  = new Hashtable();
        Hashtable jsonOutputContent = new Hashtable();

        jsonOutputHeader.Add("svc_res_code", 100);
        jsonOutputContent.Add("if_customer_exists", ifCustomerExists);
        jsonOutput.Add("header", jsonOutputHeader);
        jsonOutput.Add("content", jsonOutputContent);

        // Send the output JSON object to the client.
        // Serializing is needed to transform the object to a string.
        Response.Write(JSONUtil.toStringFromJSON(jsonOutput));
        Response.End();
    }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get the JSON input object from a client.
        Hashtable jsonInput = JSONUtil.GetJSONObject(Request);

        // Read input data from jsonInput
        string customerId     = Convert.ToString(jsonInput["customer_id"]);
        string customerPw     = Convert.ToString(jsonInput["customer_pw"]);
        string customerName   = Convert.ToString(jsonInput["customer_name"]);
        string customerMobile = Convert.ToString(jsonInput["customer_mobile"]);
        string customerEmail  = Convert.ToString(jsonInput["customer_email"]);

        // Make the connection to the database server.
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_HomeShopping"].ConnectionString);

        // Write the query to update the customer by the ID.
        string sql = "UPDATE dbo.HS_Customer SET "
                     + "customer_pw = @customerPw, "
                     + "customer_name = @customerName, "
                     + "customer_mobile = @customerMobile, "
                     + "customer_email = @customerEmail "
                     + "WHERE customer_id = @customerId";
        SqlCommand cmd = new SqlCommand(sql, con);

        cmd.Parameters.AddWithValue("@customerPw", customerPw);
        cmd.Parameters.AddWithValue("@customerName", customerName);
        cmd.Parameters.AddWithValue("@customerMobile", customerMobile);
        cmd.Parameters.AddWithValue("@customerEmail", customerEmail);
        cmd.Parameters.AddWithValue("@customerId", customerId);

        // Execute update command.
        string result = "success";

        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception ex)
        {
            result = "fail by exception";
        }

        // Create output JSON object.
        Hashtable jsonOutput = new Hashtable();

        jsonOutput.Add("update_result", result);

        // Send the output JSON object to the client.
        // Serializing is needed to transform the object to a string.
        Response.Write(JSONUtil.toStringFromJSON(jsonOutput));
        Response.End();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get the JSON input object from a client.
        Hashtable jsonInput = JSONUtil.GetJSONObject(Request);

        // Read input data from jsonInput.
        string customerId = Convert.ToString(jsonInput["customer_id"]);

        // Create output JSON object.
        Hashtable jsonOutput = new Hashtable();

        jsonOutput.Add("customers", findCustomerById(customerId));

        // Send the output JSON object to the client.
        // Serializing is needed to transform the object to a string.
        Response.Write(JSONUtil.toStringFromJSON(jsonOutput));
        Response.End();
    }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get the JSON input object from a client.
        Hashtable jsonInput = JSONUtil.GetJSONObject(Request);

        // Read input data from jsonInput.
        long dollar = Convert.ToInt64(jsonInput["dollar"]);

        // Create output data.
        long won = convertDollarToWon(dollar);

        // Create output JSON object.
        Hashtable jsonOutput = new Hashtable();

        jsonOutput.Add("won", won);
        jsonOutput.Add("dollar", dollar);

        // Send the output JSON object to the client.
        // Serializing is needed to transform the object to a string.
        Response.Write(JSONUtil.toStringFromJSON(jsonOutput));
        Response.End();
    }