# LỆNH CẦN BIẾT

## 1. câu lệnh set và gọi link help web

```csharp
// Some code
// set đường dẫn. copy paste đường dẫn vào ""
myform.LinkHelp = "https://huongdanketoan.dtechvn.com/";
// gọi web theo đường dẫn phía trên
myform.Help();
//return;

#region: Tạo code gọi link
string sLink = "https://0100108818.dtechvn.com/phan-mem-kho/po/giao-dien-xem-truoc";
myform.LinkHelp = sLink;
myform.Help();
#endregion: Tạo code gọi link
```

## 2. Chuyển xâu format thành list và remove giá trị trống

```csharp
// xau = ",1,2,3,,," => [1,2,3]
// chuyển thành list và remove giá trị trống nếu có
string sChuoi = "1,2,3,,,,";
List<string> lstChuoi = sChuoi.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
```

## 3. Câu lệnh sql gọi từ server1 sang server2

```
// Some code
//select * from OPENDATASOURCE('SQLOLEDB','@thongtinDangnhap').@databaseName.dbo.@tableName
@thongtinDangnhap= 'SERVER=DTECH\SQL2017,1688;User id=sa; PASSWORD=xxxx'
```

## 4. Tạo form nhập biến dữ liệu&#x20;

{% code fullWidth="true" %}

```csharp
// Some code
DataRow GetMoreValues(Size _size, string title, int ColumnNumber, out bool confirm, string option, params string[] from)

//
DateTime ngay0 = DateTime.Now;
DateTime tungay = myform.dauthang(ngay0.Month, ngay0.Year);
DateTime denngay = myform.cuoithang(ngay0.Month, ngay0.Year);
DateTime drTungay = new DateTime(1900, 1, 1);
DateTime drDenngay = new DateTime(1900, 1, 1);
string sWhere = "", drTaikhoan = "", drSotien = "", drTkKhNo = "", drTkKhCo = "";
int drKhachhang = 0;
DataRow dr;
// biến xem là người dùng bấm xác nhận "có hoặc không"
bool confirm = false; 
// A-danhmuc, F-Fromlist,D-ngay,N-numeric,C-text
// muốn khai báo form nhập kiểu nào thì khai báo tuần tự
string option = "AADDNAAFC"
// par là biến theo option. gán kiểu tương ứng option
string[] par = new string[option.Length];
par[0] = "Đối tượng #80#300#khachhang,khachhang,ten#0"; //A
// A - chỉ hiển thị được msthue. 
// khi lấy thì lấy id (khachhang.khachang) thay vì khachhang.msthue
par[0] = "Đối tượng #80#300#khachhang,khachhang,msthue#0";
 
par[1] = "Tài khoản #80#160#taikhoan,ma,ma#1311"; //A
par[2] = "Từ ngày #10#" + tungay.ToString("dd/MM/yyyy"); // D
par[3] = "Đến ngày #10#" + denngay.ToString("dd/MM/yyyy"); //D
par[4] = "Số tiền xử lý <= #20#" + _Vari.dpPsNo.ToString()+"#1000"; //N
par[5] = "Tài khoản Ghi nợ #80#160#taikhoan,ma,ma#8118"; // A dm tài khoản
par[6] = "Tài khoản Ghi có #80#160#taikhoan,ma,ma#7118"; // A Dm tài khoản
C.par[0] = "Lý do hủy PO: #80#300##"; // C 
Fromlist.par[7] = "Số kỳ phân tích#200#200#1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12#1";  // F Dạng fromlist               
dr = _Func.GetFormValues(new Size(300, 300), "Nhập thông tin xử lý", 1, out confirm, option, par);
    if(dr != null && confirm)
     {
      // xử lý 
     }
```

{% endcode %}

## 5. Hiển thị code khi bấm nút và giữ phím control

```csharp
// giữ phím control và click chuột trái vào nút, thì sẽ hiển thị câu lệnh
// sẽ dễ check câu lệnh hơn khi mà phải vào code lập trình. 
if(Control.ModifierKeys == Keys.Control)
		_Func.TextEditer(cmm);
```

## 6. code lấy đường dẫn cài phần mềm

```csharp
// Some code
Code ví dụ đây a à. SaveFileDialog sf = new SaveFileDialog();
//Mặc địn luôn mở thư mục chương trình
sf.InitialDirectory = Application.StartupPath;
//mở lại đường dẫn đã chọn trước đó.
sf.RestoreDirectory = true;
DialogResult dr2 = sf.ShowDialog();
```

## 7. format ngày, tháng thành 2 ký tự

```sql
-- cần xử lý kiểu ngày, tháng thành dạng text 2 ký tự
select day(vr.ngay), format(day(vr.ngay), '00')
, month(vr.ngay) , format(month(vr.ngay),'00')

-- tạo chuỗi ngày tháng năm từ vr.ngay: Ngày DD tháng MM năm YYYY
select concat('Ngày ', format(day(vr.ngay), '00')
, ' tháng ', format(month(vr.ngay),'00')
, ' năm ', format(year(vr.ngay),'0000'))

```

## 8. select gom nhiều dòng thành text cách nhau dấu phẩy

```sql
-- select gom nhiều phòng ban 
-- và thành 1 dòng theo cột bộ phận và biến @bophan (where bophan=@bophan)
SELECT STUFF((
    SELECT ', ' + phongban
    FROM TenBang
    WHERE bophan = @bophan
    FOR XML PATH('')), 1, 2, '') AS DanhSachPhongBan;
-- select gom nhiều phòng ban và thành 1 dòng theo cột bộ phận (group by bophan)  
SELECT 
    t1.bophan,
    STUFF((
        SELECT ', ' + t2.phongban
        FROM TenBang t2
        WHERE t2.bophan = t1.bophan
        FOR XML PATH(''), TYPE
    ).value('.', 'NVARCHAR(MAX)'), 1, 2, '') AS danh_sach_phong_ban
FROM TenBang t1
GROUP BY t1.bophan;

  --- gom dvdo theo nhomdvdo
  SELECT 
    t1.nhomdvdo,
    STUFF((
        SELECT ', ' + CAST(t2.dvdo AS VARCHAR(10)) 
        FROM dvdo t2
        WHERE t2.nhomdvdo = t1.nhomdvdo and t1.nhomDvdo<>0
        FOR XML PATH(''), TYPE
    ).value('.', 'NVARCHAR(MAX)'), 1, 2, '') AS danh_sach_dvdo
FROM dvdo t1
where  t1.nhomDvdo<>0
GROUP BY t1.nhomdvdo;  
```

* update user khi convert thiếu từ data convert sang data dich

```
// Some code\


select t1.ngay,t1.chungtu, t2.*
update t1 set t1.[user]=t2.[user]
from
(
select * from dulieuketoan 
)t1 inner join 
(
select ngay,chungtu,nghiepvu,[user] from dha_bn200.dbo.dulieuketoan 
group by ngay,chungtu,nghiepvu,[user]
)T2 on t1.ngay=t2.ngay and t1.chungtu=t2.chungtu and t1.nghiepvu=t2.nghiepvu
```


---

# 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/lenh-can-biet.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.
