/// <summary> /// Create a new ABi_GR object. /// </summary> /// <param name="aBi_GR_ID">Initial value of the ABi_GR_ID property.</param> public static ABi_GR CreateABi_GR(global::System.Int32 aBi_GR_ID) { ABi_GR aBi_GR = new ABi_GR(); aBi_GR.ABi_GR_ID = aBi_GR_ID; return aBi_GR; }
/// <summary> /// Deprecated Method for adding a new object to the ABi_GR EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToABi_GR(ABi_GR aBi_GR) { base.AddObject("ABi_GR", aBi_GR); }
public override System.Data.DataSet Import(System.Data.DataSet ds) { var failedRows = new DataSet(); if (ds != null && ds.Tables.Count > 0) { System.Data.DataTable dtFailed = new System.Data.DataTable("Failed_Imported"); DataColumn[] columns = new DataColumn[ds.Tables[0].Columns.Count + 1]; //ds.Tables[0].Columns.CopyTo(columns, 0); for (int i = 0; i < ds.Tables[0].Columns.Count; ++i) { columns[i] = new DataColumn(ds.Tables[0].Columns[i].ColumnName); } columns[ds.Tables[0].Columns.Count] = new DataColumn("错误原因"); dtFailed.Columns.AddRange(columns); BuildHeader(ds.Tables[0].Columns); for (int i = 0; i < ds.Tables[0].Rows.Count; ++i) { //Insert or Update the PO String poNumber; String poItemNumber; String grNumber = ""; String grItemNumber = ""; try { poNumber = GetFieldValue(ds.Tables[0].Rows[i], "PONumber").ToString(); poItemNumber = String.Format("{0:D5}", Convert.ToInt32(GetFieldValueInt(ds.Tables[0].Rows[i], "POItemNumber"))); grNumber = GetFieldValue(ds.Tables[0].Rows[i], "grNumber").ToString(); grItemNumber = String.Format("{0:D4}", Convert.ToInt32(GetFieldValueInt(ds.Tables[0].Rows[i], "grItemNumber"))); if (String.IsNullOrEmpty(poNumber) || String.IsNullOrEmpty(poItemNumber)) { List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray); row.Add(String.Format("订单号或订单行项目号为空{0},{1}", poNumber, poItemNumber)); dtFailed.Rows.Add(row.ToArray()); } else if (String.IsNullOrEmpty(grNumber) || String.IsNullOrEmpty(grItemNumber)) { List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray); row.Add(String.Format("收货单号或收货行项目号为空{0},{1}", poNumber, poItemNumber)); dtFailed.Rows.Add(row.ToArray()); } else { string vendorCode = GetFieldValue(ds.Tables[0].Rows[i], "vendorCode").ToString(); string plantCode = GetFieldValue(ds.Tables[0].Rows[i], "plantCode").ToString(); string companyCode = GetFieldValue(ds.Tables[0].Rows[i], "companyCode").ToString(); var vendor = dbContext.ABi_Vendor.FirstOrDefault(o => o.VendorCode == vendorCode); var plant = dbContext.ABi_Plant.FirstOrDefault(o => o.PlantCode == plantCode); var company = dbContext.ABi_Company.FirstOrDefault(o => o.CompanyCode == companyCode); if (vendor == null || plant == null || company == null) { //部分数据不存在 List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray); row.Add(String.Format("供应商或公司或工厂数据库内不存在")); dtFailed.Rows.Add(row.ToArray()); continue; } string moveType = Convert.ToString(GetFieldValue(ds.Tables[0].Rows[i], "moveType")); double grQuantity = Convert.ToDouble(GetFieldValue(ds.Tables[0].Rows[i], "quantity")); double grAmount = Convert.ToDouble(GetFieldValue(ds.Tables[0].Rows[i], "grAmount")); string refGrNumber = Convert.ToString(GetFieldValue(ds.Tables[0].Rows[i], "refGrNumber")); string refGrItemNumber = String.Format("{0:D4}", Convert.ToInt32(GetFieldValueInt(ds.Tables[0].Rows[i], "refGrItemNumber"))); if (moveType == "102" || moveType == "106" || moveType == "122" || moveType == "161") { grQuantity = -System.Math.Abs(grQuantity); grAmount = -System.Math.Abs(grAmount); } else if (moveType == "103") { continue; } if (moveType == "161") { if (string.IsNullOrEmpty(refGrNumber) || string.IsNullOrEmpty(refGrItemNumber)) { refGrNumber = grNumber; refGrItemNumber = grItemNumber; } } int abi_gr_id = 0; var obj = dbContext.ABi_GR.FirstOrDefault(o => o.GRNumber == grNumber && o.GRItemNumber == grItemNumber); if (obj != null) { abi_gr_id = obj.ABi_GR_ID; obj.ABi_Company_ID = company.ABi_Company_ID; obj.ABi_Plant_ID = plant.ABi_Plant_ID; obj.ABi_Vendor_ID = vendor.ABi_Vendor_ID; obj.GRAmount = grAmount; obj.GRDate = ToDateTime(GetFieldValue(ds.Tables[0].Rows[i], "GRDate")); obj.GRYear = ToDateTime(Convert.ToInt32(GetFieldValue(ds.Tables[0].Rows[i], "GRYear"))); obj.MoveType = moveType; obj.GRNumber = grNumber; obj.GRItemNumber = grItemNumber; obj.RefGRItemNumber = refGrItemNumber; obj.RefGRNumber = refGrNumber; obj.RefGRYear = ToDateTime(Convert.ToInt32(GetFieldValue(ds.Tables[0].Rows[i], "RefGRYear"))); //obj.DateCreated = DateTime.Now; obj.DateModified = DateTime.Now; obj.Quantity = grQuantity; obj.QuantityUnit = GetFieldValue(ds.Tables[0].Rows[i], "QuantityUnit").ToString(); obj.Currency = GetFieldValue(ds.Tables[0].Rows[i], "Currency").ToString(); var poObj = dbContext.ABi_PO.FirstOrDefault(o => o.PONumber == poNumber && o.POItemNumber == poItemNumber); var pogrObj = dbContext.ABi_PO_GR.FirstOrDefault(o => o.ABi_GR_ID == obj.ABi_GR_ID && o.ABi_PO_ID == poObj.ABi_PO_ID); if (pogrObj == null) { dbContext.ABi_PO_GR.AddObject(new ABi_PO_GR() { ABi_GR_ID = obj.ABi_GR_ID, ABi_PO_ID = poObj.ABi_PO_ID, DateCreated = DateTime.Now, DateModified = DateTime.Now }); } dbContext.SaveChanges(); logger.LogInfo(String.Format("Import GR (GRNumber:{0},GRItemNumber:{1},PONumber:{2},POItemNumber:{3})", grNumber, grItemNumber, poNumber, poItemNumber)); } else { var grTmp = new ABi_GR() { ABi_Company_ID = company.ABi_Company_ID, ABi_Plant_ID = plant.ABi_Plant_ID, ABi_Vendor_ID = vendor.ABi_Vendor_ID, GRAmount = grAmount, GRDate = ToDateTime(GetFieldValue(ds.Tables[0].Rows[i], "GRDate")), GRYear = ToDateTime(Convert.ToInt32(GetFieldValue(ds.Tables[0].Rows[i], "GRYear"))), MoveType = moveType, GRNumber = grNumber, GRItemNumber = grItemNumber, RefGRItemNumber = refGrItemNumber, RefGRNumber = refGrNumber, RefGRYear = ToDateTime(Convert.ToInt32(GetFieldValue(ds.Tables[0].Rows[i], "RefGRYear"))), DateCreated = DateTime.Now, DateModified = DateTime.Now, Quantity = grQuantity, QuantityUnit = GetFieldValue(ds.Tables[0].Rows[i], "QuantityUnit").ToString(), Currency = GetFieldValue(ds.Tables[0].Rows[i], "Currency").ToString() }; dbContext.ABi_GR.AddObject(grTmp); dbContext.SaveChanges(); abi_gr_id = grTmp.ABi_GR_ID; //obj = dbContext.ABi_GR.FirstOrDefault(o => o.GRNumber == grNumber && o.GRItemNumber == grItemNumber); var poObj1 = dbContext.ABi_PO.FirstOrDefault(o => o.PONumber == poNumber && o.POItemNumber == poItemNumber); var pogrObj1 = dbContext.ABi_PO_GR.FirstOrDefault(o => o.ABi_GR_ID == abi_gr_id && o.ABi_PO_ID == poObj1.ABi_PO_ID); if (pogrObj1 == null) { dbContext.ABi_PO_GR.AddObject(new ABi_PO_GR() { ABi_GR_ID = abi_gr_id, ABi_PO_ID = poObj1.ABi_PO_ID, DateCreated = DateTime.Now, DateModified = DateTime.Now }); } dbContext.SaveChanges(); logger.LogInfo(String.Format("Import GR (GRNumber:{0},GRItemNumber:{1},PONumber:{2},POItemNumber:{3})", grNumber, grItemNumber, poNumber, poItemNumber)); } } } catch (Exception ex) { List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray); row.Add(String.Format("出现异常错误:{0}", ex.Message)); dtFailed.Rows.Add(row.ToArray()); logger.LogError(String.Format("Failed GRImport({0},{1})", grNumber, grItemNumber), ex); } } failedRows.Tables.Add(dtFailed); } return failedRows; }