using log4net; using Newtonsoft.Json; using Quartz; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using JobAutoCreateFee.Model; using System.IO; namespace JobCreateFee { public class JobSiEdiReply : IJob { private ILog log = LogManager.GetLogger(typeof(JobSiEdiReply)); public void Execute(IJobExecutionContext context) { log.Debug($"Execute开始"); try { string connStr = context.JobDetail.JobDataMap.GetString("ConnectString"); string BcPath = context.JobDetail.JobDataMap.GetString("SiPath"); string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SiTmp"); if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } string[] files = Directory.GetFiles(BcPath); if (files.Length > 0) { foreach (string file in files) { FileInfo fileInfo = new FileInfo(file); string pathtxt = File.ReadAllText(file); pathtxt= pathtxt.Replace("\n", ""); var opList = pathtxt.Split('\''); var MBLNO = ""; foreach (var opstr in opList) { if (opstr.Length >= 3) { var head = opstr.Substring(0, 3); if (head == "UCM") { var headlist = opstr.Split('+'); var fieldcount = 0; foreach (var str in headlist) { if (fieldcount == 1) { MBLNO = str; } fieldcount = fieldcount + 1; } } } } if (!string.IsNullOrEmpty(MBLNO)) { log.Debug($"业务编号:" + MBLNO ); using (SqlConnection dbcon = new SqlConnection(connStr)) { dbcon.Open(); string sql = " update t_op_seae set 确认状态='已接收' where 业务编号='" + MBLNO+"'"; SqlCommand cmd = new SqlCommand(sql, dbcon); cmd.ExecuteNonQuery(); dbcon.Close(); } File.Copy(file, Path.Combine(tempPath, fileInfo.Name)); File.Delete(file); } } } } catch (Exception ex) { log.Error(ex.Message); log.Error(ex.StackTrace); } } } }