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.

148 lines
4.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FireBirdUtil.SqlUtils;
using Utils.Datas;
using WeighBusiness.BO;
using WeighBusiness.Utils;
using WeighBusiness.Utils.SqlUtils;
namespace WeighBusiness.BL
{
public static class ProduceIntakeBL
{
public static bool Insert(ProduceIntake intake,SqlHelperEx she)
{
//if (weigh.ID > 0)
// return Update(weigh);
string insertHeadSql = InsertUtil.GetInsertSql(TableNames.,
new string[] { "AccountingUnit_ID", "Department_ID", "Employee_ID", "CreateTime", "BatchNumber_ID", "ProductLink", "Routing_ID", "ProductShift_ID", "Domain_ID", "IsSend", "OutGoods_ID", "OutGoodsNum", "InputType" },
new string[] { intake.AccountingUnit_ID.ToString(), intake.Department_ID.ToString(), intake.Employee_ID.ToString(), intake.CreateTime.ToString(), intake.BatchNumber_ID.ToString(), intake.ProductLink, intake.Routing_ID.ToString(), intake.ProductShift_ID.ToString(), intake.Domain_ID.ToString(), intake.IsSend ? "1" : "0", DataTypeUtil.ToStringNullIfNull(intake.OutGoods_ID), DataTypeUtil.ToStringNullIfNull(intake.OutGoodsNum), intake.InputType.ToString() });
if (string.IsNullOrEmpty(insertHeadSql))
throw new ApplicationException("表头数据不允许为空");
bool success;
string errorMsg;
she.ExecuteNonQuery(insertHeadSql, out success, out errorMsg);
if (!success) {
she.Rollback();
throw new ApplicationException(errorMsg);
}
var intakeID = she.GetCurrentID(TableNames.);
intake.ID = intakeID;
List<string> insertDetailSqls = InsertDetailsSqls(intake.Details, intakeID);
if (insertDetailSqls.Count == 0) {
return true;
}
foreach (var detailSql in insertDetailSqls) {
she.ExecuteNonQuery(detailSql, out success,out errorMsg);
if (!success) {
she.Rollback();
throw new ApplicationException(errorMsg);
}
}
return success;
}
private static List<string> InsertDetailsSqls(List<ProduceIntake_Detail> details, long produceIntake_ID)
{
List<string> insertDetailSqls = new List<string>();
if (details == null || details.Count == 0)
return insertDetailSqls;
string[] columns = new string[] { "ProduceIntake_ID", "Goods_ID", "Number", "Times", "ProductDate" };
foreach (var d in details) {
insertDetailSqls.Add(InsertUtil.GetInsertSql(TableNames., columns, GetValue(d, produceIntake_ID)));
}
return insertDetailSqls;
}
private static string[] GetValue(ProduceIntake_Detail detail, long produceIntake_ID)
{
return new string[]{
produceIntake_ID.ToString(),
DataTypeUtil.ToStringNullIfNull(detail.Goods_ID),
DataTypeUtil.ToStringNullIfNull(detail.Number),
DataTypeUtil.ToStringNullIfNull(detail.Times),
DataTypeUtil.ToStringNullIfNull(detail.ProductDate)
};
}
public static ProduceIntake Load(long id)
{
ProduceIntake result = LocalQueryUtil.GetLocalProduceIntakeHead(id);
if (result == null)
return result;
var details = LocalQueryUtil.GetLocalProduceIntakeDetails(id);
if (details == null || details.Count == 0)
return result;
foreach (var d in details) {
result.Details.Add(d);
}
return result;
}
public static void UpdateIsSendByID(long id)
{
string updateSql = string.Format("update " + TableNames. + " set IsSend = 1 where ID ={0}", id);
bool success = true;
using (var she = new SqlHelperEx()) {
she.CreateTransaction();
she.ExecuteNonQuery(updateSql, out success);
if (!success) {
she.Rollback();
} else {
she.Commit();
}
}
}
public static List<long> GetNotSendProduceIntakeID()
{
return LocalQueryUtil.GetNotSendProduceIntakeID();
}
private static bool ExcuteSql(string sql)
{
bool success;
using (var she = new SqlHelperEx())
{
she.CreateTransaction();
she.ExecuteNonQuery(sql, out success);
if (!success)
she.Rollback();
else
she.Commit();
}
return success;
}
public static void Delete(long ID)
{
var sql = SqlUtil.GetDeleteSql(TableNames., "where ProduceIntake_ID=" + ID);
var sql2 = SqlUtil.GetDeleteSql(TableNames., "where ID=" + ID);
bool success;
using (var she = new SqlHelperEx())
{
she.CreateTransaction();
she.ExecuteNonQuery(sql, out success);
if (!success)
{
she.Rollback();
}
else
{
she.ExecuteNonQuery(sql2, out success);
if (!success)
{
she.Rollback();
}
else
{
she.Commit();
}
}
}
}
}
}