Mục Lục
Mục Lục
Giáo Trình Học EBook - Tài Liệu Học Lập Trình C Sharp Kiến Thức Căn Bản - Khai Báo Biến, Toán Tử, Mệnh Đề Điều Kiện, Lặp Video Giới thiệu về ngôn ngữ lập trình C# & .NET Framework + Khai báo biến trong C# Video Hướng dẫn tìm hiểu biến + toán tử trong lập trình C# Video Hướng dẫn tìm hiểu mệnh đề điều kiện if - else - switch trong C# In dãy Fibonacci trong C# - Tìm dãy số Fibonacci - Lập trình C# - Loop trong C# Giải phương trình bậc 2 - Lập Trình C# - Mệnh đề điều kiên if else trong # Viêt chương trình cho FlowChart - Lập trình C# - Tìm hiểu if else trong C# Hiển thị hình tam giác - Lập trình C# - Loop trong C# Viết chương trình ax + b = 0 bằng C#, C Sharp Xây dựng dự án Hello World trong C# - C Sharp Nhập và hiển thị thông tin sinh viên - Console trong C# Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# Video Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C# Video In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C# Array trong C Sharp Video Array C# - Hướng dẫn tìm hiểu Array trong C#. C Sharp, Lập Trình C#, Lập Trình C Sharp Tính tổng số chắc & Tổng số lẻ trong chuỗi - Lập Trình C# - Array Trong C# OOP - Tính Chất Đóng Gói & Kế Thừa Video Học lập trình OOP C# - Tính chất đóng gói C# - Qua ví dụ quản lý sinh viên - Lập trình C# Bài 1: Chương trình quản lý sản phẩm - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP Bài 2: Chương trình quản lý sản phẩm - Product - Lập Trình C# - Lập Trình C Sharp Chương trình quản lý công nhân - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP Chương trình quản lý sách - Develop Book Project - Lập Trình C# - OOP trong C# - C Sharp Video Chương trình quản lý sách - Develop Book Project - Lập Trình C# - OOP trong C# - C Sharp - C2010G OOP - Tính Chất Đa Hình & Trừu Tượng & Interface Ôn tập OOP - Table - Trong C# - Lập Trình C# - Lập Trình C Sharp Chường trình quản lý sở thú - Lập trình C# - Lập trình C Sharp Bài tập ôn luyện OOP + Interface trong C# - Lập Trình C# - Lập Trình C Sharp Kiểm tra 30 phút - Chương trình quản lý thiết bị phòng lab cho trường học - Lập trình C# - Khoá học lập trình C Sharp Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp Video Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp Namespace & Delegate & Event Viết chương trình quản lý sinh viên + delegate & event trong C# - Lập Trình C# - Lập Trình C Sharp Examination & Test - Lập trình C# - Lập trình C Sharp Bài tập - Xây dựng chương trình quản lý sức khoẻ - Lập trình C# Viết chương trình quản lý tiêm chủng Vacxin COVID-19 - Lập trình C Sharp nâng cao. JSON & Extension - Partial - Type Anonymous Chương trình quản lý sinh viên C# + Import/Export JSON + File - Lập Trình C# - Lập Trình C Sharp Video Chương trình quản lý sinh viên C# + Import/Export JSON + File - Lập Trình C# - Lập Trình C Sharp Chương trình nhập xuất dữ liệu điểm thi - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP Bài tập C Sharp - Chương trình quản lý cán bộ C# - C Sharp Kết Nối CSDL - C Sharp Video Quản lý sinh viên C# - Kết nối CSDL C# - Kết nối database C# Chương trình quản lý sách C# - Book project C# - CSDL Tools Import/Export JSON into Database C# - Nhập xuất JSON File vào CSDL C# - Quản lý sinh viên C# Bài tập - Viết chương trình quản lý nhập kho máy tính cho thegioididong.com C Sharp - Lập trình C Sharp Ôn Tập Tổng Quát Bài tập - Chương trình quản lý Mèo C# (C Sharp) | Chương trình quản lý Cat C# (C Sharp) Bài tập - Quản lý điểm thi Aptech bằng C# - Lập trình C Sharp [Examination] C# - Chương trình quản lý đội thi TechWiz toàn cầu Aptech Ấn Độ - C# Bài Tập - Quản lý nhà - Lập trình C# | C Sharp Bài tập - Quản lý rạp chiều phim C# - Lập trình C# Viết chương trình quản lý xe car bằng C # - C Sharp | Khoá học lập trình C# [Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp 1000 Bài tập lập trình C# - Lập trình C# - Lập Trình C Sharp Ôn tập OOP - Table - Trong C# - Lập Trình C# - Lập Trình C Sharp
C Sharp Tutorial

[Video] Viết chương trình quản lý nhập kho máy tính cho thegioididong.com C Sharp - Lập trình C Sharp - C2010G


LINK VIDEO BÀI GIẢNG

Bài tập - Viết chương trình quản lý nhập kho máy tính cho thegioididong.com C Sharp - Lập trình C Sharp



B1. Xây dựng database
create table computer (
	id int primary key auto_increment,
	name varchar(150) not null,
	distribute_name varchar(150),
	producer varchar(150),
	produce_year int,
	imported_date datetime,
	buy_price float,
	sell_price float
)

B2. Tạo project + add thư viện
B3. Models (Mapping Tables <-> Class Object)




#Models/Program.cs


using System;
using BT2493.DAO;
using BT2493.Models;
using System.Collections.Generic;

namespace BT2493
{
    class Program
    {
        static void Main(string[] args)
        {
            int choose;

            do
            {
                ShowMenu();
                choose = int.Parse(Console.ReadLine());

                switch(choose)
                {
                    case 1:
                        Input();
                        break;
                    case 2:
                        Display();
                        break;
                    case 3:
                        Search();
                        break;
                    case 4:
                        Report();
                        break;
                    case 5:
                        Console.WriteLine("Thoat!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai!!!");
                        break;
                }
            } while (choose != 5);
        }

        private static void Report()
        {
            int count = ComputerDAO.Count();
            Console.WriteLine("So san pham trong kho: " + count);
        }

        private static void Search()
        {
            Console.WriteLine("Nhap san pham can tim kiem: ");
            string name = Console.ReadLine();

            List<Computer> computerList = ComputerDAO.GetComputerList("%" + name + "%");

            foreach (Computer computer in computerList)
            {
                computer.Display();
            }
        }

        private static void Display()
        {
            List<Computer> computerList = ComputerDAO.GetComputerList(null);

            foreach(Computer computer in computerList)
            {
                computer.Display();
            }
        }

        private static void Input()
        {
            string option;

            do
            {
                Console.WriteLine("=== Nhap thong tin may tinh ===");
                Computer computer = new Computer();
                computer.Input();

                ComputerDAO.Insert(computer);

                Console.WriteLine("Ban co tiep tuc nhap hay khong Y/n?");
                option = Console.ReadLine().ToUpper();
            } while (option != "N");
        }

        static void ShowMenu()
        {
            Console.WriteLine("1. Nhap san pham");
            Console.WriteLine("2. Hien thi thong tin san pham");
            Console.WriteLine("3. Tim kiem");
            Console.WriteLine("4. Bao cao");
            Console.WriteLine("5. Thoat");
            Console.WriteLine("Chon: ");
        }
    }
}


#DAO/Computer.cs


using System;
using MySql.Data.MySqlClient;

namespace BT2493.Models
{
    public class Computer
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string DistributeName { get; set; }
        public string Producer { get; set; }
        public string ProduceYear { get; set; }
        public string ImportedDate { get; set; }
        public float BuyPrice { get; set; }
        public float SellPrice { get; set; }

        public Computer()
        {
        }

        public Computer(int id, string name, string distributeName,
            string producer, string produceYear, string importedDate,
            float buyPrice, float sellPrice)
        {
            ID = id;
            Name = name;
            DistributeName = distributeName;
            Producer = producer;
            ProduceYear = produceYear;
            ImportedDate = importedDate;
            BuyPrice = buyPrice;
            SellPrice = sellPrice;
        }

        public void Parse(MySqlDataReader reader)
        {
            Name = reader["name"].ToString();
            DistributeName = reader["distribute_name"].ToString();
            Producer = reader["producer"].ToString();
            ProduceYear = reader["produce_year"].ToString();
            ImportedDate = reader["imported_date"].ToString();
            BuyPrice = float.Parse(reader["buy_price"].ToString());
            SellPrice = float.Parse(reader["sell_price"].ToString());
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten san pham: ");
            Name = Console.ReadLine();

            Console.WriteLine("Nhap nha phan phoi: ");
            DistributeName = Console.ReadLine();

            Console.WriteLine("Nhap nha san xuat: ");
            Producer = Console.ReadLine();

            Console.WriteLine("Nhap ngay nhap kho (yyyy-MM-dd HH:ii:ss): ");
            ImportedDate = Console.ReadLine();

            Console.WriteLine("Nhap nam san xuat: ");
            ProduceYear = Console.ReadLine();

            Console.WriteLine("Nhap gia mua: ");
            BuyPrice = float.Parse(Console.ReadLine());

            Console.WriteLine("Nhap gia ban: ");
            SellPrice = float.Parse(Console.ReadLine());
        }

        public void Display()
        {
            Console.WriteLine("Ten: {0}, nha phan phoi: {1}, nha san xuat: {2}, " +
                "ngay nhap kho: {3}, gia mua: {4}, gia ban: {5}", Name, DistributeName,
                Producer, ImportedDate, BuyPrice, SellPrice);
        }
    }
}


#DAO/Config.cs


using System;
namespace BT2493.DAO
{
    public class Config
    {
        static string HOST = "localhost";
        static string PORT = "3306";
        static string DATABASE = "C2010G";
        static string USERNAME = "root";
        static string PASSWORD = "";

        public static string GetConnectionString()
        {
            string connString = String.Format("SERVER={0};PORT={1};DATABASE={2};UID={3};PASSWORD={4};SSL Mode=None",
                HOST, PORT, DATABASE, USERNAME, PASSWORD);
            return connString;
        }
    }
}


#ComputerDAO.cs


using System;
using BT2493.Models;
using MySql.Data.MySqlClient;
using System.Collections.Generic;

namespace BT2493.DAO
{
    public class ComputerDAO
    {
        public static void Insert(Computer computer)
        {
            //Open Connection
            MySqlConnection conn = new MySqlConnection(Config.GetConnectionString());
            conn.Open();

            //Query
            string sql = "insert into computer(name, distribute_name, producer, produce_year, " +
                "imported_date, buy_price, sell_price) values (@name, @distribute_name, @producer, @produce_year, " +
                "@imported_date, @buy_price, @sell_price)";
            MySqlCommand command = new MySqlCommand(sql, conn);

            command.Parameters.AddWithValue("@name", computer.Name);
            command.Parameters.AddWithValue("@distribute_name", computer.DistributeName);
            command.Parameters.AddWithValue("@producer", computer.Producer);
            command.Parameters.AddWithValue("@produce_year", computer.ProduceYear);
            command.Parameters.AddWithValue("@imported_date", computer.ImportedDate);
            command.Parameters.AddWithValue("@buy_price", computer.BuyPrice);
            command.Parameters.AddWithValue("@sell_price", computer.SellPrice);

            command.ExecuteNonQuery();
            //Close Connection
            conn.Close();
        }

        public static List<Computer> GetComputerList(string name)
        {
            List<Computer> dataList = new List<Computer>();

            //Open Connection
            MySqlConnection conn = new MySqlConnection(Config.GetConnectionString());
            conn.Open();

            //Query
            string sql = "select * from computer";
            if(name != null)
            {
                sql += " where name like @name";
            }

            MySqlCommand command = new MySqlCommand(sql, conn);
            if(name != null)
            {
                command.Parameters.AddWithValue("@name", name);
            }

            MySqlDataReader reader = command.ExecuteReader();
            while(reader.Read())
            {
                Computer computer = new Computer();
                computer.Parse(reader);

                dataList.Add(computer);
            }
            //Close Connection
            conn.Close();

            return dataList;
        }

        public static int Count()
        {
            int count = 0;

            List<Computer> dataList = new List<Computer>();

            //Open Connection
            MySqlConnection conn = new MySqlConnection(Config.GetConnectionString());
            conn.Open();

            //Query
            string sql = "select count(*) as count from computer";
            MySqlCommand command = new MySqlCommand(sql, conn);

            MySqlDataReader reader = command.ExecuteReader();
            if (reader.Read())
            {
                count = int.Parse(reader["count"].ToString());
            }
            //Close Connection
            conn.Close();

            return count;
        }
    }
}




Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó

×