private void btnRefresh_Click(object sender, EventArgs e) { try { DateTime ngayBatDau = calBatDauTu.Value; DateTime ngayKetThuc = calBatDauDen.Value; DoiTac objMoiGioi = new DoiTac(); if ((ngayKetThuc < ngayBatDau)) { MessageBox.Show(@"Ngày kết thúc phải lớn hơn ngày bắt đầu", @"Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); calBatDauDen.Focus(); } else { // bind du lieu vao grid int Type = 0; if (chkCiputra.Checked && !chkHoaHong.Checked) { Type = 1; } else if (!chkCiputra.Checked && chkHoaHong.Checked) { Type = 2; } DataSet ds = objMoiGioi.GetBaoCaoMoiGioi_PhatSinhTheoXe(txtMaMoiGioi.Text.Trim(), txtSoXe.Text.Trim(), ngayBatDau, ngayKetThuc, Type); if (ds != null && ds.Tables.Count > 1) { DataTable dt1 = ds.Tables[0]; //Table cuộc gọi có 1 xe đón DataTable dt2 = ds.Tables[1]; //Table cuộc gọi có nhiều xe đón if (dt2 != null && dt2.Rows.Count > 0) { foreach (DataRow item in dt2.Rows) { string[] arrXeDon = item["XeDonCK"].ToString().Split('.'); foreach (string xedon in arrXeDon) { //DataRow[] dr = dtXe.Select("PK_SoHieuXe = '" + xedon + "'"); //if (dr.Length > 0) { item["XeDon"] = xedon; dt1.ImportRow(item); //dt1.Rows[dt1.Rows.Count-1]["XeDon"] = xedon; } } } } if (dt1 != null) { var groupedData = from tab in dt1.AsEnumerable() group tab by tab["XeDon"] into groupDt let list = groupDt.ToList() select new { XeDon = groupDt.Key, MoiGioiCount = list.Count(), SanBay_DuongDai = list.Sum(x => x.Field <int>("SanBay_DuongDai")), BinhThuong = list.Sum(x => x.Field <int>("BinhThuong")) }; //DataTable dtReport = Global.GroupBy_Multi_Custom("XeDon", "MoiGioi","Ciputra", "ID", dt1); gridEX_TH.DataMember = "tblMoiGioiTH"; gridEX_TH.SetDataBinding(groupedData.ToList(), "tblMoiGioiTH"); grdMoiGioiCuocGoiThap.DataMember = "tblMoiGioiSoLuong"; grdMoiGioiCuocGoiThap.SetDataBinding(dt1, "tblMoiGioiSoLuong"); btnExportExcel.Enabled = true; } else { MessageBox.Show("Không tìm thấy dữ liệu"); gridEX_TH.DataMember = "tblMoiGioiTH"; gridEX_TH.SetDataBinding(null, "tblMoiGioiTH"); grdMoiGioiCuocGoiThap.DataMember = "tblMoiGioiSoLuong"; grdMoiGioiCuocGoiThap.SetDataBinding(dt1, "tblMoiGioiSoLuong"); lbMess.Text = "Không tìm thấy dữ liệu"; btnExportExcel.Enabled = false; } } } } catch (Exception ex) { Taxi.Business.LogError.WriteLogError("frmBC_6_6", ex); } }
private void btnRefresh_Click(object sender, EventArgs e) { DateTime ngayBatDau = calBatDauTu.Value; DateTime ngayKetThuc = calBatDauDen.Value; DoiTac objMoiGioi = new DoiTac(); if ((ngayKetThuc < ngayBatDau)) { MessageBox.Show("Ngày kết thúc phải lớn hơn ngày bắt đầu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); calBatDauDen.Focus(); } else { // bind du lieu vao grid int Type = 0; if (chkCiputra.Checked && !chkHoaHong.Checked) { Type = 1; } else if (!chkCiputra.Checked && chkHoaHong.Checked) { Type = 2; } DataSet ds = objMoiGioi.GetBaoCaoMoiGioi_PhatSinhTheoXe(txtMaMoiGioi.Text.Trim(), txtSoXe.Text.Trim(), ngayBatDau, ngayKetThuc, Type); if (ds != null && ds.Tables.Count > 1) { DataTable dt1 = ds.Tables[0]; //Table cuộc gọi có 1 xe đón DataTable dt2 = ds.Tables[1]; //Table cuộc gọi có nhiều xe đón if (dt2 != null && dt2.Rows.Count > 0) { foreach (DataRow item in dt2.Rows) { string[] arrXeDon = item["XeDonCK"].ToString().Split('.'); foreach (string xedon in arrXeDon) { DataRow[] dr = dtXe.Select("PK_SoHieuXe = '" + xedon + "'"); if (dr.Length > 0) { item["XeDon"] = xedon; dt1.ImportRow(item); //dt1.Rows[dt1.Rows.Count-1]["XeDon"] = xedon; } } } } if (dt1 != null) { DataTable dtReport = Global.GroupBy_Multi_Custom("XeDon", "MoiGioi", "Ciputra", "ID", dt1); gridEX_TH.DataMember = "tblMoiGioiTH"; gridEX_TH.SetDataBinding(dtReport, "tblMoiGioiTH"); grdMoiGioiCuocGoiThap.DataMember = "tblMoiGioiSoLuong"; grdMoiGioiCuocGoiThap.SetDataBinding(dt1, "tblMoiGioiSoLuong"); btnExportExcel.Enabled = true; } else { MessageBox.Show("Không tìm thấy dữ liệu"); gridEX_TH.DataMember = "tblMoiGioiTH"; gridEX_TH.SetDataBinding(null, "tblMoiGioiTH"); grdMoiGioiCuocGoiThap.DataMember = "tblMoiGioiSoLuong"; grdMoiGioiCuocGoiThap.SetDataBinding(dt1, "tblMoiGioiSoLuong"); lbMess.Text = "Không tìm thấy dữ liệu"; btnExportExcel.Enabled = false; } } } }