private void OnSearchBangKe() { InvalidCredentialsMessage.Visible = false; var thangKeKhai = DateUtil.GetDateTime(ReportMonth.Value.Trim()); var allBangKeDto = DcapServiceUtil.SearchBangKe(thangKeKhai); gvBangKe.DataSource = allBangKeDto; gvBangKe.DataBind(); Hashtable mapPaidUserName = CreateMapPaidUserName(allBangKeDto); UpdateKyNhanStatus(mapPaidUserName); }
protected void BangKeTraLuong_ExportDOC(object sender, EventArgs e) { InvalidCredentialsMessage.Visible = false; var thangKeKhai = DateUtil.GetDateTime(ReportMonth.Value.Trim()); var allBangKeDto = DcapServiceUtil.SearchBangKe(thangKeKhai); if (allBangKeDto.Length == 0) { return; } var dt = OnCreateDataTable(allBangKeDto); var fileName = String.Format("BKTL_{0:yyyyMMddHHmmssfff}", DateTime.Now) + ".doc"; var fileDir = String.Format("BKTL_{0:yyyyMMdd}", DateTime.Now); var filePath = Server.MapPath("~/upload") + "\\" + fileDir + "\\" + fileName; string directory = filePath.Substring(0, filePath.LastIndexOf("\\"));// GetDirectory(Path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter); DataGrid dataGrd = new DataGrid(); dataGrd.DataSource = dt; dataGrd.DataBind(); dataGrd.RenderControl(htmlWrite); StreamWriter vw = new StreamWriter(filePath, true, Encoding.UTF8); stringWriter.ToString().Normalize(); vw.Write(stringWriter.ToString()); vw.Flush(); vw.Close(); FileInfo file = new FileInfo(filePath); Response.Clear(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; //Add header, give a default file name for "File Download/Store as" Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); //Add header, set file size to enable browser display download progress Response.AddHeader("Content-Length", file.Length.ToString()); //Set the return string is unavailable reading for client, and must be downloaded Response.ContentType = "application/vnd.ms-word"; //Send file string to client Response.WriteFile(file.FullName); //Stop execute Response.End(); // Cleanup file.Delete(); }