# CÔNG THỨC

## 1. công thức cột gọi tên danh mục liên kết

danh mục tài sản, có cột phân xưởng.&#x20;

Trên báo cáo tài sản, cần lấy ra thông tin tên cột phân xưởng

```sql
-- Giá trị, kiểu cộng Max()
/*joindmgocPhanXuong_Taisan_PhanXuongend*/PhanXuong.Ten as PhanxuongTen
-- điều kiện: để trống
-- gộp thêm: không. 

---- danh mục Đối tượng
/*joindmgocNhomkhachhang_Khachhang_Nhomkhachhangend*/Nhomkhachhang.Ten as NhomkhachhangTen

---- danh mục Vật tư
/*joindmgocNhomVattu_Vattu_Nhomvattuend*/Nhomvattu.Ten as NhomvattuTen

---- danh mục phân bổ chi phí trả trước
/*joindmgocPhanxuong_Phanbo_Phanxuongend*/Phanxuong.Ten as PhanxuongTen
/*joindmgocPhongban_Phanbo_Phongbanend*/Phongban.Ten as PhongbanTen
/*joindmgocVuviec_Phanbo_Vuviecend*/Vuviec.Ten as VuviecTen
/*joindmgocCongtrinh_Phanbo_Congtrinhend*/Congtrinh.Ten as CongtrinhTen
/*joindmgocKhoanmuc_Phanbo_Khoanmucend*/Khoanmuc.Ten as KhoanmucTen

---- danh mục Tài sản
/*joindmgocPhanxuong_Taisan_Phanxuongend*/Phanxuong.Ten as PhanxuongTen
/*joindmgocPhongban_Taisan_Phongbanend*/Phongban.Ten as PhongbanTen
/*joindmgocVuviec_Taisan_Vuviecend*/Vuviec.Ten as VuviecTen
/*joindmgocCongtrinh_Taisan_Congtrinhend*/Congtrinh.Ten as CongtrinhTen
/*joindmgocKhoanmuc_Taisan_Khoanmucend*/Khoanmuc.Ten as KhoanmucTen
/*joindmgocLoaitaisan_Taisan_Loaitaisanend*/Loaitaisan.Ten as LoaitaisanTen
```

## 2. Công thức hàm \_fun.EditTable khi chia 0

Trường hợp áp dụng công thức A/B thì cần xử lý vấn đề chia 0

```sql
-- Some code
_Func.EditTable(dtDL, "ketqua","iif(B=0,0,A/iif(B=0,1,B))","1=1",true);
```

## 3. Công thức hàm \_fun.EditTable khi muốn round(0)

Trường hợp áp dụng công thức round(A/B,0)

```sql
-- Some code
_Func.EditTable(dtDL,"ketqua","Convert( iif(B=0,0,A/iif(B=0,1,B)),'System.Int32')","1=1",true);
```

## 4. Công thức hàm \_fun.EditTable khi muốn convert(string)

```
// Some code
_Func.EditTable(dtDL, "vtrangthaixulyten", dvTrangthai[i]["ten"].ToString(), "Convert(trangthaixuly, 'System.String')='"+ dvTrangthai[i]["trangThaiXuLy"].ToString()+"'", false);
```

## 5. Công thức groupby

```
// Some code
//DataTable dtKhoNhomkho = _Func.GroupBy(dtDL, cacCotGroup, doiVitriCacCotGroup, cacCotTinhtoan, kieuCong, capindam, strAdd ,where);
DataTable dtKhoNhomkho = _Func.GroupBy(dtDL, "khoTen,nhomkhoTen,kho,nhomkho", "", "", "", "1,1", "", "");
```

## 6. Công thức tạo table group từ view

```
// Some code
DataView dvDL = new DataView(dtDL);
DataTable dtGop = dvDL.ToTable(true, "kho", "nhomkho");
```

## 7. Format kiểu số lượng trong mẫu in báo cáo

```
// trong báo cáo, chỉ cần đặt công thức là tên cột
// format thì đặt ở format string của object
// summury: none
// 1. format kiểu số lượng
{0:#,0.00;(#,0.00); }
// 2. format kiểu tiền
{0:#,#;(#,#);#}
// 3. format đơn giá
{0:#,#.00;(#,#.00);#}
```

## 8. hàm chuyển từ ngày-đến ngày thành text ngaythangnam

```
// Some code
// sử dụng hàm: formreport.ThangQuyNamText(DateTime tungay, DateTime denngay, string ngonngu)
string ngayThangNam = formreport.ThangQuyNamText(Convert.ToDateTime(formreport.TuNgay), formreport.DenNgay, "vietnam");
rpt.Parameters["NgayThangNam"].Value = ngayThangNam.ToString();

```

## 9. Hàm convert datetime công thức cột

```
// cột báo cáo, cần add kiểu thời gian mặc định
// nếu để '01/01/1900' thì sẽ hiển thị xấu. muốn để trống
// sửa cột giá trị, để như sau.
Convert(datetime,'01/01/1900') as Ngay
```


---

# 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/cong-thuc.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.
