/// <summary> /// 从datatable将数据导入 /// 可用 /// </summary> /// <param name="dataTable"></param> /// <returns></returns> public static int InsertIntoPropertyConstraintFromExcel(DataTable dataTable) { using (var context = new AnnonContext()) { try { foreach (DataRow dataRow in dataTable.Rows) { var propertyConstraint = new PropertyConstraint { PropertyID = Convert.ToInt32(dataRow["PropertyID"].ToString()), PropertyValueIdRange = dataRow["PropertyValueIdRange"].ToString(), InfluencedPtyID = Convert.ToInt32(dataRow["InfluencedPtyID"].ToString()), InfluencedPtyValueIdRange = dataRow["InfluencedPtyValueIdRange"].ToString(), ConstraintRules = dataRow["ConstraintRules"].ToString(), InfluencedPtyDefaultValue = dataRow["InfluencedPtyDefaultValue"].ToString(), DeviceID = Convert.ToInt32(dataRow["DeviceID"].ToString()) }; context.PropertyConstraints.Add(propertyConstraint); } return context.SaveChanges(); } catch (Exception e) { return -1; } } }
/// <summary> /// 插入属性约束 /// 可用 /// </summary> /// <param name="propertyID"></param> /// <param name="propertyValueRange"></param> /// <param name="influencedPtyID"></param> /// <param name="influencePtyValueRange"></param> /// <param name="constraintRules"></param> /// <param name="influencePtyDefaultValue"></param> /// <param name="deviceId"></param> /// <returns></returns> public static int InsertIntoPropertyConstraint(int propertyID, string propertyValueRange, int influencedPtyID, string influencePtyValueRange, string constraintRules, string influencePtyDefaultValue, int deviceId) { var propertyConstraint = new PropertyConstraint { PropertyID = propertyID, PropertyValueIdRange = propertyValueRange, InfluencedPtyID = influencedPtyID, InfluencedPtyValueIdRange = influencePtyValueRange, ConstraintRules = constraintRules, InfluencedPtyDefaultValue = influencePtyDefaultValue, DeviceID = deviceId }; using (var context = new AnnonContext()) { try { context.PropertyConstraints.Add(propertyConstraint); return context.SaveChanges(); } catch (Exception e) { return -1; } } }