You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using DSWeb.Common.DB;
|
|
using log4net;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Messaging;
|
|
using System.Web;
|
|
|
|
namespace DSWeb.Common.Helper
|
|
{
|
|
public class ReturnDataHelper
|
|
{
|
|
private static ILog logger = LogManager.GetLogger("ReturnDataHelper");
|
|
|
|
public static bool ReturnData(string invId)
|
|
{
|
|
#region 回写发票数据
|
|
try
|
|
{
|
|
InvoiceDbContext invDB = new InvoiceDbContext();
|
|
CommonDataContext commonData = new CommonDataContext();
|
|
var inv = invDB.Invoices.AsNoTracking().FirstOrDefault(i => i.GID == invId);
|
|
var comp = invDB.CompanyNew.AsNoTracking().FirstOrDefault(c => c.CompId == inv.CompId);
|
|
var eInvSysCfg = commonData.SysEnumValues.FirstOrDefault(em => em.EnumTypeID == 21000 && em.EnumValueID == comp.InvoiceSystem);
|
|
string commandStr = eInvSysCfg != null ? eInvSysCfg.EnumValueName_2 : string.Empty;
|
|
|
|
var paraMqName = commonData.ParamSets.AsNoTracking().FirstOrDefault(p => p.PARAMNAME == "InvoiceSendMqName");
|
|
|
|
if (!string.IsNullOrEmpty(commandStr))
|
|
{
|
|
string recPath = $".\\Private$\\{paraMqName.PARAMVALUE}";
|
|
MessageQueue mq = null;
|
|
if (!MessageQueue.Exists(recPath))
|
|
{
|
|
mq = MessageQueue.Create(recPath);
|
|
mq.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
|
|
}
|
|
else
|
|
{
|
|
mq = new MessageQueue(recPath);
|
|
}
|
|
|
|
var obj = new
|
|
{
|
|
msgId = Guid.NewGuid().ToString(),
|
|
compId = inv.CompId,
|
|
userId = inv.UserId,
|
|
type = commandStr,
|
|
data = inv.GID
|
|
};
|
|
System.Messaging.Message mess = new System.Messaging.Message();
|
|
mess.Body = JsonConvert.SerializeObject(obj);
|
|
mess.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
|
|
mq.Send(mess);
|
|
mq.Close();
|
|
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error($"回写发票号出错,发票:{invId}");
|
|
logger.Error(ex.Message);
|
|
logger.Error(ex.StackTrace);
|
|
}
|
|
|
|
return false;
|
|
#endregion
|
|
}
|
|
}
|
|
} |