public JZFile GetSpecialFile(Guid moduleID) { String[] files = new String[] { "sys_biz_ModuleCatlog", "sys_biz_SheetCatlog", "sys_dictionary", "sys_formulas", "sys_module", "sys_sheet", "sys_module_sheet", "sys_stadium_config", "sys_module_config" }; List <String> moduleIDs = new List <string>(); moduleIDs.Add(moduleID.ToString()); Boolean flag = true; String moduleIDStr = "'" + String.Join("','", moduleIDs.ToArray()) + "'"; try { String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <String> list = new List <string>(); foreach (String tbName in files) { list.Add(Path.Combine(path, tbName + ".dat")); flag = flag && OutPutFile(tbName, path, moduleIDStr, true); } String zipFile = Path.Combine(path, moduleID + ".zip"); if (File.Exists(zipFile)) { File.Delete(zipFile); } flag = flag && JZCommonHelper.CreateZipFile(list, zipFile); if (flag) { FileStream stream = null; JZFile f = new JZFile(); f.FileName = moduleID + ".zip"; stream = new FileInfo(zipFile).OpenRead(); Byte[] buffer = new Byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); f.FileType = "all"; f.FileData = buffer; stream.Close(); return(f); } } catch (Exception ex) { logger.Error("generate special file error for module " + moduleID + ": " + ex.Message); } return(null); }
/// <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()); } }
/// <summary> ///上传试验室综合情况 /// </summary> public void UploadTestRoomInfo(string strTestRoomCodeMap, String uploadAddress, String jsdwCode) { try { Hashtable testRoomCodeMap = InitTestRoomCodeMap(strTestRoomCodeMap); String moduleID = "E77624E9-5654-4185-9A29-8229AAFDD68B"; //试验室综合情况 String ksign = "01"; //01表示试验室 UploadSetting set = GetUploadSettingByModuleID(moduleID); if (set != null) { String sql = "SELECT TestRoomCode,Data FROM dbo.sys_document WHERE ModuleID='" + moduleID + "' AND Status>0"; DataTable dt = GetDataTable(sql); List <String> files = new List <string>(); if (dt != null && dt.Rows.Count > 0) { 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); } } for (int i = 0; i < dt.Rows.Count; i++) { String testRoomCode = dt.Rows[i]["TestRoomCode"].ToString(); if (testRoomCodeMap.ContainsKey(testRoomCode)) { testRoomCode = testRoomCodeMap[testRoomCode].ToString(); } JZDocument doc = Newtonsoft.Json.JsonConvert.DeserializeObject <JZDocument>(dt.Rows[i]["Data"].ToString()); String fileName = Path.Combine(path, testRoomCode + ".xml"); if (CreatXMLFile(set, fileName, doc, testRoomCode)) { files.Add(fileName); } doc = null; Thread.Sleep(3000); } 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("试验室综合情况数据上传成功"); } else { logger.Error("试验室综合情况数据上传失败,返回值为:" + result); } } } } else { logger.Error("未找到试验室综合情况信息"); } } else { logger.Error("未找到该模板对应的上传设置"); } } catch (Exception ex) { logger.Error("UploadTestRoomInfo error:" + ex.ToString()); } }
/// <summary> /// 上传人员信息 /// </summary> public void UploadPersonInfo(string strTestRoomCodeMap, String uploadAddress, String jsdwCode) { try { Hashtable testRoomCodeMap = InitTestRoomCodeMap(strTestRoomCodeMap); String moduleID = "08899BA2-CC88-403E-9182-3EF73F5FB0CE"; //试验人员 String ksign = "02"; //02表示试验人员 UploadSetting set = GetUploadSettingByModuleID(moduleID); if (set != null) { String sql = "SELECT ID,TestRoomCode,Data FROM dbo.sys_document WHERE ModuleID='" + moduleID + "' AND Status>0"; DataTable dt = GetDataTable(sql); List <String> files = new List <String>(); if (dt != null && dt.Rows.Count > 0) { 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); } } for (int i = 0; i < dt.Rows.Count; i++) { String testRoomCode = dt.Rows[i]["TestRoomCode"].ToString(); DataRow[] drArr = dt.Select(string.Format("TestRoomCode='{0}'", testRoomCode)); if (testRoomCodeMap.ContainsKey(testRoomCode)) { testRoomCode = testRoomCodeMap[testRoomCode].ToString(); } String fileName = Path.Combine(path, testRoomCode + ".xml"); if (CreatMultiXMLFile(set, fileName, drArr, testRoomCode)) { files.Add(fileName); ProcessPersonPhoto(drArr, files, path); foreach (DataRow row in drArr) { dt.Rows.Remove(row); } } drArr = null; Thread.Sleep(3000); } 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("试验室人员上传成功"); } else { logger.Error("试验室人员上传失败,返回值为:" + result); } } } } else { logger.Error("未找到试验人员信息"); } } else { logger.Error("未找到该模板对应的上传设置"); } } catch (Exception ex) { logger.Error("UploadPersonInfo error:" + ex.ToString()); } }
public void GenerateDBUpdate(DataTable dt) { if (dt != null && dt.Rows.Count > 0) { List <String> newTB = new List <string>(); newTB.Add("dbo.sys_formulas"); newTB.Add("dbo.sys_line_formulas"); newTB.Add("dbo.sys_module"); newTB.Add("dbo.sys_sheet"); newTB.Add("dbo.sys_stadium_config"); Boolean hasNewUpdate = false; for (int i = 0; i < dt.Rows.Count; i++) { String tbName = dt.Rows[i]["TableName"].ToString().ToLower(); String sql = String.Format("SELECT COUNT(1) FROM {0} WHERE Scts_1>'{1}' ", tbName, Convert.ToDateTime(dt.Rows[i]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); if (newTB.Contains(tbName)) { sql = String.Format("SELECT COUNT(1) FROM {0} WHERE LastEditedTime>'{1}' ", tbName, Convert.ToDateTime(dt.Rows[i]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); } sql = String.Format("SELECT COUNT(1) FROM sys_sheet WHERE LastEditedTime>'{0}' ", Convert.ToDateTime(dt.Rows[i]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); Object obj = ExcuteScalar(sql); if (obj != null && obj != DBNull.Value) { hasNewUpdate = Convert.ToInt32(obj) > 0; if (hasNewUpdate) { break; } } } if (hasNewUpdate) { String userName = "******"; String pw = "wdxlzyn@#830"; String server = "ISSDCPLCDMK"; String valid = " -c -S " + server + " -U " + userName + " -P " + pw; String subFolder = GetSubFolder("3"); String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update\\" + subFolder); String file = Path.Combine(path, "sys_sheet.dat"); String bcp = "bcp \"SELECT * FROM " + Connection.Database + ".dbo.sys_sheet WHERE LastEditedTime > '" + Convert.ToDateTime(dt.Rows[0]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff") + "' \" queryout " + file + valid; JZCommonHelper.ExeCommand(bcp); String fileName = Yqun.Common.ContextCache.ApplicationContext.Current.UserName + "_" + Yqun.Common.ContextCache.ApplicationContext.Current.Identification.MacAddress + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + ".zip"; String zipFile = Path.Combine(path, fileName); if (File.Exists(zipFile)) { File.Delete(zipFile); } List <String> list = new List <string>(); list.Add(file); Boolean flag = JZCommonHelper.CreateZipFile(list, zipFile); SaveUpdateInfo(Guid.NewGuid().ToString(), fileName, "3", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); } } }
/// <summary> /// 更新一条线的所有模板、表单、公式等信息 /// </summary> /// <param name="lineID"></param> /// <returns></returns> public Boolean UpdateLine(Guid lineID, List <String> moduleIDs, Boolean isModule, Boolean isRelationSheet) { List <String> files = new List <String>(); if (isModule) { files.Add("sys_dictionary"); files.Add("sys_formulas"); files.Add("sys_module"); files.Add("sys_stadium_config"); files.Add("sys_module_config"); if (isRelationSheet) { files.Add("sys_module_sheet"); } } else { files.Add("sys_sheet"); } Sys_Line line = GetLineByID(lineID); Boolean flag = true; String moduleIDStr = "'" + String.Join("','", moduleIDs.ToArray()) + "'"; if (line != null) { try { String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update/" + line.LineName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <String> list = new List <string>(); foreach (String tbName in files) { list.Add(Path.Combine(path, tbName + ".dat")); flag = flag && OutPutFile(tbName, path, moduleIDStr, isModule); } String zipFile = Path.Combine(path, line.LineName + ".zip"); if (File.Exists(zipFile)) { File.Delete(zipFile); } flag = flag && JZCommonHelper.CreateZipFile(list, zipFile); if (flag) { FileStream stream = null; JZFile f = new JZFile(); f.FileName = line.LineName + ".zip"; stream = new FileInfo(zipFile).OpenRead(); Byte[] buffer = new Byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); f.FileType = "all"; f.FileData = buffer; stream.Close(); String lineAddress = "net.tcp://" + line.LineIP + ":" + line.LinePort + "/TransferService.svc"; object obj = CallRemoteServerMethod(lineAddress, "Yqun.BO.BusinessManager.dll", "RunUpdate", new Object[] { f, line.LineIP, line.UserName, line.PassWord, isModule, isRelationSheet }); flag = Convert.ToBoolean(obj); } } catch (Exception ex) { logger.Error("generate updated file error for line " + line.LineName + ": " + ex.Message); flag = false; } } else { flag = false; } return(flag); }