private void VeCTHD(DataTable dt) { Panel pnRowHD = null; Label lb_SoLuong = null; Label lb_Ten = null; Label lb_Gia = null; Label lb_ThanhTien = null; for (int i = 0; i < dt.Rows.Count; i++) { pnRowHD = new Panel(); lb_SoLuong = new Label(); lb_Ten = new Label(); lb_Gia = new Label(); lb_ThanhTien = new Label(); string ma = dt.Rows[i].ItemArray[1].ToString(); pnRowHD.Location = new Point(0, i * 45); pnRowHD.Name = "pnRowHD_" + ma; pnRowHD.Size = new Size(pnCTHD.Width, 45); lb_SoLuong = new Label(); lb_SoLuong.Location = new Point(0, 0); lb_SoLuong.Size = new Size(45, 45); lb_SoLuong.TextAlign = ContentAlignment.MiddleCenter; lb_SoLuong.Name = "lbSoLuong_" + ma; lb_SoLuong.Text = dt.Rows[i].ItemArray[2].ToString(); lb_SoLuong.Font = new Font("tahoma", 15f, FontStyle.Bold); pnRowHD.Controls.Add(lb_SoLuong); lb_Ten.Location = new Point(100, 5); lb_Ten.Text = bus_monan.LayTenTuMaMonAn(ma); lb_Ten.Font = new Font("tahoma", 11f, FontStyle.Bold); pnRowHD.Controls.Add(lb_Ten); lb_Gia.Location = new Point(100, 30); lb_Gia.Text = "Giá : " + bus_monan.LayGiaMonAnTheoMa(ma); pnRowHD.Controls.Add(lb_Gia); lb_ThanhTien.Location = new Point(pnRowHD.Width - lb_ThanhTien.Width - 50, 45 / 2 - 15 / 2); lb_ThanhTien.Name = "lbThanhTien_" + ma; lb_ThanhTien.Size = new Size(115, 16); lb_ThanhTien.Text = ChuyenDecimalToVND(decimal.Parse(bus_monan.LayGiaMonAnTheoMa(ma)) * decimal.Parse(lb_SoLuong.Text)); lb_ThanhTien.Font = new Font("tahoma", 11f, FontStyle.Bold); lb_ThanhTien.TextAlign = ContentAlignment.MiddleRight; pnRowHD.Controls.Add(lb_ThanhTien); pnCTHD.Controls.Add(pnRowHD); } }
private void AddListDSMA(string ma, bool tt) { DTO_ItemBill newbill = new DTO_ItemBill(); string giaban = bus_monan.LayGiaMonAnTheoMa(ma); newbill.Ma = ma; newbill.Ten = bus_monan.LayTenTuMaMonAn(ma); bool flag = false; int vitri = 0; for (int i = 0; i < lstDSMA.Count; i++) { if (lstDSMA[i].Ma == ma) { flag = true; vitri = i; break; } } if (flag) { if (tt == false) { if (lstDSMA[vitri].Soluong > 1) { lstDSMA[vitri].Soluong--; } } else { lstDSMA[vitri].Soluong++; } lstDSMA[vitri].Thanhtien = decimal.Parse(giaban) * lstDSMA[vitri].Soluong; } else { newbill.Soluong = 1; newbill.Thanhtien = decimal.Parse(giaban) * newbill.Soluong; lstDSMA.Add(newbill); } }