/// <summary> /// 客户端下载文件生成处理 /// </summary> /// <param name="yljgbm"></param> /// <param name="czList"></param> /// <returns></returns> public string downLoadFileCreate(string rndPrefix, string yljgbm, string czList, string dataType) { //lock (locker) //{ string functionName = "downLoadInfoByParm"; try { //2017-08-24 mq添加,用于判断时间间隔 //if (CheckDownloadDataExpire.CanDirectDownload(GetDownloadDirPath(), dataType, GetInterval(), yljgbm)) //{ // return CheckDownloadDataExpire.GetDownloadFilePath(dataType, yljgbm); //} DoServiceNew doservicenew = new DoServiceNew(); string resultStr = doservicenew.DoDownLoadInfo(rndPrefix, yljgbm, czList, dataType); ////将生成的文件对应的保存到静态变量中 //CheckDownloadDataExpire.AddDownloadInfo(new DownloadInfo(resultStr, dataType, yljgbm)); //日志处理 TxtLogger.Debug(string.Format("{0}:[{1}{2}]:[{3}]", functionName, yljgbm, "数据下载结束", resultStr)); return(resultStr); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]", functionName, yljgbm, "数据下载错误", ex.Message)); throw new Exception(string.Format("{1}:处理异常:{0}", ex.Message, functionName)); } //} }
public bool Append(string fileName, byte[] buffer) { bool isAppend = true; try { //上传的文件的保存路径 string filePath = System.Configuration.ConfigurationManager.AppSettings["ExcelUpFile"]; string filePathAll = string.Format("{0}{1}\\{2}", filePath, "upLoade_execute", fileName); //保存上传的内容 FileStream fs = new FileStream(filePathAll, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Seek(0, SeekOrigin.End); fs.Write(buffer, 0, buffer.Length); fs.Close(); TxtLogger.Debug(string.Format("{0}:[{1} {2}]", "Append", fileName, "数据上传")); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传正确", 1)); } catch (Exception ex) { isAppend = false; logger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "Append", fileName, "数据上传错误", ex.Message)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传错误," + ex.Message, 0)); } return(isAppend); }
public static bool DoFileIsExcute(string clientUser) { try { lock (upLocker) { //获取数据处理的状态 DBOracle dboracle = new DBOracle(); //CLCXZT 处理程序状态 1停止 2运行中 DataTable dt = dboracle.ExcuteDataTable_oracle("select * from T_JK_CXZT where CLCXZT='2' "); if (dt != null && dt.Rows.Count > 0) { TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "DoFileIsExcute", clientUser, "程序已经启动")); //程序正在执行中 return(true); } else { //处理程序没有执行,启动处理程序 string sql_Insert = string.Format("insert into T_JK_CXZT(CLCXBM,CLCXSM,CLCXZT,CZY,KSSJ)values('{0}','{1}','{2}','{3}','{4}') ", clientUser, clientUser, "2", clientUser, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")); //从数据库中获取数据状态 //DBOracle dboracle = new DBOracle(); int insertResult = dboracle.ExecuteNonQuery_oracle(sql_Insert); TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "DoFileIsExcute", clientUser, "程序正常启动")); return(false); } } } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]", "DoFileIsExcute", clientUser, "设定程序启动状态错误", ex.Message)); throw new Exception(string.Format("DoFileIsExcute:设定程序启动状态错误:{0}", ex.Message)); } }
/// <summary> /// 数据写到数据库中 /// </summary> /// <param name="dtPara"></param> private static void dataToDbFromDt(DataTable dtPara, string GuidStr) { TxtLogger.Error(string.Format("{0}:[{1}]", "dataToDbFromDt", GuidStr)); try { if (dtPara != null && dtPara.Rows.Count > 0) { //每次处理的数据条数 int pagecount = 2000; //将数据按照处理条数分次处理 for (int i = 0; i <= dtPara.Rows.Count / pagecount; i++) { DataTable dt = dtPara.Clone(); for (int j = i * pagecount; (j < (i + 1) * pagecount && j < dtPara.Rows.Count); j++) { dt.ImportRow(dtPara.Rows[j]); } DataColumn dtColumn = new DataColumn(); dtColumn.ColumnName = "DeleteGuid"; dtColumn.DefaultValue = GuidStr; dt.Columns.Add(dtColumn); TxtLogger.Debug("TableName:" + dtPara.TableName.Split(new char[] { '-' })[0]); //数据库处理 MultiInsertData(dt, dtPara.TableName.Split(new char[] { '-' })[0]); } } } catch (Exception ex) { throw ex; } }
public void DoFile(string clientUser, string GuidStr, string yljgbm) { TxtLogger.Debug(string.Format("{0}:[{1}]:[{2}]", "DoFile", clientUser, "文件处理开始")); //取得本地的保存文件地址 string filePathAll = Common.GetUploadeFilePath(); string filePathAllTo = Common.GetExcuteFilePath(); try { //文件处理 if (FileHelper.CopyDirectory(filePathAll, filePathAllTo)) { //将文件内容保存到数据库中 DoFileToDb(filePathAllTo, GuidStr, yljgbm, clientUser); //处理完当前数据后再次扫描是否存在需要处理的文件 DoFile(clientUser, GuidStr, yljgbm); } TxtLogger.Debug(string.Format("{0}:[{1}]:[{2}]", "DoFile", clientUser, "文件处理结束")); DBLogger.Insert(new LoggerInfo(clientUser, "DoFile 文件处理结束", 1)); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}]:[{2}]:[{3}]", "DoFile", clientUser, "文件处理异常", ex.Message)); DBLogger.Insert(new LoggerInfo(clientUser, string.Format("DoFile文件处理异常,{0}", ex.Message), 0)); throw ex; } finally { //将状态改变回来 Checker.ChangeExcuteStatus(); } return; }
public string DoFileThread(string clientUser, string GuidStr, string yljgbm) { try { //文件处理是否已经启动 true:已经启动 false:未启动 if (Checker.DoFileIsExcute(clientUser) == false) { startThread(clientUser, GuidStr, yljgbm); } TxtLogger.Debug(string.Format("{0}:[{1} {2}]]", "DoFileThread", clientUser, "上传数据处理程序启动")); DBLogger.Insert(new LoggerInfo(clientUser, "DoFileThread上传数据处理程序启动", 1)); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "DoFileThread", clientUser, "上传数据处理程序启动异常", ex.Message)); DBLogger.Insert(new LoggerInfo(clientUser, string.Format("DoFileThread上传数据处理程序启动异常,{0}", ex.Message), 0)); return(string.Format("0-{0}-{1}", "DoFileThread", ex.Message)); } return(string.Format("1-{0}-{1}", "DoFileThread", "正常结束")); }
public string GetExecuteSql(string tableName) { DBOracle dboracle = new DBOracle(); string str_dt_title = string.Format("select * from {0} where 1=2 ", tableName); TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "生成档案数据表结构", "sql文", str_dt_title)); DataTable dt_title = dboracle.ExcuteDataTable_oracle(str_dt_title); string strWhere = ""; if (dt_title.Columns.Contains("P_RGID") && !string.IsNullOrEmpty(_model.CzList)) { strWhere = string.Format(" and P_RGID in ('{0}')", _model.CzList.Replace(",", "','")); } else if (dt_title.Columns.Contains("PRGID") && !string.IsNullOrEmpty(_model.CzList)) { strWhere = string.Format(" and PRGID in ('{0}')", _model.CzList.Replace(",", "','")); } if (dt_title.Columns.Contains("YLJGBM") && !string.IsNullOrEmpty(_model.Yljgbm)) { strWhere = strWhere + string.Format(" and yljgbm ='{0}'", _model.Yljgbm); } else if (dt_title.Columns.Contains("YYBM") && !string.IsNullOrEmpty(_model.Yljgbm)) { strWhere = strWhere + string.Format(" and yybm ='{0}'", _model.Yljgbm); } //按机构下载时判断结束 string str_dt_data = string.Format("select * from {0} where 1=1 {1} ", tableName, strWhere); if (tableName.ToLower().Equals("t_jk_tjry_txm")) { strWhere = string.Format(" and p_rgid in ('{0}')", _model.CzList.Replace(",", "','")); str_dt_data = "select * from t_jk_tjry_txm join t_da_jkda_rkxzl on t_jk_tjry_txm.rkxzlid=t_da_jkda_rkxzl.id and t_jk_tjry_txm.nd='{0}' where 1=1 {1}"; str_dt_data = string.Format(str_dt_data, DateTime.Now.Year, strWhere); } TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "生成档案数据", "sql文", str_dt_data)); return(str_dt_data); }
public bool Verify(string fileName, string md5) { bool isVerify = true; try { //文件保存的路径 string filePathAll = Upload.Common.GetFilePathAll(fileName); string filePathAllTo = Upload.Common.GetFilePathAllTo(fileName); if (fileName.EndsWith("xls") == false) { //先判断是否是zip签名图片文件,如果是,单独处理 //先将zip移动到zip_file目录中,再解压缩,进行复制操作 if (fileName.EndsWith("zip")) { return(ZipFileOperation(fileName, md5, filePathAll)); } filePathAllTo = Upload.Common.GetXdtImgFilePathToAll(fileName); } string uploadMessage = "上传数据验证结束"; //判断文件是否正确 if (md5 != Common.Md5(filePathAll)) { isVerify = false; uploadMessage = "上传数据验证异常"; filePathAllTo = Upload.Common.GetErrorFilePath(fileName); } Upload.FileHelper.CopyDirectoryOneFile(filePathAll, filePathAllTo); TxtLogger.Debug(string.Format("{0}:[{1} {2}]", "Verify", fileName, uploadMessage)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "上传数据验证结束", 1)); } catch (Exception ex) { isVerify = false; TxtLogger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "Verify", fileName, "上传数据验证异常", ex.Message)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "上传数据验证异常," + ex.Message, 0)); } return(isVerify); }
public bool CreateFile(string fileName) { bool isCreate = true; try { //上传的文件的保存路径 string filePath = System.Configuration.ConfigurationManager.AppSettings["ExcelUpFile"]; string filePathAll = string.Format("{0}{1}\\{2}", filePath, "upLoade_execute", fileName); //首先设置上传服务器文件的路径 然后发布web服务 发布的时候要自己建一个自己知道的文件夹 "C:\NMGIS_Video\" "C:\NMGIS_Video\" FileStream fs = new FileStream(filePathAll, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Close(); TxtLogger.Debug(string.Format("{0}:[{1} {2}]", "CreateFile", fileName, "数据上传的文件创建完成")); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传的文件创建完成", 1)); } catch (Exception ex) { isCreate = false; TxtLogger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "CreateFile", fileName, "数据上传错误", ex.Message)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传错误," + ex.Message, 0)); } return(isCreate); }
/// <summary> /// 复制文件夹中的所有文件到指定文件夹 /// </summary> /// <param name="DirectoryPath">源文件夹路径</param> /// <param name="DirAddress">保存路径</param> public static void CopyDirectoryOneFile(string DirectoryPath, string DirAddress)//复制文件夹, { //保存文件的路径 string filePathTo = Path.GetDirectoryName(DirAddress); //保存文件的文件名称 string fileName = Path.GetFileName(DirAddress); try { //文件目录的处理 if (!Directory.Exists(filePathTo)) { Directory.CreateDirectory(filePathTo); } //获取要复制的文件 if (File.Exists(DirectoryPath)) { //取得要copy的文件 if (File.Exists(DirAddress)) { File.Delete(DirAddress); } //将临时文件夹的文件移到应用程序所在的目录下 File.Move(DirectoryPath, DirAddress); } TxtLogger.Debug(string.Format("{0}:[{1}{2}]]", "copyDirectoryOneFile", DirAddress, "数据复制完成")); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]", "DoFileIsExcute", DirectoryPath, "设定程序启动状态错误", ex.Message)); throw new Exception("copyDirectoryOneFile处理错误:" + fileName + ":" + ex.Message); } }