Example #1
0
        public bool QuerySave(string loginKey, ref ErrorInfo err, QUERY inEnt, IList <string> allPar)
        {
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(false);
            }

            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }


            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var  ent   = db.YL_QUERY.SingleOrDefault(a => a.ID == inEnt.ID);
                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd = true;
                        ent   = Fun.ClassToCopy <ProInterface.Models.QUERY, YL_QUERY>(inEnt);
                    }
                    else
                    {
                        //if (!inEnt.QUERY_CONF.Equals(ent.QUERY_CONF))
                        //{
                        //    inEnt.QUERY_CONF = string.Format("--{0}于{1}修改\r\n{2}",gu.UserName,DateTime.Now.ToString(),inEnt.QUERY_CONF);
                        //}

                        ent = Fun.ClassToCopy <ProInterface.Models.QUERY, YL_QUERY>(inEnt, ent, allPar);
                    }

                    if (isAdd)
                    {
                        db.YL_QUERY.Add(ent);
                    }
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(false);
                }
            }
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="db"></param>
 /// <param name="err"></param>
 /// <returns></returns>
 public static bool DBEntitiesCommit(DBEntities db, ref ErrorInfo err)
 {
     try
     {
         db.SaveChanges();
         return(true);
     }
     catch (DbEntityValidationException e)
     {
         err.IsError = true;
         err.Message = Fun.GetDbEntityErrMess(e);
     }
     catch (Exception e)
     {
         err.IsError = true;
         err.Message = Fun.GetExceptionMessage(e);
     }
     finally {
     }
     return(false);
 }
Example #3
0
        public bool FlowSave(string loginKey, ref ErrorInfo err, TFlow ent)
        {
            using (DBEntities db = new DBEntities())
            {
                ent.FlowList = JSON.EncodeToEntity <IList <TFlowFlownodeFlow> >(ent.FlowListStr);
                ent.Idxy     = JSON.EncodeToEntity <IList <IdXY> >(ent.X_Y);

                if (string.IsNullOrEmpty(ent.FLOW_TYPE))
                {
                    ent.FLOW_TYPE = "默认";
                }

                var useId = ent.FlowList.Select(x => x.FROM_FLOWNODE_ID).ToList();
                foreach (var t in ent.FlowList)
                {
                    if (!useId.Contains(t.TO_FLOWNODE_ID))
                    {
                        useId.Add(t.TO_FLOWNODE_ID);
                    }
                }

                ent.Idxy = ent.Idxy.Where(x => useId.Contains(x.Id)).ToList();

                var flow = db.YL_FLOW.SingleOrDefault(x => x.ID == ent.ID);
                if (flow == null)
                {
                    flow    = Fun.ClassToCopy <TFlow, YL_FLOW>(ent);
                    flow.ID = Fun.GetSeqID <YL_FLOW>();
                    db.YL_FLOW.Add(flow);
                }
                else
                {
                    flow = Fun.ClassToCopy <TFlow, YL_FLOW>(ent, flow);
                }

                #region  除节点
                foreach (var t in flow.YL_FLOW_FLOWNODE_FLOW.ToList())
                {
                    if (ent.FlowList.Where(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID).Count() == 0)
                    {
                        t.YL_ROLE.Clear();
                        db.YL_FLOW_FLOWNODE_FLOW.Remove(t);
                    }
                }
                #endregion

                foreach (var t in ent.FlowList)
                {
                    if (!string.IsNullOrEmpty(t.AllRoleStr))
                    {
                        string[] tmpRoleArr = t.AllRoleStr.Trim().Split(',');
                        if (tmpRoleArr.Length > 0)
                        {
                            t.AllRoleIDList = tmpRoleArr.Select(x => Convert.ToInt32(x)).ToList();
                        }
                    }
                    var thisFlow = flow.YL_FLOW_FLOWNODE_FLOW.SingleOrDefault(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID);
                    if (thisFlow == null)
                    {
                        YL_FLOW_FLOWNODE_FLOW flowF = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t);

                        flowF.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList();
                        flowF.ID      = Fun.GetSeqID <YL_FLOW_FLOWNODE_FLOW>();
                        flowF.FLOW_ID = flow.ID;
                        db.YL_FLOW_FLOWNODE_FLOW.Add(flowF);
                    }
                    else
                    {
                        thisFlow = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t, thisFlow);
                        thisFlow.YL_ROLE.Clear();
                        thisFlow.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList();
                        thisFlow         = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t);
                    }
                }
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(false);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="inEnt">实体类</param>
        /// <param name="allPar">更新的参数</param>
        /// <returns>修改任务</returns>
        public bool TaskSave(string loginKey, ref ProInterface.ErrorInfo err, ProInterface.Models.TTask inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    GlobalUser gu = Global.GetUser(loginKey);
                    if (gu == null)
                    {
                        err.IsError = true;
                        err.Message = "登录超时";
                        return(false);
                    }
                    var          ent       = db.YL_TASK.SingleOrDefault(a => a.ID == inEnt.ID);
                    YL_TASK_FLOW taskFlow0 = new YL_TASK_FLOW();
                    bool         isAdd     = false;
                    if (ent == null)
                    {
                        isAdd = true;
                        if (inEnt.FLOW_ID != null && inEnt.FLOW_ID.Value != 0)
                        {
                            #region 非任务工单
                            YL_FLOW flow  = db.YL_FLOW.SingleOrDefault(x => x.ID == inEnt.FLOW_ID);
                            TNode   tnode = new TNode();
                            tnode.FlowID       = inEnt.FLOW_ID.Value;
                            tnode.TaskName     = inEnt.TASK_NAME;
                            tnode.AllFilesStr  = inEnt.AllFilesStr;
                            tnode.UserIdArrStr = inEnt.UserIdArrStr;
                            tnode.Remark       = inEnt.REMARK;
                            FunTask.StartTask(db, ref err, gu, tnode, inEnt.NowSubmitType);

                            #endregion
                        }
                        else
                        {
                            #region 任务工单
                            FunTask.StartTaskNoFlow(db, ref err, gu, inEnt.TASK_NAME, inEnt.REMARK, inEnt.AllFilesStr, inEnt.UserIdArrStr, inEnt.ROLE_ID_STR);
                            #endregion
                        }
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.TASK, YL_TASK>(inEnt, ent, allPar);
                    }
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(false);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(false);
                }
            }
        }
Example #5
0
        public TUser UserGetAndSave(string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    string nowLoginName = inEnt.LOGIN_NAME;
                    var    userEnt      = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    var    loginEnt     = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == nowLoginName);
                    if (userEnt == null)
                    {
                        userEnt             = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                        userEnt.ID          = Fun.GetSeqID <fa_user>();
                        userEnt.CREATE_TIME = DateTime.Now;
                        userEnt.LOGIN_COUNT = 0;
                        userEnt.REGION      = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION;
                        db.fa_user.Add(userEnt);
                    }

                    if (loginEnt == null)
                    {
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt);
                        loginEnt.ID       = Fun.GetSeqID <fa_login>();
                        loginEnt.PASSWORD = (string.IsNullOrEmpty(inEnt.PassWord)) ? AppSet.DefaultPwd.Md5() : inEnt.PassWord.Md5();
                        loginEnt.REGION   = userEnt.REGION;
                        db.fa_login.Add(loginEnt);
                    }

                    IList <int> allRoleId = userEnt.fa_role.Select(x => x.ID).ToList();
                    foreach (var t in inEnt.RoleAllID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList())
                    {
                        allRoleId.Add(t);
                    }
                    ;
                    userEnt.fa_role.Clear();
                    userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList();

                    db.SaveChanges();
                    inEnt    = Fun.ClassToCopy <fa_user, TUser>(userEnt, inEnt);
                    inEnt.ID = userEnt.ID;
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(inEnt);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(null);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(null);
                }
            }
        }
Example #6
0
        public object UserAdd(string loginKey, ref ErrorInfo err, TUser inEnt)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            using (DBEntities db = new DBEntities())
            {
                fa_user reEnt  = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                var     nowDis = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID);
                reEnt.CREATE_TIME = DateTime.Now;
                reEnt.DISTRICT_ID = nowDis.ID;
                reEnt.LOGIN_COUNT = 0;

                IList <int> moduleID = new List <int>();
                foreach (var str in inEnt.RoleAllID.Split(','))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        moduleID.Add(Convert.ToInt32(str));
                    }
                }
                reEnt.ID      = Fun.GetSeqID <fa_user>();
                reEnt.REGION  = nowDis.REGION;
                reEnt.fa_role = db.fa_role.Where(x => moduleID.Contains(x.ID)).ToList();
                reEnt.fa_district1.Clear();
                if (!string.IsNullOrEmpty(inEnt.UserDistrict))
                {
                    var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    reEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList();
                }
                reEnt = db.fa_user.Add(reEnt);

                fa_login login = new fa_login();
                login.ID         = Fun.GetSeqID <fa_login>();
                login.LOGIN_NAME = inEnt.LOGIN_NAME;
                if (!string.IsNullOrEmpty(inEnt.PassWord))
                {
                    login.PASSWORD = inEnt.PassWord.Md5();
                }
                else
                {
                    login.PASSWORD = AppSet.DefaultPwd.Md5();
                }
                login.PHONE_NO      = inEnt.PHONE_NO;
                login.IS_LOCKED     = inEnt.IS_LOCKED;
                login.LOCKED_REASON = inEnt.LOCKED_REASON;
                login.REGION        = reEnt.REGION;
                login = db.fa_login.Add(login);


                try
                {
                    db.SaveChanges();
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    return(reEnt.ID);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Example #7
0
        public IList <QueryCfg> QueryGetCfg(string loginKey, ref ErrorInfo err, string sql, string queryCode)
        {
            using (DBEntities db = new DBEntities())
            {
                var query = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);

                IList <QueryCfg> nowCfgList = new List <QueryCfg>();
                GlobalUser       gu         = Global.GetUser(loginKey);
                if (gu == null)
                {
                    err.IsError = true;
                    err.Message = "用户登录超时,请重新登录";
                    return(nowCfgList);
                }

                if (sql.IndexOf("<sql>") > -1)
                {
                    var xml = XmlHelper.Document.Load(sql);
                }



                sql = ReplacePer(sql, gu, null);


                DataTable dt = new DataTable();
                try
                {
                    dt = ExecuteGetNullTable(query.DB_SERVER_ID.Value, sql);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(nowCfgList);
                }
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    var            t          = dt.Columns[i];
                    var            tmp        = t.DataType.FullName.ToLower().Substring(t.DataType.FullName.IndexOf(".") + 1);
                    IList <string> numberList = new[] { "int", "decimal", "double", "int64", "int16" };
                    if (numberList.Contains(tmp))
                    {
                        tmp = "int";
                    }
                    string searchType   = "";
                    string searchScript = null;
                    switch (tmp)
                    {
                    case "int":
                        searchScript = "$('{@this}').numberbox({min:0,precision:0});";
                        searchType   = "numberbox";
                        break;

                    case "datetime":
                        searchScript = "$('{@this}').datetimebox({showSeconds: false,required: false});";
                        searchType   = "datetimebox";
                        break;

                    default:
                        searchType = "text";
                        break;
                    }

                    nowCfgList.Add(new QueryCfg()
                    {
                        FieldName    = t.ColumnName,
                        Show         = true,
                        FieldType    = t.DataType.FullName,
                        Width        = 0,
                        CanSearch    = true,
                        SearchType   = searchType,
                        SearchScript = searchScript,
                        Sortable     = true,
                        Alias        = t.Caption
                    });
                }
                #region 获取当前状态
                {
                    var queryEnt = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);
                    if (queryEnt != null)
                    {
                        IList <QueryCfg> old = JSON.EncodeToEntity <IList <QueryCfg> >(queryEnt.QUERY_CFG_JSON);
                        if (old != null)
                        {
                            for (int i = 0; i < nowCfgList.Count; i++)
                            {
                                var t0 = old.SingleOrDefault(x => x.FieldName == nowCfgList[i].FieldName);
                                if (t0 != null)
                                {
                                    nowCfgList[i] = t0;
                                }
                            }
                        }
                    }
                }
                #endregion
                return(nowCfgList);
            }
        }