/// <summary> /// 导入隐患标准库 /// </summary> /// <param name="one"></param> /// <param name="two"></param> /// <param name="three"></param> /// <param name="four"></param> /// <param name="five"></param> /// <param name="content"></param> /// <param name="require"></param> /// <param name="norm"></param> /// <returns></returns> public string Save(string one, string two, string three, string four, string five, string content, string require, string norm) { DataTable dt = BaseRepository().FindTable(string.Format("select id,encode from BIS_HTSTANDARD where name='{0}' and parentid='0' and createuserorgcode='{1}'", one, ERCHTMS.Code.OperatorProvider.Provider.Current().OrganizeCode)); string enCode = ""; string parentId = ""; HtStandardEntity entity = new HtStandardEntity(); if (dt.Rows.Count > 0) { enCode = dt.Rows[0][1].ToString(); parentId = dt.Rows[0][0].ToString(); entity = BaseRepository().FindEntity(parentId); if (!string.IsNullOrEmpty(two)) { object obj = BaseRepository().FindObject(string.Format("select id from BIS_HTSTANDARD where name='{0}' and parentid='{1}'", two, parentId)); if (obj == null) { int count = BaseRepository().FindObject(string.Format("select count(1) from BIS_HTSTANDARD where parentid='{0}'", parentId)).ToInt(); count++; if (count.ToString().Length < 2) { enCode += "00" + count; } else if (count.ToString().Length >= 2 && count.ToString().Length < 3) { enCode += "0" + count; } else { enCode += count.ToString(); } entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = enCode, Name = two, Parentid = parentId, lev = 2 }; entity.Create(); this.BaseRepository().Insert(entity); parentId = entity.Id; } else { parentId = obj.ToString(); entity = this.BaseRepository().FindEntity(parentId); if (!string.IsNullOrEmpty(three)) { obj = BaseRepository().FindObject(string.Format("select id from BIS_HTSTANDARD where name='{0}' and parentid='{1}'", three, parentId)); if (obj == null) { int count = BaseRepository().FindObject(string.Format("select count(1) from BIS_HTSTANDARD where parentid='{0}'", parentId)).ToInt(); count++; enCode = entity.EnCode; if (count.ToString().Length < 2) { enCode += "00" + count; } else if (count.ToString().Length >= 2 && count.ToString().Length < 3) { enCode += "0" + count; } else { enCode += count.ToString(); } entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = enCode, Name = three, Parentid = parentId, lev = 3 }; entity.Create(); this.BaseRepository().Insert(entity); parentId = entity.Id; } else { parentId = obj.ToString(); entity = this.BaseRepository().FindEntity(parentId); } if (!string.IsNullOrEmpty(four)) { obj = BaseRepository().FindObject(string.Format("select id from BIS_HTSTANDARD where name='{0}' and parentid='{1}'", four, parentId)); if (obj == null) { enCode = entity.EnCode; int count = BaseRepository().FindObject(string.Format("select count(1) from BIS_HTSTANDARD where parentid='{0}'", parentId)).ToInt(); count++; if (count.ToString().Length < 2) { enCode += "00" + count; } else if (count.ToString().Length >= 2 && count.ToString().Length < 3) { enCode += "0" + count; } else { enCode += count.ToString(); } entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = enCode, Name = four, Parentid = parentId, lev = 4 }; entity.Create(); this.BaseRepository().Insert(entity); parentId = entity.Id; } else { parentId = obj.ToString(); entity = this.BaseRepository().FindEntity(parentId); } if (!string.IsNullOrEmpty(five)) { obj = BaseRepository().FindObject(string.Format("select id from BIS_HTSTANDARD where name='{0}' and parentid='{1}'", five, parentId)); if (obj == null) { enCode = entity.EnCode; int count = BaseRepository().FindObject(string.Format("select count(1) from BIS_HTSTANDARD where parentid='{0}'", parentId)).ToInt(); count++; if (count.ToString().Length < 2) { enCode += "00" + count; } else if (count.ToString().Length >= 2 && count.ToString().Length < 3) { enCode += "0" + count; } else { enCode += count.ToString(); } entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = enCode, Name = five, Parentid = parentId, lev = 5 }; entity.Create(); this.BaseRepository().Insert(entity); } else { parentId = obj.ToString(); entity = this.BaseRepository().FindEntity(parentId); } } } } } } } else { int count = BaseRepository().FindObject(string.Format("select count(1) from BIS_HTSTANDARD where parentid='0'")).ToInt(); if (count.ToString().Length < 2) { enCode = "00" + count; } else if (count.ToString().Length >= 2 && count.ToString().Length < 3) { enCode = "0" + count; } else { enCode = count.ToString(); } entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = enCode, Name = one, Parentid = "0", lev = 1 }; entity.Create(); parentId = entity.Id; if (this.BaseRepository().Insert(entity) > 0) { if (!string.IsNullOrEmpty(two)) { entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = entity.EnCode + "001", Name = two, Parentid = entity.Id, lev = 2 }; entity.Create(); parentId = entity.Id; if (this.BaseRepository().Insert(entity) > 0) { if (!string.IsNullOrEmpty(three)) { entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = entity.EnCode + "001", Name = three, Parentid = entity.Id, lev = 3 }; entity.Create(); parentId = entity.Id; if (this.BaseRepository().Insert(entity) > 0) { if (!string.IsNullOrEmpty(four)) { entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = entity.EnCode + "001", Name = four, Parentid = entity.Id, lev = 4 }; entity.Create(); parentId = entity.Id; if (this.BaseRepository().Insert(entity) > 0) { if (!string.IsNullOrEmpty(five)) { entity = new HtStandardEntity { Id = System.Guid.NewGuid().ToString(), EnCode = entity.EnCode + "001", Name = five, Parentid = entity.Id, lev = 5 }; entity.Create(); parentId = entity.Id; this.BaseRepository().Insert(entity); } } } } } } } } } HtStandardItemEntity item = new HtStandardItemEntity { StId = entity.Id, StCode = entity.EnCode, Content = content.Trim(), Require = require.Trim(), Norm = norm.Trim().Replace("?", "") }; item.Create(); new RepositoryFactory <HtStandardItemEntity>().BaseRepository().Insert(item); return(parentId); }