using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
using System.Transactions;
namespace CY.SQLDAL
{
public class EC_SpecialOrdersDAL : IEC_SpecialOrdersDAL
{
private Database _dataBase = null;
public EC_SpecialOrdersDAL()
{
_dataBase = new Database();
}
public EC_SpecialOrdersDAL(Database database)
{
_dataBase = database;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_SpecialOrders trueModel = model as Model.EC_SpecialOrders;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter(){Direction=ParameterDirection.ReturnValue,SqlDbType = SqlDbType.Int},
new SqlParameter("@Memberid",trueModel.Memberid),
new SqlParameter("@PO_OrderId",trueModel.PO_OrderId),
new SqlParameter("@PO_OrderNum",trueModel.PO_OrderNum),
new SqlParameter("@PSO_OrderNum",trueModel.PSO_OrderNum),
new SqlParameter("@PSO_OrderPeople",trueModel.PSO_OrderPeople),
new SqlParameter("@PSO_OrderTime",trueModel.PSO_OrderTime),
new SqlParameter("@PSO_Work",trueModel.PSO_Work),
new SqlParameter("@PSO_Remarks",trueModel.PSO_Remarks),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@OrderNum",trueModel.OrderNum),
new SqlParameter("@IsPrint",trueModel.IsPrint)
};
try
{
_dataBase.Query("sp_EC_SpecialOrders_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
trueModel.Keyid = (int)sqlParms[0].Value;
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_SpecialOrders trueModel = model as Model.EC_SpecialOrders;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid),
new SqlParameter("@Memberid",trueModel.Memberid),
new SqlParameter("@PO_OrderId",trueModel.PO_OrderId),
new SqlParameter("@PO_OrderNum",trueModel.PO_OrderNum),
new SqlParameter("@PSO_OrderNum",trueModel.PSO_OrderNum),
new SqlParameter("@PSO_OrderPeople",trueModel.PSO_OrderPeople),
new SqlParameter("@PSO_OrderTime",trueModel.PSO_OrderTime),
new SqlParameter("@PSO_Work",trueModel.PSO_Work),
new SqlParameter("@PSO_Remarks",trueModel.PSO_Remarks),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@OrderNum",trueModel.OrderNum),
new SqlParameter("@IsPrint",trueModel.IsPrint)
};
try
{
_dataBase.Query("sp_EC_SpecialOrders_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_SpecialOrders trueModel = model as Model.EC_SpecialOrders;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
try
{
_dataBase.Query("sp_EC_SpecialOrders_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
{
throw new NotImplementedException();
}
///
/// 单个查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
throw new NotImplementedException();
}
///
/// 根据编号获得信息
///
///
///
public EC_SpecialOrders GetModelByKeyid(int? Keyid)
{
if (Keyid == null)
return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "EC_SpecialOrders", string.Format(" Keyid='{0}'", Keyid)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
///
/// 根据订单编号获得信息
///
///
///
public EC_SpecialOrders GetModelByOrderId(int? OrderId)
{
if (OrderId == null)
return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "EC_SpecialOrders", string.Format(" PO_OrderId='{0}'", OrderId)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
///
/// 根据编号获得版面信息
///
///
///
public IEnumerable GetEC_SpecialForumsListByKeyid(int? Keyid)
{
try
{
if (Keyid == null)
return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "EC_SpecialForums", string.Format(" SpecialOrderId='{0}'", Keyid)) as IList;//执行查询
return result;//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据会员编号获取最新专版施工单号
///
/// 会员编号
///
public string GetPSO_OrderNum(Guid Memberid)
{
if (Memberid == null)
return null;//错误数据返会空
string NumberHead = DateTime.Now.ToString("yyyyMMdd");
string NumberFoot = "001";
try
{
IList result = _dataBase.SelectModel("*", "EC_SpecialOrders", string.Format(" Memberid='{0}' and PSO_OrderNum like '{1}%'", Memberid, NumberHead)) as IList;//执行查询
if (result != null && result.Count > 0)
NumberFoot = (result.Count + 1).ToString("000");
else
NumberFoot = "001";
}
catch (Exception ex)
{
NumberFoot = "001";
}
return NumberHead + NumberFoot;
}
///
/// 新增专版施工单
///
///
///
///
///
///
public bool AddSpecialForums(EC_OrderOperate m_EC_OrderOperate, EC_SpecialOrders m_EC_SpecialOrders, OA_OrderWorkListRelation m_OA_OrderWorkListRelation, List m_EC_SpecialForumsList, List m_OA_InventoryList, List m_OA_OutOfStorageList)
{
try
{
bool result = false;
EC_OrderBasicDAL dal_EC_OrderBasicDAL = new EC_OrderBasicDAL(_dataBase);
EC_OrderExtendDAL dal_EC_OrderExtendDAL = new EC_OrderExtendDAL(_dataBase);
OA_OrderWorkListRelationDAL dal_OA_OrderWorkListRelationDAL = new OA_OrderWorkListRelationDAL(_dataBase);
EC_SpecialForumsDAL dal_EC_SpecialForumsDAL = new EC_SpecialForumsDAL(_dataBase);
using (TransactionScope t_TransactionScope = new TransactionScope())
{
result = dal_EC_OrderExtendDAL.UpSurplusPrintNum(m_EC_OrderOperate.OrderId, -1, m_EC_SpecialOrders.Operator);
if (result)
{
result = dal_EC_OrderBasicDAL.UpdateOrderStateUnit(m_EC_OrderOperate);
if (result)
{
result = InserModel(m_EC_SpecialOrders);
if (result)
{
m_OA_OrderWorkListRelation.RelationTargetId = m_EC_SpecialOrders.Keyid;
result = dal_OA_OrderWorkListRelationDAL.InserModel(m_OA_OrderWorkListRelation);
if (result)
{
foreach (var m_EC_SpecialForums in m_EC_SpecialForumsList)
{
if (result)
{
m_EC_SpecialForums.SpecialOrderId = m_EC_SpecialOrders.Keyid;
result = dal_EC_SpecialForumsDAL.InserModel(m_EC_SpecialForums);
}
else
{
return false;
}
}
if (result)
{
t_TransactionScope.Complete();
}
}
}
}
}
}
OA_InventoryDAL dal_OA_InventoryDAL = new OA_InventoryDAL();
OA_OutOfStorageDAL dal_OA_OutOfStorageDAL = new OA_OutOfStorageDAL();
if (result)
{
foreach (var m_OA_Inventory in m_OA_InventoryList)
{
dal_OA_InventoryDAL.UpdateModel(m_OA_Inventory);
}
foreach (var m_OA_OutOfStorage in m_OA_OutOfStorageList)
{
m_OA_OutOfStorage.Remark = string.Format("专版:" + m_EC_SpecialOrders.PSO_OrderNum + "");
dal_OA_OutOfStorageDAL.InserModel(m_OA_OutOfStorage);
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 修改专版施工单
///
///
///
///
public bool UpdateSpecialForums(EC_SpecialOrders m_EC_SpecialOrders, List m_EC_SpecialForumsList, List m_OA_InventoryList, List m_OA_OutOfStorageList)
{
try
{
bool result = false;
EC_SpecialForumsDAL dal_EC_SpecialForumsDAL = new EC_SpecialForumsDAL(_dataBase);
List m_EC_SpecialForumsList_Old = GetEC_SpecialForumsListByKeyid(m_EC_SpecialOrders.Keyid) as List;
using (TransactionScope t_TransactionScope = new TransactionScope())
{
result = UpdateModel(m_EC_SpecialOrders);
if (result)
{
foreach (var m_EC_SpecialForums in m_EC_SpecialForumsList_Old)
{
if (result)
{
result = dal_EC_SpecialForumsDAL.DeleteModel(m_EC_SpecialForums);
}
else
return false;
}
foreach (var m_EC_SpecialForums in m_EC_SpecialForumsList)
{
if (result)
{
m_EC_SpecialForums.SpecialOrderId = m_EC_SpecialOrders.Keyid;
result = dal_EC_SpecialForumsDAL.InserModel(m_EC_SpecialForums);
}
else
return false;
}
if (result)
{
t_TransactionScope.Complete();
}
}
}
OA_InventoryDAL dal_OA_InventoryDAL = new OA_InventoryDAL();
OA_OutOfStorageDAL dal_OA_OutOfStorageDAL = new OA_OutOfStorageDAL();
if (result)
{
foreach (var m_OA_Inventory in m_OA_InventoryList)
{
dal_OA_InventoryDAL.UpdateModel(m_OA_Inventory);
}
foreach (var m_OA_OutOfStorage in m_OA_OutOfStorageList)
{
m_OA_OutOfStorage.Remark = string.Format("专版:" + m_EC_SpecialOrders.PSO_OrderNum + "");
dal_OA_OutOfStorageDAL.InserModel(m_OA_OutOfStorage);
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, Guid MemberId, string PrintName, string
CustomName, string PSO_OrderNum, DateTime? beginTime, DateTime? endTime)
{
try
{
string Condition = " 1=1 ";
if (MemberId != Guid.Empty)
{
Condition += " and MemberId = '" + MemberId + "'";
}
if (beginTime.HasValue)
{
Condition += string.Format(" and CAST(CreateTime AS DATE) >='{0}'", beginTime);
}
if (endTime.HasValue)
{
Condition += string.Format(" and CAST(CreateTime AS DATE) <='{0}'", endTime);
}
if (!string.IsNullOrEmpty(CustomName))
{
Condition += string.Format(" and b.BuyerName like '%{0}%'", CustomName);
}
if (!string.IsNullOrEmpty(PrintName))
{
Condition += string.Format(" and b.DocumentName like '%{0}%'", PrintName);
}
if (!string.IsNullOrEmpty(PSO_OrderNum))
{
Condition += string.Format(" and PSO_OrderNum like '%{0}%'", PSO_OrderNum);
}
return _dataBase.SelectModelPage(pagination, " a.*,b.BuyerName as CustomName,b.DocumentName as PrintName ", " EC_SpecialOrders as a left join EC_OrderBasic as b on a.PO_OrderId = b.Keyid ", " PSO_OrderNum DESC ", " PSO_OrderNum DESC ", Condition);
}
catch (Exception ex)
{
throw ex;
}
}
}
}