//新增
        public bool CreateRepeatRow(ref ValidationErrors errors, string code)
        {
            try
            {
                //测试关键数值是否有效

                if (caseRepository.GetById(code) == null)
                {
                    errors.Add("不存在的用例!");
                    return(false);
                }
                //不是空值时成立
                if (caseRepository.GetById(code) != null)
                {
                    DEF_TestCaseRelation entity = new DEF_TestCaseRelation();
                    entity.PCode  = code;
                    entity.CCode  = code;
                    entity.Sort   = 1;
                    entity.ReMark = "";
                    m_Rep.Create(entity);
                }

                return(true);
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
            }
            return(false);
        }
 public bool Edit(ref ValidationErrors errors, string id, int sort)
 {
     try
     {
         string[] ids = id.Split('_');
         if (ids.Length != 2)
         {
             return(false);
         }
         else
         {
             DEF_TestCaseRelation entity = m_Rep.GetById(ids[0], ids[1]);
             if (entity == null)
             {
                 errors.Add("不存在的用例关系!");
                 return(false);
             }
             entity.Sort = sort;
             return(m_Rep.Edit(entity));
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         return(false);
     }
 }
        public virtual bool Create(ref ValidationErrors errors, DEF_TestCaseRelationModel model)
        {
            try
            {
			    DEF_TestCaseRelation entity = m_Rep.GetById(model.PCode);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return false;
                }
                entity = new DEF_TestCaseRelation(); 
				entity.PCode = model.PCode;
				entity.CCode = model.CCode;
				entity.ReMark = model.ReMark;
				entity.Sort = model.Sort;
  

                if (m_Rep.Create(entity))
                {
                    return true;
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }
        public virtual bool Edit(ref ValidationErrors errors, DEF_TestCaseRelationModel model)
        {
            try
            {
                DEF_TestCaseRelation entity = m_Rep.GetById(model.PCode);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return false;
                }
                              				entity.PCode = model.PCode;
				entity.CCode = model.CCode;
				entity.ReMark = model.ReMark;
				entity.Sort = model.Sort;
 


                if (m_Rep.Edit(entity))
                {
                    return true;
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return false;
                }

            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }
        //新增
        public bool Create(ref ValidationErrors errors, string code, string codeIds)
        {
            try
            {
                //测试关键数值是否有效

                if (caseRepository.GetById(code) == null)
                {
                    errors.Add("不存在的用例!");
                    return(false);
                }

                string[] arr = codeIds.Split(',');
                foreach (string str in arr)
                {
                    //数据库没有,存在这个用例,不是空值时成立,是否存在交叉引用
                    if (!entityIsExist(code, str) && !entityIsExist(str, code) && code != str && caseRepository.GetById(str) != null)
                    {
                        DEF_TestCaseRelation entity = new DEF_TestCaseRelation();
                        entity.PCode  = code;
                        entity.CCode  = str;
                        entity.ReMark = "";
                        entity.Sort   = 1;
                        m_Rep.Create(entity);
                    }
                    else
                    {
                        errors.Add(str + "存在交叉引用!请检查" + str + "。");
                    }
                }
                if (m_Rep.GetTestCaseRelationByCode(code) > 1)
                {
                    if (entityIsExist(code, code))
                    {
                        if (!Delete(ref errors, code, code))
                        {
                            errors.Add("删除默认行出错!请手动删除" + code);
                            return(false);
                        }
                    }
                }
                if (errors.Error != "")
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
            }
            return(false);
        }
        public int DeleteByPcodeCcode(string pcode, string ccode)
        {
            DEF_TestCaseRelation deleteItem = Context.DEF_TestCaseRelation.SingleOrDefault(a => a.PCode == pcode && a.CCode == ccode);

            if (deleteItem != null)
            {
                Context.DEF_TestCaseRelation.Remove(deleteItem);
                return(Context.SaveChanges());
            }
            return(0);
        }
        public virtual DEF_TestCaseRelationModel GetById(string id)
        {
            if (IsExists(id))
            {
                DEF_TestCaseRelation entity = m_Rep.GetById(id);
                DEF_TestCaseRelationModel model = new DEF_TestCaseRelationModel();
                              				model.PCode = entity.PCode;
				model.CCode = entity.CCode;
				model.ReMark = entity.ReMark;
				model.Sort = entity.Sort;
 
                return model;
            }
            else
            {
                return null;
            }
        }