/// <summary>
        /// 编辑一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个部门</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysDepartment entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addSysDocumentId    = new List <string>();
            List <string> deleteSysDocumentId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysDocumentId.GetIdSort(), entity.SysDocumentIdOld.GetIdSort(), ref addSysDocumentId, ref deleteSysDocumentId);


            SysDepartment editEntity = repository.Edit(db, entity);



            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑部门出错了");
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 编辑一个角色
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个角色</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysRole entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int     count      = 1;
            SysRole editEntity = repository.Edit(db, entity);

            List <string> addSysPersonId    = new List <string>();
            List <string> deleteSysPersonId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(), ref addSysPersonId, ref deleteSysPersonId);
            if (addSysPersonId != null && addSysPersonId.Count() > 0)
            {
                foreach (var item in addSysPersonId)
                {
                    SysPerson sys = new SysPerson {
                        Id = item
                    };
                    db.SysPerson.Attach(sys);
                    editEntity.SysPerson.Add(sys);
                    count++;
                }
            }
            if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0)
            {
                List <SysPerson> listEntity = new List <SysPerson>();
                foreach (var item in deleteSysPersonId)
                {
                    SysPerson sys = new SysPerson {
                        Id = item
                    };
                    listEntity.Add(sys);
                    db.SysPerson.Attach(sys);
                }
                foreach (SysPerson item in listEntity)
                {
                    editEntity.SysPerson.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑角色出错了");
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// 编辑一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addSysOperationId    = new List <string>();
            List <string> deleteSysOperationId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysOperationId.GetIdSort(), entity.SysOperationIdOld.GetIdSort(), ref addSysOperationId, ref deleteSysOperationId);
            List <SysOperation> listEntitySysOperation = new List <SysOperation>();

            if (deleteSysOperationId != null && deleteSysOperationId.Count() > 0)
            {
                foreach (var item in deleteSysOperationId)
                {
                    SysOperation sys = new SysOperation {
                        Id = item
                    };
                    listEntitySysOperation.Add(sys);
                    entity.SysOperation.Add(sys);
                }
            }

            SysMenu editEntity = repository.Edit(db, entity);


            if (addSysOperationId != null && addSysOperationId.Count() > 0)
            {
                foreach (var item in addSysOperationId)
                {
                    SysOperation sys = new SysOperation {
                        Id = item
                    };
                    db.SysOperation.Attach(sys);
                    editEntity.SysOperation.Add(sys);
                    count++;
                }
            }
            if (deleteSysOperationId != null && deleteSysOperationId.Count() > 0)
            {
                foreach (SysOperation item in listEntitySysOperation)
                {
                    editEntity.SysOperation.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                //修改后重置菜单编码
                List <int> flags = new List <int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return(true);
            }
            else
            {
                validationErrors.Add("编辑菜单出错了");
            }
            return(false);
        }
        /// <summary>
        /// 设置一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="entity">一个部门</param>
        /// <returns>是否设置成功</returns>
        public bool SetSysDepartment(ref ValidationErrors validationErrors, SysDocument entity)
        {
            bool bResult = false;
            int  count   = 0;

            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    SysDocument editEntity = repository.GetById(db, entity.Id);

                    List <string> addSysDepartmentId    = new List <string>();
                    List <string> deleteSysDepartmentId = new List <string>();
                    if (entity.SysDepartmentId != null)
                    {
                        addSysDepartmentId = entity.SysDepartmentId.Split(',').ToList();
                    }
                    if (entity.SysDepartmentIdOld != null)
                    {
                        deleteSysDepartmentId = entity.SysDepartmentIdOld.Split(',').ToList();
                    }
                    DataOfDiffrent.GetDiffrent(addSysDepartmentId, deleteSysDepartmentId, ref addSysDepartmentId, ref deleteSysDepartmentId);

                    if (addSysDepartmentId != null && addSysDepartmentId.Count() > 0)
                    {
                        foreach (var item in addSysDepartmentId)
                        {
                            SysDepartment sys = new SysDepartment {
                                Id = item
                            };
                            db.SysDepartment.Attach(sys);
                            editEntity.SysDepartment.Add(sys);
                            count++;
                        }
                    }
                    if (deleteSysDepartmentId != null && deleteSysDepartmentId.Count() > 0)
                    {
                        List <SysDepartment> listEntity = new List <SysDepartment>();
                        foreach (var item in deleteSysDepartmentId)
                        {
                            SysDepartment sys = new SysDepartment {
                                Id = item
                            };
                            listEntity.Add(sys);
                            db.SysDepartment.Attach(sys);
                        }
                        foreach (SysDepartment item in listEntity)
                        {
                            editEntity.SysDepartment.Remove(item);//查询数据库
                            count++;
                        }
                    }

                    if (count > 0 && count == repository.Save(db))
                    {
                        transactionScope.Complete();
                        bResult = true;
                    }
                    else if (count == 0)
                    {
                        validationErrors.Add("数据没有改变");
                    }
                }
                catch (Exception ex)
                {
                    Transaction.Current.Rollback();
                    ExceptionsHander.WriteExceptions(ex);
                    validationErrors.Add("编辑出错了。原因" + ex.Message);
                }
            }

            return(bResult);
        }
        /// <summary>
        /// 编辑一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个部门</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysDepartment entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addSysDocumentId    = new List <string>();
            List <string> deleteSysDocumentId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysDocumentId.GetIdSort(), entity.SysDocumentIdOld.GetIdSort(), ref addSysDocumentId, ref deleteSysDocumentId);
            List <SysDocument> listEntitySysDocument = new List <SysDocument>();

            if (deleteSysDocumentId != null && deleteSysDocumentId.Count() > 0)
            {
                foreach (var item in deleteSysDocumentId)
                {
                    SysDocument sys = new SysDocument {
                        Id = item
                    };
                    listEntitySysDocument.Add(sys);
                    entity.SysDocument.Add(sys);
                }
            }

            SysDepartment editEntity = repository.Edit(db, entity);


            if (addSysDocumentId != null && addSysDocumentId.Count() > 0)
            {
                foreach (var item in addSysDocumentId)
                {
                    SysDocument sys = new SysDocument {
                        Id = item
                    };
                    db.SysDocument.Attach(sys);
                    editEntity.SysDocument.Add(sys);
                    count++;
                }
            }
            if (deleteSysDocumentId != null && deleteSysDocumentId.Count() > 0)
            {
                foreach (SysDocument item in listEntitySysDocument)
                {
                    editEntity.SysDocument.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑部门出错了");
            }
            return(false);
        }
        /// <summary>
        /// 建立方案保存下一步
        /// </summary>
        /// <param name="validationErrors"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool EditInst(ref ValidationErrors validationErrors, PREPARE_SCHEME entity)
        {
            try
            {
                if (entity == null)
                {
                    return(false);
                }
                List <string>  addMETERING_STANDARD_DEVICEID    = new List <string>();
                List <string>  deleteMETERING_STANDARD_DEVICEID = new List <string>();
                PREPARE_SCHEME prepare = null;
                if (entity != null)
                {
                    prepare = repository.GetById(entity.ID);
                }
                DataOfDiffrent.GetDiffrent(entity.METERING_STANDARD_DEVICEID.GetIdSort(), entity.METERING_STANDARD_DEVICEIDOld.GetIdSort(), ref addMETERING_STANDARD_DEVICEID, ref deleteMETERING_STANDARD_DEVICEID);

                PREPARE_SCHEME editEntity = repository.EditInst(db, entity);

                if (addMETERING_STANDARD_DEVICEID != null && addMETERING_STANDARD_DEVICEID.Count() > 0)
                {
                    foreach (var item in addMETERING_STANDARD_DEVICEID)
                    {
                        STANDARDCHOICE sys = new STANDARDCHOICE
                        {
                            ID = Result.GetNewId(),
                            PREPARE_SCHEMEID           = entity.ID,
                            METERING_STANDARD_DEVICEID = item.Split('*')[0],
                            GROUPS       = item.Split('*')[1],
                            TYPE         = item.Split('*')[2],
                            NAMES        = item.Split('*')[3],
                            CREATEPERSON = entity.CREATEPERSON,
                            CREATETIME   = entity.CREATETIME
                        };
                        //db.STANDARDCHOICE.Attach(sys);
                        editEntity.STANDARDCHOICE.Add(sys);
                    }
                }
                if (deleteMETERING_STANDARD_DEVICEID != null && deleteMETERING_STANDARD_DEVICEID.Count() > 0)
                {
                    foreach (var item in deleteMETERING_STANDARD_DEVICEID)
                    {
                        string ID = item.Split('*')[0];

                        STANDARDCHOICE sys = new STANDARDCHOICE()
                        {
                            ID = ID
                        };

                        db.STANDARDCHOICE.Attach(sys);
                        editEntity.STANDARDCHOICE.Remove(sys);
                        db.STANDARDCHOICE.Remove(sys);
                    }
                }
                #region 更新了引用方案,需要删除原方案数据所录入的数据
                if (prepare != null && !string.IsNullOrWhiteSpace(prepare.SCHEMEID) && prepare.SCHEMEID != entity.SCHEMEID)
                {
                    List <QUALIFIED_UNQUALIFIED_TEST_ITE> deleteQUALIFIED_UNQUALIFIED_TEST_ITEList = (from f in db.QUALIFIED_UNQUALIFIED_TEST_ITE
                                                                                                      where f.PREPARE_SCHEMEID == entity.ID
                                                                                                      select f).ToList();
                    db.QUALIFIED_UNQUALIFIED_TEST_ITE.RemoveRange(deleteQUALIFIED_UNQUALIFIED_TEST_ITEList);
                }
                #endregion

                repository.Save(db);

                return(true);
            }
            catch (Exception ex)
            {
                validationErrors.Add(ex.Message);
                ExceptionsHander.WriteExceptions(ex);
            }
            return(false);
        }
Exemple #7
0
        /// <summary>
        /// 编辑一个社保种类
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个社保种类</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, InsuranceKind entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addPoliceOperationId    = new List <string>();
            List <string> deletePoliceOperationId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.PoliceOperationId.GetIdSort(), entity.PoliceOperationIdOld.GetIdSort(), ref addPoliceOperationId, ref deletePoliceOperationId);
            List <PoliceOperation> listEntityPoliceOperation = new List <PoliceOperation>();

            if (deletePoliceOperationId != null && deletePoliceOperationId.Count() > 0)
            {
                foreach (var item in deletePoliceOperationId)
                {
                    PoliceOperation sys = new PoliceOperation {
                        Id = Convert.ToInt32(item)
                    };
                    listEntityPoliceOperation.Add(sys);
                    entity.PoliceOperation.Add(sys);
                }
            }

            InsuranceKind editEntity = repository.Edit(db, entity);


            if (addPoliceOperationId != null && addPoliceOperationId.Count() > 0)
            {
                foreach (var item in addPoliceOperationId)
                {
                    PoliceOperation sys = new PoliceOperation {
                        Id = Convert.ToInt32(item)
                    };
                    db.PoliceOperation.Attach(sys);
                    editEntity.PoliceOperation.Add(sys);
                    count++;
                }
            }
            if (deletePoliceOperationId != null && deletePoliceOperationId.Count() > 0)
            {
                foreach (PoliceOperation item in listEntityPoliceOperation)
                {
                    editEntity.PoliceOperation.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑社保种类出错了");
            }
            return(false);
        }
Exemple #8
0
        /// <summary>
        /// 编辑一个户口性质
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个户口性质</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, PoliceAccountNature entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addCityId    = new List <string>();
            List <string> deleteCityId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.CityId.GetIdSort(), entity.CityIdOld.GetIdSort(), ref addCityId, ref deleteCityId);
            List <City> listEntityCity = new List <City>();

            if (deleteCityId != null && deleteCityId.Count() > 0)
            {
                foreach (var item in deleteCityId)
                {
                    City sys = new City {
                        Id = item
                    };
                    listEntityCity.Add(sys);
                    entity.City.Add(sys);
                }
            }

            PoliceAccountNature editEntity = repository.Edit(db, entity);


            if (addCityId != null && addCityId.Count() > 0)
            {
                foreach (var item in addCityId)
                {
                    City sys = new City {
                        Id = item
                    };
                    db.City.Attach(sys);
                    editEntity.City.Add(sys);
                    count++;
                }
            }
            if (deleteCityId != null && deleteCityId.Count() > 0)
            {
                foreach (City item in listEntityCity)
                {
                    editEntity.City.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑户口性质出错了");
            }
            return(false);
        }
        /// <summary>
        /// 编辑一个标准装置/计量标准器信息
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个标准装置/计量标准器信息</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, METERING_STANDARD_DEVICE entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            var data = (from m in db.METERING_STANDARD_DEVICE
                        where m.ID == entity.ID
                        select m).FirstOrDefault();//在数据的原始数据


            data.NAME = entity.NAME;



            List <string> addPREPARE_SCHEMEID    = new List <string>();
            List <string> deletePREPARE_SCHEMEID = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.PREPARE_SCHEMEID.GetIdSort(), entity.PREPARE_SCHEMEIDOld.GetIdSort(), ref addPREPARE_SCHEMEID, ref deletePREPARE_SCHEMEID);
            List <PREPARE_SCHEME> listEntityPREPARE_SCHEME = new List <PREPARE_SCHEME>();

            if (deletePREPARE_SCHEMEID != null && deletePREPARE_SCHEMEID.Count() > 0)
            {
                foreach (var item in deletePREPARE_SCHEMEID)
                {
                    PREPARE_SCHEME sys = new PREPARE_SCHEME {
                        ID = item
                    };
                    listEntityPREPARE_SCHEME.Add(sys);
                    entity.PREPARE_SCHEME.Add(sys);
                }
            }

            METERING_STANDARD_DEVICE editEntity = repository.Edit(db, entity);


            if (addPREPARE_SCHEMEID != null && addPREPARE_SCHEMEID.Count() > 0)
            {
                foreach (var item in addPREPARE_SCHEMEID)
                {
                    PREPARE_SCHEME sys = new PREPARE_SCHEME {
                        ID = item
                    };
                    db.PREPARE_SCHEME.Attach(sys);
                    editEntity.PREPARE_SCHEME.Add(sys);
                    count++;
                }
            }
            if (deletePREPARE_SCHEMEID != null && deletePREPARE_SCHEMEID.Count() > 0)
            {
                foreach (PREPARE_SCHEME item in listEntityPREPARE_SCHEME)
                {
                    editEntity.PREPARE_SCHEME.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑标准装置/计量标准器信息出错了");
            }
            return(false);
        }
        /// <summary>
        /// 编辑一个预备方案
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个预备方案</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, PREPARE_SCHEME entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addMETERING_STANDARD_DEVICEID    = new List <string>();
            List <string> deleteMETERING_STANDARD_DEVICEID = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.METERING_STANDARD_DEVICEID.GetIdSort(), entity.METERING_STANDARD_DEVICEIDOld.GetIdSort(), ref addMETERING_STANDARD_DEVICEID, ref deleteMETERING_STANDARD_DEVICEID);
            List <METERING_STANDARD_DEVICE> listEntityMETERING_STANDARD_DEVICE = new List <METERING_STANDARD_DEVICE>();

            if (deleteMETERING_STANDARD_DEVICEID != null && deleteMETERING_STANDARD_DEVICEID.Count() > 0)
            {
                foreach (var item in deleteMETERING_STANDARD_DEVICEID)
                {
                    METERING_STANDARD_DEVICE sys = new METERING_STANDARD_DEVICE {
                        ID = item
                    };
                    listEntityMETERING_STANDARD_DEVICE.Add(sys);
                    entity.METERING_STANDARD_DEVICE.Add(sys);
                }
            }

            PREPARE_SCHEME editEntity = repository.Edit(db, entity);


            if (addMETERING_STANDARD_DEVICEID != null && addMETERING_STANDARD_DEVICEID.Count() > 0)
            {
                foreach (var item in addMETERING_STANDARD_DEVICEID)
                {
                    METERING_STANDARD_DEVICE sys = new METERING_STANDARD_DEVICE {
                        ID = item
                    };
                    db.METERING_STANDARD_DEVICE.Attach(sys);
                    editEntity.METERING_STANDARD_DEVICE.Add(sys);
                    count++;
                }
            }
            if (deleteMETERING_STANDARD_DEVICEID != null && deleteMETERING_STANDARD_DEVICEID.Count() > 0)
            {
                foreach (METERING_STANDARD_DEVICE item in listEntityMETERING_STANDARD_DEVICE)
                {
                    editEntity.METERING_STANDARD_DEVICE.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑预备方案出错了");
            }
            return(false);
        }