Hi fabio,
I fill the grid as normal. I work well. Just when I export with big data on the grid then I have a problem.
private void btnSummaryByCustomer_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
try
{
DateTime dFromDate = (DateTime)txtFromDate.Value;
DateTime dToDate = (DateTime)txtToDate.Value;
List<string> itemBoKhongBom = new List<string>();//Nhằm lưu mã bộ không có BOM, nếu không có BOM sẽ không xóa
int result = DateTime.Compare(dFromDate, dToDate);
if (result > 0)
{
MessageBox.Show("Pls check the date.", "information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
if (dFromDate.AddDays(31) <= dToDate)
{
MessageBox.Show("The period is only 1 month. Pls enter again.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtFromDate.Focus();
return;
}
if (string.IsNullOrEmpty(txtWarehouse.Text))
{
MessageBox.Show("Pls enter the warehouse code.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtWarehouse.Focus();
return;
}
//Get Exchange rate
string sExchangeRate = txtExchangeRate.Text.Trim();
double dExchangeRate = 1;
if (!double.TryParse(sExchangeRate, out dExchangeRate))
{
MessageBox.Show("Pls check the exchange rate.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
string wareHouse = txtWarehouse.Text;
//Nếu ngày nhập vào okay thì bắt đầu kiểm tra dữ liệu
ExactDB objGiaoHang = new ExactDB();
//Neu ton tai moi thuc hien
DataTable dtResult = new DataTable();
//Kho nệm: '301 '
dtResult = objGiaoHang.GetDnByWarehouseFromTo_Update(wareHouse, dFromDate, dToDate); //Lấy số lượng giao hàng từ ngày đến ngày
if (dtResult == null || dtResult.Rows.Count == 0)
{
MessageBox.Show("There is no any document match with your request.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
#region Export data to flexgrid
fgGiaoHang.BeginUpdate();
this.iniFlexgridKhachHang(1);
int hangBatDau = 1;
foreach (DataRow dtRow in dtResult.Rows)
{
string sIbtDoc = dtRow["IbtDoc"] != null ? dtRow["IbtDoc"].ToString() : "";
if (string.IsNullOrEmpty(sIbtDoc))
{
fgGiaoHang.Rows.Add();
hangBatDau = fgGiaoHang.Rows.Count - 1;
fgGiaoHang[hangBatDau, 3] = dtRow["DocDate"]; //.ToString();
fgGiaoHang[hangBatDau, 1] = dtRow["DebCode"];
string tenKH = dtRow["DebName"].ToString();
tenKH = AllLib.StringExtension.VNItoUNICODE(tenKH);
fgGiaoHang[hangBatDau, 2] = tenKH;
fgGiaoHang[hangBatDau, 4] = dtRow["DnNumber"];
fgGiaoHang[hangBatDau, 5] = dtRow["ItemCode"];
string sProductName = dtRow["Description"].ToString();
sProductName = AllLib.StringExtension.VNItoUNICODE(sProductName);
fgGiaoHang[hangBatDau, 6] = sProductName;
string sDvt = dtRow["Unitcode"].ToString();
sDvt = AllLib.StringExtension.VNItoUNICODE(sDvt);
fgGiaoHang[hangBatDau, 7] = sDvt;
string sQtyIn = dtRow["QtyIn"].ToString();
string sQtyOut = dtRow["QtyOut"].ToString();
double dQtyIn = 0;
if (!double.TryParse(sQtyIn, out dQtyIn))
{
dQtyIn = 0;
}
double dQtyOut = 0;
if (!double.TryParse(sQtyOut, out dQtyOut))
{
dQtyOut = 0;
}
fgGiaoHang[hangBatDau, 8] = dQtyOut - dQtyIn;
string ghiChu = dtRow["Remark"] != null ? dtRow["Remark"].ToString() : "";
ghiChu = AllLib.StringExtension.VNItoUNICODE(ghiChu);
fgGiaoHang[hangBatDau, 9] = ghiChu;
fgGiaoHang[hangBatDau, 10] = dtRow["OrderNo"];
fgGiaoHang[hangBatDau, 11] = dtRow["DnNumberOnPXK"];
fgGiaoHang[hangBatDau, 12] = dtRow["InvNo"];
fgGiaoHang[hangBatDau, 13] = dtRow["VATPercent"];
fgGiaoHang[hangBatDau, 14] = dtRow["AmountWithoutVAT"];
fgGiaoHang[hangBatDau, 15] = dtRow["AmountWithVAT"];
}
}
fgGiaoHang.Cols[14].Format = "#,##0.00"; // thousands
fgGiaoHang.Cols[15].Format = "#,##0.00"; // thousands
fgGiaoHang.Cols[3].Format = "dd/MM/yyyy"; // Re-format the date column
#endregion
#region Arrange and Total
//Sắp xếp
//Apply sorting on multiple columns
fgGiaoHang.Cols[1].Sort = SortFlags.Ascending;//Ma khach hang
fgGiaoHang.Cols[4].Sort = SortFlags.Ascending;//So DN
//Call the Sort method
fgGiaoHang.Sort(SortFlags.UseColSort, 1, 4);
//Sắp xếp: note không cần sắp xếp vì khi lấy dữ liệu ra đã sắp xếp theo Ngày và Mã khách hàng
//Thiết lập SubTotal
fgGiaoHang.Tree.Column = 0;//Nút subtotal ở cột ngoài cùng
fgGiaoHang.Tree.Style = TreeStyleFlags.Simple;
//Xoá subtotal hiện tại
fgGiaoHang.Subtotal(AggregateEnum.Clear);
//Total dựa trên Ngày tính ở cột số lượng
fgGiaoHang.Subtotal(AggregateEnum.Sum, 1, 1, 8, "{0}");//So luong
fgGiaoHang.Subtotal(AggregateEnum.Sum, 1, 1, 14, "{0}");//Tong chua VAT
fgGiaoHang.Subtotal(AggregateEnum.Sum, 1, 1, 15, "{0}");//Tong co VAT
//Thêm Grand total
fgGiaoHang.Subtotal(AggregateEnum.Sum, -1, -1, 8, "Tổng tất cả");
fgGiaoHang.Subtotal(AggregateEnum.Sum, -1, -1, 14, "Tổng tất cả");
fgGiaoHang.Subtotal(AggregateEnum.Sum, -1, -1, 15, "Tổng tất cả");
fgGiaoHang.Cols[0].Width = 100;
fgGiaoHang.Tree.Show(1);
#endregion
#region Fill some more information at the node line
for (int j = 1; j < fgGiaoHang.Rows.Count; j++)
{
if (fgGiaoHang.Rows[j].IsNode == true && fgGiaoHang.Rows[j].Node.Level == 1)
{
fgGiaoHang[j, 1] = fgGiaoHang[j + 1, 1];//Mã khách hàng
fgGiaoHang[j, 2] = fgGiaoHang[j + 1, 2];//Tên khách hàng
}
}
#endregion
}
}
}
catch (Exception ex)
{
if (ex.Message.IndexOf("Exception has been thrown by the target of an invocation") >= 0)
{
MessageBox.Show("It took to long or you don't have a right to access.\nPls contact your admin.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("The error is \n" + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
finally
{
fgGiaoHang.EndUpdate();
//reset cursor
this.Cursor = Cursors.Default;
}
}
Thanks,
Duyet Le