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
{
///
/// 插入车辆到数据库中。
/// 全部成功,返回true;只要有一个失败,则返回false
///
public static bool InsertCar(IList allNeedInsert, out Dictionary faileds)
{
faileds = new Dictionary();
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;
}
///
/// 插入会计单位到数据库中。
/// 全部成功,返回true;只要有一个失败,则返回false
///
public static bool InsertAccountingUnit(IList allNeedInsert, out Dictionary faileds)
{
faileds = new Dictionary();
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;
}
}
}