Bao cao thuc tap- trung tam athena

25
BÁO CÁO TIẾN ĐỘ THỰC TẬP ĐỢT 2 (ca thực tập sang thứ 2,4,6) Đề Tài: Xây Dựng Phần Mềm Quản Lý Khách Hàng Trên Hệ Điều Hành Android SVTH: Nguyễn Duy Bá Tài GVHD: Thầy Võ Đỗ Thắng

description

no coment

Transcript of Bao cao thuc tap- trung tam athena

Page 1: Bao cao thuc tap- trung tam athena

BÁO CÁO TIẾN ĐỘ THỰC TẬP ĐỢT 2

(ca thực tập sang thứ 2,4,6)

Đề Tài: Xây Dựng Phần Mềm Quản Lý Khách Hàng Trên Hệ Điều Hành Android

SVTH: Nguyễn Duy Bá Tài

GVHD: Thầy Võ Đỗ Thắng

Page 2: Bao cao thuc tap- trung tam athena

I. Dữ Liệu Database lưu trên localhost

Hiện có là bảng customer, các bảng khác sẽ được cập nhật sau:

Gồm các trường: id, name, gender, mobile email, birth_day, create_at, dtl(diểm tích lũy),

Updated_at,type_customer.

Page 3: Bao cao thuc tap- trung tam athena

II. Kết Nối PHP, MYSQL với Localhost- Tạo kết nối giữa android để cập nhật dữ liệu lên về thông qua kết nối PHP, với các

phần source code read all customer, read detail customer, deleting customer, update customer..vv, đối với các bảng khác sẽ có các phần source tương ứng PHP, MYSQL

- Source code PHP, MYSQL.

db_config.php: định nghĩa các phần user, name database, localhost, password

<?php

/*

* All database connection variables

*/

define('DB_USER',"root");

define('DB_PASSWORD',"");

define('DB_DATABASE',"customer_management");

define('DB_SERVER',"localhost");

?>

db_connect.php:

<?php

/**

* A class file to connect to database

*/

Page 4: Bao cao thuc tap- trung tam athena

class DB_CONNECT {

// constructor

function __construct() {

//connecting to database

$this->connect();

}

// destructor

function __destruct() {

// closing db connection

$this->close();

}

/**

* Function to connect with database

*/

function connect() {

// import database connection variables

require_once __DIR__ . '/db_config.php';

mysql_query("SET NAMES 'utf8'");

// Connecting to mysql database

$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());

Page 5: Bao cao thuc tap- trung tam athena

// Selecing database

$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());

// returing connection cursor

return $con;

}

/**

* Function to close db connection

*/

function close() {

// closing db connection

mysql_close();

}

}

?>

read_all_customer: đọc các hàng của database

<?php

/*

* Following code will list all the customer

Page 6: Bao cao thuc tap- trung tam athena

*/

// array for JSON response

$response = array();

// include db connect class

require_once __DIR__ . '/db_connect.php';

// connecting to db

$db = new DB_CONNECT();

mysql_query("SET NAMES 'UTF8'");

// get all customer from customer table

$result = mysql_query("SELECT *FROM customer") or die(mysql_error());

$result1 = mysql_query("UPDATE customer SET type_customer ='VIP' WHERE dtl >50 AND dtl <200");

$result2 = mysql_query("UPDATE customer ORDER BY dtl DESC ");

// check for empty result

if (mysql_num_rows($result) > 0) {

// looping through all results

// customer node

$response["customers"] = array();

while ($row = mysql_fetch_array($result)) {

// temp user array

Page 7: Bao cao thuc tap- trung tam athena

$customers = array();

$customers["pid"] =$row["pid"];

$customers["name"] = $row["name"];

$customers["mobile"] = $row["mobile"];

$customers["gender"] = $row["gender"];

$customers["email"] = $row["email"];

$customers["birth_day"] =$row["birth_day"];

$customers["address"] = $row["address"];

$customers["dtl"] = $row["dtl"];

$customers["type_customer"] = $row["type_customer"];

$customers["created_at"] = $row["created_at"];

// push single product into final response array

array_push($response["customers"], $customers);

}

// success

//mysql_free_result($result);

$response["success"] = 1;

// echoing JSON response

echo json_encode($response);

} else {

// no customer found

Page 8: Bao cao thuc tap- trung tam athena

$response["success"] = 0;

$response["message"] = "No customer found";

// echo no users JSON

echo json_encode($response);

}

?>

read_customer: đọc 1 row

<?php

/*

* Following code will get single customer details

* A customer is identified by customer id (pid)

*/

// array for JSON response

$response = array();

// include db connect class

require_once __DIR__ . '/db_connect.php';

// connecting to db

$db = new DB_CONNECT();

mysql_query("SET NAMES 'UTF8'");

Page 9: Bao cao thuc tap- trung tam athena

// check for post data

if (isset($_GET["pid"])) {

$pid = $_GET['pid'];

// get a customer from customers table

$result = mysql_query("SELECT *FROM customer WHERE pid = $pid");

if (!empty($result)) {

// check for empty result

if (mysql_num_rows($result) > 0) {

$result = mysql_fetch_array($result);

$customer = array();

$customer["pid"] = $result["pid"];

$customer["name"] = $result["name"];

$customer["mobile"] = $result["mobile"];

$customer["gender"] = $result["gender"];

$customer["email"] = $result["email"];

$customer["birth_day"] = $result["birth_day"];

$customer["address"] = $result["address"];

$customer["dtl"] = $result["dtl"];

$customer["type_customer"] = $result["type_customer"];

$customer["created_at"] =$result["created_at"];

// success

$response["success"] = 1

// user node

Page 10: Bao cao thuc tap- trung tam athena

$response["customer"] = array();

array_push($response["customer"], $customer);

// echoing JSON response

echo json_encode($response);

} else {

// no customer found

$response["success"] = 0;

$response["message"] = "No customer found";

// echo no users JSON

echo json_encode($response);

}

} else {

// no customer found

$response["success"] = 0;

$response["message"] = "No customer found";

// echo no users JSON

echo json_encode($response);

}

} else {

// required field is missing

$response["success"] = 0;

$response["message"] = "Required field(s) is missing";

// echoing JSON response

echo json_encode($response);

Page 11: Bao cao thuc tap- trung tam athena

}

?>

create_customer: tạo customer mới

<?php

/*

* Following code will create a new customer row

* All product details are read from HTTP Post Request

*/

// array for JSON response

$response = array();

// check for required fields

if (isset($_POST['name']) && isset($_POST['mobile']) && isset($_POST['gender']) &&

isset($_POST['email']) && isset($_POST['birth_day']) && isset($_POST['address'])

&& isset($_POST['dtl']) && isset($_POST['type_customer'])) {

$name = $_POST['name'];

$mobile = $_POST['mobile'];

$gender = $_POST['gender'];

$email = $_POST['email'];

$birth_day = $_POST['birth_day'];

Page 12: Bao cao thuc tap- trung tam athena

$address = $_POST['address'];

$dtl = $_POST['dtl'];

$type_customer = $_POST['type_customer'];

// include db connect class

require_once __DIR__ . '/db_connect.php';

mysql_query("SET NAMES 'utf8'");

// connecting to db

$db = new DB_CONNECT();

// mysql inserting a new row

$result = mysql_query("INSERT INTO customer(name, mobile, gender, email, birth_day,

address,dtl,type_customer) VALUES('$name','$mobile','$gender','$email', '$birth_day','$address','$dtl','$type_customer')");

// check if row inserted or not

if ($result) {

// successfully inserted into database

$response["success"] = 1;

$response["message"] = "Customer successfully created.";

// echoing JSON response

echo json_encode($response);

} else {

// failed to insert row

$response["success"] = 0;

Page 13: Bao cao thuc tap- trung tam athena

$response["message"] = "Oops! An error occurred.";

// echoing JSON response

echo json_encode($response);

}

} else {

// required field is missing

$response["success"] = 0;

$response["message"] = "Required field(s) is missing";

// echoing JSON response

echo json_encode($response);

}

?>

delete_customer: xoa customer

<?php

/*

* Following code will delete a product from table

* A product is identified by product id (pid)

*/

// array for JSON response

Page 14: Bao cao thuc tap- trung tam athena

$response = array();

// check for required fields

if (isset($_POST['pid'])) {

$pid = $_POST['pid'];

// include db connect class

require_once __DIR__ . '/db_connect.php';

// connecting to db

$db = new DB_CONNECT();

// mysql update row with matched pid

$result = mysql_query("DELETE FROM customer WHERE pid = $pid");

// check if row deleted or not

if (mysql_affected_rows() > 0) {

// successfully updated

$response["success"] = 1;

$response["message"] = "customer successfully deleted";

// echoing JSON response

echo json_encode($response);

} else {

Page 15: Bao cao thuc tap- trung tam athena

// no product found

$response["success"] = 0;

$response["message"] = "No product found";

// echo no users JSON

echo json_encode($response);

}

} else {

// required field is missing

$response["success"] = 0;

$response["message"] = "Required field(s) is missing";

// echoing JSON response

echo json_encode($response);

}

?>

update_customer: cập nhật lại customer

<?php

/*

* Following code will update a product information

* A product is identified by product id (pid)

*/

Page 16: Bao cao thuc tap- trung tam athena

// array for JSON response

$response = array();

// check for required fields

if (isset($_POST['pid'])&&isset($_POST['name']) && isset($_POST['mobile']) && isset($_POST['gender']) &&

isset($_POST['email']) && isset($_POST['birth_day']) && isset($_POST['address'])&& isset($_POST['dtl']) && isset($_POST['type_customer'])) {

$pid = $_POST['pid'];

$name = $_POST['name'];

$mobile = $_POST['mobile'];

$gender = $_POST['gender'];

$email = $_POST['email'];

$birth_day = $_POST['birth_day'];

$address = $_POST['address'];

$dtl = $_POST['dtl'];

$type_customer = $_POST['type_customer'];

// include db connect class

require_once __DIR__ . '/db_connect.php';

// connecting to db

Page 17: Bao cao thuc tap- trung tam athena

$db = new DB_CONNECT();

// mysql update row with matched pid

$result = mysql_query("UPDATE customer SET name ='$name', mobile='$mobile', gender='$gender', email='$email', birth_day='$birth_day',

address='$address',dtl='$dtl',type_customer='$type_customer' WHERE pid = $pid");

// check if row inserted or not

if ($result) {

// successfully updated

$response["success"] = 1;

$response["message"] = "Product successfully updated.";

// echoing JSON response

echo json_encode($response);

} else {

}

} else {

// required field is missing

$response["success"] = 0;

$response["message"] = "Required field(s) is missing";

// echoing JSON response

Page 18: Bao cao thuc tap- trung tam athena

echo json_encode($response);

}

?>

III. Layout và Các class xử lý trong Android

-cấu trúc cây đang có hiện tại trong project

Page 19: Bao cao thuc tap- trung tam athena

IV. Kết Quả Đạt Được

Page 20: Bao cao thuc tap- trung tam athena
Page 21: Bao cao thuc tap- trung tam athena