<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vonglapwhile
{
    class Program
    {
        static void Main(string[] args)
        {
            #region Uoc chung lon nhat
            int a, b;
            Console.WriteLine("Nhap vao so a ");
            int.TryParse(Console.ReadLine(), out a);
            Console.WriteLine("Nhap vao so b ");
            int.TryParse(Console.ReadLine(), out b);
            //0*1=0=>while sai (5)
            while (a * b > 0)
            {

                //10>3(1)
                //1>3 false=>if sai(3)
                if (a > b)
                {
                    //10%3=1(2)
                    a = a % b;
                }
                //3%1=0(4)
                else
                    b = b % a;
            }
            Console.WriteLine("UCLN la : {0}", a + b);
            #endregion
            #region La so nguyen to
            {
                int c;
                Console.WriteLine("Nhap so c: ");
                int.TryParse(Console.ReadLine(), out c);
                int i = 2;
                while (i <= c)
                {
                    if (c % i == 0)
                    {
                        if (c == i)
                        {
                            Console.WriteLine("La so nguyen to");
                        }
                        else
                            Console.WriteLine("Khong la nguyen to");
                        break;
                    }
                    else
                        i++;

                }
            }
            #endregion
            #region Do_While
            {
                int d;
                bool kt;
                Console.WriteLine("Nhap so nguyen: ");
                do
                {

                    kt = int.TryParse(Console.ReadLine(), out d);
                    Console.WriteLine("Nhap lai ");
                    if (kt == true)
                    {
                        if (d <= 0)
                        {
                            kt = false;
                        }
                    }
                } while (kt == false);

            }
            #endregion
        }
    }
}


<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sudungmang
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] masinhvien = { 1, 2, 3, 4, 5, 8, 99};
            string[] danhsachtensinhvien = new string[3];
            for (int i = 0; i < masinhvien.Length; i++)
            {
                Console.WriteLine("Phan tu thu {0} la {1}", i, masinhvien[i]);
            }
            for (int k = 0; k < danhsachtensinhvien.Length; k++)
            {
                Console.WriteLine("Nhap ten sinh vien thu {0}  ", k+1);
                danhsachtensinhvien[k] = Console.ReadLine();
            }
            for (int j = 0; j < danhsachtensinhvien.Length; j++)
            {
                Console.WriteLine("Ten sinh vien thu {0} la {1}", j + 1,danhsachtensinhvien[j]);
                
            }
            Array.Sort(masinhvien);
            
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class FormTimmin : Form
    {
        public FormTimmin()
        {
            InitializeComponent();
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sudungham
{
    class PhuongTrinh
    {/// <summary>
     /// Tinh tong 2 so nguyen (tuong tu nhu Random)
     /// </summary>
     /// <param name="a"></param>
     /// <param name="b"></param>
     /// <returns></returns>
        public double Tong(double a, double b)
        {
            return a + b;
        }
        public double Hieu(double c, double d)
        {
            return c - d;
        }
        public double Thuong(double c, double d)
        {
            return c / d;
        }
        public double Tich(double c, double d)
        {
            return c * d;
        }

        public double PhuongTrinhBac1(double v1, double v2)
        {
            if (v1 == 0)
                if (v2 == 0)
                    throw new Exception("Phuong trinh vo so nghiem");
                else
                    throw new Exception("Phuong trinh vo nghiem");
            Console.WriteLine("PT co nghiem la {0} ", -v2 / v1);
            return -v2 / v1;
        }

        public double[] PhuongTrinhBacHai(double v12, double v13, double v14)
        {
            if (v12 == 0)
                throw new Exception("Khong Phai phuong trinh bac 2");
            double d = v13*v13 - 4 * v12 * v14;
            if(d<0)
                throw new Exception("Vo nghiem");
            double[] nghiem = new double[2];
            nghiem[0] = (-v13 + Math.Sqrt(d)) / (2 * v12);
            nghiem[1] = (-v13 - Math.Sqrt(d)) / (2 * v12);
            return nghiem;
        }

        public double Timmax(double x, double y, double z)
        {
            double max = x;
            if (max < y)
                max=y;
            if (max < z)
                max = z;
            return max;
        }

        internal double Timmin(double x, double y, double z)
        {
            double min = x;
            if (min > y)
                min = y;
            if (min > z)
                min = z;
            return min;
        }
    }
}
<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace baitoanvonglap
{
    class Program
    {
        static void Main(string[] args)
        {
            /*  #region tinh tong tu 1 den n
              int n,tong = 0;
              Console.WriteLine("Nhap cac so n: ");
              n = int.Parse(Console.ReadLine());
              for (int i = 1; i <= n; i++)
              {
                  tong = tong + i;  
              }
              Console.WriteLine("tong tu 1 toi {1} la {0}", tong, n);
              #endregion
              #region Tinh n!
              int a;
              int giaithua = 1;
              Console.WriteLine("Nhap so a: ");
              a = int.Parse(Console.ReadLine());
              for(int j=1;j<=a;j++)
              {
                  giaithua = giaithua * j;
              }
              Console.WriteLine("Giai thua cua {0}! = {1}", a, giaithua);
              #endregion
              #region Tinh tong day so
              {
                  double b, p=1, s = 0;  
                  Console.WriteLine("Nhap so b ");
                  b = double.Parse(Console.ReadLine());
                  for(int k=1;k<=b;k++)
                      //Cach 1 
                  //{
                    //  p = p * k; 
                      //s = s + (1 / p);
                  //}
                  //Cach 2
                  {
                      s = s + (double)(1.0 / k);
                  }
                  Console.WriteLine("tong day so= {0}", s );

              }
              #endregion*/
            int soNguyen;
            for (; ; )
            {
                bool kt = int.TryParse(Console.ReadLine(), out soNguyen);
                if (kt == true)
                {
                    break;
                }
                Console.WriteLine("nhap lai so nguyen");
            }
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.Text;
using System.Threading.Tasks;

namespace FormQuanLySinhVien
{
    class Sinhvien
    {
        public string MaSV { get; set; }
        public string TenSV { get; set; }
        public string SDT { get; set; }
        public string DiaChi { get; set; }
        public bool GioiTinh { get; set; }
        public DateTime NgaySinh { get; set; }
        public static List<Sinhvien> DanhSachSinhVien;
        private static Sinhvien ThongTinSinhVienSua;
        public Sinhvien() { }
        public Sinhvien(string maSV, string tenSV, string sDT, string diaChi, bool gioiTinh, DateTime ngaySinh)
        {
            MaSV = maSV;
            TenSV = tenSV;
            SDT = sDT;
            DiaChi = diaChi;
            GioiTinh = gioiTinh;
            NgaySinh = ngaySinh;
        }

        public static List<Sinhvien> GetDanhSachSinhVien()
        {
            if (DanhSachSinhVien == null)
                return new List<Sinhvien>();
            return DanhSachSinhVien;
        }

        public int Tuoi()
        {
            int nam = DateTime.Now.Year;
            int namsinh = this.NgaySinh.Year;
            return nam - namsinh;
        }
        public string SinhVien2String()
        {
            return String.Format(@"{0}, {1}, {2}, {3}, {4}, {5}", MaSV, TenSV, SDT, DiaChi, GioiTinh, NgaySinh);
        }

        public static Sinhvien SinhVienbyId(string masV)
        {
            foreach (var sv in DanhSachSinhVien)
            {
                if (sv.MaSV == masV)
                    return sv;
            }
            return new Sinhvien();
        }
        //gán thông tin sinh viên cần sửa
        public static void SetSinhVienSua(Sinhvien svSua)
        {
            ThongTinSinhVienSua = svSua;
        }
        public static Sinhvien  GetSinhVienSua()
        {
            if(ThongTinSinhVienSua == null)
            {
                return new Sinhvien();
            }    
           return ThongTinSinhVienSua;
        }
        /// <summary>
        /// Class thêm sinh viên
        /// </summary>
        public void Them()
        {
            if (DanhSachSinhVien == null)
                DanhSachSinhVien = new List<Sinhvien>();
            DanhSachSinhVien.Add(this);
        }
        /// <summary>
        /// Sinhvien thêm sinhvien
        /// </summary>
        /// <param name="sv"></param>
        public static void Them(Sinhvien sv)
        {
            if (DanhSachSinhVien == null)
                DanhSachSinhVien = new List<Sinhvien>();
            DanhSachSinhVien.Add(sv);
        }
        public static void Xoa(string maSV)
        {
            DanhSachSinhVien.RemoveAll(sv => sv.MaSV == maSV);
        }
        public static void Sua(Sinhvien sinhvien)
        {
            Xoa(sinhvien.MaSV);
            Them(sinhvien);
        }
    }
}
<file_sep>﻿using sudungham;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApp1
{
    public partial class FormGiaiPhuongTrinhBacHai : Form
    {
        public FormGiaiPhuongTrinhBacHai()
        {
            InitializeComponent();
        }

        private void btntinh_Click(object sender, EventArgs e)
        {
            try
            {
                double a, b, c;
                if(double.TryParse(txtsothunhat.Text, out a)==false)
                {
                    txtsothunhat.SelectAll();
                    txtsothunhat.Focus();
                    throw new Exception("Du lieu khong hop le");
                }
                if (double.TryParse(txtsothuhai.Text, out b) == false)
                {
                    txtsothuhai.SelectAll();
                    txtsothuhai.Focus();
                    throw new Exception("Du lieu khong hop le");
                }
                if (double.TryParse(txtsothuba.Text, out c) == false)
                {
                    txtsothuba.SelectAll();
                    txtsothuba.Focus();
                    throw new Exception("Du lieu khong hop le");
                }
                PhuongTrinh  pt = new PhuongTrinh();
                double [] nghiem = pt.PhuongTrinhBacHai(a,b,c);
                // txtketqua1.Text =  pt.PhuongTrinhBacHai(a, b, c)[0].ToString();
                //txtketqua.Text =  pt.PhuongTrinhBacHai(a, b, c)[1].ToString();
                txtketqua.Text = nghiem[0].ToString();
                txtketqua1.Text = nghiem[1].ToString();

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message,"Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
            
        }

        private void txtketqua_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sudungvonglap
{
    class Program
    {
        static void Main(string[] args)
        {
            #region Vong lap for
            for (int i = 0; i < 100; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine("xin chao {0}", i);
                }
            }
            #endregion
            #region Nhap day so tu ban phim
            int a;
            Console.WriteLine("Nhap so a : ");
            a = int.Parse(Console.ReadLine());
            for (int i = 0; i <= a; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine(i);
                }
            }
            #endregion
            #region Bang cuu chuong
            //int b;
            //Console.WriteLine("Nhap mot so bat ki");
            //b = int.Parse(Console.ReadLine());
            Console.WriteLine("Bang cuu chuong");
            for (int i = 2; i <= 9; i++)
            {
                for (int k = 2; k <= 10; k++)
                {
                    Console.WriteLine("{0} x {1}= {2} ", i,k, i *k);
                }
              
            }
            #endregion
            
        }
    }
}

<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormQuanLySinhVien
{
    public partial class FormCapNhatBangDiem : Form
    {
        public int IsThis = 1;
        const int Sua = 0;
        const int Them = 1;
        
        public FormCapNhatBangDiem()
        {
            InitializeComponent();
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            try
            {
                BangDiem bd = GetInputForm();
                if(IsThis == 1)
                {
                    BangDiem.Them(bd);
                    ResetData();
                    //reset data
                }
                else
                {
                    //sua
                    BangDiem.Sua(bd);
                    IsThis = Them;
                    ResetData();
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void ResetData()
        {
            dgvbangdiem.DataSource = BangDiem.GetDanhSachBangDiem().ToList();
        }

        private BangDiem GetInputForm()
        {
            if(txtdiemtoan.Text=="")
            {
                txtdiemtoan.SelectAll();
                txtdiemtoan.Focus();
                throw new Exception("Bạn Chưa Nhập điểm Toán");
            }
            if (txtdiemhoa.Text == "")
            {
                txtdiemhoa.SelectAll();
                txtdiemhoa.Focus();
                throw new Exception("Bạn Chưa Nhập điểm Hóa");
            }
            if (txtdiemly.Text == "")
            {
                txtdiemly.SelectAll();
                txtdiemly.Focus();
                throw new Exception("Bạn Chưa Nhập điểm Lý");
            }
            double toan, ly, hoa;
            #region diemtoan
            if (double.TryParse(txtdiemtoan.Text, out toan) == true)
            {
                if(toan >10 || toan <0)
                {
                    txtdiemtoan.SelectAll();
                    txtdiemtoan.Focus();
                    throw new Exception("Điểm không hợp lệ");
                }
            }
            else
            {
                txtdiemtoan.SelectAll();
                txtdiemtoan.Focus();
                throw new Exception("Điểm không hợp lệ");
            }
            #endregion
            #region diemhoa
            if (double.TryParse(txtdiemhoa.Text, out hoa) == true)
            {
                if (hoa > 10 || hoa < 0)
                {
                    txtdiemhoa.SelectAll();
                    txtdiemhoa.Focus();
                    throw new Exception("Điểm không hợp lệ");
                }
            }
            else
            {
                txtdiemhoa.SelectAll();
                txtdiemhoa.Focus();
                throw new Exception("Điểm không hợp lệ");
            }
            #endregion
            #region diemly
            if (double.TryParse(txtdiemly.Text, out ly) == true)
            {
                if (ly > 10 || ly < 0)
                {
                    txtdiemly.SelectAll();
                    txtdiemly.Focus();
                    throw new Exception("Điểm không hợp lệ");
                }
            }
            else
            {
                txtdiemly.SelectAll();
                txtdiemly.Focus();
                throw new Exception("Điểm không hợp lệ");
            }
            #endregion
            Sinhvien iteamSV = (Sinhvien)cbbmasinhvien.SelectedItem;
            LopHoc iteamLH = (LopHoc)cbbmalop.SelectedItem;
            return new BangDiem( iteamLH.MaLop, iteamSV.MaSV, toan, ly , hoa);
        }

        private void FormCapNhatBangDiem_Load(object sender, EventArgs e)
        {
            cbbmalop.DataSource = LopHoc.GetDanhSachLopHoc().ToList();
            cbbmalop.DisplayMember = "TenLop";
            cbbmalop.ValueMember = "MaLop";
            cbbmasinhvien.DataSource = Sinhvien.GetDanhSachSinhVien().ToList();
            cbbmasinhvien.DisplayMember = "TenSinhVien";
            cbbmasinhvien.ValueMember = "MaSV";

        }

        private void dgvbangdiem_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            IsThis = Sua;
            string MaSV = dgvbangdiem.Rows[e.RowIndex].Cells[0].Value.ToString();
            string MaLop = dgvbangdiem.Rows[e.RowIndex].Cells[1].Value.ToString();
            //Lấy thông tin dòng cần sửa
           BangDiem bdSua = BangDiem.BangDiemByMaSVMaLop( MaLop,  MaSV);
            // gán thông tin dòng cần sửa vào form
            SetInputForm(bdSua);
        }

        private void SetInputForm(BangDiem bdSua)
        {
            txtdiemtoan.Text = bdSua.DiemToan.ToString() ;
            txtdiemhoa.Text = bdSua.DiemHoa.ToString();
            txtdiemly.Text = bdSua.DiemLy.ToString();
            cbbmalop.SelectedValue = bdSua.MaLop;
            cbbmasinhvien.SelectedValue = bdSua.MaSV;
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            var isOk = MessageBox.Show("Muốn Xóa Không");
            if (isOk == DialogResult.OK)
                return;
            BangDiem bdSua = GetInputForm();
            BangDiem.Xoa(bdSua.MaLop, bdSua.MaSV);
        }
    }
}
<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace muatrongnam
{
    class Program
    {
        static void Main(string[] args)
        {
            int thang;
            Console.WriteLine("Nhap vao thang tuong ung: ");
            thang = int.Parse(Console.ReadLine());
            switch (thang)
            {
                case 1: Console.WriteLine("mua xuan"); break;
                case 2: Console.WriteLine("mua xuan"); break;
                case 3: Console.WriteLine("mua xuan"); break;
                case 4: Console.WriteLine("mua ha"); break;
                case 5: Console.WriteLine("mua ha"); break;
                case 6: Console.WriteLine("mua ha"); break;
                case 7: Console.WriteLine("mua thu"); break;
                case 8: Console.WriteLine("mua thu"); break;
                case 9: Console.WriteLine("mua thu"); break;
                case 10: Console.WriteLine("mua dong"); break;
                case 11: Console.WriteLine("mua dong"); break;
                case 12: Console.WriteLine("mua dong"); break;
                default: Console.WriteLine("nhap thang khong ton tai"); break;
            }
        }
    }
}<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace giaiphuongtrinhbac2
{
    class phuongtrinhbac2
    {
        static void Main(string[] args)
        {
            float a, b, c, d, x;
            Console.WriteLine("Nhap vao so a: ");
            a = float.Parse(Console.ReadLine());

            Console.WriteLine("Nhap vao so b: ");
            b = float.Parse(Console.ReadLine());

            Console.WriteLine("Nhap vao so c: ");
            c = float.Parse(Console.ReadLine());
            d = b * b - 4 * a * c;
            if (a == 0)
            {
                Console.WriteLine("Phuong trinh vo nghia");
            }
            else
            {

                if (d > 0)
                {
                    Console.WriteLine("Phuong trinh co 2 nghiem phan biet x1={0}, x2={1}", (-b + Math.Sqrt(d)) / 2 * a, (-b - Math.Sqrt(d)) / 2 * a);
                }
                else
                    Console.WriteLine("Phuong trinh vo nghiem");
            }
        }
    }
}
<file_sep>﻿using sudungham;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class FormGiaiPhuongTrinhBacNhat : Form
    {
        public FormGiaiPhuongTrinhBacNhat()
        {
            InitializeComponent();
        }

        private void btntinh_Click(object sender, EventArgs e)
        {
            try
            {
                double a, b;
                if (double.TryParse(txtsothunhat.Text, out a) == false)
                {
                    txtsothunhat.SelectAll();
                    txtsothunhat.Focus();
                    throw new Exception("Du lieu nhap khong hop le");
                }
                if (double.TryParse(txtsothuhai.Text, out b) == false)
                {
                    txtsothuhai.SelectAll();
                    txtsothuhai.Focus();
                    throw new Exception("Du lieu nhap khong hop le");
                }
                if (a == 0)
                {
                    txtsothunhat.SelectAll();
                    txtsothunhat.Focus();
                    throw new Exception("Vo nghia");
                }
                PhuongTrinh pt = new PhuongTrinh();
                txtketqua.Text = pt.PhuongTrinhBac1(a, b).ToString();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Loi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }


        private void txtsothunhat_TextChanged(object sender, EventArgs e)
        {
            double a;
            if (double.TryParse(txtsothunhat.Text, out a) == false)
            {
                txtsothunhat.Text = " ";
            }
        }

        private void txtsothuhai_TextChanged(object sender, EventArgs e)
        {
            double b;
            if (double.TryParse(txtsothunhat.Text, out b) == false)
            {
                txtsothuhai.Text = " ";
            }
        }

        private void txttieude_TextChanged(object sender, EventArgs e)
        {

        }
        private void btnThoat_Click(object sender, EventArgs e)
        {
           
                this.Close();
            
        }

        private void FormGiaiPhuongTrinhBacNhat_FormClosing(object sender, FormClosingEventArgs e)
        {
            var isOk = MessageBox.Show("Ban co muon thoat khong", "ThongBao", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (isOk == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FormQuanLySinhVien
{
    class LopHoc
    {
        public string MaLop { get; set; }
        public string TenLop { get; set; }
        public string DiaChi { get; set; }
       public static List<LopHoc> DanhSachLopHoc;
        private static LopHoc ThongTinSuaLopHoc;
        public LopHoc()
        {
        }

        public LopHoc(string maLop, string tenLop, string diaChi)
        {
            MaLop = maLop;
            TenLop = tenLop;
            DiaChi = diaChi;
        }
        public string LopHoc2String()
        {
            return String.Format("{0},{1},{2},", MaLop, TenLop, DiaChi);
        }

        public static List<LopHoc> GetDanhSachLopHoc()
        {
            if (DanhSachLopHoc == null)
                return new List<LopHoc>();
            return DanhSachLopHoc;
        }

        /// <summary>
        /// thêm thông tin đối tượng hiện tại vào danh sách
        /// là this
        /// </summary>

        public void Them()
        {
            if (DanhSachLopHoc == null)
                DanhSachLopHoc = new List<LopHoc>();
            DanhSachLopHoc.Add(this);

        }
        public static void Xoa(string maLopHoc)
        {
            DanhSachLopHoc.RemoveAll(lophoc => lophoc.MaLop == maLopHoc);
        }
        public static void Sua(LopHoc lopHoc)
        {
            Xoa(lopHoc.MaLop);
            Them(lopHoc);
        }

        private static void Them(LopHoc lopHoc)
        {
            if (DanhSachLopHoc == null)
                DanhSachLopHoc = new List<LopHoc>();
            DanhSachLopHoc.Add(lopHoc);
        }

        public static LopHoc LopHocById(string maLopHoc)
        {
            if(DanhSachLopHoc!= null)
                foreach (var lophoc in DanhSachLopHoc)
                {
                    if (lophoc.MaLop == maLopHoc)
                        return lophoc;
                }
            return new LopHoc();
        }

        public static void SetThongTinSuaLopHoc(LopHoc lhSua)
        {
            ThongTinSuaLopHoc = lhSua;
        }
        public static LopHoc GetThongTinSuaLopHoc()
        {
            if (ThongTinSuaLopHoc != null)
                return ThongTinSuaLopHoc;
            return new LopHoc();
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormQuanLySinhVien
{
    public partial class FormSuaLopHoc : Form
    {
        public FormSuaLopHoc()
        {
            InitializeComponent();
            SetInputForm(LopHoc.GetThongTinSuaLopHoc());
        }

        private void SetInputForm(LopHoc lopHoc)
        {
            txtmalop.Text = lopHoc.MaLop;
            txttenlop.Text = lopHoc.TenLop;
            txtdiachi.Text = lopHoc.DiaChi;
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            try
            {
                LopHoc lhSua = GetInputForm();
                LopHoc.Sua(lhSua);
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private LopHoc GetInputForm()
        {
           if(txtmalop.Text=="")
            {
                throw new Exception("Nhập vào mã lớp");
            }
            if (txttenlop.Text == "")
            {
                throw new Exception("Nhập vào tên lớp");
            }
            if (txtdiachi.Text == "")
            {
                throw new Exception("Nhập vào địa chỉ");
            }
            return new LopHoc(txtmalop.Text, txttenlop.Text, txtdiachi.Text);
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            var isOk = MessageBox.Show("Bạn có muốn xóa không ?", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            if (isOk != DialogResult.OK)
                return;
            LopHoc.Xoa(LopHoc.GetThongTinSuaLopHoc().MaLop);
            DialogResult = DialogResult.OK;
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void btnnuttru_Click(object sender, EventArgs e)
        {
            Form PT = new FormPhepTru();
            PT.Show();
        }

        private void btnnutcong_Click(object sender, EventArgs e)
        {
            FormPhepCong formPhepCong = new FormPhepCong();
            formPhepCong.Show();
        }

        private void btnphepnhan_Click(object sender, EventArgs e)
        {
            FormPhepNhan formPhepNhan = new FormPhepNhan();
            formPhepNhan.Show();

        }

        private void btnphepchia_Click(object sender, EventArgs e)
        {
            FormPhepChia formPhepChia = new FormPhepChia();
            formPhepChia.Show();

        }

        private void FormMain_Load(object sender, EventArgs e)
        {

        }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            var isOk = MessageBox.Show("Ban co muon thoat khong", "Thong bao", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
            if (isOk == DialogResult.No)
            {
                e.Cancel = true;
            }
            if (isOk == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
        }


        private void cộngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form PC = new FormPhepCong();
            PC.Show();
        }

        private void trừToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form PT = new FormPhepTru();
            PT.Show();
        }

        private void nhânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormPhepNhan formPhepNhan = new FormPhepNhan();
            formPhepNhan.Show();
        }

        private void chiaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormPhepChia formPhepChia = new FormPhepChia();
            formPhepChia.Show();

        }

        private void phươngTrìnhBậc1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormGiaiPhuongTrinhBacNhat formGiaiPhuongTrinhBacNhat = new FormGiaiPhuongTrinhBacNhat();
            formGiaiPhuongTrinhBacNhat.Show();
        }

        private void phươngTrìnhBậc2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form PTB2 = new FormGiaiPhuongTrinhBacHai();
            PTB2.Show();
        }

        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
                this.Close();
        }

        private void tìmMaxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form TimM = new FormTimMax();
            TimM.Show();
        }

        private void tìmMinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form Timm = new FormTimmin();
            Timm.Show();
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class FormDangNhap : Form
    {
        public FormDangNhap()
        {
            InitializeComponent();
        }

        private void btndangnhap_Click(object sender, EventArgs e)
        {
            try
            {
                if(txttaikhoan.Text==" ")
                {
                    throw new Exception("Tên Đăng nhập không hợp lệ");
                }
                if(txtmatkhau.Text=="")
                {
                    throw new Exception("Mật khẩu không hợp lệ");
                }
                if (txttaikhoan.Text == "admin" && txtmatkhau.Text == "123456")
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                    throw new Exception("Sai tên đăng nhập");
            }
            catch (Exception ex)
            {

                lblthongbao.Text = ex.Message;
            }
        }

        private void FormDangNhap_Load(object sender, EventArgs e)
        {

        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtmatkhau_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
<file_sep>﻿using sudungham;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class FormPhepChia : Form
    {
        public FormPhepChia()
        {
            InitializeComponent();
        }

        private void btntinh_Click(object sender, EventArgs e)
        {
            try
            {
                double a, b;
                if(double.TryParse(txtsothunhat.Text, out a)==false)
                {
                    txtsothunhat.SelectAll();
                    txtsothunhat.Focus();
                    throw new Exception("Du lieu nhap khong hop le");
                }
                if (double.TryParse(txtsothuhai.Text, out b) == false)
                {
                    txtsothuhai.SelectAll();
                    txtsothuhai.Focus();
                    throw new Exception("Du lieu nhap khong hop le");
                      
                }
                if (b == 0)
                {
                    txtsothuhai.SelectAll();
                    txtsothuhai.Focus();
                    throw new Exception("Loi khong xac dinh");
                }
                PhuongTrinh pt = new PhuongTrinh();
                txtketqua.Text = pt.Thuong(a, b).ToString(); 
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Loi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormQuanLySinhVien
{
    public partial class FormThemSinhVien : Form
    {
        public FormThemSinhVien()
        {
            InitializeComponent();
        }

        private void FormThemSinhVien_Load(object sender, EventArgs e)
        {
            List<GioiTinh> lgt = GioiTinh.Get();
            cbbgioitinh.DataSource = lgt;
            cbbgioitinh.DisplayMember = "Name";
            cbbgioitinh.ValueMember = "Id";
            //gán giá trị mặc định
            cbbgioitinh.SelectedIndex = 0;


        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Sinhvien sv = GetInPutSinhVien();
                Sinhvien.Them(sv);
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Lỗi hệ thống", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        } 

        private Sinhvien GetInPutSinhVien()
        {
            if (txtmasv.Text == "")
            {
                txtmasv.Focus();
                throw new Exception(" Nhập mã sinh viên");
            }
            if (txttensv.Text == "")
            {
                txttensv.Focus();
                throw new Exception(" Nhập tên sinh viên");
            }
            if (txtdiachi.Text == "")
            {
                txtdiachi.Focus();
                throw new Exception(" Nhập địa chỉ ");
            }
            GioiTinh gt = (GioiTinh)
                cbbgioitinh.SelectedItem;
            return new Sinhvien(txtmasv.Text, txttensv.Text, txtdiachi.Text, txtsdt.Text,gt.Id,dtngaysinh.Value);
        }

    }
 }

<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thangtrongnam
{
    class Program
    {
        static void Main(string[] args)
        {
            int thang, nam;
            Console.WriteLine("nhap thang : ");
            thang = int.Parse(Console.ReadLine());
            Console.WriteLine("nhap nam : ");
            nam = int.Parse(Console.ReadLine());
            if (thang == 2)
            {
                if (nam % 4 == 0 && nam % 100 > 0)
                {
                    Console.WriteLine("Thang 2 co 29 ngay");
                }
                else
                {
                    Console.WriteLine("thang 2 co 28 ngay");
                }
            }
            else
            {
                switch (thang)
                {
                    case 1: Console.WriteLine("Thang 1 co 31 ngay"); break;

                    case 3: Console.WriteLine("Thang 3 co 31 ngay"); break;

                    case 4: Console.WriteLine("Thang 4 co 30 ngay"); break;

                    case 5: Console.WriteLine("Thang 5 co 31 ngay"); break;

                    case 6: Console.WriteLine("Thang 6 co 30 ngay"); break;

                    case 7: Console.WriteLine("Thang 7 co 31 ngay"); break;

                    case 8: Console.WriteLine("Thang 8 co 31 ngay"); break;

                    case 9: Console.WriteLine("Thang 9 co 30 ngay"); break;

                    case 10: Console.WriteLine("Thang 10 co 31 ngay"); break;

                    case 11: Console.WriteLine("Thang 11 co 30 ngay"); break;

                    case 12: Console.WriteLine("Thang 12 co 31 ngay"); break;
                    default: Console.WriteLine("Nhap Thang khong phu hop"); break;
                }
            }
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormQuanLySinhVien
{
    public partial class FormDanhSachSinhVien : Form
    {
        private object sv;

        public FormDanhSachSinhVien()
        {
            InitializeComponent();
        }

        private void FormDanhSachSinhVien_Load(object sender, EventArgs e)
        {
            resetDanhSachSinhVien();
        }

        private void resetDanhSachSinhVien()
        {
            Sinhvien sv = new Sinhvien();
            if (Sinhvien.DanhSachSinhVien != null)
                dgvdanhsachsinhvien.DataSource = Sinhvien.GetDanhSachSinhVien().ToList();   
        }

        private void btnthem_Click(object sender, EventArgs e)
        {
            Form fthemsv = new FormThemSinhVien();
            var isOk = fthemsv.ShowDialog();
            if(isOk==DialogResult.OK)
            {
                resetDanhSachSinhVien();
            }    
        }

        private void dgvdanhsachsinhvien_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string masV = dgvdanhsachsinhvien.Rows[e.RowIndex].Cells[0].Value.ToString();
            Sinhvien svSua = Sinhvien.SinhVienbyId(masV);
            Sinhvien.SetSinhVienSua(svSua);
            Form fSuasv = new FormSuaSinhVien();
            
         var isok =   fSuasv.ShowDialog();
            if(isok==DialogResult.OK)
            {
                resetDanhSachSinhVien();
            }    
            
        }

       
    }
}
<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sudungham
{
    class Program
        
    {
        static void Main(string[] args)
        {
            //XinChao();
            //XinChao(Console.ReadLine());
            try
            {
                Menu();
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
            
        }

        private static void Menu()
        {
            Console.WriteLine("Chon Phuong Trinh");
            Console.WriteLine("1. Giai phuong trinh bac 1");
            Console.WriteLine("2. Tinh giai thua");
            Console.WriteLine("3. Tinh Tong hai so nguyen");
            Console.WriteLine("4. Tinh Hieu hai so nguyen");
            Console.WriteLine("5. Phep chia hai so nguyen");
            Console.WriteLine("6. Phep nhan hai so nguyen");
            Console.WriteLine("7. Giai Phuong trinh bac 2");
            Console.WriteLine("8. Tim so lon nhat");
            Console.WriteLine("8. Tim so be nhat");


            Console.WriteLine("Chon:");
            string chon = Console.ReadLine();
            switch(chon)
            {
                case "1": Phuongtrinhbac1(); break;
                case "2": Tinhgiaithua(); break;
                case "3": TinhTong(); break;
                case "4": TinhHieu(); break;
                case "5": TinhThuong(); break;
                case "6": TinhTich(); break;
                case "7": GiaiPhuongTrinhbac2(); break;
                case "8": Timsolonnhat(); break;
                case "9": Timsobenhat(); break;

                case "exit": return;
            }
            Console.WriteLine(" ");
            Menu();
        }

        private static void Timsobenhat()
        {
            double x, y, z;
            Console.WriteLine("Nhap vao so thu nhat");
            double.TryParse(Console.ReadLine(), out x);
            Console.WriteLine("Nhap vao so thu hai");
            double.TryParse(Console.ReadLine(), out y);
            Console.WriteLine("Nhap vao so thu ba");
            double.TryParse(Console.ReadLine(), out z);
            PhuongTrinh pt = new PhuongTrinh();
            double kq10 = pt.Timmin(x,y,z);

        }

        private static void Timsolonnhat()
        {
            double x, y, z;
            Console.WriteLine("Nhap vao so thu nhat ");
            double.TryParse(Console.ReadLine(), out x);
            Console.WriteLine("Nhap vao so thu hai");
            double.TryParse(Console.ReadLine(), out y);
            Console.WriteLine("Nhap vao so thu ba ");
            double.TryParse(Console.ReadLine(), out z);
            PhuongTrinh pt = new PhuongTrinh();
            double kq9 = pt.Timmax(x, y, z);
            Console.WriteLine("Ket Qua {0}", kq9);
        }

        private static void GiaiPhuongTrinhbac2()
        {
            double v12, v13,v14;
            Console.WriteLine("Nhap vao so thu nhat ");
            double.TryParse(Console.ReadLine(), out v12);
            Console.WriteLine("Nhap vao so thu hai");
            double.TryParse(Console.ReadLine(), out v13);
            Console.WriteLine("Nhap vao so thu ba ");
            double.TryParse(Console.ReadLine(), out v14);
            PhuongTrinh pt = new PhuongTrinh();
            double [] kq8 = pt.PhuongTrinhBacHai(v12, v13, v14);
            Console.WriteLine("Ket Qua nghiem thu 1 {0}", kq8[0]);
            Console.WriteLine("Ket Qua nghiem thu 2 {0}", kq8[1]);

        }

        private static void TinhTich()
        {
            double v10, v11;
            Console.WriteLine("Nhap vao so thu nhat ");
            double.TryParse(Console.ReadLine(), out v10);
            Console.WriteLine("Nhap vao so thu hai ");
            double.TryParse(Console.ReadLine(), out v11);
            PhuongTrinh pt = new PhuongTrinh();
            double kq7 = pt.Tich(v10, v11);
            Console.WriteLine("Ket Qua {0}", kq7);
        }

        private static void TinhThuong()
        {
            double v8, v9;
            Console.WriteLine("Nhap vao so thu nhat ");
            double.TryParse(Console.ReadLine(), out v8);
            Console.WriteLine("Nhap vao so thu hai ");
            double.TryParse(Console.ReadLine(), out v9);
            PhuongTrinh pt = new PhuongTrinh();
            double kq6 = pt.Thuong(v8, v9);
            Console.WriteLine("Ket Qua {0}", kq6);
        }

        private static void TinhHieu()
        {
            double v6, v7;
            Console.WriteLine("Nhap vao so thu nhat ");
            double.TryParse(Console.ReadLine(), out v6);
            Console.WriteLine("Nhap vao so thu hai ");
            double.TryParse(Console.ReadLine(), out v7);
            PhuongTrinh pt = new PhuongTrinh();
            double kq5 = pt.Hieu(v6, v7);
            Console.WriteLine("Ket Qua {0}", kq5);

        }

        private static void TinhTong()
        {
            double v4, v5;
            Console.WriteLine("Nhap vao so thu nhat ");
            double.TryParse(Console.ReadLine(), out v4);
            Console.WriteLine("Nhap vao so thu hai ");
            double.TryParse(Console.ReadLine(), out v5);
            PhuongTrinh pt = new PhuongTrinh();
            double kq4 = pt.Tong(v4, v5);
            Console.WriteLine("Ket Qua {0}", kq4);
        }

        private static void Tinhgiaithua()
        {
            int v3;
            Console.WriteLine("Nhap vao so c");
            int.TryParse(Console.ReadLine(), out v3);
            int kq1 = Tinhgiaithua(v3);
            Console.WriteLine("Ket qua {0}", kq1);

        }

        private static int Tinhgiaithua(int v3)
        {
            if (v3 == 1)
                return 1;
            return v3 * Tinhgiaithua(v3 - 1);
        
        }
        private static void Phuongtrinhbac1()
        {
            double v1, v2;
                    Console.WriteLine("Nhap Vao so a ");
            double.TryParse(Console.ReadLine(), out v1);
                    Console.WriteLine("Nhap Vao so b ");
            double.TryParse(Console.ReadLine(), out v2);
            PhuongTrinh pt = new PhuongTrinh();
            double kq = pt.PhuongTrinhBac1(v1, v2);
            Console.WriteLine("Ket qua {0}", kq);
        }

        private static double Phuongtrinhbac1(double v1, double v2)
            {
                if (v1 == 0)
                    if (v2 == 0)
                        throw new Exception("Phuong trinh vo so nghiem");
                    else
                        throw new Exception("Phuong trinh vo nghiem");
                Console.WriteLine("PT co nghiem la {0} ", -v2 / v1);
                return -v2 / v1;
            }

            private static void XinChao(string v)
            {
                Console.WriteLine("Xin chao! {0} ", v);
            }

            private static void XinChao()
            {
                Console.WriteLine("Xin Chao:");
            }
        }

        
    }

<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FormQuanLySinhVien
{
    class BangDiem 
    {
        public string  MaLop { get; set; }
        public string MaSV { get; set; }
        public double DiemToan { get; set; }
        public double DiemLy { get; set; }
        public double DiemHoa { get; set; }
        public static List<BangDiem> DanhSachBangDiem { get; set; }

        public BangDiem(string maLop, string maSV, double diemToan, double diemLy, double diemHoa)
        {
            MaLop = maLop;
            MaSV = maSV;
            DiemToan = diemToan;
            DiemLy = diemLy;
            DiemHoa = diemHoa;
        }

        public BangDiem()
        {
        }

        public string BangDiem2String()
        {
            return String.Format("{0},{1},{2},{3},{4}", MaLop, MaSV, DiemToan, DiemLy, DiemHoa);
        }
        public static List<BangDiem> GetDanhSachBangDiem()
        {
            if (DanhSachBangDiem == null)
                return new List<BangDiem>();
            return DanhSachBangDiem;
        }
        public static void Them(BangDiem bd)
        {
            if (DanhSachBangDiem == null)
                DanhSachBangDiem = new List<BangDiem>();
            DanhSachBangDiem.Add(bd);
        }
        public static void Xoa(string malophoc, string masinhvien )
        {
            DanhSachBangDiem.RemoveAll(iteam => iteam.MaLop== malophoc && iteam.MaSV == masinhvien );
        }
        public static void Sua(BangDiem bd)
        {
            Xoa(bd.MaLop, bd.MaSV);
            Them(bd);
        }

        internal static BangDiem BangDiemByMaSVMaLop(string masv,  string malop)
        {
            foreach (var item in DanhSachBangDiem)
            {
                if (item.MaLop == malop && item.MaSV == masv)
                    return item;
            }
            return new BangDiem();
        }
    }
}
<file_sep>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nhapsongaunhien
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            Console.WriteLine("Nhap vao so a: ");
            a = int.Parse(Console.ReadLine());
            Random b = new Random();
            int kq = b.Next(0, 20);
            Console.WriteLine("Xuat ra ket qua {0}",kq );
            if (a == b.Next(0, 20))
            {
                Console.WriteLine("Ban da doan dung");
            }
            else
                Console.WriteLine("Ban da doan khong dung");
        }
    }
}
