//Event Vật tư private void txt_IdVattu_TextChanged(object sender, EventArgs e) { try { if (dgv_Vattu1.SelectedCells.Count > 0) { string ml = (dgv_Vattu1.SelectedCells[0].OwningRow.Cells["Maloai"].Value).ToString().Trim(); LoaiVatTu lvt = VatTuDAO.Instance.GetIDLoaiVattu(ml); cb_maloai.SelectedItem = lvt; int index = -1; int i = 0; foreach (LoaiVatTu item in cb_maloai.Items) { if (item.Maloai == lvt.Maloai) { index = i; break; } i++; } cb_maloai.SelectedIndex = index; } } catch { } }
//--------------------------------------------------------------------- //Thao tác với vật tư public LoaiVatTu GetIDLoaiVattu(string id) { LoaiVatTu lvt = null; string query = "select * from LOAIVATTU where MALOAI = '" + id + "'"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { lvt = new LoaiVatTu(item); return(lvt); } return(lvt); }
public List <LoaiVatTu> SearchLoaiVattu(string tenl) { List <LoaiVatTu> loaivattu = new List <LoaiVatTu>(); //string s = "MALOAI, TENVATTU, DVT, DONGIA = (PARSENAME(convert(varchar, convert(money, DONGIA), 1), 2)), SOLUONGTON"; string query = string.Format("select * from LOAIVATTU where dbo.fuConvertToUnsign1(TENLOAI) like N'%' + dbo.fuConvertToUnsign1(N'{0}') + '%'", tenl); DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { LoaiVatTu vattu = new LoaiVatTu(item); loaivattu.Add(vattu); } return(loaivattu); }
//--------------------------------------------------------------------- //Thao tác với loại vật tư trong csdl--------------------------------- public List <LoaiVatTu> LoadLoaiVattu() { List <LoaiVatTu> loaivattu = new List <LoaiVatTu>(); //string s = "MALOAI, TENVATTU, DVT, DONGIA = (PARSENAME(convert(varchar, convert(money, DONGIA), 1), 2)), SOLUONGTON"; string query = "select * from LOAIVATTU"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { LoaiVatTu vattu = new LoaiVatTu(item); loaivattu.Add(vattu); } return(loaivattu); }
private void Save() { if (string.IsNullOrEmpty(txtTenLVT.Text.Trim())) { MessageBox.Show("Tên nhà cung cấp không được để trống.", CommonConstant.MESSAGE_WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string info = ""; if (flag)//sua ban ghi { var model = db.LoaiVatTus.Find(txtMaLVT.Text); model.TenLoaiVT = txtTenLVT.Text; model.MaLoaiVT = txtMaLVT.Text; model.MoTa = txtMoTa.Text; info = "Sửa thông tin loại vật tư"; } else { LoaiVatTu obj = new LoaiVatTu(); obj.MaLoaiVT = GenerateID(); obj.TenLoaiVT = txtTenLVT.Text; obj.MoTa = txtMoTa.Text; info = "Thêm mới loại vật tư"; db.LoaiVatTus.Add(obj); } int record = db.SaveChanges(); if (record > 0) { MessageBox.Show(info + " thành công.", CommonConstant.MESSAGE_INFO, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show(string.Format("Xảy ra lỗi, vui lòng kiểm tra lại!"), CommonConstant.MESSAGE_WARNING, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public static void UpdateEntity(InputUpdateLoaiVatTuDto dto, LoaiVatTu vt) { vt.Id = dto.Id; vt.Name = dto.Name; vt.Description = dto.Description; }