private void Hh_SoLuong_KeyPressed(object sender, EventArgs e) { tong = 0; for (int i = 0; i < pnlMatHang.Controls.Count; i++) { if (pnlMatHang.Controls[i] is HangHoaControl) { HangHoaControl hh = pnlMatHang.Controls[i] as HangHoaControl; if (hh.ChkLucChon.Checked && hh.TxtSoLuong.Text != "") { tong += (decimal)(int.Parse(hh.TxtSoLuong.Text.Replace(",", "")) * hh.DonGia); } } } txtThanhTien.Text = tong != 0 ? XuLyDuLieu.ChuanHoaTien(tong) + " VND" : ""; }
private void Hh_Chk_LuaChon_CheckChanged(object sender, EventArgs e) { HangHoaControl HangHoa = sender as HangHoaControl; if (HangHoa.ChkLucChon.Checked) { if (HangHoa.TxtSoLuong.Text != "") { tong += (decimal)(int.Parse(HangHoa.TxtSoLuong.Text.Replace(",", "")) * HangHoa.DonGia); } } else { if (HangHoa.TxtSoLuong.Text != "") { tong -= (decimal)(int.Parse(HangHoa.TxtSoLuong.Text.Replace(",", "")) * HangHoa.DonGia); } } txtThanhTien.Text = tong != 0 ? XuLyDuLieu.ChuanHoaTien(tong) + " VND" : ""; }
private void frmMain_Load(object sender, EventArgs e) { listMatHang = new List <MatHang>(); StreamReader r; try { r = new StreamReader("Mathang.txt"); } catch (FileNotFoundException) { MessageBox.Show("Không tìm thấy file Mặt hàng.txt", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } //Đọc mặt hàng vào class while (!r.EndOfStream) { MatHang mh = new MatHang(r.ReadLine()); if (mh.TenMatHang != "") { listMatHang.Add(mh); } } //Đọc class vào control for (int i = 0; i < listMatHang.Count; i++) { HangHoaControl hh = new HangHoaControl(listMatHang[i].TenMatHang, listMatHang[i].DonGia); hh.Location = new Point(5, (hh.Height + 2) * i); hh.FocusSoLuongHang += Hh_FocusSoLuongHang; hh.SoLuong_Changed += Hh_SoLuong_KeyPressed; hh.Chk_LuaChon_CheckChanged += Hh_Chk_LuaChon_CheckChanged; //MessageBox.Show(hh.DonGia.ToString()); pnlMatHang.Controls.Add(hh); } }