protected void btnLoadFile_Click(object sender, EventArgs e) { if (this.refImg.Count < 2) { for (int i = 0; i < FileUpload1.PostedFiles.Count; i++) { HttpPostedFile _postedFile = FileUpload1.PostedFiles[i]; if ((Path.GetExtension(_postedFile.FileName).Equals(".jpg"))) { string yyyy = DateTime.Now.ToString("yyyy"); string MM = DateTime.Now.ToString("MM"); string dd = DateTime.Now.ToString("dd"); String source_file = String.Format(Configurations.PATH_SOURCE, yyyy, MM, dd, this.jobSample.job_number, Path.GetFileName(_postedFile.FileName)); String source_file_url = String.Concat(Configurations.HOST, String.Format(Configurations.PATH_URL, yyyy, MM, dd, this.jobSample.job_number, Path.GetFileName(_postedFile.FileName))); if (!Directory.Exists(Path.GetDirectoryName(source_file))) { Directory.CreateDirectory(Path.GetDirectoryName(source_file)); } _postedFile.SaveAs(source_file); template_seagate_copperwire_img _img = new template_seagate_copperwire_img(); _img.id = CustomUtils.GetRandomNumberID(); _img.sample_id = this.SampleID; _img.img_type = this.refImg.Count + 1;// i + 1; _img.path_img1 = source_file_url; this.refImg.Add(_img); } } gvRefImages.DataSource = this.refImg; gvRefImages.DataBind(); } }
protected void gvRefImages_RowUpdating(object sender, GridViewUpdateEventArgs e) { int _id = Convert.ToInt32(gvRefImages.DataKeys[e.RowIndex].Values[0].ToString()); DropDownList _ddlImgType = (DropDownList)gvRefImages.Rows[e.RowIndex].FindControl("ddlImgType"); if (_ddlImgType != null) { template_seagate_copperwire_img _tmp = this.refImg.Find(x => x.id == _id); if (_tmp != null) { _tmp.img_type = Convert.ToInt32(_ddlImgType.SelectedValue); } } gvRefImages.EditIndex = -1; gvRefImages.DataSource = this.refImg; gvRefImages.DataBind(); }
protected void gvRefImages_RowCommand(object sender, GridViewCommandEventArgs e) { CommandNameEnum cmd = (CommandNameEnum)Enum.Parse(typeof(CommandNameEnum), e.CommandName, true); if (!String.IsNullOrEmpty(e.CommandArgument.ToString())) { int PKID = int.Parse(e.CommandArgument.ToString().Split(Constants.CHAR_COMMA)[0]); template_seagate_copperwire_img _mesa = this.refImg.Find(x => x.id == PKID); if (_mesa != null) { switch (cmd) { case CommandNameEnum.Delete: this.refImg.Remove(_mesa); break; } gvRefImages.DataSource = this.refImg; gvRefImages.DataBind(); } } }
protected void lbDownload_Click(object sender, EventArgs e) { DataTable dt = Extenders.ObjectToDataTable(this.coverpages[0]); ReportHeader reportHeader = ReportHeader.getReportHeder(this.jobSample); ReportParameterCollection reportParameters = new ReportParameterCollection(); reportParameters.Add(new ReportParameter("CustomerPoNo", reportHeader.cusRefNo)); reportParameters.Add(new ReportParameter("AlsThailandRefNo", reportHeader.alsRefNo)); reportParameters.Add(new ReportParameter("Date", reportHeader.cur_date.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("Company", reportHeader.addr1)); reportParameters.Add(new ReportParameter("Company_addr", reportHeader.addr2)); reportParameters.Add(new ReportParameter("DateSampleReceived", reportHeader.dateOfDampleRecieve.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("DateAnalyzed", reportHeader.dateOfAnalyze.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("DateTestCompleted", reportHeader.dateOfTestComplete.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("SampleDescription", reportHeader.description)); reportParameters.Add(new ReportParameter("Test", "-")); reportParameters.Add(new ReportParameter("ResultDesc", lbResultDesc.Text)); reportParameters.Add(new ReportParameter("AlsSingaporeRefNo", (String.IsNullOrEmpty(this.jobSample.singapore_ref_no) ? String.Empty : this.jobSample.singapore_ref_no))); // Variables Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; List <template_seagate_copperwire_img> dat = new List <template_seagate_copperwire_img>(); template_seagate_copperwire_img tmp = new template_seagate_copperwire_img(); template_seagate_copperwire_img corImg = this.refImg.Where(x => x.img_type.Value == 1).FirstOrDefault(); if (corImg != null) { tmp.img1 = CustomUtils.GetBytesFromImage(corImg.path_img1); } corImg = this.refImg.Where(x => x.img_type.Value == 2).FirstOrDefault(); if (corImg != null) { tmp.img2 = CustomUtils.GetBytesFromImage(corImg.path_img1); } dat.Add(tmp); // Setup the report viewer object and get the array of bytes ReportViewer viewer = new ReportViewer(); viewer.ProcessingMode = ProcessingMode.Local; viewer.LocalReport.ReportPath = Server.MapPath("~/ReportObject/copperwire_seagate.rdlc"); viewer.LocalReport.SetParameters(reportParameters); viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt)); // Add datasource here viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", dt)); // Add datasource here viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet3", dat.ToDataTable())); // Add datasource here string download = String.Empty; StatusEnum status = (StatusEnum)Enum.Parse(typeof(StatusEnum), this.jobSample.job_status.ToString(), true); switch (status) { case StatusEnum.ADMIN_CONVERT_WORD: if (!String.IsNullOrEmpty(this.jobSample.path_word)) { Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); } else { byte[] bytes = viewer.LocalReport.Render("Word", null, out mimeType, out encoding, out extension, out streamIds, out warnings); if (!Directory.Exists(Server.MapPath("~/Report/"))) { Directory.CreateDirectory(Server.MapPath("~/Report/")); } using (FileStream fs = File.Create(Server.MapPath("~/Report/") + this.jobSample.job_number + "_orginal." + extension)) { fs.Write(bytes, 0, bytes.Length); } #region "Insert Footer & Header from template" Document doc1 = new Document(); doc1.LoadFromFile(Server.MapPath("~/template/") + "Blank Letter Head - EL.doc"); HeaderFooter header = doc1.Sections[0].HeadersFooters.Header; HeaderFooter footer = doc1.Sections[0].HeadersFooters.Footer; Document doc2 = new Document(Server.MapPath("~/Report/") + this.jobSample.job_number + "_orginal." + extension); foreach (Section section in doc2.Sections) { foreach (DocumentObject obj in header.ChildObjects) { section.HeadersFooters.Header.ChildObjects.Add(obj.Clone()); } foreach (DocumentObject obj in footer.ChildObjects) { section.HeadersFooters.Footer.ChildObjects.Add(obj.Clone()); } } doc2.SaveToFile(Server.MapPath("~/Report/") + this.jobSample.job_number + "." + extension); #endregion Response.ContentType = mimeType; Response.AddHeader("Content-Disposition", "attachment; filename=" + this.jobSample.job_number + "." + extension); Response.WriteFile(Server.MapPath("~/Report/" + this.jobSample.job_number + "." + extension)); Response.Flush(); #region "Delete After Download" String deleteFile1 = Server.MapPath("~/Report/") + this.jobSample.job_number + "." + extension; String deleteFile2 = Server.MapPath("~/Report/") + this.jobSample.job_number + "_orginal." + extension; if (File.Exists(deleteFile1)) { File.Delete(deleteFile1); } if (File.Exists(deleteFile2)) { File.Delete(deleteFile2); } #endregion } break; case StatusEnum.LABMANAGER_CHECKING: case StatusEnum.LABMANAGER_APPROVE: case StatusEnum.LABMANAGER_DISAPPROVE: if (!String.IsNullOrEmpty(this.jobSample.path_word)) { Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); } break; case StatusEnum.ADMIN_CONVERT_PDF: if (!String.IsNullOrEmpty(this.jobSample.path_word)) { Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); } //if (!String.IsNullOrEmpty(this.jobSample.path_word)) //{ // Word2Pdf objWorPdf = new Word2Pdf(); // objWorPdf.InputLocation = String.Format("{0}{1}", Configurations.PATH_DRIVE, this.jobSample.path_word); // objWorPdf.OutputLocation = String.Format("{0}{1}", Configurations.PATH_DRIVE, this.jobSample.path_word).Replace("doc", "pdf"); // try // { // objWorPdf.Word2PdfCOnversion(); // Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word).Replace("doc", "pdf")); // } // catch (Exception ex) // { // Console.WriteLine(); // Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); // } //} break; } }