private void tbTen_Leave(object sender, EventArgs e) { tbTen.Text = TienIch.ToTitleCase(tbTen.Text); string sqlSelect = "Select Ten from Thuoc where Ten=N'" + tbTen.Text + "'"; if (DataBaseFunction.IsExisted(sqlSelect)) { TienIch.ShowCanhBao("Cảnh Báo", "Thuốc này đã tồn tại trong csdl"); tbTen.SelectionLength = tbTen.Text.Length; } }
private void AddCongDungChoThuoc(string tenThuoc) { string sqlSelect = "Select Id from Thuoc where Ten=N'" + tenThuoc + "'"; int thuocId = DataBaseFunction.GetItemId(sqlSelect); List <int> danhSachCongDung = new List <int>(); foreach (string item in clbCongDung.CheckedItems) { string sqlSelectId = "Select Id from CongDung where Ten=N'" + item + "'"; danhSachCongDung.Add(DataBaseFunction.GetItemId(sqlSelectId)); } foreach (int idCongDung in danhSachCongDung) { if (!DataBaseFunction.IsExisted("Select * from ThuocCongDung where IdThuoc=" + thuocId + " and IdCongDung=" + idCongDung)) { string sqlInsert = "Insert into ThuocCongDung(IdThuoc,IdCongDung) values(" + thuocId + "," + idCongDung + ")"; DataBaseFunction.ExcuteSQL(sqlInsert); } } }