> For the complete documentation index, see [llms.txt](https://kythuat.dtechvn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kythuat.dtechvn.com/nghiep-vu/code-brow-cot.md).

# CODE BROW CỘT

* Gán dữ liệu
* Lấy giá trị trên lưới
* Lấy giá trị trên form
* Lưu ý trường hợp copy paste nhiều dòng

```csharp
// tạo đối tượng dtg là lưới nhập liệu, để gọi cho thuận tiện
_DataGridView dtg = myform.DTG0001 as _DataGridView;
// lấy dòng hiện thời
DataRow drfocus = myform.DTG0001.CurrentRow;
// nếu copy paste thì lấy dòng đang edit
if(myform.DTG0001.RowEdited>= 0 && myform.DTG0001.RowEdited< myform.DTG0001.gridView1.RowCount)
	drfocus = myform.DTG0001.GetDataRow(myform.DTG0001.RowEdited);
// lấy danh mục của cột danh mục. thì lấy dòng index là dòng đang sửa
// với  myform.DTG0001.RowEdited là dòng đang sửa. 
// nếu CurrentRow thì sẽ là dòng tích chuột ban đầu, nếu copy paste nhiều dòng sẽ ko đúng
DataRow drKhachhang = dtg.GetCurrentRowComboBoxCell(  myform.DTG0001.RowEdited, "khachhang");	

if(drfocus["nhomvat"].ToString() == "6") // không đủ điều kiện khấu trừ
	{
	//Nếu không có cột tkno2 ở dưới lưới thì thông báo
		if(!myform.DTG0001.ContainsColumn("TkNo2"))
		{
		//
			_Func.ThongBaoLoi("Giao diện không có cột [Tk thuế] để ghi nhận sang tài khoản chi phí. Hãy báo lại Dtech thiết lập.");
			return;
		}

		if(drfocus.Table.Columns.Contains("TkNo2"))		
		{
			if(myform.NghiepVu.ToString() == "1047" || myform.NghiepVu.ToString() == "1035")
				{
					if(myform.DTG0001.ContainsColumn("TkCo"))//tk nợ dưới lưới
					drfocus["TkNo2"] = drfocus["TkCo"];
					else if(myform.txtTkhoanCo.Visible)//tk nợ trên form
					drfocus["TkNo2"] = myform.txtTkhoanCo.Value;
				}
				else
				{
					if(myform.DTG0001.ContainsColumn("TkNo"))//tk nợ dưới lưới
					drfocus["TkNo2"] = drfocus["TkNo"];
					else if(myform.txtTkhoanNo.Visible)//tk nợ trên form
					drfocus["TkNo2"] = myform.txtTkhoanNo.Value;
				}
				if(string.IsNullOrWhiteSpace(drfocus["TkNo2"].ToString()))
					_Func.ThongBaoLoi("Với hóa đơn không đủ điều kiện khấu trừ, bạn cần chọn thông tin cột [Tk thuế] là tài khoản chi phí");
			}
	}
	else
	{
		if(drfocus.Table.Columns.Contains("TkNo2"))
		{
			drfocus["TkNo2"] = "";
		}
	}
```

## lấy dòng danh mục của id đang chọn

```csharp
// lấy dòng danh mục hiện thời của id đang chọn trên giao diện lưới
_DataGridView dtg = myform.DTG0001 as _DataGridView;
DataRow drvattu = dtg.GetCurrentRowComboBoxCell(dtg.CurrentRowIndex, "VatTu");

// lấy dòng danh mục hiện thời của id đang chọn trên giao diện chung
if(myform.txtKhachHangMa.CurrentRow.Table.Columns.Contains("nhanvienGiamsat"))
		myform.txtnhanvienma.Value = myform.txtKhachHangMa.CurrentRow["nhanvienGiamsat"];

// kiểm tra cột có tồn tại dưới lưới
if(dtg.ContainsColumn("Kho"))
{
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://kythuat.dtechvn.com/nghiep-vu/code-brow-cot.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
