# IN MẪU DẠNG GROUP

## YÊU CẦU

* Trên dữ liệu, các dòng dữ liệu thuộc 01 nhóm GroupIn
* Khi view in thì 01 nhóm GroupIn sẽ in thành 1 bộ chứng từ riêng
* Ví dụ:
  * Sổ chi tiết vật tư in liên tục: 01 vật tư khi in là 01 bộ chứng từ riêng biệt

## HƯỚNG DẪN

### Yêu cầu dữ liệu

* Có 01 cột dùng để xử lý in theo nhóm. Gọi là GroupIn
* Sắp xêp tuần tự theo GroupIn
* Trong GroupIn, sắp xếp theo 1 tiêu chí khác, để đảm bảo các lần in khác nhau đều được sắp xếp theo cùng 1 nguyên tắc

### Xử lý mẫu in

### 1. Tạo GroupHeader1 (Level0) để vẽ tiêu đề cột

* Thêm 01 groupHeader&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2FtzrWX3ndLbR95HpC5qLT%2FT%E1%BA%A1o%20groupHeader1.png?alt=media&#x26;token=0f75a376-283c-4198-9b67-3f426b2f3cfa" alt=""><figcaption><p>Tạo 01 groupHeader</p></figcaption></figure>

* Cấu hình group cho band vừa tạo&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2FOR7K5bvmSx7AXmNvJYdx%2Fc%E1%BA%A5u%20h%C3%ACnh%20groupHeader%20theo%20groupFields.png?alt=media&#x26;token=ea5d74ee-8f2c-41d7-b034-54254e7d9dcd" alt=""><figcaption><p>Cấu hình groupFields</p></figcaption></figure>

### 2. Tạo GroupHeader2 (Level1) để vẽ nội dung pageHeader

* Thêm 01 groupHeader&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2FtzrWX3ndLbR95HpC5qLT%2FT%E1%BA%A1o%20groupHeader1.png?alt=media&#x26;token=0f75a376-283c-4198-9b67-3f426b2f3cfa" alt=""><figcaption><p>Tạo groupHeader </p></figcaption></figure>

* Cấu hình group cho band vừa tạo&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2FOR7K5bvmSx7AXmNvJYdx%2Fc%E1%BA%A5u%20h%C3%ACnh%20groupHeader%20theo%20groupFields.png?alt=media&#x26;token=ea5d74ee-8f2c-41d7-b034-54254e7d9dcd" alt=""><figcaption><p>cấu hình groupFields</p></figcaption></figure>

### 3. Tạo GroupFooter để vẽ nội dung sum tổng cuối cùng của bảng

* Tạo groupFooter&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2F9C8JPlNcVDtGFJWKJffL%2FT%E1%BA%A1o%20groupFooter.png?alt=media&#x26;token=7e38a5b7-c943-4461-bc9f-a2662840765f" alt=""><figcaption><p>Tạo 01 groupFooter - tạo nội dung sum tổng kết sau detail</p></figcaption></figure>
* Cấu hình ngắt trang giữa các group: Nếu không cấu hình thì các group sẽ in liên tục trên cùng 1 tờ giấy, mong muốn là kết thúc 1 group thì ngắt trang để in group mới&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2F8E9iHH18VMLUkV3w5P9d%2Fc%E1%BA%A5u%20h%C3%ACnh%20groupFooter%20-%20Ng%E1%BA%AFt%20trang.png?alt=media&#x26;token=45053960-0275-46eb-990f-8446dcb0deb7" alt=""><figcaption><p>Cấu hình groupFooter - Ngắt trang</p></figcaption></figure>

### 4. Tạo detail - vẽ nộ dung lưới chi tiết

* Giữ nguyên detail&#x20;

### 5. Xử lý sum cột của detail trong mẫu in group

* Nếu không cấu hình, thì sum(cột) sẽ là sum(all dòng) của bảng dữ liệu thay vì là của các dòng trong group&#x20;

  <figure><img src="https://3934179848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpqWC051kMhpZgqZaU9Oy%2Fuploads%2FeDN3vm8FC2MeBjo0VYVy%2Fsum%20t%E1%BB%95ng%20cu%E1%BB%91i%20theo%20t%E1%BB%ABng%20nh%C3%B3m.png?alt=media&#x26;token=b58e2e63-e18b-4ee2-85d0-6aa946b07829" alt=""><figcaption><p>Cấu hình groupFooter - tính sum(cột) các dòng thuộc group</p></figcaption></figure>

* Xử lý đọc tiền ra chữ. Do không thể truyền thông qua biến parameter nên cần xử lý lại dataSource của phiếu in. Thêm cột docsorachu và gán nội dung vào để sử dụng trong mẫu in

```csharp
// Some code
/*
- do mẫu in theo group(kho) nên cần xử lý lại tienhang, docsorachu theo từng kho
- group kho
- sum tienhang theo kho, docsorachu theo kho
*/
if(!dt.Columns.Contains("tienhang"))
	dt.Columns.Add(new DataColumn() { ColumnName = "tienhang", DataType = typeof(int), DefaultValue = 0 });
if(!dt.Columns.Contains("docsorachu"))
	dt.Columns.Add(new DataColumn() { ColumnName = "docsorachu", DataType = typeof(string), DefaultValue = "" });
string sWhere = "";
decimal TienHang = 0, TienHangNgoaiTe = 0;
DataView dtDL = new DataView(dt);
DataTable dtKho = dtDL.ToTable(true, new string[] { "kho" });
if(_Vari.Developer || _Vari.Customer)
	{
		dtKho.TableName = "";
		_Func.ViewTable(dtKho);
	}
			
if(dtKho != null && dtKho.Rows.Count != 0)
	{
		for (int i = 0; i < dtKho.Rows.Count; i++)
			{
				swhere = "tkco like '15%' and khutrung<>3 and kho="+ dtKho.Rows[i]["kho"].ToString(); // nếu phiếu xuất thì đổi điều kiện
				//_Func.TextEditer(swhere);
				decimal.TryParse(dt.Compute("Sum(psno)", swhere).ToString(), out TienHang);
				//MessageBox.Show(TienHang.ToString());
				_Func.EditTable(dt, "tienhang", TienHang, "kho="+ dtKho.Rows[i]["kho"].ToString(), false);
				_Func.EditTable(dt, "docsorachu", formreport.BangChu(TienHang.ToString(), loaitien) , "kho="+ dtKho.Rows[i]["kho"].ToString(), false);
			}
	}
```
