Пример #1
0
        public string GetExcelReportData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            QCReportDataObject ds = new QCReportDataObject();

            try
            {
                SqlDataAdapter adap = new SqlDataAdapter();
                adap.SelectCommand             = new SqlCommand("QCReportRpt_function_GetReportData", new SqlConnection(Library.Helper.GetSQLConnectionString()));
                adap.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
                adap.SelectCommand.Parameters.AddWithValue("@QCReportID", id);
                adap.TableMappings.Add("Table", "QCReportDataView");
                adap.TableMappings.Add("Table1", "QCReportDefectDataView");
                adap.TableMappings.Add("Table2", "QCReportDetailDataView");
                adap.TableMappings.Add("Table3", "QCReportImageDataView");
                adap.TableMappings.Add("Table4", "QCReportSummaryDataView");
                adap.TableMappings.Add("Table5", "QCReportTestEnvironmentDataView");
                adap.TableMappings.Add("Table6", "QCReportFactoryOrderDetailReportDataView");
                adap.Fill(ds);

                var list = "";
                for (var j = 0; j < ds.QCReportFactoryOrderDetailReportDataView.Count; j++)
                {
                    var jItem = ds.QCReportFactoryOrderDetailReportDataView[j];
                    if (list != "")
                    {
                        list += ", ";
                    }
                    list += jItem.ProformaInvoiceNo;
                }

                ds.QCReportDataView[0].ProformaInvoiceNo = list;

                //Remove table not use
                ds.Tables.Remove("QCReportImageMatrix");
                ds.Tables.Remove("QCReportTestEnviromentMatrix");
                ds.Tables.Remove("QCReportFactoryOrderDetailReportDataView");
                ds.AcceptChanges();


                return(Library.Helper.CreateReportFileWithEPPlus2(ds, "QCReport"));
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex, ds);
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(string.Empty);
            }
        }
Пример #2
0
        public string GetExportPDF(int id, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };
            QCReportDataObject ds = new QCReportDataObject();

            try
            {
                SqlDataAdapter adap = new SqlDataAdapter();
                adap.SelectCommand             = new SqlCommand("QCReportRpt_function_GetReportData", new SqlConnection(Library.Helper.GetSQLConnectionString()));
                adap.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
                adap.SelectCommand.Parameters.AddWithValue("@QCReportID", id);
                adap.TableMappings.Add("Table", "QCReportDataView");
                adap.TableMappings.Add("Table1", "QCReportDefectDataView");
                adap.TableMappings.Add("Table2", "QCReportDetailDataView");
                adap.TableMappings.Add("Table3", "QCReportImageDataView");
                adap.TableMappings.Add("Table4", "QCReportSummaryDataView");
                adap.TableMappings.Add("Table5", "QCReportTestEnvironmentDataView");
                adap.TableMappings.Add("Table6", "QCReportFactoryOrderDetailReportDataView");
                adap.Fill(ds);

                var list = "";
                for (var j = 0; j < ds.QCReportFactoryOrderDetailReportDataView.Count; j++)
                {
                    var jItem = ds.QCReportFactoryOrderDetailReportDataView[j];
                    if (list != "")
                    {
                        list += ", ";
                    }
                    list += jItem.ProformaInvoiceNo;
                }

                ds.QCReportDataView[0].ProformaInvoiceNo = list;
                ds.Tables.Remove("QCReportFactoryOrderDetailReportDataView");

                if (!ds.QCReportDataView[0].IsThumbnailLocationNull() && !string.IsNullOrEmpty(ds.QCReportDataView[0].ThumbnailLocation))
                {
                    ds.QCReportDataView[0].ThumbnailLocation = FrameworkSetting.Setting.MediaThumbnailUrl + ds.QCReportDataView[0].ThumbnailLocation;
                }

                int     imagePosition = 1;
                DataRow imageDataRow  = null;
                int     totalRowsI    = 0;
                int     totalCountI   = ds.QCReportImageDataView.Count();
                foreach (var item in ds.QCReportImageDataView)
                {
                    totalRowsI++;

                    if (imageDataRow == null)
                    {
                        imageDataRow = ds.QCReportImageMatrix.NewRow();
                    }

                    if (imagePosition == 1)
                    {
                        if (!item.IsThumbnailLocationNull() && !string.IsNullOrEmpty(item.ThumbnailLocation))
                        {
                            imageDataRow["ThumbnailLocation1"] = FrameworkSetting.Setting.MediaThumbnailUrl + item.ThumbnailLocation;
                        }
                        if (!item.IsFileLocationNull() && !string.IsNullOrEmpty(item.FileLocation))
                        {
                            imageDataRow["FileLocation1"] = FrameworkSetting.Setting.MediaThumbnailUrl + item.FileLocation;
                        }
                        if (!item.IsImageTitleNull() && !string.IsNullOrEmpty(item.ImageTitle))
                        {
                            imageDataRow["ImageTitle1"] = item.ImageTitle;
                        }

                        if (totalRowsI == totalCountI)
                        {
                            //Add data
                            ds.QCReportImageMatrix.Rows.Add(imageDataRow);
                        }
                        //Change position
                        imagePosition++;
                    }
                    else if (imagePosition == 2)
                    {
                        if (!item.IsThumbnailLocationNull() && !string.IsNullOrEmpty(item.ThumbnailLocation))
                        {
                            imageDataRow["ThumbnailLocation2"] = FrameworkSetting.Setting.MediaThumbnailUrl + item.ThumbnailLocation;
                        }
                        if (!item.IsFileLocationNull() && !string.IsNullOrEmpty(item.FileLocation))
                        {
                            imageDataRow["FileLocation2"] = FrameworkSetting.Setting.MediaThumbnailUrl + item.FileLocation;
                        }
                        if (!item.IsImageTitleNull() && !string.IsNullOrEmpty(item.ImageTitle))
                        {
                            imageDataRow["ImageTitle2"] = item.ImageTitle;
                        }

                        if (totalRowsI == totalCountI)
                        {
                            //Add data
                            ds.QCReportImageMatrix.Rows.Add(imageDataRow);
                        }
                        //Change position
                        imagePosition++;
                    }
                    else if (imagePosition == 3)
                    {
                        if (!item.IsThumbnailLocationNull() && !string.IsNullOrEmpty(item.ThumbnailLocation))
                        {
                            imageDataRow["ThumbnailLocation3"] = FrameworkSetting.Setting.MediaThumbnailUrl + item.ThumbnailLocation;
                        }
                        if (!item.IsFileLocationNull() && !string.IsNullOrEmpty(item.FileLocation))
                        {
                            imageDataRow["FileLocation3"] = FrameworkSetting.Setting.MediaThumbnailUrl + item.FileLocation;
                        }
                        if (!item.IsImageTitleNull() && !string.IsNullOrEmpty(item.ImageTitle))
                        {
                            imageDataRow["ImageTitle3"] = item.ImageTitle;
                        }
                        //Add data
                        ds.QCReportImageMatrix.Rows.Add(imageDataRow);
                        //Change position
                        imagePosition = imagePosition - 2;
                        //
                        imageDataRow = null;
                    }
                }

                int     testEnviromentPosition = 1;
                DataRow enviromentDataRow      = null;
                int     totalRowsE             = 0;
                int     totalCountE            = ds.QCReportTestEnvironmentDataView.Count();
                foreach (var item in ds.QCReportTestEnvironmentDataView)
                {
                    totalRowsE++;

                    if (enviromentDataRow == null)
                    {
                        enviromentDataRow = ds.QCReportTestEnviromentMatrix.NewRow();
                    }

                    if (testEnviromentPosition == 1)
                    {
                        if (!item.IsQCReportTestEnvironmentItemNMNull() && !string.IsNullOrEmpty(item.QCReportTestEnvironmentItemNM))
                        {
                            enviromentDataRow["QCReportTestEnvironmentItemNM1"] = item.QCReportTestEnvironmentItemNM;
                        }
                        if (!item.IsQCReportTestEnvironmentCategoryNMNull() && !string.IsNullOrEmpty(item.QCReportTestEnvironmentCategoryNM))
                        {
                            enviromentDataRow["QCReportTestEnvironmentCategoryNM1"] = item.QCReportTestEnvironmentCategoryNM;
                        }
                        if (!item.IsIsSelectedTextNull())
                        {
                            enviromentDataRow["IsSelectedText1"] = item.IsSelectedText;
                        }
                        if (totalRowsE == totalCountE)
                        {
                            //Add data
                            ds.QCReportTestEnviromentMatrix.Rows.Add(enviromentDataRow);
                        }
                        //Change position
                        testEnviromentPosition++;
                    }
                    else if (testEnviromentPosition == 2)
                    {
                        if (!item.IsQCReportTestEnvironmentItemNMNull() && !string.IsNullOrEmpty(item.QCReportTestEnvironmentItemNM))
                        {
                            enviromentDataRow["QCReportTestEnvironmentItemNM2"] = item.QCReportTestEnvironmentItemNM;
                        }
                        if (!item.IsQCReportTestEnvironmentCategoryNMNull() && !string.IsNullOrEmpty(item.QCReportTestEnvironmentCategoryNM))
                        {
                            enviromentDataRow["QCReportTestEnvironmentCategoryNM2"] = item.QCReportTestEnvironmentCategoryNM;
                        }
                        if (!item.IsIsSelectedTextNull())
                        {
                            enviromentDataRow["IsSelectedText2"] = item.IsSelectedText;
                        }
                        if (totalRowsE == totalCountE)
                        {
                            //Add data
                            ds.QCReportTestEnviromentMatrix.Rows.Add(enviromentDataRow);
                        }
                        //Change position
                        testEnviromentPosition++;
                    }
                    else if (testEnviromentPosition == 3)
                    {
                        if (!item.IsQCReportTestEnvironmentItemNMNull() && !string.IsNullOrEmpty(item.QCReportTestEnvironmentItemNM))
                        {
                            enviromentDataRow["QCReportTestEnvironmentItemNM3"] = item.QCReportTestEnvironmentItemNM;
                        }
                        if (!item.IsQCReportTestEnvironmentCategoryNMNull() && !string.IsNullOrEmpty(item.QCReportTestEnvironmentCategoryNM))
                        {
                            enviromentDataRow["QCReportTestEnvironmentCategoryNM3"] = item.QCReportTestEnvironmentCategoryNM;
                        }
                        if (!item.IsIsSelectedTextNull())
                        {
                            enviromentDataRow["IsSelectedText3"] = item.IsSelectedText;
                        }
                        //Add data
                        ds.QCReportTestEnviromentMatrix.Rows.Add(enviromentDataRow);
                        //Change position
                        testEnviromentPosition = testEnviromentPosition - 2;
                        //
                        enviromentDataRow = null;
                    }
                }

                //Remove table not use
                ds.AcceptChanges();

                return(Library.Helper.CreateReceiptPrintout2(ds, "QCReport_pdf.rdlc"));
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(string.Empty);
            }
        }