|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using Utils.Datas;
|
|
|
using WeighBusiness.BO;
|
|
|
using WeighBusiness.Utils.SqlUtils;
|
|
|
|
|
|
namespace WeighBusiness.Utils
|
|
|
{
|
|
|
public class SynchronousLogQueryUtil
|
|
|
{
|
|
|
#region 用于查询时显示同步信息。如果改回不显示同步信息,还需要修改相应的调用这些方法的方法。
|
|
|
private const string selectHeadAndSynchronousLogSql =
|
|
|
@"select {0} o.ID,o.IsChecked,o.CreateDateTime,o.CarNumber,o.Number,o.HeadWeight,o.Remote_Weigh_ID,s.SynchronousMessage
|
|
|
from {1} o left join {2} s on o.ID = s.terminalbillid
|
|
|
{3}
|
|
|
order by o.id desc";
|
|
|
///// <summary>
|
|
|
///// 查询称重表头数据、对应的同步数据。
|
|
|
///// </summary>
|
|
|
///// <param name="isTop">是否前10条</param>
|
|
|
///// <param name="isSynchronous">是否同步。为空:所有数据</param>
|
|
|
///// <param name="isChecked">是否已审核。为空:所有数据</param>
|
|
|
//public static List<System.Tuple<Weigh, SynchronousLog>> GetAllLocalWeighHeads_Synchronous(bool isTop, bool? isSynchronous, bool? isChecked)
|
|
|
//{
|
|
|
// var topString = isTop ? "first (10)" : string.Empty;
|
|
|
// var whereString = string.Empty;
|
|
|
// if (isSynchronous.HasValue) {
|
|
|
// if (isSynchronous.Value)
|
|
|
// whereString = "where o.Remote_Weigh_ID > 0";
|
|
|
// else
|
|
|
// whereString = "where (o.Remote_Weigh_ID = 0 or o.Remote_Weigh_ID is null)";
|
|
|
// }
|
|
|
// if (isChecked.HasValue) {
|
|
|
// if (whereString.IsNullOrEmpty())
|
|
|
// whereString = "where o.IsChecked = '" + isChecked + "'";
|
|
|
// else
|
|
|
// whereString += " and o.IsChecked = '" + isChecked + "'";
|
|
|
// }
|
|
|
// return GetAllLocalWeighHeads_Synchronous(topString, whereString);
|
|
|
//}
|
|
|
|
|
|
//private static List<Tuple<Weigh, SynchronousLog>> GetAllLocalWeighHeads_Synchronous(string topString, string whereString)
|
|
|
//{
|
|
|
// var billInfos = new List<Tuple<Weigh, SynchronousLog>>();
|
|
|
// var querySql = selectHeadAndSynchronousLogSql.FormatWith(topString, TableNames.称重表, TableNames.同步日志, whereString);
|
|
|
// var table = SqlHelperEx.DoQuery(querySql);
|
|
|
// foreach (DataRow row in table.Rows) {
|
|
|
// var newWeigh = new Weigh() {
|
|
|
// ID = DataTypeUtil.GetLongNum(row["ID"]),
|
|
|
// IsChecked = DataTypeUtil.GetBoolData(table.Rows[0]["IsChecked"]),
|
|
|
// CreateDateTime = DataTypeUtil.GetDateTimeNullData(row["CreateDateTime"]),
|
|
|
// CarNumber = DataTypeUtil.GetIntNullNum(row["CarNumber"]),
|
|
|
// Number = DataTypeUtil.GetIntNullNum(row["Number"]),
|
|
|
// HeadWeight = DataTypeUtil.GetDecimalNullNum(row["HeadWeight"]),
|
|
|
// Remote_Weigh_ID = DataTypeUtil.GetLongNullNum(row["Remote_Weigh_ID"]),
|
|
|
// };
|
|
|
// var newlog = new SynchronousLog() {
|
|
|
// //RemoteBillID = DataTypeUtil.GetLongNum(row["RemoteBillID"]),
|
|
|
// SynchronousMessage = row["SynchronousMessage"].ToString(),
|
|
|
// };
|
|
|
// billInfos.Add(new Tuple<Weigh, SynchronousLog>(newWeigh, newlog));
|
|
|
// }
|
|
|
|
|
|
// return billInfos;
|
|
|
//}
|
|
|
#endregion
|
|
|
|
|
|
public static SynchronousLog GetLocalSynchronousLog(long id)
|
|
|
{
|
|
|
string querySql = @"select ID,BillTypeID,TerminalBillID,RemoteBillID,SynchronousMessage from {0} where ID = ".FormatWith(TableNames.同步日志) + id;
|
|
|
var table = SqlHelperEx.DoQuery(querySql);
|
|
|
if (table.Rows.Count == 0)
|
|
|
return null;
|
|
|
var result = new SynchronousLog() {
|
|
|
ID = id,
|
|
|
BillTypeID = DataTypeUtil.GetShortNum(table.Rows[0]["BillTypeID"]),
|
|
|
TerminalBillID = DataTypeUtil.GetLongNum(table.Rows[0]["TerminalBillID"]),
|
|
|
RemoteBillID = DataTypeUtil.GetLongNum(table.Rows[0]["RemoteBillID"]),
|
|
|
SynchronousMessage = DataTypeUtil.ToStringEmptyIfNull(table.Rows[0]["SynchronousMessage"]),//为null时,赋值为string.Empty
|
|
|
};
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static SynchronousLog GetLocalSynchronousLogFromBillID(short billTypeID, long terminalBillID)
|
|
|
{
|
|
|
string querySql = @"select first 1 ID,BillTypeID,TerminalBillID,RemoteBillID,SynchronousMessage from {0} where BillTypeID = ".FormatWith(TableNames.同步日志) + billTypeID + " and TerminalBillID = " + terminalBillID + " order by ID desc";
|
|
|
var table = SqlHelperEx.DoQuery(querySql);
|
|
|
if (table.Rows.Count == 0)
|
|
|
return null;
|
|
|
var result = new SynchronousLog() {
|
|
|
ID = DataTypeUtil.GetLongNum(table.Rows[0]["ID"]),
|
|
|
BillTypeID = billTypeID,
|
|
|
TerminalBillID = terminalBillID,
|
|
|
RemoteBillID = DataTypeUtil.GetLongNum(table.Rows[0]["RemoteBillID"]),
|
|
|
SynchronousMessage = DataTypeUtil.ToStringEmptyIfNull(table.Rows[0]["SynchronousMessage"]),//为null时,赋值为string.Empty
|
|
|
};
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static long[] GetAllNotSynchronousBillIDs(short billTypeID)
|
|
|
{
|
|
|
string querySql = @"select TerminalBillID from {0} where BillTypeID = ".FormatWith(TableNames.同步日志) + billTypeID + " and RemoteBillID < 1 order by ID";
|
|
|
var table = SqlHelperEx.DoQuery(querySql);
|
|
|
if (table.Rows.Count == 0)
|
|
|
return null;
|
|
|
List<long> result = new List<long>();
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
result.Add(DataTypeUtil.GetLongNum(row["TerminalBillID"]));
|
|
|
return result.ToArray();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|