private void cmbSanPham_SelectedIndexChanged(object sender, EventArgs e) { try { PhieuNhapCtrlTr hddvctr = new PhieuNhapCtrlTr(); SanPhamObjTr dvobj = new SanPhamObjTr(); dvobj.MaSP = cmbSanPham.SelectedValue.ToString(); DataTable dt = ChiTietPhieuNhapCtrlTr.GetListTuDongThemGia(dvobj); if (dt.Rows.Count > 0) { double gia = double.Parse(dt.Rows[0][1].ToString()); txtDonGia.Text = gia.ToString(); lblthanhtien.Text = (float.Parse(txtDonGia.Text) * int.Parse(nudSoluong.Text)).ToString(); } //if (dt.Rows.Count > 0) //{ // double gia = double.Parse(dt.Rows[0][1].ToString()); // txtDonGia.Text = gia.ToString(); // txtDonGia.Text = string.Format( "{0:0,0}", float.Parse(txtDonGia.Text) + " VNĐ"); //} } catch { } }
private void btnThem_Click(object sender, EventArgs e) { this.cmbSanPham.Enabled = true; this.cmbChungLoai.Enabled = true; this.nudSoluong.Enabled = true; this.btnLuu.Enabled = false; this.btnSanPham.Enabled = true; this.btnXoa.Enabled = true; this.btnHuy.Enabled = true; this.btnSanPham.Visible = true; this.btnLuu.Visible = true; this.btnHuy.Visible = true; this.btnThem.Visible = false; this.btnSua.Visible = false; this.btnXoa.Visible = true; this.btnIn.Visible = false; this.btntrolai.Visible = false; this.cmbNhaCC.Enabled = true; this.cmbNhanVien.Enabled = true; this.cmbChungLoai.Enabled = true; m_chucnang = "them"; this.cmbNhanVien.DropDownStyle = ComboBoxStyle.DropDown; this.cmbNhaCC.DropDownStyle = ComboBoxStyle.DropDown; this.cmbChungLoai.DropDownStyle = ComboBoxStyle.DropDown; DataTable dtpn = new DataTable(); dtpn = PhieuNhapCtrlTr.GetListPhieuNhap(); string s = ""; if (dtpn.Rows.Count <= 0) { s = "0"; } else { s = "HBL"; s = (int.Parse(dtpn.Rows[dtpn.Rows.Count - 1][0].ToString().Trim()) + 1).ToString(); } lblMaPN.Text = s; cmbSanPham.ResetText(); cmbChungLoai.ResetText(); lblthanhtien.Text = "0"; lbltongtien.Text = "0"; nudSoluong.Value = 0; cmbNhanVien.ResetText(); cmbNhaCC.ResetText(); ChiTietPhieuNhapObjTr cthddvobj = new ChiTietPhieuNhapObjTr(); cthddvobj.MaPN = lblMaPN.Text; dt = ChiTietPhieuNhapCtrlTr.GetListCTPhieuNhap(cthddvobj); dtvChiTietPhieuNhap.DataSource = dt; // dtDSCT.Rows.Clear(); }
private void btnLuu_Click(object sender, EventArgs e) { try { if (m_chucnang == "them") { if (lblMaPN.Text == "" || cmbNhanVien.Text == "" || cmbNhaCC.Text == "") { MessageBox.Show("Chưa chọn thông tin!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { PhieuNhapObjTr hddvobj = new PhieuNhapObjTr(); hddvobj.MaPN = lblMaPN.Text.Trim(); hddvobj.TongTien = float.Parse(lbltongtien.Text.Trim()); hddvobj.NgayNhap = dtpNgayLap.Value; hddvobj.MaNV = cmbNhanVien.SelectedValue.ToString(); hddvobj.MaNCC = cmbNhaCC.SelectedValue.ToString(); if (MessageBox.Show(string.Format("Thêm Phiếu Nhập Hàng Có Mã Số Hóa Đơn {0}", hddvobj.MaPN), "Thông Báo", MessageBoxButtons.OKCancel) == DialogResult.OK) { if (PhieuNhapCtrlTr.InsertPhieuNhap(hddvobj) > 0) { for (int i = 0; i < dtvChiTietPhieuNhap.Rows.Count; i++) { ChiTietPhieuNhapObjTr cthddvobj = new ChiTietPhieuNhapObjTr(); cthddvobj.MaSP = dtvChiTietPhieuNhap.Rows[i].Cells[1].Value.ToString().Trim(); cthddvobj.MaPN = lblMaPN.Text; cthddvobj.ChungLoai = dtvChiTietPhieuNhap.Rows[i].Cells[3].Value.ToString().Trim(); cthddvobj.SoLuong = int.Parse(dtvChiTietPhieuNhap.Rows[i].Cells[4].Value.ToString()); cthddvobj.DonGia = float.Parse(dtvChiTietPhieuNhap.Rows[i].Cells[5].Value.ToString()); cthddvobj.ThanhTien = float.Parse(dtvChiTietPhieuNhap.Rows[i].Cells[6].Value.ToString()); ChiTietPhieuNhapCtrlTr.InsertPhieuNhap(cthddvobj); } MessageBox.Show("Thêm Phiếu Nhập thành công.", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); this.cmbSanPham.Enabled = false; this.cmbChungLoai.Enabled = false; this.nudSoluong.Enabled = false; this.btnSanPham.Visible = false; this.btnLuu.Visible = false; this.btnHuy.Visible = false; this.btnThem.Visible = true; this.btnSua.Visible = true; this.btnXoa.Visible = false; this.btnIn.Visible = true; this.btntrolai.Visible = true; this.cmbNhanVien.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbNhaCC.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbChungLoai.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbNhaCC.Enabled = false; this.cmbNhanVien.Enabled = false; this.cmbChungLoai.Enabled = false; frmNhapHang_Load(sender, e); } else { MessageBox.Show("Mã Phiếu Nhập Đã Có,Vui Lòng Nhập Lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } if (m_chucnang == "sua") { if (lblMaPN.Text == "" || cmbNhanVien.Text == "" || cmbNhaCC.Text == "") { MessageBox.Show("Chưa chọn thông tin!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { PhieuNhapObjTr hddvobj = new PhieuNhapObjTr(); hddvobj.MaPN = lblMaPN.Text.Trim(); hddvobj.TongTien = float.Parse(lbltongtien.Text.Trim()); hddvobj.NgayNhap = dtpNgayLap.Value; hddvobj.MaNV = cmbNhanVien.SelectedValue.ToString(); hddvobj.MaNCC = cmbNhaCC.SelectedValue.ToString(); if (MessageBox.Show(string.Format("Sửa Phiếu Nhập Có Mã Số Hóa Đơn {0}", hddvobj.MaPN), "Thông Báo", MessageBoxButtons.OKCancel) == DialogResult.OK) { if (PhieuNhapCtrlTr.UpdatePhieuNhap(hddvobj) > 0) { MessageBox.Show("Sửa thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.cmbSanPham.Enabled = false; this.cmbChungLoai.Enabled = false; this.nudSoluong.Enabled = false; this.btnSanPham.Visible = false; this.btnLuu.Visible = false; this.btnHuy.Visible = false; this.btnThem.Visible = true; this.btnSua.Visible = true; this.btnXoa.Visible = false; this.btnIn.Visible = true; this.btntrolai.Visible = true; this.cmbNhanVien.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbNhaCC.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbChungLoai.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbNhaCC.Enabled = false; this.cmbNhanVien.Enabled = false; this.cmbChungLoai.Enabled = false; } else { MessageBox.Show("Không Sửa Được!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } catch (Exception ex) { } }