Exemple #1
0
        public DISTRICT DistrictAdd(string loginKey, ref ErrorInfo err, DISTRICT inEnt)
        {
            using (DBEntities db = new DBEntities())
            {
                YL_DISTRICT reEnt = Fun.ClassToCopy <ProInterface.Models.DISTRICT, YL_DISTRICT>(inEnt);
                #region 计算ID_PATH和Level_ID
                if (reEnt.PARENT_ID == null)
                {
                    reEnt.LEVEL_ID = 1;
                    reEnt.ID_PATH  = ".";
                }
                else
                {
                    var parent = db.YL_DISTRICT.Single(x => x.ID == reEnt.PARENT_ID);
                    if (parent == null)
                    {
                        reEnt.LEVEL_ID = 1;
                        reEnt.ID_PATH  = ".";
                    }
                    else
                    {
                        reEnt.ID_PATH  = parent.ID_PATH + reEnt.PARENT_ID + ".";
                        reEnt.LEVEL_ID = parent.LEVEL_ID + 1;
                    }
                }
                #endregion
                reEnt.ID = Fun.GetSeqID <YL_DISTRICT>();
                #region 计算REGION

                GlobalUser gu = Global.GetUser(loginKey);
                if (gu == null)
                {
                    reEnt.REGION = reEnt.ID.ToString();
                }
                else
                {
                    reEnt.REGION = gu.Region;
                }
                #endregion
                reEnt.CODE   = (string.IsNullOrEmpty(inEnt.CODE)) ? reEnt.ID.ToString() : inEnt.CODE;
                reEnt.IN_USE = 1;
                reEnt        = db.YL_DISTRICT.Add(reEnt);
                try
                {
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    return(Fun.ClassToCopy <YL_DISTRICT, DISTRICT>(reEnt));
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Exemple #2
0
        public bool DistrictEdit(string loginKey, ref ErrorInfo err, DISTRICT inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var reEnt = db.YL_DISTRICT.SingleOrDefault(a => a.ID == inEnt.ID);
                    if (reEnt.PARENT_ID != inEnt.PARENT_ID)
                    {
                        var parentOld = db.YL_DISTRICT.SingleOrDefault(x => x.ID == reEnt.PARENT_ID);
                        var pathOld   = (parentOld == null) ? "." : parentOld.ID_PATH + parentOld.ID + ".";
                        var parentNew = db.YL_DISTRICT.SingleOrDefault(x => x.ID == inEnt.PARENT_ID);
                        var pathNew   = (parentNew == null) ? "." : parentNew.ID_PATH + parentNew.ID + ".";
                        if (parentOld == null)
                        {
                            parentOld = new YL_DISTRICT();
                        }
                        if (parentNew == null)
                        {
                            parentNew = new YL_DISTRICT();
                        }
                        int levelChange = parentNew.LEVEL_ID - parentOld.LEVEL_ID;

                        reEnt.LEVEL_ID = parentNew.LEVEL_ID + 1;
                        reEnt.ID_PATH  = pathNew;
                        DistrictSetLevelId(reEnt.ID, reEnt.LEVEL_ID, reEnt.ID_PATH, db);
                        //var t = db.YL_DISTRICT.Where(x => x.ID_PATH.IndexOf(pathOld) == 0).Update(x => new YL_DISTRICT { ID_PATH = x.ID_PATH.Replace(pathOld, pathNew), LEVEL_ID = x.LEVEL_ID + levelChange });
                    }
                    else
                    {
                        var parentNew = db.YL_DISTRICT.SingleOrDefault(x => x.ID == inEnt.PARENT_ID);
                        if (parentNew == null)
                        {
                            reEnt.LEVEL_ID = 1;
                            reEnt.ID_PATH  = ".";
                        }
                        else
                        {
                            reEnt.LEVEL_ID = parentNew.LEVEL_ID + 1;
                            reEnt.ID_PATH  = parentNew.ID_PATH + parentNew.ID + ".";
                        }
                    }
                    reEnt = Fun.ClassToCopy <ProInterface.Models.DISTRICT, YL_DISTRICT>(inEnt, reEnt, allPar);

                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(false);
                }
            }
        }