private void BrowseShopping() { string sql = "SELECT * FROM Shopping WHERE IDKhachHang = " + Convert.ToInt64(lookKhachHang.EditValue) + " AND TrangThai = 1"; dtS = new ShoppingBLL().GetShopping(sql); foreach (DataRow dr in dtS.Rows) { DataRow newRow = dt.NewRow(); newRow[0] = "Shopping"; newRow[1] = dr["NgayMua"]; newRow[4] = newRow[2] = dr["TongTien"]; newRow[3] = String.Format("{0:0.0000}", 0); dt.Rows.Add(newRow); } }
private void btnBuy_Click(object sender, EventArgs e) { if (lookKhachHang.ItemIndex == -1) { MessageBox.Show("Vui lòng chọn Khách Hàng...", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (dtChoose.Rows.Count == 0) { MessageBox.Show("Giỏ hàng trống...", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // Insert Shopping string sql = "SELECT * FROM Shopping"; DataTable dtS = new ShoppingBLL().GetShopping(sql); Shopping s = new Shopping(iD, Convert.ToInt64(lookKhachHang.EditValue), frmDichVu.iDNhanVien, DateTime.Now, tongTien, "", true); try { new ShoppingBLL().Add(dtS, s); new ShoppingBLL().SaveData(ref dtS); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Insert CTShopping sql = "SELECT * FROM ChiTietShopping"; DataTable dtCTS = new ChiTietShoppingBLL().GetChiTietShopping(sql); foreach (DataRow dr in dtChoose.Rows) { ChiTietShopping cts = new ChiTietShopping(iD, Convert.ToInt32(dr[colID.FieldName]), soLuong, thanhTien); try { new ChiTietShoppingBLL().Add(dtCTS, cts); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Update SanPham: SoLuong try { new SanPhamBLL().SubstractSoLuong(dtSP, Convert.ToInt32(dr[colID.FieldName]), Convert.ToInt32(dr[colSoLuong.FieldName])); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // Save CTShopping try { new ChiTietShoppingBLL().SaveData(ref dtCTS); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Save CTShopping try { new SanPhamBLL().SaveData(ref dtSP); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Mua thành công...", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); uscShopping_Load(sender, e); }