ĐÁP ÁN FULL CODE VÀ HÌNH BTNT ASSIGMENT OPT4

9 4.9K 82
ĐÁP ÁN FULL CODE VÀ HÌNH BTNT ASSIGMENT OPT4

Đang tải... (xem toàn văn)

Thông tin tài liệu

... private void Form1_Load(object sender, EventArgs e) { } } } Chạy chương trình Bấm vào Start data lên Đã thêm vào bảng Thoát chương trình ... SqlDataAdapter(cmd); //tạo đtượng DataTable SqlDataApdater DataTable dt = new DataTable(); //đổ liệu vào DataTable dt da.Fill(dt); cmd.Dispose(); Closeconnect(); return dt; } public static void ex2(string

Assignment 04 – Opt 1 1. Write an application to allow the user to add or update his/her profile data to the trainees list of the application, details as described below: - On entering the application, the user is asked to input his/her account, first-name, lastname, email. Those must not be empty. When valid data are inputted, The user’s profile information would be added or updated into the database. The update occurs only in the case his/her account exists already. The user would be redirected to the trainees list page which would show the guests who are accessed the application. Any input data validation or application exception must be handled. Warning and error messages must be shown to the user. 2. From the trainees list page, the user can add one or more feedbacks related to his/her training course (selected from the list). The feedback information includes: - Feedback type, choose from one of following types: The course objectives were met (Mục tiêu khóa học đã đạt được) The level of the course is appropriate (Khóa học phù hợp với trình độ của học viên) This course will be useful for my work (Khóa học bổ ích cho công việc của bạn) The training materials were good (Tài liệu giảng dạy chuẩn bị tốt) The organization of the course (facility) was good (Cơ sở vật chất và công tác tổ chức tốt) Subject coverage is good with respect to courseware (Đảm bảo đủ nội dung c/t học) Your questions/doubts were answered satisfactorily and teacher support is good (Giảng viên hỗ trợ và giải đáp thắc mắc tốt cho học viên) The quality of trainer instruction and communication was good. (Kỹ năng sư phạm của GV tốt) Feedback rate, rate of of below 5 value (this is required data) Strongly disagree (1) Disagree (2) Neutral (3) Agree (4) Strongly agree (5) Feedback notes, for each feedback item (this is optional data) For each course, when giving feedbacks on all feedback types, the user can store those to the database. Requirements: - Use MSSQL server as the database. Use ADO.Net for building DAO Build BOs use DAO classes. Tạo Class Ketnoi using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace Bai1 { class ketnoi { public static SqlConnection conn = null; public static string connect = ""; //khai báo 2 thành viên của Class public static void Openconnect() //phương thức mở kết nối { try { string connect = @"server = MAY-15\MISASME2015;database = trainees;integrated security = true"; conn = new SqlConnection(connect); conn.Open(); // mở kết nối //MessageBox.Show("Ket noi thanh cong", "Connect Database"); } catch { MessageBox.Show("Ket noi loi!?", "Connect Database"); } } public static void Closeconnect()// phương thức đóng kết nối { try { string connect = @"server = MAY-15\MISASME2015;database = trainees;integrated security = true"; conn = new SqlConnection(connect); conn.Close(); //MessageBox.Show("Ngat ket noi thanh cong", "DisConnect Database"); } catch (Exception ex) { MessageBox.Show("Ngat ket noi loi!?" + ex, "DisConnect Database"); } } public static DataTable ex1(string sql) //chạy 1 Select query { Openconnect();//conn.Open(); //mở kết nối SqlCommand cmd = new SqlCommand(sql, conn); //tạo đtượng SqlCommand SqlDataAdapter da = new SqlDataAdapter(cmd); //tạo đtượng DataTable SqlDataApdater DataTable dt = new DataTable(); //đổ dữ liệu vào DataTable dt da.Fill(dt); cmd.Dispose(); Closeconnect(); return dt; } public static void ex2(string sql) //chạy 1 Action query: Insert, Update, Delete { //tạo đối tượng SqlCommand mới Openconnect(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); //thi hành query cmd.Dispose(); Closeconnect(); } } } Tạo Class Thaotac using using using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks; System.Data; System.Data.SqlClient; namespace Bai1 { class thaotac { ketnoi x = new ketnoi(); public DataTable ShowAccount() //trả về các Acconut { string sql = "select * from hocvien"; DataTable dt = new DataTable(); dt = ketnoi.ex1(sql); return dt; } public void Insertnv(string a, string b, string c, string d) //thêm 1 Nniên { string sql = "Insert into hocvien(account,firstname,lastname,email) Values('" + a + "','" + b + "','" + c + "','" + d + "')"; ketnoi.ex2(sql); //gọi thi hành phương thức ex2 } public void Updatenv(string a, string b, string c, string d) //sửa 1 Nviên { string sql = "Update hocvien set firstname='" + b + "', lastname=" + c + ", email='" + d + "' where account='" + a + "'"; ketnoi.ex2(sql); //gọi thi hành phương thức ex2 } public void Deletenv(string a) //sửa 1 Account { } string sql = "delete hocvien where account='" + a + "'"; ketnoi.ex2(sql); //gọi thi hành phương thức ex2 public Boolean Findnv(string a) //tìm 1 Account { string sql = "select * from hocvien where account = '" + a + "'"; DataTable dt = new DataTable(); dt = ketnoi.ex1(sql); //gọi thi hành phương thức ex1 if (dt.Rows.Count == 0) return false; else return true; } } } Chương trình Form1.cs using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Threading.Tasks; System.Windows.Forms; namespace Bai1 { public partial class Form1 : Form { thaotac x = new thaotac(); // khởi tạo đt thao tác để gọi các phương thức của nó trong Form. public void ResetForm() // xoá nội dung các Control trên Form { T1.Text = ""; T2.Text = ""; T3.Text = ""; T4.Text = ""; } T1.Focus(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ketnoi.Openconnect(); dgv.DataSource = ketnoi.ex1("select * from hocvien"); ketnoi.Closeconnect(); } private void button6_Click(object sender, EventArgs e) { if (MessageBox.Show("Có chắc không?", "Exit Project", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) Application.Exit(); } private void button2_Click(object sender, EventArgs e) { ResetForm(); } private void button4_Click(object sender, EventArgs e) { if ((T1.TextLength == 0) && (T2.TextLength == 0) && (T3.TextLength == 0) && (T4.TextLength == 0)) MessageBox.Show("Không được để trống !!!!", "Insert data"); else { string a = T1.Text.ToString(); string b = T2.Text.ToString(); //string d =dtp4.Value.ToShortDateString(); //string d = Convert.ToDateTime(dtp4.Value).ToString("dd/MM/yyyy"); string c = T3.Text.ToString(); string d = T4.Text.ToString(); if (x.Findnv(a) == false) { x.Insertnv(a, b, c, d); MessageBox.Show("Thêm xong", "Insert Data"); ketnoi.Openconnect(); dgv.DataSource = ketnoi.ex1("select * from hocvien"); } else { x.Updatenv(a, b, c, d); MessageBox.Show("Sửa xong", "Update Data"); ketnoi.Openconnect(); dgv.DataSource = ketnoi.ex1("select * from hocvien"); } ResetForm(); } } private void button3_Click(object sender, EventArgs e) { if (T1.TextLength == 0) MessageBox.Show("Phải nhập Mã số cần xoá!", "Delete 1 Record"); else { x.Deletenv(T1.Text); MessageBox.Show("Xoá xong", "Delete a Record"); ketnoi.Openconnect(); dgv.DataSource = ketnoi.ex1("select * from hocvien"); ResetForm(); } } private void button5_Click(object sender, EventArgs e) { if (T1.TextLength == 0) MessageBox.Show("Phải nhập Mã số cần tìm!", "Find Record"); else { if (x.Findnv(T1.Text) == false) MessageBox.Show("Không tìm thấy!", "Find Record"); else MessageBox.Show("Tìm thấy, Nhân viên có Mã số: " + T1.Text, "Find Record"); ResetForm(); } } private void Form1_Load(object sender, EventArgs e) { } } } Chạy chương trình Bấm vào Start hiện data lên Đã thêm vào bảng Thoát chương trình

Ngày đăng: 30/09/2015, 08:37

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan