You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

64 lines
2.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Update.WeighTerminalService;
using WeighBusiness.Utils;
using WeighBusiness.Utils.SqlUtils;
namespace Update.Utils
{
public class DatabaseUtil
{
/// <summary>
/// 插入车辆到数据库中。
/// 全部成功,返回true;只要有一个失败,则返回false
/// </summary>
public static bool InsertCar(IList<ClientCar> allNeedInsert, out Dictionary<long, string> faileds)
{
faileds = new Dictionary<long, string>();
bool successResult = true;
using (var she = new SqlHelperEx()) {
foreach (var needInsertItem in allNeedInsert) {
string insertSql = InsertUtil.GetInsertSql(TableNames., new string[] { "Car_ID", "Car_Name" }, new string[] { needInsertItem.Car_ID.ToString(), needInsertItem.Car_Name });
if (string.IsNullOrEmpty(insertSql))
continue;
bool success;
she.ExecuteNonQuery(insertSql, out success);
if (!success) {
faileds.Add(needInsertItem.Car_ID, needInsertItem.Car_Name);
successResult = false;
continue;
}
}
}
return successResult;
}
/// <summary>
/// 插入会计单位到数据库中。
/// 全部成功,返回true;只要有一个失败,则返回false
/// </summary>
public static bool InsertAccountingUnit(IList<ClientAccountingUnit> allNeedInsert, out Dictionary<long, string> faileds)
{
faileds = new Dictionary<long, string>();
bool successResult = true;
using (var she = new SqlHelperEx()) {
foreach (var needInsertItem in allNeedInsert) {
string insertSql = InsertUtil.GetInsertSql(TableNames., new string[] { "AccountingUnit_ID", "AccountingUnit_Name" }, new string[] { needInsertItem.AccountingUnit_ID.ToString(), needInsertItem.AccountingUnit_Name });
if (string.IsNullOrEmpty(insertSql))
continue;
bool success;
she.ExecuteNonQuery(insertSql, out success);
if (!success) {
faileds.Add(needInsertItem.AccountingUnit_ID, needInsertItem.AccountingUnit_Name);
successResult = false;
continue;
}
}
}
return successResult;
}
}
}