/// <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); }
public bool SmsSendAdd(string loginKey, ref ErrorInfo err, string phone, string conten, int?messageId) { using (DBEntities db = new DBEntities()) { YL_SMS_SEND ent = new YL_SMS_SEND(); ent.KEY = Guid.NewGuid().ToString().Replace("-", ""); ent.MESSAGE_ID = messageId; ent.PHONE_NO = phone; ent.ADD_TIME = DateTime.Now; ent.CONTENT = conten; ent.STAUTS = "等待"; db.YL_SMS_SEND.Add(ent); try { db.SaveChanges(); } catch (DbEntityValidationException e) { err.IsError = true; err.Message = Fun.GetDbEntityErrMess(e); return(false); } return(true); } }
/// <summary> /// 修改登录 /// </summary> /// <param name="loginKey">登录凭证</param> /// <param name="err">错误信息</param> /// <param name="inEnt">实体类</param> /// <param name="allPar">更新的参数</param> /// <returns>修改登录</returns> public object Login_Save(string loginKey, ref ProInterface.ErrorInfo err, ProInterface.Models.LOGIN inEnt, IList <string> allPar) { using (DBEntities db = new DBEntities()) { try { var ent = Login_Save(db, loginKey, ref err, inEnt, allPar); db.SaveChanges(); return(ent); } catch (DbEntityValidationException e) { err.IsError = true; err.Message = Fun.GetDbEntityErrMess(e); return(null); } catch (Exception e) { err.IsError = true; err.Message = e.Message; return(null); } } }
public bool DataDownEventStart(string loginKey, ref ErrorInfo err, int downID) { if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(false); } GlobalUser gu = Global.GetUser(loginKey); using (DBEntities db = new DBEntities()) { var down = db.YL_DATA_DOWN.SingleOrDefault(x => x.ID == downID); // string s = GetSelectScript(down.SELECT_SCRIPT); //获得相对应的参数 //GetMonthPath(ref belongMonth, ref path, down.CREATE_TYPE, down.CREATE_TABLE_NAME); string tableName = Fun.ReplaceDataTime(down.CREATE_TABLE_NAME, DateTime.Now, loginKey); var eventEnt = new YL_DATA_DOWN_EVENT(); eventEnt.ID = Fun.GetSeqID <YL_DATA_DOWN_EVENT>(); eventEnt.TARGET_NAME = tableName; eventEnt.ALL_NUM = 0; eventEnt.LAST_MONTH_NUM = 0; eventEnt.PATH = down.TO_PATH; eventEnt.DATA_DOWN_ID = downID; eventEnt.START_TIME = DateTime.Now; eventEnt.USER_ID = gu.UserId; db.YL_DATA_DOWN_EVENT.Add(eventEnt); try { db.SaveChanges(); } catch (DbEntityValidationException dbEx) { err.IsError = true; err.Message = Fun.GetDbEntityErrMess(dbEx); return(false); } string createScript = ""; if (!string.IsNullOrEmpty(down.CREATE_SCRIPT)) { createScript = down.CREATE_SCRIPT.Replace("{@TABLE_NAME}", eventEnt.TARGET_NAME); } foreach (var to in down.YL_DATA_DOWN_TO.ToList()) { var toServer = to.YL_DB_SERVER; #region 在目标服务器上创建表 try { try { DbServerNonQuery(toServer.ID, "drop table " + eventEnt.TARGET_NAME); } catch (Exception e) { } DbServerNonQuery(toServer.ID, createScript); } catch (Exception e) { err.IsError = true; err.Message = "在服务器【" + toServer.NICKNAME + "】上建表失败:\r\nSQL:" + createScript + "\r\n" + e.Message; return(false); } #endregion foreach (var from in down.YL_DB_SERVER.ToList()) { YL_DATA_DOWN_TASK task = new YL_DATA_DOWN_TASK(); task.ID = Fun.GetSeqID <YL_DATA_DOWN_TASK>(); task.NAME = eventEnt.TARGET_NAME; task.SELECT_SCRIPT = down.SELECT_SCRIPT; task.EVENT_ID = eventEnt.ID; #region 替换SELECT_SCRIPT foreach (var replace in JSON.EncodeToEntity <IList <KV> >(to.REPLACE_STR)) { task.SELECT_SCRIPT = task.SELECT_SCRIPT.Replace(replace.K, replace.V); } task.SELECT_SCRIPT = Fun.ReplaceDataTime(task.SELECT_SCRIPT, DateTime.Now, loginKey); #endregion #region 生成@[00-99] if (task.SELECT_SCRIPT.IndexOf("@") != -1) { task.SELECT_SCRIPT = Fun.GetSelectScript(task.SELECT_SCRIPT); } #endregion //设置存放路径 task.TO_PATH = Fun.ReplaceDataTime(down.TO_PATH, DateTime.Now, loginKey); int thisAllNum = 0; task.ALL_NUM = thisAllNum; int upMonthNum = 0; task.LAST_MONTH_NUM = upMonthNum; task.SELECT_DB_SERVER = from.ID; task.SELECT_SERVER = string.Format("(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVER=DEDICATED)(SID={2})))", from.IP, from.PORT, from.DBNAME); task.SELECT_UID = from.UID; task.SELECT_PWD = from.PASSWORD; task.EVENT_TYPE = 1; if (down.SUCC_SCRIPT != null) { task.SUCC_SCRIPT = down.SUCC_SCRIPT.Replace("{@TABLE_NAME}", eventEnt.TARGET_NAME); } task.TO_DB_SERVER = toServer.ID; task.TO_SERVER = toServer.DBNAME; task.TO_UID = toServer.UID; task.TO_PWD = toServer.PASSWORD; task.CREATE_SCRIPT = createScript; task.ERROR_NUM = 0; task.STATUS = "等待"; task.PAGE_SIZE = down.PAGE_SIZE; task.SPLIT_STR = down.SPLIT_STR; task.IS_CANCEL = 0; task.ORDER_NUM = task.ID; db.YL_DATA_DOWN_TASK.Add(task); } } db.SaveChanges(); return(true); } }
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); }
/// <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); } } }
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); } } }
public TUser UserSave(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 { var idPar = allPar.SingleOrDefault(x => x == "ID"); if (idPar != null) { allPar.Remove(idPar); } var userEnt = db.fa_user.SingleOrDefault(a => a.ID == inEnt.ID); if (userEnt == null) { userEnt = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME); } var loginEnt = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME); bool isAdd = false; if (userEnt == null) { isAdd = true; userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt); if (userEnt.ID == 0) { 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; } else { if (db.fa_user.Where(x => x.LOGIN_NAME == inEnt.LOGIN_NAME && x.ID != userEnt.ID).Count() > 0) { err.IsError = true; err.Message = "登录工号已经存在"; return(null); } userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt, userEnt, allPar); } if (loginEnt == null) { loginEnt = Fun.ClassToCopy <TUser, fa_login>(inEnt); loginEnt.ID = Fun.GetSeqID <fa_login>(); loginEnt.PASSWORD = AppSet.DefaultPwd.Md5(); loginEnt.REGION = userEnt.REGION; db.fa_login.Add(loginEnt); } else { if (db.fa_login.Where(x => x.LOGIN_NAME == loginEnt.LOGIN_NAME && x.ID != loginEnt.ID).Count() > 0) { err.IsError = true; err.Message = "登录工号已经存在"; return(null); } loginEnt = Fun.ClassToCopy <TUser, fa_login>(inEnt, loginEnt, allPar); loginEnt.PHONE_NO = inEnt.PHONE_NO; } if (allPar.Contains("RoleAllID")) { IList <int> allRoleId = new List <int>(); allRoleId = inEnt.RoleAllID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList(); userEnt.fa_role.Clear(); userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList(); } if (isAdd) { db.fa_user.Add(userEnt); } userEnt.fa_district1.Clear(); if (!string.IsNullOrEmpty(inEnt.UserDistrict)) { var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList(); userEnt.fa_district1 = db.fa_district.Where(x => disArrList.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 (Exception e) { err.IsError = true; if (e.Message.IndexOf("EntityValidationErrors") > -1) { err.Message = Fun.GetDbEntityErrMess(e as DbEntityValidationException); } else { System.Data.Entity.Infrastructure.DbUpdateException t = e as System.Data.Entity.Infrastructure.DbUpdateException; err.Message = t.Message; } return(null); } } }
public object BulletinSave(string loginKey, ref ErrorInfo err, ProInterface.Models.TBulletin inEnt, IList <string> allPar) { if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(null); } using (DBEntities db = new DBEntities()) { GlobalUser gu = Global.GetUser(loginKey); inEnt.AllFiles = JSON.EncodeToEntity <IList <FILES> >(inEnt.AllFilesStr == null ? "[]" : inEnt.AllFilesStr); IList <int> fileIdList = inEnt.AllFiles.Select(x => x.ID).ToList(); if (string.IsNullOrEmpty(inEnt.AllRoleId)) { err.IsError = true; err.Message = string.Format("保存失败,没有选择可查看的角色", inEnt.AllRoleId); return(null); } IList <int> AllRoleId = inEnt.AllRoleId.Split(',').Select(x => Convert.ToInt32(x)).ToList(); YL_BULLETIN reEnt = new YL_BULLETIN(); if (inEnt.ID == 0) { reEnt = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt); reEnt.ID = Fun.GetSeqID <YL_BULLETIN>(); reEnt.YL_FILES = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList(); reEnt.YL_ROLE = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList(); reEnt.PUBLISHER = gu.UserName; reEnt.CREATE_TIME = DateTime.Now; reEnt.UPDATE_TIME = DateTime.Now; reEnt.REGION = gu.Region; reEnt.USER_ID = gu.UserId; reEnt = db.YL_BULLETIN.Add(reEnt); UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add); } else { reEnt = db.YL_BULLETIN.SingleOrDefault(x => x.ID == inEnt.ID); if (reEnt.USER_ID != gu.UserId) { err.IsError = true; err.Message = string.Format("该公告是【{0}】添加的,不能修改", reEnt.PUBLISHER); return(null); } reEnt = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt, reEnt, allPar); var allNowFiles = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList(); foreach (var t in reEnt.YL_FILES.ToList()) { if (allNowFiles.SingleOrDefault(x => x.ID == t.ID) == null) { reEnt.YL_FILES.Remove(t); db.YL_FILES.Remove(t); } } reEnt.YL_FILES.Clear(); reEnt.YL_ROLE.Clear(); reEnt.YL_ROLE = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList(); reEnt.YL_FILES = allNowFiles; reEnt.PUBLISHER = gu.UserName; reEnt.UPDATE_TIME = DateTime.Now; UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit); } try { //FunTask.StartTask(db, ref err, 1, "阅读公告信息", gu); db.SaveChanges(); return(reEnt.ID); } catch (DbEntityValidationException e) { err.IsError = true; err.Message = Fun.GetDbEntityErrMess(e); err.Excep = e; return(null); } } }