public void TeacherDelete(Teacher entity, DbTrans tran) { if (tran == null) { tran = Gateway.Default.BeginTrans(); } try { tran.Delete <Teacher>(Teacher._.Th_ID == entity.Th_ID); tran.Delete <TeacherHistory>(TeacherHistory._.Th_ID == entity.Th_ID); tran.Update <Accounts>(new Field[] { Accounts._.Ac_IsTeacher }, new object[] { false }, Accounts._.Ac_ID == entity.Ac_ID); tran.Commit(); if (!string.IsNullOrWhiteSpace(entity.Th_Photo)) { WeiSha.WebControl.FileUpload.Delete("Teacher", entity.Th_Photo); } } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); tran.Dispose(); } Extend.LoginState.Accounts.Refresh(entity.Ac_ID); }
/// <summary> /// <param name="tran">事务</param> /// </summary> /// <param name="set"></param> /// <param name="tran"></param> /// <returns></returns> public LearningCard[] CardGenerate(LearningCardSet set, DbTrans tran) { int count = 0; //要生成的数量 int realcount = Gateway.Default.Count <LearningCard>(LearningCard._.Lcs_ID == set.Lcs_ID); //实际数量 //如果实际数量小于要生成的数量,则只生成差额 if (realcount < set.Lcs_Count) { count = set.Lcs_Count - realcount; } //如果实际数量小于要生成的数量,则删除多余(如果已经使用的过的,不可删除) if (realcount > set.Lcs_Count) { bool isNull = false; if (tran == null) { tran = Gateway.Default.BeginTrans(); isNull = true; } Song.Entities.LearningCard[] rcs = tran.From <LearningCard>().Where(LearningCard._.Lcs_ID == set.Lcs_ID && LearningCard._.Lc_IsUsed == false) .ToArray <LearningCard>(realcount - set.Lcs_Count); foreach (LearningCard r in rcs) { tran.Delete <LearningCard>(r); } if (isNull) { tran.Commit(); tran.Dispose(); tran.Close(); } return(null); } //生成学习卡 LearningCard[] cards = new LearningCard[count]; for (int i = 0; i < count; i++) { cards[i] = CardGenerate(set, i); } //判断是否重复 for (int i = 0; i < cards.Length; i++) { for (int j = 0; j < cards.Length; j++) { if (j <= i) { continue; } if (cards[i].Lc_Code == cards[j].Lc_Code) { cards[i] = CardGenerate(set, i * j + DateTime.Now.Millisecond); i = j = 0; } } } return(cards); }
public void Dispose() { if (DbTrans != null) { DbTrans.Dispose(); DbTrans = null; } if (DbConn != null) { DbConn.Dispose(); DbConn = null; } }
/// <summary> /// 结算会员洗码费 /// </summary> /// <param name="model"></param> /// <param name="head"></param> /// <param name="error"></param> /// <returns></returns> public bool SettleWashF(ClientSearc model, HeadMessage head, out ErrorMessage error) { error = new ErrorMessage(); error.ErrNo = "0004"; DbTrans trans = null; try { string strSql = Common.SqlTemplateCommon.GetSql("SetWashFlag"); string opSql = Common.SqlTemplateCommon.GetSql("SettleWashF"); if (string.IsNullOrEmpty(strSql) || string.IsNullOrEmpty(opSql)) { error.ErrMsg = "服务端没有读取到SetWashFlag数据模板,请联系管理员"; return(false); } string billID = Guid.NewGuid().ToString().Replace("-", ""); if (string.IsNullOrEmpty(model.C_ID) || string.IsNullOrEmpty(model.StartDate) || string.IsNullOrEmpty(model.EndDate)) { error.ErrMsg = "没有接收到正确的请求参数"; return(false); } strSql = strSql.Replace("${BillID}", billID); strSql = strSql.Replace("${ClientID}", model.C_ID); strSql = strSql.Replace("${SettleDate}", model.StartDate); strSql = strSql.Replace("${EndDate}", model.StartDate); opSql = opSql.Replace("${CreateID}", head.LoginID); opSql = opSql.Replace("${ClientID}", model.C_ID); opSql = opSql.Replace("${BillID}", billID); opSql = opSql.Replace("${IP}", head.Ip); opSql = opSql.Replace("${Address}", Common.CommonHelper.ipToAddr(head.Ip)); opSql = opSql.Replace("${Operator}", head.Account); opSql = opSql.Replace("${StartDate}", model.StartDate); opSql = opSql.Replace("${EndDate}", model.EndDate); trans = Db.Context_SqlServer.BeginTransaction(); SettleModel settle = trans.FromSql(strSql).ToFirst <SettleModel>(); if (settle != null) { opSql = opSql.Replace("${Counts}", settle.C_Counts.ToString()); opSql = opSql.Replace("${Point}", ((int)settle.C_Amount).ToString()); opSql = opSql.Replace("${WashRate}", settle.C_WashR); opSql = opSql.Replace("${WashSum}", settle.C_WashS.ToString()); error.ErrMsg = "洗码费结算成功"; trans.FromSql(opSql).ToDataSet(); trans.Commit(); return(true); } else { error.ErrMsg = "没有可结算的洗码费"; return(false); } } catch (Exception ex) { Common.LogHelper.WriteLog(typeof(ClientListDAL), ex); error.ErrMsg = ex.Message.Replace("\r", "").Replace("\n", ""); trans.Rollback(); return(false); } finally { if (trans != null) { trans.Close(); trans.Dispose(); } } }
/// <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(); } } }