private void btnThemPhieuThu_Click(object sender, EventArgs e) { if (btnThemPhieuThu.Text == "Xác Nhận") { DTO_PhieuThu phieuthu = new DTO_PhieuThu(); phieuthu.MaNV = long.Parse(cbManv.SelectedValue.ToString()); phieuthu.Ngaythu = dtpkNgayThu.Value; phieuthu.MaNCC = long.Parse(cbMancc.SelectedValue.ToString()); phieuthu.Sotien = uint.Parse(numSoTien.Value.ToString()); if (pt.themPhieuThu(phieuthu)) { MessageBox.Show("Thêm phiếu thu thành công!"); dataPhieuThu.DataSource = pt.LayDanhSachPhieuThu(); } else { MessageBox.Show("Thêm phiếu thu thất bại \nvui lòng kiểm tra lại!"); return; } SetDefault(false); btnThemPhieuThu.Text = "Thêm Phiếu Thu"; btnXoa.Text = "Xóa"; } else { SetDefault(true); btnThemPhieuThu.Text = "Xác Nhận"; btnXoa.Text = "Hủy"; } reset(); }
private void btnXoaHang_Click(object sender, EventArgs e) { if (btnXoaHang.Text == "Xóa Hàng") { DialogResult result = MessageBox.Show("Bạn chắc chắn muốn xóa mặc hàng này", "XÓA MẶC HÀNG", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { try { DataGridViewRow row = this.dataCTPhieuThu.Rows[index]; // this.numSoTien.Value = uint.Parse(row.Cells[3].Value.ToString()); long id = long.Parse(row.Cells[0].Value.ToString()); if (ctpn.XoaChiTiet(id)) { dataCTPhieuThu.DataSource = ctpn.LayDanhSachChiTietPhieuNhap(long.Parse(txtId.Text)); DTO_PhieuThu phieuthu = new DTO_PhieuThu(); phieuthu.Id = long.Parse(txtId.Text); //phieuthu.MaNCC = long.Parse(cbMancc.SelectedValue.ToString()); phieuthu.Sotien = -(double)(numGiaNhap.Value * numSoLuongHang.Value); pt.capnhapphieuthu(phieuthu); dataPhieuThu.DataSource = pt.LayDanhSachPhieuThu(); CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[dataCTPhieuThu.DataSource]; myCurrencyManager.Refresh(); reset(); MessageBox.Show("Xóa hàng thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); SetDefault(false); } else { MessageBox.Show("Xóa hàng thất bài", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Vui lòng chọn hàng trước!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { DialogResult result = MessageBox.Show("Bạn chắc chắn muốn hủy", "HỦY THAO TÁC", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { btnThemHang.Text = "Thêm Hàng"; btnXoaHang.Text = "Xóa Hàng"; //btnSua.Enabled = true; btnThemHang.Enabled = true; if (string.IsNullOrEmpty(txtId.Text)) { btnXoaHang.Enabled = false; } SetDefault(false); numSoTien.Value = 0; reset(); } } }
private void btnSua_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(cbDVT.Text)) { MessageBox.Show("Vui lòng chọn phiếu thu để cập nhật", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning); SetDefault(true); } else { if (btnSua.Text == "Sửa") { btnSua.Text = "Cập nhật"; btnXoa.Text = "Hủy"; btnThemPhieuThu.Enabled = false; SetDefault(true); } else { DialogResult result = MessageBox.Show("Bạn chắc chắn muốn cập nhật", "THÔNG BÁO", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { DTO_PhieuThu phieuthu = new DTO_PhieuThu(); phieuthu.Id = long.Parse(txtId.Text); phieuthu.MaNV = long.Parse(cbManv.SelectedValue.ToString()); phieuthu.Ngaythu = dtpkNgayThu.Value; phieuthu.MaNCC = long.Parse(cbMancc.SelectedValue.ToString()); phieuthu.Sotien = uint.Parse(numSoTien.Value.ToString()); if (pt.SuaPhieuThu(phieuthu)) { btnSua.Text = "Sửa"; btnXoa.Text = "Xóa"; btnThemPhieuThu.Enabled = true; dataPhieuThu.DataSource = pt.LayDanhSachPhieuThu(); CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[dataPhieuThu.DataSource]; myCurrencyManager.Refresh(); MessageBox.Show("Cập nhật phiếu thu thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); SetDefault(false); reset(); numSoTien.Value = 0; } else { MessageBox.Show("Vui lòng kiểm tra lại quy định và dữ liệu", "Cập nhật phiếu thu thất bại", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
public List <DTO_PhieuThu> LayDanhSachPhieuThu() { List <DTO_PhieuThu> ds = new List <DTO_PhieuThu>(); string query = string.Empty; query = "SELECT * FROM tblhoadonnhap"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { DTO_PhieuThu pt = new DTO_PhieuThu(); pt.Id = long.Parse(reader["id"].ToString()); pt.MaNV = long.Parse(reader["manv"].ToString()); pt.Ngaythu = DateTime.Parse(reader["ngayTiepNhan"].ToString()); pt.MaNCC = long.Parse(reader["mancc"].ToString()); pt.Sotien = (double)reader.GetDecimal(4); ds.Add(pt); } } con.Close(); con.Dispose(); } catch { con.Close(); return(null); } } } return(ds); }
public bool SuaPhieuThu(DTO_PhieuThu pt) { string query = string.Empty; query = "UPDATE [tblhoadonnhap] " + "SET [tongtien] = @sotien " + "WHERE [id] = @id"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@sotien", Decimal.Parse(pt.Sotien.ToString())); cmd.Parameters.AddWithValue("@id", pt.Id); try { con.Open(); if (cmd.ExecuteNonQuery() > 0) { con.Close(); con.Dispose(); return(true); } else { con.Close(); return(false); } } catch { con.Close(); return(false); } } } }
public bool ThemPhieuThu(DTO_PhieuThu pt) { string query = string.Empty; query += "INSERT INTO tblhoadonnhap ([manv],[ngayTiepNhan],[mancc],[tongtien]) "; query += " VALUES (@manv, @ngaythu, @mancc, @sotien)"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@manv", pt.MaNV); cmd.Parameters.AddWithValue("@ngaythu", pt.Ngaythu); cmd.Parameters.AddWithValue("@mancc", pt.MaNCC); cmd.Parameters.AddWithValue("@sotien", decimal.Parse(pt.Sotien.ToString())); //try { con.Open(); if (cmd.ExecuteNonQuery() > 0) { con.Close(); con.Dispose(); return(true); } else { con.Close(); return(false); } } //catch { con.Close(); return(false); } } } }
public bool ThemPhieuThu(DTO_PhieuThu pt) { string query = string.Empty; query += "INSERT INTO tblPhieuThu ([ngayThu],[maDL],[soTienThu]) "; query += " VALUES (@ngaythu, @madl, @sotien)"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@ngaythu", pt.Ngaythu); cmd.Parameters.AddWithValue("@madl", pt.MaDL); cmd.Parameters.AddWithValue("@sotien", decimal.Parse(pt.Sotien.ToString())); try { con.Open(); if (cmd.ExecuteNonQuery() > 0) { con.Close(); con.Dispose(); return(true); } else { con.Close(); return(false); } } catch { con.Close(); return(false); } } } }
private void btnThemHang_Click(object sender, EventArgs e) { long mahang = 0; if (btnThemHang.Text == "Xác Nhận") { if (checkvalid()) { DTO_Hang hang = new DTO_Hang(); DTO_ChiTietPhieuNhap ct = new DTO_ChiTietPhieuNhap(); //hàng mới if (rbHangMoi.Checked) { hang.TenMatHang = txttenhang1.Text; hang.CongDung = txtCongDung.Text; hang.XuatXu = txtXuatSu.Text; hang.ThanhPhan = txtThanhPhan.Text; hang.MaDVT = long.Parse(cbDVT.SelectedValue.ToString()); hang.MaNhomHang = long.Parse(cbMaNhom.SelectedValue.ToString()); hang.SoLuong = int.Parse(numSoLuongHang.Value.ToString()); hang.GiaNhap = double.Parse(numGiaNhap.Value.ToString()); hang.GiaBan = double.Parse(numGiaBan.Value.ToString()); if (hanghoa.ThemMatHang(hang)) { hang.MaMatHang = hanghoa.timMaHang(hang.TenMatHang); MessageBox.Show("Thêm hàng thành công!"); } else { MessageBox.Show("Thêm hàng thất bại \nvui lòng kiểm tra lại!"); return; } } else if (rbHangSan.Checked) { hang = hanghoa.timHang(long.Parse(cbtenhang.SelectedValue.ToString())); if (hanghoa.suaSoluongHangTrongKho(long.Parse(cbtenhang.SelectedValue.ToString()), (int)numSoLuongHang.Value)) { MessageBox.Show("Thêm hàng thành công!"); } else { MessageBox.Show("Thêm hàng thất bại \nvui lòng kiểm tra lại!"); return; } } //mahang = hanghoa.timMaHang(hang.TenMatHang); ct.MaHD = long.Parse(txtId.Text); ct.Mahang = hang.MaMatHang; ct.SoLuong = (int)numSoLuongHang.Value; ct.DonGiaBan = long.Parse(numGiaNhap.Value.ToString()); if (ctpn.ThemChiTietPX(ct)) { dataCTPhieuThu.DataSource = ctpn.LayDanhSachChiTietPhieuNhap(long.Parse(txtId.Text)); DTO_PhieuThu phieuthu = new DTO_PhieuThu(); phieuthu.Id = long.Parse(txtId.Text); //phieuthu.MaNCC = long.Parse(cbMancc.SelectedValue.ToString()); phieuthu.Sotien = ct.SoLuong * ct.DonGiaBan; pt.capnhapphieuthu(phieuthu); dataPhieuThu.DataSource = pt.LayDanhSachPhieuThu(); reset(); } else { MessageBox.Show("Thêm hàng thất bại \nvui lòng kiểm tra lại!"); return; } rbHangSan.Checked = true; SetDefault(false); btnThemHang.Enabled = true; btnThemHang.Text = "Thêm Hàng"; btnXoaHang.Text = "Xóa Hàng"; } } else { SetDefault(true); btnThemHang.Text = "Xác Nhận"; btnXoaHang.Text = "Hủy"; reset(); } }
public bool SuaPhieuThu(DTO_PhieuThu s) { return(pt.SuaPhieuThu(s)); }
public bool themPhieuThu(DTO_PhieuThu phieuthu) { return(pt.ThemPhieuThu(phieuthu)); }
public bool capnhapphieuthu(DTO_PhieuThu s) { return(pt.capnhatPhieuThu(s)); }