CNCEC_SUBQHSE_WUHUAN/SGGL/BLL/Common/DataCleanupMergeHelper.cs

72 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
namespace BLL
{
/// <summary>
/// 数据合并清理
/// </summary>
public class DataCleanupMergeHelper
{
/// <summary>
/// 数据合并清理
/// </summary>
/// <param name="exTable">排除操作数据表</param>
/// <param name="columType">替换字段(模糊匹配)</param>
/// <param name="mergeDataIds">需要替换的数据值</param>
/// <param name="dataId">新的字段数据值</param>
/// <returns></returns>
public static bool DataCleanupMerge(string exTable, string columType, List<string> mergeDataIds, string dataId, ref string msg)
{
bool result = false;
try
{
Model.SGGLDB db = Funs.DB;
var clist = db.DataIdMove.Where(x => x.ColumType == columType && x.NewIds == dataId).ToList();
db.DataIdMove.DeleteAllOnSubmit(clist);
db.SubmitChanges();
List<Model.DataIdMove> list = new List<Model.DataIdMove>();
foreach (var mergeId in mergeDataIds)
{
list.Add(new Model.DataIdMove { OldId = mergeId.Trim(), NewIds = dataId.Trim(), ColumType = columType });
}
db.DataIdMove.InsertAllOnSubmit(list);
db.SubmitChanges();
//SP_DataIdMove[排除操作数据表,替换字段(模糊匹配),字段数据值]
string strSql = $"exec SP_DataIdMove '{exTable}','{columType}','{dataId}'";
result = BLL.SQLHelper.ExecuteSql(strSql);
//SqlParameter[] parameters = {
// new SqlParameter("@exTable", exTable),
// new SqlParameter("@colums", columType),
// new SqlParameter("@trueId", dataId),
// new SqlParameter("@returnVal", SqlDbType.Int)
//};
//BLL.SQLHelper.ExecuteNonQueryStoredProcedure("SP_DataIdMove", parameters);
//int succ = BLL.SQLHelper.ExecuteProcedure("SP_DataIdMove", parameters);
//Thread.Sleep(30000); // 等待30秒30000毫秒等于30秒
if (result)
{
db.DataIdMove.DeleteAllOnSubmit(list);
db.SubmitChanges();
msg = "数据合并成功!";
}
else
{
msg = "数据合并失败,请稍后再试!";
}
}
catch (Exception ex)
{
msg = ex.Message;
result = false;
}
return result;
}
}
}