public static List <NguyenLieuDTO> LayDanhSachTatCaNguyenLieu() { SqlConnection connection = DataProvider.GetConnection(); string query = "SELECT ma_nguyen_lieu, ten_nguyen_lieu, so_luong, don_vi_tinh, trang_thai FROM NguyenLieu"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <NguyenLieuDTO> result = new List <NguyenLieuDTO>(); if (reader.HasRows) { while (reader.Read()) { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNguyenLieu = reader.GetInt32(0); nguyenlieu.TenNguyenLieu = reader.GetString(1); nguyenlieu.SoLuong = reader.GetDouble(2); nguyenlieu.DonViTinh = reader.GetString(3); nguyenlieu.TrangThai = reader.GetBoolean(4); result.Add(nguyenlieu); } } connection.Close(); return(result); }
private void btnSuaNguyenLieu_Click(object sender, EventArgs e) { NguyenLieuDTO nguyenLieu = new NguyenLieuDTO(); nguyenLieu.MaNguyenLieu = Convert.ToInt32(txtMaNguyenLieu.Text); nguyenLieu.TenNguyenLieu = txtTenNguyenLieu.Text; if (txtSoLuong.Text != "") { nguyenLieu.SoLuong = Convert.ToInt32(txtSoLuong.Text); } else { nguyenLieu.SoLuong = 0; } nguyenLieu.DonViTinh = txtDonViTinh.Text; nguyenLieu.TrangThai = true; if (NguyenLieuBUS.SuaNguyenLieu(nguyenLieu)) { MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LamMoiNguyenLieu(); NL_LoadDanhSachNguyenLieu(GetTimKiemNguyenLieu()); dgvNguyenLieu.ClearSelection(); } else { MessageBox.Show("Sửa thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); nguyenLieu = null; } }
//Them private void button1_Click(object sender, EventArgs e) { if (!testtext()) { return; } NguyenLieuDTO nl = new NguyenLieuDTO(); nl.manl = textBox1.Text; nl.tennl = textBox2.Text; nl.dongia = int.Parse(textBox3.Text); nl.donvi = textBox4.Text; nl.trongkho = int.Parse(textBox5.Text); nl.hsd = dateTimePicker1.Value; //2. Kiểm tra data hợp lệ or not //3. Thêm vào DB bool kq = nlBUS.Them(nl); if (kq == false) { System.Windows.MessageBox.Show("Thêm nguyên liẹu thất bại. Vui lòng kiểm tra lại dũ liệu"); } else { System.Windows.MessageBox.Show("Thêm nguyên liẹu thành công"); clear(); } loadData_Vao_GridView(); }
private void button1_Click(object sender, EventArgs e) { //1. Map data from GUI NguyenLieuDTO nl = new NguyenLieuDTO(); nl.manl = label7.Text; nl.tennl = textBox2.Text; nl.dongia = int.Parse(textBox3.Text); nl.donvi = textBox4.Text; nl.trongkho = int.Parse(textBox5.Text); nl.hsd = dateTimePicker1.Value; //2. Kiểm tra data hợp lệ or not //3. Thêm vào DB bool kq = nlBUS.Sua(nl); if (kq == false) { MessageBox.Show("Sửa nguyên liệu thất bại. Vui lòng kiểm tra lại dũ liệu"); } else { MessageBox.Show("Sửa nguyên liệu thành công"); this.Close(); } }
private void btnThem_Click(object sender, EventArgs e) { if (nl == null) { if (!RegexForm()) { return; } else { GetInfoResultNguyenLieu(); if (NguyenLieuBUS.ThemNguyenLieu(nl)) { //MessageBox.Show("Thêm nguyên liệu mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); LoadDSNguyenLieu(); LamMoi(); AddStatus(1); } else { MessageBox.Show("Mã nguyên liệu không được phép trùng nhau", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); nl = null; } } } }
public void NguyenLieu_SelectAllMa() { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNl = cbtennl.SelectedValue.ToString(); DataTable dt = nguyenlieu_bus.NguyenLieu_SelectAllMa(nguyenlieu); datanguyenlieukho.DataSource = dt; }
public void NguyenLieu_SelectAllMa() { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNl = cbtennl.SelectedValue.ToString(); DataTable dt = nguyenlieu_bus.NguyenLieu_SelectAllMa(nguyenlieu); cbdvt.Text = dt.Rows.Count == 0 ? "" : dt.Rows[0][1].ToString(); }
public void NguyenLieu_Delete() { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNl = cbnguyenlieu.SelectedValue.ToString(); DataTable dt = nguyenlieu_bus.NguyenLieu_Delete(nguyenlieu); MessageBox.Show(dt.Rows[0][0].ToString(), "Thông báo", MessageBoxButtons.OK); }
public void NguyenLieu_SelectAllMa(string manl) { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNl = manl; DataTable dt = nguyenlieu_bus.NguyenLieu_SelectAllMa(nguyenlieu); datactnguyenlieu.DataSource = dt; }
public void NguyenLieu_Insert() { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNl = txtnguyenlieu.Text; nguyenlieu.TenNl = cbnguyenlieu.Text; DataTable dt = nguyenlieu_bus.NguyenLieu_Insert(nguyenlieu); MessageBox.Show(dt.Rows[0][0].ToString(), "Thông báo", MessageBoxButtons.OK); }
private void grid_chiTietPhieuDat_CellValidated(object sender, DataGridViewCellEventArgs e) { NguyenLieuDTO nlDTO = (NguyenLieuDTO)grid_chiTietPhieuDat.CurrentRow.Cells["gridCTPhieuDatHang_cNguyenLieu"].Value; int soLuongDatHang = Convert.ToInt32(grid_chiTietPhieuDat.CurrentRow.Cells["gridCTPhieuDatHang_cLuongDat"].Value); decimal thanhTien = Convert.ToDecimal(nlDTO.DonGia * soLuongDatHang); grid_chiTietPhieuDat.CurrentRow.Cells["gridCTPhieuDatHang_cThanhTien"].Value = thanhTien; lb_tongSoTien.Text = tinhTongSoTien().ToString() + "000 VNĐ"; }
private bool inGrid_chiTietPhieuDatOrNot(NguyenLieuDTO dto) { for (int i = 0; i < grid_chiTietPhieuDat.RowCount; i++) { if (dto.MaNguyenLieu == ((NguyenLieuDTO)(grid_chiTietPhieuDat.Rows[i].Cells["gridCTPhieuDatHang_cNguyenLieu"].Value)).MaNguyenLieu) { return(true); } } return(false); }
public List <NguyenLieuDTO> loadNguyenLieuList() { List <NguyenLieuDTO> tableList = new List <NguyenLieuDTO>(); DataTable data = DataProvider.Instance.executeQuery("select * from NguyenLieu"); foreach (DataRow item in data.Rows) { NguyenLieuDTO table = new NguyenLieuDTO(item); tableList.Add(table); } return(tableList); }
public NguyenLieuDTO GetListNguyenLieu(DataRow row) { NguyenLieuDTO NL = new NguyenLieuDTO { MANL = row["MANL"].ToString().Trim(), TENNL = row["TENNL"].ToString().Trim(), DVT = row["DVT"].ToString().Trim(), DONGIA = int.Parse(row["DONGIA"].ToString()) }; return(NL); }
private void btnHoanTat_Click(object sender, EventArgs e) { if (dgvDSCTHDNhap.Rows.Count == 0) { MessageBox.Show("Bạn chưa thêm thông CTHD nhập!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { if (hd != null) { hd.MaNCC = cboNhaCC.SelectedValue.ToString(); hd.NgayNhap = dtpNgayNhap.Value; if (HDNhapBUS.CapNhatTrangThaiHD(hd.MaHDNhap, 1) && HDNhapBUS.HoanTatHD(hd)) { LoadDSHDNhap(); //MessageBox.Show("Tạo hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); // Cập nhật nguyên liệu số lượng tồn kho - tăng for (int i = 0; i < dgvDSCTHDNhap.Rows.Count; i++) { DataTable dt = NguyenLieuBUS.LayDSMaNL(); foreach (DataRow dr in dt.Rows) { NguyenLieuDTO nl = new NguyenLieuDTO(); nl.MaNL = dr["MaNL"].ToString(); if (dgvDSCTHDNhap.Rows[i].Cells["colMaNL_CTHD"].Value.ToString() == nl.MaNL) { cthd = new CTHDNhapDTO(); cthd.MaHDNhap = Convert.ToInt32(dgvDSCTHDNhap.Rows[i].Cells["colMaHDNhap_CTHD"].Value); cthd.MaNL = dgvDSCTHDNhap.Rows[i].Cells["colMaNL_CTHD"].Value.ToString(); int sltk = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) + CTHDNhapBUS.LaySoLuongHienTai(cthd.MaHDNhap, cthd.MaNL); if (NguyenLieuBUS.CapNhatSoLuongTonKhoTang(cthd.MaHDNhap, cthd.MaNL, sltk)) { //MessageBox.Show("Cập nhật số lượng tồn kho thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); } else { MessageBox.Show("Cập nhật số lượng tồn kho thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { MessageBox.Show("Tạo hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public List <NguyenLieuDTO> getListNguyenLieu() { string strSQL = "SELECT * FROM NGUYENLIEU WHERE TrangThai=1 "; List <NguyenLieuDTO> listData = new List <NguyenLieuDTO>(); DataTable data = DataProvider.Instance.ExecuteQuery(strSQL); foreach (DataRow row in data.Rows) { NguyenLieuDTO item = new NguyenLieuDTO(row); listData.Add(item); } return(listData); }
public List <NguyenLieuDTO> TimKiemNguyenLieuDAO(String value) { string strSQL = "SELECT * FROM NGUYENLIEU WHERE TENNL LIKE N'{0}%'"; string SqlFormat = string.Format(strSQL, value); List <NguyenLieuDTO> listData = new List <NguyenLieuDTO>(); DataTable data = DataProvider.Instance.ExecuteQuery(SqlFormat); foreach (DataRow row in data.Rows) { NguyenLieuDTO item = new NguyenLieuDTO(row); listData.Add(item); } return(listData); }
// Khôi phục trạng thái nguyên liệu public static bool KhoiPhucTrangThaiNguyenLieu(NguyenLieuDTO nl) { string query = "UPDATE [tblNguyenLieu] SET [MaLoaiNL] = @MaLoaiNL,[MaNCC] = @MaNCC,[TenNL] = @TenNL,[DonViTinh] = @DonViTinh,[DonGia] = @DonGia,[SoLuongTonKho] = @SLTK,[TrangThai] = @TrangThai WHERE MaNL = @MaNL"; SqlParameter[] pars = new SqlParameter[8]; pars[0] = new SqlParameter("@MaNL", nl.MaNL); pars[1] = new SqlParameter("@MaLoaiNL", nl.MaLoaiNL); pars[2] = new SqlParameter("@MaNCC", nl.MaNCC); pars[3] = new SqlParameter("@TenNL", nl.TenNL); pars[4] = new SqlParameter("@DonViTinh", nl.DonViTinh); pars[5] = new SqlParameter("@DonGia", nl.DonGia); pars[6] = new SqlParameter("@SLTK", nl.SoLuongTonKho); pars[7] = new SqlParameter("@TrangThai", true); return(DataProvider.ExecuteUpdateQuery(query, pars) == 1); }
void GetInfoResultNguyenLieu() { if (nl == null) { nl = new NguyenLieuDTO(); } nl.MaNL = txtMaNL.Text; nl.TenNL = txtTenNL.Text; nl.DonViTinh = cboDonViTinh.SelectedItem.ToString(); nl.DonGia = Convert.ToInt32(txtDonGia.Text); nl.SoLuongTonKho = Convert.ToInt32(txtSLTonKho.Text); nl.MaLoaiNL = cboLoaiNL.SelectedValue.ToString(); nl.MaNCC = cboNhaCC.SelectedValue.ToString(); nl.TrangThai = chkTrangThai.Checked; }
public IHttpActionResult GetNguyenLieu(int id) { NguyenLieu s = db.NguyenLieus.Find(id); if (s == null) { return(NotFound()); } // convert to DTO. NguyenLieuDTO hdndto = new NguyenLieuDTO { NguyenLieuID = s.NguyenLieuID, Gia = s.Gia, TenNL = s.TenNL, MoTa = s.MoTa }; return(Ok(hdndto)); }
public static bool ThemNguyenLieu(NguyenLieuDTO nl) { string query = "INSERT INTO [tblNguyenLieu]([MaNL],[MaLoaiNL],[MaNCC],[TenNL],[DonViTinh],[DonGia],[SoLuongTonKho],[TrangThai]) VALUES(@MaNL,@MaLoaiNL,@MaNCC,@TenNL,@DonViTinh,@DonGia,@SLTK,@TrangThai)"; SqlParameter[] pars = new SqlParameter[8]; pars[0] = new SqlParameter("@MaNL", nl.MaNL); pars[1] = new SqlParameter("@MaLoaiNL", nl.MaLoaiNL); pars[2] = new SqlParameter("@MaNCC", nl.MaNCC); pars[3] = new SqlParameter("@TenNL", nl.TenNL); pars[4] = new SqlParameter("@DonViTinh", nl.DonViTinh); pars[5] = new SqlParameter("@DonGia", nl.DonGia); pars[6] = new SqlParameter("@SLTK", nl.SoLuongTonKho); pars[7] = new SqlParameter("@TrangThai", true); return(DataProvider.ExecuteInsertQuery(query, pars) == 1); }
private void txt_ten_TextChanged(object sender, EventArgs e) { if (txt_ten.Text != "") { NguyenLieuDTO nguyenLieuCanTim = new NguyenLieuDTO(); nguyenLieuCanTim.TenNguyenLieu = txt_ten.Text; grid_ds.Rows.Clear(); timKiemNguyenLieuGanDung(nguyenLieuCanTim); } else { cb_monAn_SelectedIndexChangedShowGridKetQua(); } lb_soLuongKQ.Text = grid_ds.RowCount.ToString(); }
private void timKiemNguyenLieuGanDung(NguyenLieuDTO nl) { ArrayList ds = new ArrayList(); ds = KhoHangBUS.layDSKhoHang_NguyenLieu(GlobalVariables.maNhaHang, nl); //MessageBox.Show(ds.Count.ToString()); for (int i = 0; i < ds.Count; i++) { KhoHang_NguyenLieuDTO dto = (KhoHang_NguyenLieuDTO)ds[i]; if (!ingrid_dsOrNot(dto)) { grid_ds.Rows.Add(); showThongTinKhoHang_NguyenLieuDTOLenGrid(grid_ds.RowCount - 1, dto); } } }
//sua private void suaToolStripMenuItem_Click(object sender, EventArgs e) { int currentRowIndex = dsnguyenlieu.CurrentCellAddress.Y;// 'current row selected //'Verify that indexing OK if (-1 < currentRowIndex && currentRowIndex < dsnguyenlieu.RowCount) { NguyenLieuDTO nl = (NguyenLieuDTO)dsnguyenlieu.Rows[currentRowIndex].DataBoundItem; if (nl != null) { SuaNguyenLieu frm = new SuaNguyenLieu(nl); frm.ShowDialog(); loadData_Vao_GridView(); } } }
public static List <NguyenLieuDTO> LayDanhSachNguyenLieu(string timKiem, bool trangThai) { SqlConnection connection = DataProvider.GetConnection(); string query = "SELECT [ma_nguyen_lieu],[ten_nguyen_lieu],[so_luong],[don_vi_tinh],[trang_thai] FROM [NguyenLieu] WHERE 1=1"; SqlCommand command = new SqlCommand(); if (timKiem != string.Empty) { query += " AND ten_nguyen_lieu LIKE N'%'+@timKiem+'%'"; command.Parameters.Add("@timKiem", System.Data.SqlDbType.NVarChar, 255).Value = timKiem; } if (trangThai) { query += " AND trang_thai=1"; } else { query += " AND trang_thai=0"; } command.CommandText = query; command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <NguyenLieuDTO> result = new List <NguyenLieuDTO>(); if (reader.HasRows) { while (reader.Read()) { NguyenLieuDTO nguyenlieu = new NguyenLieuDTO(); nguyenlieu.MaNguyenLieu = reader.GetInt32(0); nguyenlieu.TenNguyenLieu = reader.GetString(1); nguyenlieu.SoLuong = reader.GetDouble(2); nguyenlieu.DonViTinh = reader.GetString(3); nguyenlieu.TrangThai = reader.GetBoolean(4); result.Add(nguyenlieu); } } connection.Close(); return(result); }
public NguyenLieuDTO[] GetListNguyenLieu() { DataTable table = Da.Query("select * from NGUYENLIEU"); int n = table.Rows.Count; int i; if (n == 0) { return(null); } NguyenLieuDTO[] list = new NguyenLieuDTO[n]; for (i = 0; i < n; i++) { list[i] = GetListNguyenLieu(table.Rows[i]); } return(list); }
public DataTable NguyenLieu_Delete(NguyenLieuDTO nguyenlieu) { try { openConnect(); SqlCommand cmd = new SqlCommand("NGUYENLIEU_Delete", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("MANGUYENLIEU", nguyenlieu.MaNl)); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); closeConnect(); return(dt); } catch { return(null); } }
private void highlightNguyenLieuDaChonDuocNhaCungCapDapUng(NhaCungCapDTO dto) { ArrayList temp = dto.DsNguyenLieu; int soDongGrid_nguyenLieuCanDatHang = grid_nguyenLieuCanDatHang.RowCount; for (int i = 0; i < soDongGrid_nguyenLieuCanDatHang; i++) { if (Convert.ToBoolean(grid_nguyenLieuCanDatHang.Rows[i].Cells[0].Value) == true) { for (int j = 0; j < temp.Count; j++) { NguyenLieuDTO nlNCC = (NguyenLieuDTO)temp[j]; MonAn_NguyenLieuDTO nlCanDatHang = (MonAn_NguyenLieuDTO)grid_nguyenLieuCanDatHang.Rows[i].Cells["grid_nguyenLieuCanDatHang_cNguyenLieu"].Value; if (nlNCC.MaNguyenLieu == nlCanDatHang.NguyenLieu.MaNguyenLieu) { grid_nguyenLieuCanDatHang.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue; } } } } }
//xoa private void xoaToolStripMenuItem_Click(object sender, EventArgs e) { int currentRowIndex = dsnguyenlieu.CurrentCellAddress.Y;// 'current row selected //'Verify that indexing OK if (-1 < currentRowIndex && currentRowIndex < dsnguyenlieu.RowCount) { NguyenLieuDTO kn = (NguyenLieuDTO)dsnguyenlieu.Rows[currentRowIndex].DataBoundItem; if (kn != null) { bool kq = nlBUS.Xoa(kn); if (kq == false) { MessageBox.Show("Xóa nguyên liệu thất bại. Vui lòng kiểm tra lại dũ liệu"); } else { MessageBox.Show("Xóa nguyên liệu thành công"); this.loadData_Vao_GridView(); } } } }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { grid_chiTietPhieuDat.Rows.Clear(); for (int i = 0; i < grid_tabPage_NCC_nhaCungCapPhuHop.RowCount; i++) { if (Convert.ToBoolean(grid_tabPage_NCC_nhaCungCapPhuHop.Rows[i].Cells[0].Value) == true) { NhaCungCapDTO nccDTO = (NhaCungCapDTO)grid_tabPage_NCC_nhaCungCapPhuHop.Rows[i].Cells["grid_NCCPhuHop_cTenNhaCungCap"].Value; for (int j = 0; j < nccDTO.DsNguyenLieu.Count; j++) { NguyenLieuDTO nlDTO = (NguyenLieuDTO)nccDTO.DsNguyenLieu[j]; if (!inGrid_chiTietPhieuDatOrNot(nlDTO)) { grid_chiTietPhieuDat.Rows.Add(); grid_chiTietPhieuDat.Rows[grid_chiTietPhieuDat.RowCount - 1].Cells["gridCTPhieuDatHang_cNCC"].Value = nccDTO; grid_chiTietPhieuDat.Rows[grid_chiTietPhieuDat.RowCount - 1].Cells["gridCTPhieuDatHang_cNguyenLieu"].Value = nlDTO; grid_chiTietPhieuDat.Rows[grid_chiTietPhieuDat.RowCount - 1].Cells["gridCTPhieuDatHang_cDonVi"].Value = nlDTO.DonViTinh; } } } } }