@@ -22,6 +22,9 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem
/// </summary>
public class Ass_FixAssetsService : RepositoryFactory
{
private DataSourceIBLL dataSourceIBLL = new DataSourceBLL();
private DataItemIBLL dataItemIBLL = new DataItemBLL();
#region 获取数据
/// <summary>
@@ -330,10 +333,11 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem
{
failDt.Columns.Add(dc.ColumnName, dc.DataType);
}
IEnumerable<Ass_FixAssetsEntity> Ass_FixAssetsHistory = this.BaseRepository("CollegeMIS").FindList<Ass_FixAssetsEntity>("select * from Ass_FixAssets" );
var db = this.BaseRepository().BeginTrans( );
IEnumerable<Ass_FixAssetsEntity> Ass_FixAssetsHistory = db.FindList<Ass_FixAssetsEntity>("select * from Ass_FixAssets");
List<Ass_FixAssetsEntity> Ass_FixAssetsinsert = new List<Ass_FixAssetsEntity>();
var db = this.BaseRepository("CollegeMIS").BeginTrans();
// 循环遍历导入
foreach (DataRow dr in dt.Rows)
{
@@ -464,7 +468,7 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem
}
if (Ass_FixAssetsinsert.Count(s => s.FACode == dr["资产编号"].ToString()) > 0)
{
throw (new Exception("资产编号导入数据 重复"));
throw (new Exception("导入数据中 资产编号重复"));
}
//写入要导入替换的数据
@@ -472,39 +476,40 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem
{
FAId = Guid.NewGuid().ToString(),
FACode = dr["资产编号"].ToString(),
//ATGId = dr["资产编号"].ToString( ),
//ATId = dr["资产编号"].ToString( ),
ATGId = dataSourceIBLL.GetKeyByValue("Ass_AssetsType", "aname", dr["资产国标大类"].ToString(), "atid" ),
ATId = dataSourceIBLL.GetKeyByValue("Ass_AssetsType", "aname", dr["资产分类"].ToString(), "atid" ),
FAName = dr["资产名称"].ToString(),
FinanceEntryDate = dr["财务入账日期"].ToDate( ),
//ValueType = dr["资产编号"].ToString( ),
FinanceEntryDate = Convert.ToDateTime( dr["财务入账日期"]),
ValueType = FindDataItemValue(dataItemIBLL.GetDetailList("ValueType"), dr["价值类型"].ToString(), "价值类型", false ),
Value = dr["价值"].ToDecimal(),
//GetWay = dr["资产编号"].ToString( ),
GetDate = dr["取得日期"].ToDate( ),
//UseCondition = dr["资产编号"].ToString( ),
//UseDepartment = dr["资产编号"].ToString( ),
//ManageDepartment = dr["资产编号"].ToString( ),
//UsePeople = dr["资产编号"].ToString( ),
GetWay = FindDataItemValue(dataItemIBLL.GetDetailList("GetWay"), dr["取得方式"].ToString(), "取得方式", false ),
GetDate = Convert.ToDateTime( dr["取得日期"]),
UseCondition = FindDataItemValue(dataItemIBLL.GetDetailList("AssState"), dr["使用状况"].ToString(), "使用状况", false ),
UseDepartment = dataSourceIBLL.GetKeyByValue("classdata", "name", dr["使用部门"].ToString(), "id" ),
ManageDepartment = dataSourceIBLL.GetKeyByValue("classdata", "name", dr["管理部门"].ToString(), "id" ),
UsePeople = dataSourceIBLL.GetKeyByValue("teacheruserdata", "f_realname", dr["使用人"].ToString(), "f_userid" ),
Amount = dr["数量"].ToInt(),
MakePeople = dr["制单人"].ToString(),
MakeDate = dr["制单时间"].ToDate( ),
//Unit = dr["资产编号"].ToString( ),
//CardStatus = dr["资产编号"].ToString( ),
MakeDate = Convert.ToDateTime( dr["制单时间"]),
Unit = dataSourceIBLL.GetKeyByValue("company", "f_fullname", dr["所属单位"].ToString(), "f_companyid" ),
CardStatus = FindDataItemValue(dataItemIBLL.GetDetailList("CardStatus"), dr["卡片状态"].ToString(), "卡片状态", false ),
DepreciationLife = dr["折旧年限"].ToInt(),
AccumulatedDepreciation = dr["累计折旧"].ToDecimal(),
HaveDepreciationMonths = dr["已提折旧月数"].ToInt(),
MonthlyDepreciation = dr["月折旧额"].ToDecimal(),
//DepreciationMothod = dr["资产编号"].ToString( ),
DepreciationMothod = FindDataItemValue(dataItemIBLL.GetDetailList("DepreciationMothod"), dr["折旧方法"].ToString(), "折旧方法", false ),
NetValue = dr["净值"].ToDecimal(),
PurchaseOrganizationForm = dr["采购组织形式"].ToString(),
Brand = dr["品牌"].ToString(),
SpecificationModel = dr["规格型号"].ToString(),
//StorageId = dr["资产编号"].ToString( ),
//SupplierId = dr["资产编号"].ToString( ),
StorageId = dataSourceIBLL.GetKeyByValue("Ass_StorageData", "sname", dr["存放地点"].ToString(), "sid" ),
SupplierId = dataSourceIBLL.GetKeyByValue("Ass_SupplierData", "sname", dr["销售商"].ToString(), "sid" ),
UseArea = dr["使用权面积/建筑面积"].ToDecimal(),
FinancialAppropriation = dr["财政拨款"].ToDecimal(),
NonFinancialAppropriation = dr["非财政拨款"].ToDecimal(),
AccountDocumentNumber = dr["会计凭证号"].ToString(),
//DepreciationStatus = dr["资产编号"].ToString(),
DepreciationStatus = FindDataItemValue(dataItemIBLL.GetDetailList("DepreciationStatus"), dr["折旧/摊销状态"].ToString(), "折旧/摊销状态", false),
//默认数据
CreateTime = DateTime.Now,
CreateUserId = LoginUserInfo.Get().userId,
@@ -513,71 +518,10 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem
Status = 0,
ProcessId = Guid.NewGuid().ToString(),
};
var detailList = this.BaseRepository().FindList<DataItemDetailEntity>(@"SELECT t.*,t2.F_ItemCode FROM LR_Base_DataItemDetail t
INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
WHERE t.F_DeleteMark = 0");
var ValueType = dr["价值类型"].ToString().Trim();
var ValueTypelity = detailList.FirstOrDefault(x => x.F_ItemCode == "ValueType" && x.F_ItemName == ValueType);
if (!string.IsNullOrEmpty(ValueType) && ValueTypelity == null)
{
throw (new Exception("【价值类型】数据字典找不到对应的数据"));
}
else
{
Ass_FixAssetsEntity.ValueType = ValueTypelity?.F_ItemValue;
}
var GetWay = dr["取得方式"].ToString().Trim();
var GetWaylity = detailList.FirstOrDefault(x => x.F_ItemCode == "GetWay" && x.F_ItemName == GetWay);
if (!string.IsNullOrEmpty(GetWay) && GetWaylity == null)
{
throw (new Exception("【取得方式】数据字典找不到对应的数据"));
}
else
{
Ass_FixAssetsEntity.GetWay = GetWaylity?.F_ItemValue;
}
var UseCondition = dr["使用状况"].ToString().Trim();
var UseConditionlity = detailList.FirstOrDefault(x => x.F_ItemCode == "UseCondition" && x.F_ItemName == GetWay);
if (!string.IsNullOrEmpty(UseCondition) && UseConditionlity == null)
{
throw (new Exception("【使用状况】数据字典找不到对应的数据"));
}
else
{
Ass_FixAssetsEntity.UseCondition = GetWaylity?.F_ItemValue;
}
var CardStatus = dr["卡片状态"].ToString().Trim();
var CardStatuslity = detailList.FirstOrDefault(x => x.F_ItemCode == "CardStatus" && x.F_ItemName == GetWay);
if (!string.IsNullOrEmpty(CardStatus) && CardStatuslity == null)
{
throw (new Exception("【卡片状态】数据字典找不到对应的数据"));
}
else
{
Ass_FixAssetsEntity.CardStatus = GetWaylity?.F_ItemValue;
}
var DepreciationMothod = dr["折旧方法"].ToString().Trim();
var DepreciationMothodlity = detailList.FirstOrDefault(x => x.F_ItemCode == "DepreciationMothod" && x.F_ItemName == GetWay);
if (!string.IsNullOrEmpty(DepreciationMothod) && DepreciationMothodlity == null)
{
throw (new Exception("【折旧方法】数据字典找不到对应的数据"));
}
else
{
Ass_FixAssetsEntity.DepreciationMothod = GetWaylity?.F_ItemValue;
}
var DepreciationStatus = dr["折旧/摊销状态"].ToString().Trim();
var DepreciationStatuslity = detailList.FirstOrDefault(x => x.F_ItemCode == "DepreciationStatus" && x.F_ItemName == GetWay);
if (!string.IsNullOrEmpty(DepreciationStatus) && DepreciationStatuslity == null)
{
throw (new Exception("【折旧/摊销状态】数据字典找不到对应的数据"));
}
else
{
Ass_FixAssetsEntity.DepreciationStatus = GetWaylity?.F_ItemValue;
}
Ass_FixAssetsinsert.Add(Ass_FixAssetsEntity);
db.Delete<Ass_FixAssetsEntity>(x => x.FACode == dr["资产编号"].ToString());
var FACode = dr["资产编号"].ToString();
db.Delete<Ass_FixAssetsEntity>(x => x.FACode == FACode && x.Status == 0);
snum++;
}
catch (Exception ex)
@@ -612,5 +556,31 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem
}
#endregion
/// <summary>
/// 数据字典查找Value
/// </summary>
/// <param name="dataItemList">数据字典数据</param>
/// <param name="itemName">项目名</param>
/// <param name="colName">列名</param>
/// <returns></returns>
private string FindDataItemValue(List<DataItemDetailEntity> dataItemList, string itemName, string colName, bool IsMandatory)
{
DataItemDetailEntity dataItem = dataItemList.Find(t => t.F_ItemName == itemName);
if (dataItem != null)
{
return dataItem.F_ItemValue;
}
else
{
if (IsMandatory)
{
throw (new Exception("【" + colName + "】数据字典找不到对应值"));
}
else
{
return "";
}
}
}
}
}