# LẤY ĐIỀU KIỆN LỌC BÁO CÁO ĐỂ XỬ LÝ CODE BÁO CÁO

* Khi người dùng chọn điều kiện lọc báo cáo, thì có thể lấy ra được điều kiện là gì, để từ đó xử lý tiếp code
* ví dụ: Báo cáo chi tiết công nợ thì cần phải chọn đối tượng công nợ, nếu không chọn thì không chạy báo cáo
* Code nút "trước tất cả"

```
// code nút "Trước tất cả"
try
		{
			//--Nếu không phải báo cáo enter chi tiết thì mới chạy vì khi gọi enter chi tiết đã tryền tk vào rồi
			if(formBaoCao.Visible && formBaoCao.txtReport.Value == Convert.ToInt16(drReport["report"]))
			{
				DataTable dtfil = formBaoCao.GetTableValueFilterOnForm();
				// MessageBox.Show(formBaoCao.form26.Name);
				if(dtfil == null || dtfil.Rows.Count == 0)
				{
					_Func.ThongBao("Bạn vui lòng chọn tài khoản xem báo cáo!!! ",true);
					formBaoCao.StopRun = true;
				}
				else
				{
					DataRow[] drf = dtfil.Select("SourceName = 'taikhoan' and SelectedValue<>''");
					if(drf.Length == 0)
					{
						_Func.ThongBao("Bạn vui lòng chọn Tài khoản xem báo cáo!!!",true);
						formBaoCao.StopRun = true;
					}
				}
			}
			
		}
		catch(Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
```

* Trường hợp muốn lấy toàn bộ điều kiện where ở giao diện điều kiện lọc báo cáo

```sql
-- câu lệnh trả ra điều kiện lọc bên ngoài của báo cáo
string dieukienLocBaocao = formBaoCao.GetWhereCondition(false)
.Replace("where", "").Replace("WHERE", "").Replace("DuLieuKeToan", "t1");
-- replace where để tránh bị thừa khi mà add vào câu lệnh tính toán
-- cấu lệnh trả về DuLieuKeToan. nên cần xử lý tùy theo câu lệnh gốc ghép vào

```

* Trường hợp muốn lấy điều kiện lọc mặc định trong cấu hình của báo cáo

```csharp
/*
- lấy điều kiện ở drReport["dieukien"]
- điều kiện này lấy từ vr. nên lưu ý câu lệnh gốc cần from từ vr
- nếu không from từ vr thì cần xử lý lại replace(dieukien,'vr.', 'xx.')
*/
	if(!string.IsNullOrWhiteSpace(drReport["dieukien"].ToString()))
			cmmDvdo += "and " + drReport["dieukien"].ToString();
			
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kythuat.dtechvn.com/bao-cao/lay-dieu-kien-loc-bao-cao-de-x-ly-code-bao-cao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
