/// <summary> /// 增加实体 /// </summary> /// <param name="model"></param> /// <returns></returns> public int AddModel(T model) { if (_trans != null) { return(_trans.Insert <T>(model)); } return(DBSession.CurrentSession.Insert <T>(model)); }
/// <summary> /// 保存用户 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool SaveExt(Mes_Sys_User obj) { int result = -1; try { using (DbTrans trans = this.CurDbSession.BeginTransaction()) { //1.保存用户 if (obj.ID > 0) { result = trans.Update <Mes_Sys_User>(obj); } else { result = trans.Insert <Mes_Sys_User>(obj); } if (result <= 0) { trans.Rollback(); return(false); } //2.保存用户角色、部门关系表 string sql = @"DELETE FROM Mes_Sys_Map WHERE UserID ='{0}'; INSERT INTO Mes_Sys_Map(UserID,RoleID,OrgID,RecordStatus,Creater,CreatedTime)VALUES('{0}',{1},{2},1,'{3}',GETDATE())"; sql = string.Format(sql, obj.UserID, obj.RoleID, obj.OrgID, obj.Creater); result = trans.FromSql(sql).ExecuteNonQuery(); if (result <= 0) { trans.Rollback(); return(false); } //提交事务 trans.Commit(); } } catch (System.Exception ex) { throw ex; } return(true); }
/// <summary> /// 新增会员 /// </summary> /// <param name="model"></param> /// <param name="head"></param> /// <param name="error"></param> /// <returns></returns> public bool InsertClient(ClientSearc model, HeadMessage head, out ErrorMessage error) { error = new ErrorMessage(); error.ErrNo = "0004"; DbTrans tran = null; DbBatch batch = null; try { #region 操作前验证 if (string.IsNullOrEmpty(model.C_UserID)) { error.ErrMsg = "新增会员时登录名称不能为空"; return(false); } if (string.IsNullOrEmpty(model.C_Name)) { error.ErrMsg = "新增会员时会员名称不能为空"; return(false); } if (string.IsNullOrEmpty(model.C_Pwd)) { error.ErrMsg = "新增会员时密码不能为空"; return(false); } if (string.IsNullOrEmpty(model.C_AID)) { error.ErrMsg = "新增会员时必须指定所属代理"; return(false); } #endregion string tableSql = SqlTemplateCommon.GetSql("T_GetAllT_Tables"); string oddSql = SqlTemplateCommon.GetSql("ClntOdds"); if (string.IsNullOrEmpty(tableSql) || string.IsNullOrEmpty(oddSql)) { error.ErrMsg = "服务端没有读取到T_GetAllT_Tables/oddSql数据模板,请联系管理员"; return(false); } List <TableModel> tableList = Db.Context_SqlServer.FromSql(tableSql).ToList <TableModel>(); //获取系统中的所有桌台 ClientOdds standardOdd = Db.Context_SqlServer.FromSql(oddSql).ToFirst <ClientOdds>(); //获取会员标准赔率对象 List <T_Authority> authList = new List <T_Authority>(); //给新增会员配置所有桌台权限 T_Client dbClnt = new T_Client(); T_ClientEx dbClntEx = new T_ClientEx(); T_OperationLog opLog = new T_OperationLog(); T_Agent pAgent = AgentListDAL.First(a => a.AgentID == model.C_AID); if (pAgent == null) { error.ErrMsg = "指定的所属代理无效,新增会员失败"; return(false); } if (model.C_WashR != null && model.C_WashR > pAgent.WashRate) { model.C_WashR = pAgent.WashRate; //如果新增会员的洗码率大于父级代理的洗码率则赋值为父级代理的洗码率 } if (pAgent.DrawRate == 0) //如果父级代理的和局率为0,则它的直属会员的和局率只能为0 { model.C_DrawR = 0; } else { if (pAgent.DrawRate > 0 && model.C_DrawR <= 0) { model.C_DrawR = pAgent.DrawRate; } else { if (model.C_DrawR != null && model.C_DrawR > pAgent.DrawRate) { model.C_DrawR = pAgent.DrawRate; //如果新增会员的和局率大于父级代理的和局率则赋值为父级代理的和局率 } } } if (model.C_MX_Z != null && model.C_MX_Z > pAgent.Max_Z) { model.C_MX_Z = pAgent.Max_Z; //如果新增会员的最大限红大于父级代理的最大限红则赋值为父级代理的最大限红 } if (model.C_MN_Z != null && model.C_MN_Z < pAgent.Min_Z) { model.C_MN_Z = pAgent.Min_Z; //如果新增会员的最小限红小于父级代理的最小限红则赋值为父级代理的最小限红 } #region 构造桌台权限 if (tableList != null && tableList.Count > 0) { foreach (var item in tableList) { T_Authority authority = new T_Authority(); authority.ClientID = model.C_ID; authority.TableID = item.T_ID; authority.Priority = "C"; if (model.C_MN_Z != null) { authority.Min_Z = model.C_MN_Z; authority.Min_ZD = model.C_MN_Z / 10; authority.Min_XD = model.C_MN_Z / 10; authority.Min_X = model.C_MN_Z; authority.Min_H = model.C_MN_Z / 10; } if (model.C_MX_Z != null) { authority.Max_ZD = model.C_MX_Z / 10; authority.Max_Z = model.C_MX_Z; authority.Max_XD = model.C_MX_Z / 10; authority.Max_X = model.C_MX_Z; authority.Max_H = model.C_MX_Z / 10; } authList.Add(authority); } } #endregion #region 构造新增会员对象 dbClnt.ClientID = Guid.NewGuid().ToString().Replace("-", ""); dbClnt.CreateID = head.LoginID; dbClnt.Balance = 0; dbClnt.Principal = 0; dbClnt.State = "YES";//新增会员默认为启用状态 dbClnt.CreateTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); dbClnt.AgentID = model.C_AID; dbClnt.ClientName = model.C_Name; dbClnt.LogName = model.C_UserID; dbClnt.F_2 = model.C_F2; dbClnt.IsHide = "FALSE"; dbClnt.Pwd = model.C_Pwd; if (model.C_WashT != null) { dbClnt.WashType = (model.C_WashT == true) ? "S" : "D"; } if (model.C_WashR != null) { dbClnt.WashRate = model.C_WashR; } if (model.C_DrawR != null) { dbClnt.DrawRate = model.C_DrawR; } if (model.C_MN_Z != null) { dbClnt.Min_H = model.C_MN_Z / 10; dbClnt.Min_X = model.C_MN_Z; dbClnt.Min_XD = model.C_MN_Z / 10; dbClnt.Min_Z = model.C_MN_Z; dbClnt.Min_ZD = model.C_MN_Z / 10; } if (model.C_MX_Z != null) { dbClnt.Max_H = model.C_MX_Z / 10; dbClnt.Max_X = model.C_MX_Z; dbClnt.Max_XD = model.C_MX_Z / 10; dbClnt.Max_Z = model.C_MX_Z; dbClnt.Max_ZD = model.C_MX_Z / 10; } #endregion #region 构造会员扩展对象 dbClntEx.ClientID = model.C_ID; dbClntEx.ClientDataShow = (model.C_HdShow == true) ? 2 : 1; if (model.C_ODF != null) { dbClntEx.Odds_Fu_Client = (model.C_ODF > 0) ? model.C_ODF : standardOdd.C_ODF; } if (model.C_ODH != null) { dbClntEx.Odds_H_Client = (model.C_ODH > 0) ? model.C_ODH : standardOdd.C_ODH; } if (model.C_ODHe != null) { dbClntEx.Odds_He_Client = (model.C_ODHe > 0) ? model.C_ODHe : standardOdd.C_ODHe; } if (model.C_ODL != null) { dbClntEx.Odds_Long_Client = (model.C_ODL > 0) ? model.C_ODL : standardOdd.C_ODL; } if (model.C_ODX != null) { dbClntEx.Odds_X_Client = (model.C_ODX > 0) ? model.C_ODX : standardOdd.C_ODX; } if (model.C_ODXD != null) { dbClntEx.Odds_XD_Client = (model.C_ODXD > 0) ? model.C_ODXD : standardOdd.C_ODXD; } if (model.C_ODZ != null) { dbClntEx.Odds_Z_Client = (model.C_ODZ > 0) ? model.C_ODZ : standardOdd.C_ODZ; } if (model.C_ODZD != null) { dbClntEx.Odds_ZD_Client = (model.C_ODZD > 0) ? model.C_ODZD : standardOdd.C_ODZD; } #endregion #region 构造操作日志对象 opLog.LogID = Guid.NewGuid().ToString().Replace("-", ""); opLog.LogInfo = DateTime.Now.ToString() + head.Account + "新增会员" + dbClnt.LogName; opLog.LogTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); //DateTime.Now.ToString(); opLog.OpID = head.LoginID; opLog.LogType = "新增会员"; #endregion tran = Db.Context_SqlServer.BeginTransaction(); batch = Db.Context_SqlServer.BeginBatchConnection(30, tran); tran.Insert <T_Client>(dbClnt); tran.Insert <T_ClientEx>(dbClntEx); batch.Insert <T_Authority>(authList.ToArray()); tran.Insert <T_OperationLog>(opLog); batch.Execute(); tran.Commit(); error.ErrMsg = "新增会员成功"; error.ErrNo = "0000"; return(true); } catch (Exception ex) { tran.Rollback(); Common.LogHelper.WriteLog(typeof(ClientListDAL), ex); error.ErrMsg = ex.Message.Replace("\r", "").Replace("\n", ""); return(false); } finally { if (batch != null) { batch.Close(); batch.Dispose(); } if (tran != null) { tran.Close(); tran.Dispose(); } } }