private ChiTietPhieuXuat getChiTietFormFRM() { if (txtSoLuong.Text == "") { txtSoLuong.Text = "0"; } ChiTietPhieuXuat chiTiet = new ChiTietPhieuXuat() { MaPX = txtMaPX.Text, MaHH = MaHH(), SoLuong = int.Parse(txtSoLuong.Text), ThanhTien = float.Parse(txtThanhTien.Text), GhiChu = rtxtGhiChu.Text }; return(chiTiet); }
private void btnAdd_Click(object sender, EventArgs e) { tongTien = 0; if (txtDonGia.Text == "" || txtDonGia.Text == null) { MessageBox.Show("Nhap don gia"); return; } txtThanhTien.Text = (int.Parse(txtDonGia.Text) * int.Parse(txtSoLuong.Text)).ToString(); if (tongTien > 1700000000) { MessageBox.Show("Số tiền của bạn quá cao"); } else { if (action == 1) { foreach (DataRow dr in dataTableChiTiet.Rows) { if (dr["MaHH"].ToString() == cbb_TenHH.SelectedValue.ToString()) { int quantity = int.Parse(txtSoLuong.Text); int b = int.Parse((int.Parse(txtDonGia.Text) * (quantity - int.Parse(dr["SoLuong"].ToString()))).ToString()); //if ((quantity - int.Parse(dr["SoLuong"].ToString())) > 0) //{ // tongTien = tongTien + b; //} //else //{ // tongTien = tongTien - (int.Parse(txtDonGia.Text) * (int.Parse(dr["SoLuong"].ToString()) - quantity)); //} dr["SoLuong"] = quantity; dr["ThanhTien"] = quantity * int.Parse(txtDonGia.Text); dr["DonGia"] = txtDonGia.Text; btnAdd.Text = "Thêm"; } tongTien += int.Parse(dr["ThanhTien"].ToString()); } } else { int a = 0; foreach (DataRow dr in dataTableChiTiet.Rows) { if (dr["MaHH"].ToString() == cbb_TenHH.SelectedValue.ToString()) { a = 1; int quantity = int.Parse(txtSoLuong.Text); dr["SoLuong"] = int.Parse(dr["SoLuong"].ToString()) + quantity; dr["ThanhTien"] = int.Parse(dr["SoLuong"].ToString()) * int.Parse(txtDonGia.Text); dr["DonGia"] = txtDonGia.Text; tongTien += int.Parse(dr["ThanhTien"].ToString()); } // tongTien += int.Parse(dr["ThanhTien"].ToString()); } if (a != 1) { DataRow newChiTiet = dataTableChiTiet.NewRow(); ChiTietPhieuXuat chiTiet = getChiTietFormFRM(); newChiTiet["MaPX"] = chiTiet.MaPX; newChiTiet["MaHH"] = chiTiet.MaHH; newChiTiet["TenHang"] = cbb_TenHH.Text; newChiTiet["SoLuong"] = chiTiet.SoLuong; newChiTiet["DonGia"] = txtDonGia.Text; newChiTiet["ThanhTien"] = chiTiet.SoLuong * int.Parse(txtDonGia.Text); newChiTiet["GhiChu"] = rtxtGhiChu.Text; dataTableChiTiet.Rows.Add(newChiTiet); dgv_ChiTietPhieuXuat.DataSource = dataTableChiTiet; foreach (DataRow dr in dataTableChiTiet.Rows) { // tongTien = 0; tongTien += int.Parse(dr["ThanhTien"].ToString()); } } } dgv_ChiTietPhieuXuat.DataSource = dataTableChiTiet; // tongTien = tongTien + int.Parse(txtThanhTien.Text); } txtTongTien.Text = tongTien.ToString(); btnAddNew.Enabled = true; btnSave.Enabled = true; btnCancel.Enabled = false; btnEdit.Enabled = false; btnDelete.Enabled = false; btnAdd.Enabled = false; txtSoLuong.Enabled = false; cbb_TenHH.Enabled = false; txtDonGia.Text = "0"; txtDonGia.Enabled = false; status = 0; }
private void btnSave_Click(object sender, EventArgs e) { ChiTietPhieuXuat chiTiet; if (exportNew == true) { PhieuXuat phieuXuat = new PhieuXuat() { MaPX = txtMaPX.Text.ToUpper(), MaNV = Config.CURRENT_NHANVIEN, MaCH = cbb_TenCH.SelectedValue.ToString(), NgayXuat = dtpNgayXuat.Value, ChietKhau = 0, ThanhTien = int.Parse(txtTongTien.Text), TongTien = int.Parse(txtTongTien.Text), GhiChu = rtxtGhiChu.Text }; int res = Bus.AddPhieuXuat(phieuXuat); int result; chiTiet = new ChiTietPhieuXuat(); foreach (DataRow dr in dataTableChiTiet.Rows) { chiTiet = new ChiTietPhieuXuat() { MaHH = dr["MaHH"].ToString(), MaPX = dr["MaPX"].ToString(), SoLuong = int.Parse(dr["SoLuong"].ToString()), GhiChu = dr["GhiChu"].ToString(), ThanhTien = int.Parse(dr["ThanhTien"].ToString()), DonGia = int.Parse(dr["DonGia"].ToString()) }; result = Bus.AddChiTietPhieuXuat(chiTiet); } if (res > 0) { MessageBox.Show("Thêm hóa đơn thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon .Information); } else { MessageBox.Show("Thêm hóa đơn thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon .Information); } } else { PhieuXuat phieuXuat = new PhieuXuat() { MaPX = txtMaPX.Text.ToUpper(), MaNV = Config.CURRENT_NHANVIEN, MaCH = cbb_TenCH.SelectedValue.ToString(), NgayXuat = dtpNgayXuat.Value, ChietKhau = 0, ThanhTien = int.Parse(txtTongTien.Text), TongTien = int.Parse(txtTongTien.Text), GhiChu = rtxtGhiChu.Text }; int result; int a = Bus.DeleteCTPX(maPX); chiTiet = new ChiTietPhieuXuat(); foreach (DataRow dr in dataTableChiTiet.Rows) { chiTiet = new ChiTietPhieuXuat() { MaHH = dr["MaHH"].ToString(), MaPX = dr["MaPX"].ToString(), SoLuong = int.Parse(dr["SoLuong"].ToString()), GhiChu = dr["GhiChu"].ToString(), ThanhTien = int.Parse(dr["ThanhTien"].ToString()), DonGia = int.Parse(dr["DonGia"].ToString()) }; result = Bus.UpdateChiTietPhieuXuat(chiTiet); } int res = Bus.UpdatePhieuXuat(phieuXuat); // int result = Bus.UpdateChiTietPhieuXuat(chiTiet); if (res > 0) { MessageBox.Show("Update thanh cong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon .Information); } else { MessageBox.Show("Update that bai", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon .Information); } } MessageBox.Show("Thêm Hóa Đơn thành công!", "Thông báo", MessageBoxButtons.OK); this.Close(); this.Close(); }