Example #1
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }

            FpSpread.Dispose();
            fpSheetEditor1.Dispose();

            fpSheetEditor1 = null;

            base.Dispose(disposing);
        }
Example #2
0
        /// <summary>
        /// 上传试验数据
        /// </summary>
        public void UploadTestDataInfo(string strTestRoomCodeMap, String uploadAddress, String jsdwCode)
        {
            try
            {
                Hashtable testRoomCodeMap = InitTestRoomCodeMap(strTestRoomCodeMap);
//                String sql = @"SELECT top 100 ID,TestRoomCode,Data,WillUploadCount,ModuleID,BGBH,CreatedTime FROM dbo.sys_document WHERE
//            ModuleID NOT IN ('E77624E9-5654-4185-9A29-8229AAFDD68B','08899BA2-CC88-403E-9182-3EF73F5FB0CE',
//            'BA23C25D-7C79-4CB3-A0DC-ACFA6C285295') AND Status>0 AND NeedUpload=1 and BGBH is not null and BGBH<>''  ORDER BY CreatedTime ";//排除人员、设备、试验室
                String         sql   = @"SELECT top 100 ID FROM dbo.sys_document WHERE 
            ModuleID NOT IN ('E77624E9-5654-4185-9A29-8229AAFDD68B','08899BA2-CC88-403E-9182-3EF73F5FB0CE',
            'BA23C25D-7C79-4CB3-A0DC-ACFA6C285295') AND Status>0 AND NeedUpload=1 and BGBH is not null and BGBH<>''  ORDER BY CreatedTime ";//排除人员、设备、试验室
                DataTable      dtIDs = GetDataTable(sql);
                ModuleHelper   mh    = new ModuleHelper();
                DocumentHelper dh    = new DocumentHelper();
                if (dtIDs != null && dtIDs.Rows.Count > 0)
                {
                    String        ksign = "05";//05表示试验数据
                    List <String> files = new List <String>();
                    #region 创建目录
                    String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "Temp/TestDataUpload/试验数据");
                    DeleteDirAllFile(path);
                    if (!Directory.Exists(path))
                    {
                        try
                        {
                            Directory.CreateDirectory(path);
                        }
                        catch (Exception ee)
                        {
                            logger.Error(ee.Message);
                        }
                    }
                    #endregion
                    #region 回收应用程序池
                    //string strRealPath = System.Web.Hosting.HostingEnvironment.MapPath("~");
                    //logger.Error("strRealPath:" + strRealPath);
                    //strRealPath = strRealPath.Substring(0, strRealPath.Length - 1);
                    //int LastIndex = strRealPath.LastIndexOf('\\');
                    //string AppPoolName = strRealPath.Substring(LastIndex + 1, strRealPath.Length - LastIndex - 1);
                    //logger.Error("AppPoolName:" + AppPoolName);
                    //string method = "Recycle";
                    //try
                    //{
                    //    DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                    //    DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");
                    //    findPool.Invoke(method, null);
                    //    appPool.CommitChanges();
                    //    appPool.Close();
                    //    logger.Error("应用程序池名称回收成功");
                    //}
                    //catch (Exception ex)
                    //{
                    //    logger.Error("回收失败:" + ex.Message);
                    //}
                    #endregion
                    StringBuilder   strIDs    = new StringBuilder();
                    UploadSetting[] usArr     = new UploadSetting[dtIDs.Rows.Count];
                    DataRow[]       docRowArr = new DataRow[dtIDs.Rows.Count];
                    int[]           wucArr    = new int[dtIDs.Rows.Count];//WillUploadCount
                    #region 创建资料列表
                    for (int i = 0; i < dtIDs.Rows.Count; i++)
                    {
                        string    strID           = dtIDs.Rows[i]["ID"].ToString();
                        string    strSQL          = "SELECT ID,TestRoomCode,Data,WillUploadCount,ModuleID,BGBH,CreatedTime FROM dbo.sys_document where ID='" + strID + "'";
                        DataTable dt              = GetDataTable(strSQL);
                        String    testRoomCode    = dt.Rows[0]["TestRoomCode"].ToString();
                        string    strModuleID     = dt.Rows[0]["ModuleID"].ToString();
                        string    strBGBH         = dt.Rows[0]["BGBH"].ToString();
                        string    docDateDir      = DateTime.Parse(dt.Rows[0]["CreatedTime"].ToString()).ToString("yyyy/MM/dd");
                        int       WillUploadCount = int.Parse(dt.Rows[0]["WillUploadCount"].ToString());
                        strIDs.AppendFormat("'{0}'", strID);
                        if (i < dt.Rows.Count - 1)
                        {
                            strIDs.Append(",");
                        }
                        Sys_Module    module = mh.GetModuleBaseInfoByID(new Guid(strModuleID));
                        UploadSetting set    = module.UploadSetting;
                        if (set != null)
                        {
                            if (testRoomCodeMap.ContainsKey(testRoomCode))
                            {
                                testRoomCode = testRoomCodeMap[testRoomCode].ToString();
                            }
                            string strSourceFile = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), string.Format("source/{0}/{1}.pdf", docDateDir, strID));
                            string strDestFile   = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), string.Format("Temp/TestDataUpload/试验数据/{0}_{1}.pdf", testRoomCode, strBGBH));
                            if (!File.Exists(strSourceFile))
                            {
                                //logger.Error(string.Format("{1} ID:{0}不存在,生成文件开始", strID, i));
                                #region 生成PDF和图片
                                JZDocument doc      = Newtonsoft.Json.JsonConvert.DeserializeObject <JZDocument>(dt.Rows[0]["Data"].ToString());
                                FpSpread   fpSpread = new FpSpread();
                                //int rIndex = 0;
                                //foreach (JZSheet sheet in doc.Sheets)
                                //{
                                //if (rIndex == module.ReportIndex)
                                //{
                                String    sheetXML  = JZCommonHelper.GZipDecompressString(mh.GetSheetXMLByID(doc.Sheets[module.ReportIndex].ID));// mh.GetSheetXMLByID(sheet.ID);
                                SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), sheetXML, "SheetView") as SheetView;
                                SheetView.Tag = doc.Sheets[module.ReportIndex].ID;
                                SheetView.Cells[0, 0].Value = "";
                                SheetView.Protect           = true;
                                foreach (JZCell dataCell in doc.Sheets[module.ReportIndex].Cells)
                                {
                                    Cell cell = SheetView.Cells[dataCell.Name];

                                    if (cell != null)
                                    {
                                        cell.Value = dataCell.Value;
                                    }
                                }
                                fpSpread.Sheets.Add(SheetView);
                                //}
                                //else
                                //{
                                //    //fpSpread.Sheets.Add(null);
                                //}
                                //sheetXML = null;
                                //SheetView = null;
                                //    rIndex++;
                                //}

                                //自动生成Excel,图片和报告页的pdf
                                SourceHelper sourceHelper = new SourceHelper();
                                sourceHelper.CreateRalationFilesSync(fpSpread, doc.ID, module.ReportIndex, docDateDir);
                                fpSpread.Dispose();
                                doc = null;
                                #endregion
                                logger.Error(string.Format("{1} ID:{0}不存在,生成文件成功", strID, i));
                                //Thread.Sleep(10000);
                            }
                            else
                            {
                                logger.Error(string.Format("{1} ID:{0}存在,不需要生成文件", strID, i));
                            }
                            File.Copy(strSourceFile, strDestFile, true);
                            files.Add(strDestFile);

                            usArr[i]     = set;
                            docRowArr[i] = dt.Rows[0];
                            wucArr[i]    = WillUploadCount;
                            //JZDocument doc = Newtonsoft.Json.JsonConvert.DeserializeObject<JZDocument>(dt.Rows[i]["Data"].ToString());
                            //String fileName = Path.Combine(path, dt.Rows[i]["ID"].ToString() + ".xml");
                            //if (CreatXMLFile(set, fileName, doc, testRoomCode))
                            //{
                            //    files.Add(fileName);
                            //}
                        }
                        else
                        {
                            usArr[i]     = null;
                            docRowArr[i] = dt.Rows[0];
                            wucArr[i]    = WillUploadCount;
                            logger.Error("未找到该模板对应的上传设置,资料ID:" + strID);
                        }
                    }
                    #endregion
                    //logger.Error("reportInfo 0");
                    String fileName = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "Temp/TestDataUpload/试验数据/reportInfo.xml");
                    //生成reportInfo.xml
                    CreatReportInfoXMLFile(usArr, fileName, docRowArr, jsdwCode, wucArr);
                    //logger.Error("reportInfo 1");
                    files.Add(fileName);

                    #region   资料
                    if (files.Count > 0)
                    {
                        String zipFile = Path.Combine(path, "试验报告.zip");
                        if (File.Exists(zipFile))
                        {
                            try
                            {
                                File.Delete(zipFile);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.Message);
                            }
                        }
                        if (JZCommonHelper.CreateZipFile(files, zipFile))
                        {
                            FileStream stream = null;
                            stream = new FileInfo(zipFile).OpenRead();
                            Byte[] buffer = new Byte[stream.Length];
                            stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
                            stream.Close();
                            String result = UploadToServer(uploadAddress, buffer, ksign, jsdwCode);
                            if (result == "1")
                            {
                                logger.Error("试验报告上传成功");
                                if (strIDs.Length > 0)
                                {
                                    dh.UpdateDocumentNeedUpload(strIDs.ToString());
                                }
                            }
                            else
                            {
                                logger.Error("试验报告上传失败,返回值为:" + result);
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    logger.Info("未找到试验数据信息");
                }
            }
            catch (Exception ex)
            {
                logger.Error("UploadTestDataInfo error:" + ex.ToString());
            }
        }