First assignment-- front-end and back-end separation contacts programming

832201114陈欣蕾 2024-10-30 23:39:23

First assignment-- front-end and back-end separation contacts programming

Project Directory

  1. Introduction

  2. PSP Table

  3. Basic Functions

  4. Design and Implementation Process

  5. Functional Structure Diagram

  6. Code Explanation

  7. Personal Journey and Learnings

Introduction

Course For This Assignment2401_MU_SE_EE308FZ
FZU ID /Name832201114 陈欣蕾
MU ID22126937
Assignment RequirementsDesign a front-end and back-end separation contact
Objectives of This AssignmentContact management including adding, modifying and deleting
Cloud Linkhttp://60.204.237.201:8888/

Task Description

This assignment emphasizes the creation of a contact management application that highlights the separation between front-end and back-end technologies. The application should incorporate essential features for adding, updating, and removing contacts, with all data stored in a back-end database. Students are free to select any visualization technology, provided that the architecture adheres to the requirement of separating front-end and back-end components.

Project Significance

  • Separation of Front-end and Back-end: By using front-end technologies (HTML, CSS, JS) and back-end technologies (PHP), learn how to achieve front-end and back-end interaction and understand their relationship.

  • Enhancing Programming Skills: Apply programming knowledge in a real project to improve coding abilities and problem-solving skills.

  • Implementing Basic Functions: Master the specific implementation of CRUD operations (Create, Read, Update, Delete) by managing user information.

  • Understanding the Web Development Process: Gain a deep understanding of the request-response model and learn how to handle user input and return data.

  • Mastering Data Storage: Learn how to manage user data on the back-end (e.g., using a database) and display it on the front-end.

  • Personal Project Management: Develop the ability to complete projects independently and enhance self-management and time management skills.

PSP Table

TaskActual Time(hours)Estimated Time(hours)Description
Requirement Analysis11Clarify project requirements and define basic functions and design approach.
Technical Preparation45Learn relevant technologies (PHP, MySQL, HTML, CSS, JavaScript).
Database Design and Setup23Design database tables and create structure for storing contact information.
Front-end Development810Use HTML and CSS to build the user interface; implement dynamic interactions with JavaScript.
Back-end Development811Write back-end logic using PHP and interact with MySQL for data management.
Implement Features11Implement Create, Update, and Delete operations for contact information.
Function Testing and Debugging0.50.5Test all features and debug code to ensure stable system performance.
Documentation Writing23Write project documentation, including user guides and technical details.
Final Check and Optimization11.5Conduct final checks on code and functionality, make necessary optimizations.
Total27.536Organize project files and submit the assignment on time.
  • Total Actual Time: 27.5 hours
  • Total Estimated Time: 36 hours

Basic Functions

Add

Modify

Delete

Design and Implementation Process

Requirement Analysis:

  • Identified core functionalities needed for the contacts management system: adding, modifying, and deleting contacts.
  • Considered user interface requirements and interaction flows for a smooth user experience.

Implementation:

Front-end Development

In front-end development, I used HTML, CSS, and JavaScript. Here’s what I did:

  • User Interface Design:

    • Built the basic page structure using HTML, including forms and a contact list display.
    • Created an input form with fields for name, phone number, location, and notes to facilitate user input.
  • Styling:

    • Used CSS to add styles to the form and list, enhancing user experience and making the interface more visually appealing and user-friendly.
  • Dynamic Interaction:

    • Implemented JavaScript for interaction with the back end:
      • Adding Contacts: Used AJAX to send POST requests to the back end with user input data.
      • Modifying Contacts: Enabled the functionality to populate the form with selected contact information for direct editing.
      • Deleting Contacts: Added delete buttons in the contact list, sending DELETE requests via AJAX.
  • Data Display:

    • On page load, used AJAX to fetch all contact information and dynamically generate the contact list for easy viewing.

Back-end Development

In back-end development, I used PHP and MySQL for data processing. Here’s what I did:

  • Data Reception and Processing:

    • Created PHP scripts to handle requests from the front end, processing different operations (adding, modifying, and deleting contacts).
  • Adding Contacts:

    • Received POST requests from the front end, extracted name, phone number, location, and notes, and inserted them into the MySQL database.
  • Modifying Contacts:

    • Handled PUT requests to read the contact information to be modified, found the corresponding record in the database, and updated the information.
  • Deleting Contacts:

    • Processed DELETE requests to remove specified contact records from the database based on contact ID.
  • Querying Contacts:

    • Created GET request handlers to query all contact information from the MySQL database and return it in JSON format to the front end.

Database

In terms of database management, I used MySQL for data storage. Here’s what I did:

  • Database Design:
    • Created a table named contacts with the following fields:
      • id (primary key, auto-increment)
      • name (contact name)
      • phone (contact phone number)
      • location (contact location)
      • notes (additional notes)
  • Data Management:
    • Ensured the database structure was reasonable to support subsequent add, delete, and modify operations, maintaining data integrity and consistency.
  • Data Operations:
    • Interacted with the database during add, modify, and delete operations to ensure each action correctly reflected in the database.

Functional Structure Diagram

img

Code Explanation

  • Front-end Code

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 20px;
  background-image: url('pic.jpg');
  background-size: cover;
}

.container {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.8);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.form-container {
  margin-bottom: 20px;
}

input {
  margin-right: 10px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  padding: 8px 12px;
  background-color: #14ab65;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #14ab65;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

th,
td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

th {
  background-color: #f2f2f2;
}
  • Code Interpretation

The index.html file is structured with several key components: it includes input fields for entering a contact's name, phone number, location, and notes, as well as "Add" and "Save" buttons to submit the form. A table displays the list of all contacts. Additionally, css.css is an optional stylesheet that can be customized to enhance the webpage's appearance according to user preferences. The front-end system interacts with the back end via AJAX, utilizing several main interfaces: a POST request to api.php?action=add for adding contacts, another POST request to api.php?action=edit for editing existing contacts, a POST request to api.php?action=delete for deleting contacts, and a GET request to api.php?action=get to retrieve all contact information from the database.

  • Back-end Code

<?php

header("Content-Type: application/json; charset=UTF-8");

$servername = "localhost";
$username = "root"; 
$password = "root"; 
$dbname = "contacts"; 

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$action = $_GET['action'] ?? null;

switch ($action) {
    case 'add':
        $姓名 = $_POST['姓名'];
        $手机号 = $_POST['手机号'];
        $归属地 = $_POST['归属地'];
        $备注 = $_POST['备注'];
        $stmt = $conn->prepare("INSERT INTO contacts (姓名, 手机号, 归属地, 备注) VALUES (?, ?, ?, ?)");
        $stmt->bind_param("ssss", $姓名, $手机号, $归属地, $备注);
        $stmt->execute();
        echo json_encode(["success" => true]);
        break;

    case 'edit':
        $姓名 = $_POST['姓名'];
        $手机号 = $_POST['手机号'];
        $归属地 = $_POST['归属地'];
        $备注 = $_POST['备注'];
        $stmt = $conn->prepare("UPDATE contacts SET 手机号=?, 归属地=?, 备注=? WHERE 姓名=?");
        $stmt->bind_param("ssss", $手机号, $归属地, $备注, $姓名);
        $stmt->execute();
        echo json_encode(["success" => true]);
        break;

    case 'delete':
        $姓名 = $_POST['姓名'];
        $stmt = $conn->prepare("DELETE FROM contacts WHERE 姓名=?");
        $stmt->bind_param("s", $姓名);
        $stmt->execute();
        echo json_encode(["success" => true]);
        break;

    case 'get':
        $result = $conn->query("SELECT * FROM contacts");
        $contacts = [];
        while ($row = $result->fetch_assoc()) {
            $contacts[] = $row;
        }
        echo json_encode($contacts);
        break;

    default:
        echo json_encode(["error" => "Invalid action"]);
        break;

}

$conn->close();
?>
  • Code Interpretation

The Contacts Management System is a simple application that allows users to add, edit, delete, and view contact information. Built using PHP and MySQL, the front end utilizes HTML and JavaScript for interaction with the back end. Key functionalities include adding contacts by entering their name, phone number, location, and notes, editing existing contacts, deleting saved contacts, and displaying all contacts in a table format. The technology stack consists of HTML, CSS, and JavaScript for the front end, with PHP for the back end and MySQL for database management. Additionally, create a database named contacts and a table within it, structured as follows:

CREATE TABLE contacts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    phone VARCHAR(50) NOT NULL,
    location VARCHAR(100),
    notes TEXT
);

Personal Journey and Learnings

During the development process, I encountered several challenges. First, the design and implementation of the front end left me feeling confused. Especially when using JavaScript for dynamic interactions, the process of debugging and troubleshooting often consumed a significant amount of my time. Additionally, working with PHP and MySQL for back-end data interaction made me realize the crucial importance of proper database design and the correctness of SQL statements. Several times, improper SQL syntax led to issues with data retrieval and storage, prompting me to reflect on the need for greater attention to detail when writing code. Another challenge was effectively managing the project structure. Initially, I did not adequately plan the file structure, which made maintaining functionality difficult. This highlighted the importance of good code organization and project management habits.

On a technical level, this assignment allowed me to delve deeper into using HTML, CSS, and JavaScript to create intuitive and visually appealing user interfaces. With HTML, I was able to effectively structure the web pages, and by utilizing CSS, I enhanced the aesthetic appeal of the interface. Furthermore, the introduction of JavaScript enabled me to implement dynamic interactions on the web pages, improving the overall user experience. In the back end, I mastered how to effectively process and store data using PHP and MySQL. The flexibility of PHP allowed me to write scripts that handle user requests and interact with the MySQL database, ensuring data accuracy and security. I gained a deep understanding of the implementation of Create, Update, Delete operations, including how to create new contacts, modify existing contact information, delete unnecessary contacts, and query and display all contact information.

This assignment provided me with a deeper understanding of front-end and back-end interactions and made me recognize the importance of good documentation and comments for future maintenance and code upgrades. Overall, this individual project not only enhanced my technical skills but also strengthened my ability to work independently and manage my time effectively. Faced with challenges, I learned how to effectively seek solutions and optimize workflows. These experiences will lay a solid foundation for my future studies and career development. I look forward to applying the knowledge I've gained to practical applications in future projects as I continue to explore the vast field of software engineering.

...全文
305 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文针对5MW风电永磁直驱发电机-1200V直流并网系统,构建了基于Simulink的仿真模型,重点研究了在强弱电网适配场景下构网型(GFM)与跟网型(GFL)逆变器并联系统的协同控制逻辑及其暂态动态行为。通过建立包含风力机、永磁同步发电机、机侧变流器、直流环节、网侧变流器及电网接口在内的完整系统模型,实现了从风能捕获到直流并网的全流程仿真。研究深入探讨了GFM与GFL逆变器在不同电网强度下的动态交互特性,包括功率分配、频率响应、电压支撑能力及稳定性表现,并提出有效的分层协同控制策略,以提升系统在弱电网条件下的运行稳定性和电能质量。仿真结果验证了所提控制策略在抑制功率振荡、改善频率调节和增强系统鲁棒性方面的优越性能。; 适合人群:具备电力系统、电力电子及自动控制基础知识,从事新能源发电、微电网、并网技术等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入理解永磁直驱风电机组并网系统的整体结构与工作原理;②掌握构网型与跟网型逆变器的核心控制差异及其在混合系统中的协同机制;③研究强弱电网环境下并网系统的稳定性问题及先进控制策略的设计方法;④为相关科研课题的仿真建模、算法开发与实验验证提供可靠的技术参考与案例支持。; 阅读建议:学习者应结合Simulink软件动手搭建和调试仿真模型,重点关注逆变器控制模块的实现细节与参数设置。建议在掌握基础模型后,通过改变电网强度、负载条件或控制参数等方式开展对比实验,观察系统的动态响应变化,从而深化对理论知识的理解并提升解决实际工程问题的能力。
内容概要:本文提出了一种基于粒子群优化算法(PSO)的风光储能微电网日前经济调度模型,充分考虑了需求响应机制的影响。研究构建了一个包含风力发电、光伏发电、储能系统及可调负荷的综合微电网系统,通过建立以系统综合运行成本最小化为目标的优化模型,综合考量了可再生能源出力的不确定性、负荷波动以及分时电价等因素。文中详细阐述了模型的数学构建过程,包括目标函数的设计、各类物理约束(如功率平衡、储能容量与充放电速率限制)的处理,以及需求响应对用户侧负荷曲线的调节作用,并提供了完整的Python代码实现方案,通过仿真验证了该方法在降低系统运行成本、提升可再生能源消纳能力和优化负荷曲线方面的有效性。; 适合人群:具备一定电力系统基础知识和Python编程能力的高校学生、研究人员及从事微电网规划、能源优化调度等相关领域的工程技术人员。; 使用场景及目标:①用于研究和实现计及多种可再生能源与储能系统的微电网经济调度问题;②学习如何将粒子群优化算法应用于电力系统优化领域;③掌握需求响应机制在削峰填谷、优化负荷曲线中的具体建模与实现方法。; 阅读建议:此资源结合了理论模型、优化算法与编程实践,建议读者在学习过程中重点关注模型构建的逻辑、PSO算法的参数设置及其在调度问题中的应用细节,并动手运行和调试所提供的Python代码,以加深对微电网经济调度全过程的理解。

173

社区成员

发帖
与我相关
我的任务
社区描述
2401_MU_SE_FZU
软件工程 高校
社区管理员
  • FZU_SE_TeacherL
  • 助教-吴可仪
  • 助教-孔志豪
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧