private void Submit(out string msg, int userID, out int retSiid) { msg = ""; retSiid = 0; int retsqid = 0; string datainfoStr = DataStr; SurveyInfoData sInfoData = null; sInfoData = (SurveyInfoData)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(datainfoStr, typeof(SurveyInfoData)); #region 验证数据正确性 if (sInfoData != null) { CheckData(sInfoData, out msg); if (msg != "") { return; } } else { msg += "获取数据出错"; return; } #endregion #region 准备数据 #region 定义变量 Entities.SurveyInfo sModel = null; Entities.SurveyQuestion qModel = null; Entities.SurveyOption oModel = null; Entities.SurveyMatrixTitle mModel = null; List <Entities.SurveyQuestion> qList = null; List <Entities.SurveyOption> oList = null; List <Entities.SurveyMatrixTitle> mList = null; List <Entities.SurveyOptionSkipQuestion> skipNewList = new List <SurveyOptionSkipQuestion>(); //要新加入的 List <Entities.SurveyOptionSkipQuestion> skipUpdateList = new List <SurveyOptionSkipQuestion>(); //要更新的 List <Entities.SurveyOptionSkipQuestion> skipDeleteList = new List <SurveyOptionSkipQuestion>(); //要删除的 List <Entities.SurveyQuestion> addQudstionList = new List <SurveyQuestion>(); List <Entities.SurveyOption> addOptionList = new List <SurveyOption>(); List <Entities.SurveyMatrixTitle> addMatrixList = new List <SurveyMatrixTitle>(); List <StringBuilder> listLogStr = new List <StringBuilder>(); //用户操作日志 StringBuilder sblogstr = new StringBuilder(); string logstr = ""; int intVal = 0; int existflog = 0; OptionSkip skipTemp = null; List <OptionSkip> skipListTemp = new List <OptionSkip>(); #endregion if (sInfoData.siid != "" && int.TryParse(sInfoData.siid, out intVal)) { int siid = int.Parse(sInfoData.siid); #region 编辑 #region 获取问卷 sModel = BLL.SurveyInfo.Instance.GetSurveyInfo(siid); #region 判断状态 if ((sModel.Status != 0 && sModel.Status != 1) && Action == "sub") { msg += "当前状态下不允许提交操作"; return; } if (sModel.Status != 0 && Action == "save") { msg += "当前状态下不允许保存操作"; return; } if (sModel.Status != 0 && Action == "preview") // || Action == "preview") { msg += "当前状态下不允许预览操作"; return; } #endregion #endregion #region 获取问题 qList = BLL.SurveyQuestion.Instance.GetSurveyQuestionList(siid); #endregion #region 获取选项 oList = BLL.SurveyOption.Instance.GetSurveyOptionList(siid); #endregion #region 获取矩阵标题 mList = BLL.SurveyMatrixTitle.Instance.GetMatrixTitleList(siid); #endregion if (sModel != null) { #region 修改问卷信息 sModel.Name = sInfoData.name; sModel.BGID = int.Parse(sInfoData.bgid); sModel.SCID = int.Parse(sInfoData.scid); sModel.Description = sInfoData.desc; if (Action == "sub") { sModel.Status = 1; sModel.IsAvailable = 1;//提交后是启用状态 } else { sModel.Status = 0; sModel.IsAvailable = -1;//不是提交,可用状态为空 } #region 记日志 sblogstr = new StringBuilder(); logstr = "更新了调查问卷‘" + sInfoData.name + "’的信息【ID:" + sModel.SIID + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion #endregion #region 修改问题 #region 判断是 新增 or 编辑 or 删除 #region 判断编辑和删除的 foreach (Entities.SurveyQuestion qitem in qList) { existflog = 0; if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == qitem.SQID.ToString()) { //有,就是编辑 existflog = 1; break; } } } if (existflog == 0) { //在页面传来的对象中没有,是删除 qitem.actionFlog = -1; #region 记日志 sblogstr = new StringBuilder(); logstr = "删除了调查问卷【" + sInfoData.name + "】下的问题‘" + qitem.Ask + "’【SQID:" + qitem.SQID + ",SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } else { qitem.actionFlog = 0; } } #endregion #region 判断新加的问题 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { existflog = 0; foreach (Entities.SurveyQuestion qitem in qList) { if (qitem.SQID.ToString() == qDataItem.sqid) { existflog = 1; } } if (existflog == 0) { //没找到,就是新加的 qModel = new SurveyQuestion(); qModel.SIID = siid; qModel.Ask = qDataItem.ask; qModel.AskCategory = int.Parse(qDataItem.askcategory); qModel.SQID = int.Parse(qDataItem.sqid); qModel.ShowColumnNum = int.Parse(qDataItem.showcolumnnum); qModel.MaxTextLen = int.Parse(qDataItem.maxtextlen); qModel.MinTextLen = int.Parse(qDataItem.mintextlen); qModel.Status = 0; qModel.OrderNum = int.Parse(qDataItem.ordernum); qModel.CreateTime = DateTime.Now; qModel.CreateUserID = userID; qModel.ModifyTime = DateTime.Now; qModel.ModifyUserID = userID; qModel.IsMustAnswer = int.Parse(qDataItem.IsMustAnswer); qModel.IsStatByScore = int.Parse(qDataItem.IsStatByScore); qModel.QuestionLinkId = int.Parse(qDataItem.QuestionLinkId); addQudstionList.Add(qModel); #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】下的问题‘" + qDataItem.ask + "’【SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } } #endregion #endregion #region 修改编辑的问题 foreach (Entities.SurveyQuestion qitem in qList) { if (qitem.actionFlog == 0) //是编辑 { if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == qitem.SQID.ToString()) { qitem.Ask = qDataItem.ask; qitem.ShowColumnNum = int.Parse(qDataItem.showcolumnnum); qitem.MaxTextLen = int.Parse(qDataItem.maxtextlen); qitem.MinTextLen = int.Parse(qDataItem.mintextlen); qitem.OrderNum = int.Parse(qDataItem.ordernum); qitem.ModifyTime = DateTime.Now; qitem.ModifyUserID = userID; qitem.IsMustAnswer = int.Parse(qDataItem.IsMustAnswer); qitem.IsStatByScore = int.Parse(qDataItem.IsStatByScore); qitem.QuestionLinkId = int.Parse(qDataItem.QuestionLinkId); } } } } } #endregion #endregion #region 修改选项 #region 判断编辑和删除 foreach (Entities.SurveyOption oItem in oList) { existflog = 0; if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == oItem.SQID.ToString()) { if (qDataItem.option != null) { foreach (SurveyOptionInfoData oinfoItem in qDataItem.option) { if (oinfoItem.sqid == oItem.SQID.ToString() && oinfoItem.soid == oItem.SOID.ToString()) { existflog = 1;//找到了,就是编辑 break; } } } } } } if (existflog == 1) { //编辑 oItem.actionFlog = 0; } else { //没找到,就是删除 oItem.actionFlog = -1; #region 记日志 sblogstr = new StringBuilder(); logstr = "删除了调查问卷【" + sInfoData.name + "】中的选项‘" + oItem.OptionName + "’【SOID:" + oItem.SOID + ",SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } #endregion #region 判断新增 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.option != null) { foreach (SurveyOptionInfoData oinfoItem in qDataItem.option) { if (int.Parse(oinfoItem.soid) < 0) { //新增的 oModel = new SurveyOption(); oModel.SOID = int.Parse(oinfoItem.soid); oModel.SIID = siid; oModel.SQID = int.Parse(oinfoItem.sqid); oModel.OptionName = oinfoItem.optionname; oModel.IsBlank = int.Parse(oinfoItem.isblank); oModel.Score = int.Parse(oinfoItem.score); oModel.OrderNum = int.Parse(oinfoItem.ordernum); oModel.Status = 0; oModel.CreateTime = DateTime.Now; oModel.CreateUserID = userID; oModel.ModifyTime = DateTime.Now; oModel.ModifyUserID = userID; oModel.linkid = int.Parse(oinfoItem.linkid); addOptionList.Add(oModel); #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】中的选项‘" + oModel.OptionName + "’【SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } } } } #endregion #region 修改编辑的选项 foreach (Entities.SurveyOption oitem in oList) { if (oitem.actionFlog == 0) //是编辑 { if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.option != null) { foreach (SurveyOptionInfoData oDataItem in qDataItem.option) { if (oDataItem.soid == oitem.SOID.ToString()) { oitem.OptionName = oDataItem.optionname; oitem.IsBlank = int.Parse(oDataItem.isblank); oitem.Score = int.Parse(oDataItem.score); oitem.OrderNum = int.Parse(oDataItem.ordernum); oitem.ModifyTime = DateTime.Now; oitem.ModifyUserID = userID; oitem.linkid = int.Parse(oDataItem.linkid); } } } } } } } #endregion #endregion #region 修改矩阵 #region 判断编辑和删除 foreach (Entities.SurveyMatrixTitle mItem in mList) { existflog = 0;//从页面对象中找 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == mItem.SQID.ToString()) { if (qDataItem.matrix != null) { foreach (SurveyMatiexInfoData minfoItem in qDataItem.matrix) { if (minfoItem.sqid == mItem.SQID.ToString() && minfoItem.smtid == mItem.SMTID.ToString()) { existflog = 1;//找到了,就是编辑 break; } } } } } } if (existflog == 1) { //编辑 mItem.actionFlog = 0; } else { //没找到,就是删除 mItem.actionFlog = -1; #region 记日志 sblogstr = new StringBuilder(); logstr = "删除了调查问卷【" + sInfoData.name + "】中的矩阵标题‘" + mItem.TitleName + "’【SMTID:" + mItem.SMTID + ",SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } #endregion #region 判断新增 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.matrix != null) { foreach (SurveyMatiexInfoData minfoItem in qDataItem.matrix) { if (minfoItem.smtid == "") { //新增的 mModel = new SurveyMatrixTitle(); mModel.SIID = siid; mModel.SQID = int.Parse(minfoItem.sqid); mModel.TitleName = minfoItem.titlename; mModel.Status = 0; mModel.Type = int.Parse(minfoItem.type); mModel.CreateUserID = userID; mModel.CreateTime = DateTime.Now; addMatrixList.Add(mModel); #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】中的矩阵标题‘" + mModel.TitleName + "’【SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } } } } #endregion #region 修改编辑的矩阵 foreach (Entities.SurveyMatrixTitle mitem in mList) { if (mitem.actionFlog == 0) //是编辑 { if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.matrix != null) { foreach (SurveyMatiexInfoData mDataItem in qDataItem.matrix) { if (mDataItem.smtid == mitem.SMTID.ToString()) { mitem.TitleName = mDataItem.titlename; mitem.Type = int.Parse(mDataItem.type); } } } } } } } #endregion #endregion } else { msg += "没找到相应问卷<br/>"; } #endregion } else { //新增 #region 问卷实体类 sModel = new Entities.SurveyInfo(); sModel.Name = sInfoData.name; sModel.BGID = int.Parse(sInfoData.bgid); sModel.SCID = int.Parse(sInfoData.scid); sModel.Description = sInfoData.desc; if (Action == "sub") { sModel.Status = 1; sModel.IsAvailable = 1;//提交后是启用状态 } else { sModel.Status = 0; sModel.IsAvailable = -1;//不是提交,可用状态为空 } sModel.CreateTime = DateTime.Now; sModel.CreateUserID = userID; #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion #endregion #region 问卷问题 qList = new List <Entities.SurveyQuestion>(); oList = new List <Entities.SurveyOption>(); mList = new List <Entities.SurveyMatrixTitle>(); if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData item in sInfoData.questList) { #region 问卷问题 qModel = new Entities.SurveyQuestion(); qModel.SQID = int.Parse(item.sqid); qModel.Ask = item.ask; qModel.AskCategory = int.Parse(item.askcategory); qModel.ShowColumnNum = int.Parse(item.showcolumnnum); qModel.MaxTextLen = int.Parse(item.maxtextlen); qModel.MinTextLen = int.Parse(item.mintextlen); qModel.Status = 0; qModel.OrderNum = int.Parse(item.ordernum); qModel.CreateTime = DateTime.Now; qModel.CreateUserID = userID; qModel.ModifyTime = DateTime.Now; qModel.ModifyUserID = userID; qModel.IsMustAnswer = int.Parse(item.IsMustAnswer); qModel.IsStatByScore = int.Parse(item.IsStatByScore); qModel.QuestionLinkId = int.Parse(item.QuestionLinkId); qList.Add(qModel); #endregion #region 问卷选项 if (item.option != null) { foreach (SurveyOptionInfoData oitem in item.option) { if (oitem.sqid == item.sqid) { oModel = new Entities.SurveyOption(); oModel.SOID = int.Parse(oitem.soid); oModel.SQID = int.Parse(oitem.sqid); oModel.OptionName = oitem.optionname; oModel.IsBlank = int.Parse(oitem.isblank); oModel.Score = int.Parse(oitem.score); oModel.OrderNum = int.Parse(oitem.ordernum); oModel.Status = 0; oModel.CreateTime = DateTime.Now; oModel.CreateUserID = userID; oModel.ModifyTime = DateTime.Now; oModel.ModifyUserID = userID; oModel.linkid = int.Parse(oitem.linkid); oList.Add(oModel); } } } #endregion #region 问卷矩阵标题 if (item.matrix != null) { foreach (SurveyMatiexInfoData mitem in item.matrix) { if (mitem.sqid == item.sqid) { mModel = new Entities.SurveyMatrixTitle(); mModel.SQID = int.Parse(mitem.sqid); mModel.TitleName = mitem.titlename; mModel.Status = 0; mModel.Type = int.Parse(mitem.type); mModel.CreateTime = DateTime.Now; mModel.CreateUserID = userID; mList.Add(mModel); } } } #endregion } } #endregion } #endregion #region 建立选项与跳题对照 if (oList != null) { foreach (Entities.SurveyOption oItem in oList) { skipTemp = new OptionSkip(); skipTemp.Soid = oItem.SOID; skipTemp.Sqid = (int)oItem.SQID; skipTemp.LinkId = oItem.linkid; skipListTemp.Add(skipTemp); } } if (addOptionList != null) { foreach (Entities.SurveyOption oItem in addOptionList) { skipTemp = new OptionSkip(); skipTemp.Soid = oItem.SOID; skipTemp.Sqid = (int)oItem.SQID; skipTemp.LinkId = oItem.linkid; skipListTemp.Add(skipTemp); } } #endregion #region 提交事务 string connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC"); SqlConnection connection = new SqlConnection(connectionstrings); connection.Open(); SqlTransaction tran = connection.BeginTransaction("SampleTransaction"); try { if (sInfoData.siid != "" && int.TryParse(sInfoData.siid, out intVal)) { //编辑 retSiid = int.Parse(SIID); #region 编辑问卷 BLL.SurveyInfo.Instance.Update(tran, sModel); #endregion #region 编辑问题 #region 除、编辑问题 foreach (Entities.SurveyQuestion qitem in qList) { if (qitem.actionFlog == 0) { //编辑 BLL.SurveyQuestion.Instance.Update(tran, qitem); //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.LinkId == qitem.QuestionLinkId) { skipItem.LinkId = qitem.SQID; } } } else if (qitem.actionFlog == -1) { //删除 retsqid = BLL.SurveyQuestion.Instance.Delete(tran, qitem.SQID); } } #endregion #region 添加问题 foreach (Entities.SurveyQuestion qItem in addQudstionList) { retsqid = BLL.SurveyQuestion.Instance.Insert(tran, qItem); if (retsqid > 0) { //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Sqid == qItem.SQID)//新增的SQID都是 临时负数 { skipItem.Sqid = retsqid; } if (skipItem.LinkId == qItem.QuestionLinkId) { skipItem.LinkId = retsqid; } } //维护选项的问卷ID foreach (Entities.SurveyOption oItem in addOptionList) { if (oItem.SQID == qItem.SQID) { oItem.SQID = retsqid; } } //维护矩阵的问卷ID foreach (Entities.SurveyMatrixTitle mItem in addMatrixList) { if (mItem.SQID == qItem.SQID) { mItem.SQID = retsqid; } } } else { msg += "添加问题失败"; return; } } #endregion #endregion #region 添加选项 #region 除、编辑选项 foreach (Entities.SurveyOption oItem in oList) { if (oItem.actionFlog == 0) { //编辑选项 BLL.SurveyOption.Instance.Update(tran, oItem); } else if (oItem.actionFlog == -1) { BLL.SurveyOption.Instance.Delete(tran, oItem.SOID); } } #endregion #region 添加选项 foreach (Entities.SurveyOption oItem in addOptionList) { int retSOID = BLL.SurveyOption.Instance.Insert(tran, oItem); if (retSOID > 0) { //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Soid == oItem.SOID) { skipItem.Soid = retSOID; } } } } #endregion #endregion #region 添加矩阵标题 #region 除、编辑矩阵标题 foreach (Entities.SurveyMatrixTitle mItem in mList) { if (mItem.actionFlog == 0) { //编辑选项 BLL.SurveyMatrixTitle.Instance.Update(tran, mItem); } else if (mItem.actionFlog == -1) { BLL.SurveyMatrixTitle.Instance.Delete(tran, mItem.SMTID); } } #endregion #region 添加矩阵标题 foreach (Entities.SurveyMatrixTitle mItem in addMatrixList) { BLL.SurveyMatrixTitle.Instance.Insert(tran, mItem); } #endregion #endregion } else { #region 保存问卷 retSiid = BLL.SurveyInfo.Instance.Insert(tran, sModel); #endregion #region 保存问题 foreach (SurveyQuestion qitem in qList) { qitem.SIID = retSiid; retsqid = BLL.SurveyQuestion.Instance.Insert(tran, qitem); //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Sqid == qitem.SQID)//新增的SQID都是 临时负数 { skipItem.Sqid = retsqid; } if (skipItem.LinkId == qitem.QuestionLinkId) { skipItem.LinkId = retsqid; } } #region 保存问题选项 foreach (SurveyOption oitem in oList) { if (oitem.SQID == qitem.SQID) { oitem.SIID = retSiid; oitem.SQID = retsqid; int retSoid = BLL.SurveyOption.Instance.Insert(tran, oitem); //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Soid == oitem.SOID) { skipItem.Soid = retSoid; } } } } #endregion #region 保存矩阵标题 foreach (SurveyMatrixTitle mitem in mList) { if (mitem.SQID == qitem.SQID) { mitem.SIID = retSiid; mitem.SQID = retsqid; BLL.SurveyMatrixTitle.Instance.Insert(tran, mitem); } } #endregion } #endregion } #region 更新选项跳题对照表 foreach (OptionSkip item in skipListTemp) { Entities.SurveyOptionSkipQuestion curskipModel = null; curskipModel = BLL.SurveyOptionSkipQuestion.Instance.GetModelBySoid(item.Soid); if (curskipModel != null) { //存在跳题 if (item.LinkId == 0) { skipDeleteList.Add(curskipModel); } else { if (curskipModel.SQID != item.LinkId) { //如果跳题有改变 curskipModel.SQID = item.LinkId; skipUpdateList.Add(curskipModel); // BLL.SurveyOptionSkipQuestion.Instance.Update(tran,curskipModel); } } } else { //不存在 if (item.LinkId != 0) { //,就插入 curskipModel = new SurveyOptionSkipQuestion(); curskipModel.SOID = item.Soid; curskipModel.SQID = item.LinkId; curskipModel.Status = 0; skipNewList.Add(curskipModel); // BLL.SurveyOptionSkipQuestion.Instance.Insert(tran,curskipModel); } } } foreach (Entities.SurveyOptionSkipQuestion item in skipDeleteList) { BLL.SurveyOptionSkipQuestion.Instance.Delete(tran, item.RecID); } foreach (Entities.SurveyOptionSkipQuestion item in skipUpdateList) { BLL.SurveyOptionSkipQuestion.Instance.Update(tran, item); } foreach (Entities.SurveyOptionSkipQuestion item in skipNewList) { BLL.SurveyOptionSkipQuestion.Instance.Insert(tran, item); } #endregion #region 保存用户操作日志 foreach (StringBuilder sbStr in listLogStr) { BLL.Util.InsertUserLog(tran, sbStr.ToString()); } #endregion tran.Commit(); } catch (Exception ex) { if (tran.Connection != null) { tran.Rollback(); } msg = ex.Message.ToString(); } finally { connection.Close(); } #endregion }
private RaceControlLogic() { var configuration = ConfigurationUtil.GetConfiguration(); connectionFactory = DefaultConnectionFactory.FromConfiguration(configuration, "HuraceDbConnection"); }
public void Setup() { configuration = ConfigurationUtil.GetConfiguration(); connectionFactory = DefaultConnectionFactory.FromConfiguration(configuration, "HuraceDbConnection"); raceDataDao = new AdoRaceDataDao(connectionFactory); }
protected override CommandResult <Hashtable> OnExecute(object commandParameter) { var result = new CommandResult <Hashtable>(); var param = commandParameter as DrawPrizeParameter; result.Data = new Hashtable(); using (CoreContext context = new CoreContext()) { var act = context.ActivityInfo.Where(a => a.StartTime <= DateTime.Now && a.EndTime >= DateTime.Now && a.Status == 1 && a.Kind == param.Kind).FirstOrDefault(); if (act == null) { result.ErrorCode = -1; result.ErrorMessage = "活动已结束"; return(result); } Hashtable pconfig = JsonConvert.DeserializeObject <Hashtable>(act.ProductConfig); var zlopenid = context.MemberInfo.Where(m => m.AccountId == param.MemberAccount).Select(m => m.ZlOpenId).FirstOrDefault(); //扣减次数,使用数据库锁 if (context.Database.ExecuteSqlCommand(@"update member_draw_count set current_count=(current_count-1) where member_account=@p0 and current_count-1>=0", zlopenid) > 0) { var LogCount = context.ActivityLog.Where(l => l.MemberAccount == zlopenid && l.ActivityId == act.Recid).Count(); var res = new NewMemberSkillCommand().Execute(new NewMemberSkillParameter() { MemberAccount = zlopenid, LogCount = LogCount, Prize = pconfig }); Hashtable prize = null; if (res.ErrorCode == 0 && (Convert.ToBoolean(res.Data["isNew"]) || Convert.ToBoolean(res.Data["is30"]))) { result.ErrorCode = res.ErrorCode; result.ErrorMessage = res.ErrorMessage; prize = res.Data["Prize"] as Hashtable; } else { var connect = ConfigurationUtil.GetSection("ConnectionStrings")["ShopConnectString"]; decimal payFee = 0; using (MySqlConnection con = new MySqlConnection(connect)) { con.Open(); MySqlCommand com1 = new MySqlCommand("select sum(payment_fee) as PayFee from shop_order_info " + "where member_account=?acc and pay_status=1 and order_no like '%00' and date(payment_time)>='2018-11-01' and date(payment_time)<='2018-11-11' ", con); com1.Parameters.Add(new MySqlParameter("?acc", zlopenid)); var Reader1 = com1.ExecuteReader(); while (Reader1.Read()) { if (Reader1["PayFee"] != DBNull.Value) { payFee = Convert.ToDecimal(Reader1["PayFee"]); } } Reader1.Close(); con.Close(); } //遍历奖品规则 var redisdb = RedisClient.GetDatabase(1); foreach (var item in (pconfig["PayPrize"] as JArray).ToObject <List <Hashtable> >()) { JObject condiction = item["Condition"] as JObject; string key = "level:" + condiction["Fee"].Value <string>(); if (redisdb.HashExists(key, param.MemberAccount)) { continue; } if (payFee >= condiction["Fee"].Value <decimal>()) { prize = (item["Prize"] as JObject).ToObject <Hashtable>(); //处理实物奖品 if (prize["Kind"] as string == "RealPrize") { //var hash = (prize["RealPrize"] as JObject).ToObject<Hashtable>(); var _realprize = new List <PrizeModel>(); foreach (var hash in (prize["RealPrize"] as JArray).ToObject <List <Hashtable> >()) { if (DateTime.Parse(hash["start"] as string) <= DateTime.Now && DateTime.Parse(hash["end"] as string) >= DateTime.Now) { _realprize.Add(new PrizeModel() { PrizeCode = hash["PrizeCode"] as string, PrizeName = hash["PrizeName"] as string, Kind = prize["Kind"] as string }); } } string RealPrize = ""; if (_realprize.Count != 0) { var r = new Random(Guid.NewGuid().GetHashCode()); var index = r.Next(0, _realprize.Count); RealPrize = redisdb.ListLeftPop("Prize:" + _realprize[index].PrizeCode); } if (!string.IsNullOrEmpty(RealPrize)) { prize = JsonConvert.DeserializeObject <Hashtable>(RealPrize); } else { prize = null; } } if (prize != null) { redisdb.HashIncrementAsync(key, param.MemberAccount); } break; } } } if (prize != null) { result.Data = prize; var p = new PrizeInfo() { Status = 1, ActId = act.Recid, CouponId = Convert.ToInt32(prize["CouponId"]), CreateDate = DateTime.Now, MemberAccount = zlopenid, PrizeCode = prize["PrizeCode"] as string, PrizeName = prize["PrizeName"] as string, Kind = prize["Kind"] as string, }; context.PrizeInfo.Add(p); if (prize["Kind"] as string == "Coupon") { //调用获取优惠券 var url = ConfigurationUtil.GetSection("CouponUrl").Value as string; //领取抵扣优惠券 try { ActiveMQMessagePusher.Push("Command", new Dictionary <string, string> { { "caller", "Restful" }, { "url", url } }, new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) } ); } catch (Exception) { } //var couponres = ZlanAPICaller.Call<CommandResult<string>>(url, new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) }); //if (couponres.ErrorCode == 0) //{ // couponticket = couponres.Data; //} //else //{ // LogUtil.Log("DrawPrize_TakeCoupon", p.Recid.ToString(), $"input=>{JsonConvert.SerializeObject(new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) })}#error=>{res.ErrorMessage}"); //} } } else { result.ErrorMessage = "未中奖,换个姿势再试试吧"; result.ErrorCode = -22; } } else { result.ErrorCode = -21; result.ErrorMessage = "每下单68元,即获得一次抽奖机会,上不封顶"; } context.ActivityLog.Add(new ActivityLog() { MemberAccount = zlopenid, ActivityId = act.Recid, CreateTime = DateTime.Now, Memo = result.Data.Keys.Count > 0 ? "抽中:" + result.Data["PrizeName"] as string : result.ErrorMessage }); context.SaveChanges(); } return(result); }
/// <summary> /// 对于memberInfo 或者 parameterInfo 进行设值 /// </summary> /// <param name="context"></param> /// <param name="classType"></param> /// <param name="memberType"></param> /// <param name="memberInfo"></param> /// <param name="parameterInfo"></param> /// <returns></returns> private object Resolve(IComponentContext context, Type classType, Type memberType, MemberInfo memberInfo, ParameterInfo parameterInfo = null) { if (classType == null) { return(null); } if (string.IsNullOrEmpty(this.value)) { return(null); } try { if (!this.value.StartsWith("#{") || !this.value.EndsWith("}")) { var parameterValue = this.value; var parseValue = parameterInfo == null ? TypeManipulation.ChangeToCompatibleType(parameterValue, memberType, memberInfo) : TypeManipulation.ChangeToCompatibleType(parameterValue, memberType, parameterInfo); return(parseValue); } else { var key = this.value.Substring(2, this.value.Length - 3)?.Trim(); var componentModelCacheSingleton = context.Resolve <ComponentModelCacheSingleton>(); if (componentModelCacheSingleton.ComponentModelCache.TryGetValue(classType, out ComponentModel component)) { foreach (var metaSource in component.MetaSourceList) { if (metaSource.Configuration == null) { continue; } IConfigurationSection metData = metaSource.Configuration.GetSection(key); var parameterValue = ConfigurationUtil.GetConfiguredParameterValue(metData); if (parameterValue == null) { //表示key不存在 从下一个source里面去寻找 continue; } var parseValue = parameterInfo == null ? TypeManipulation.ChangeToCompatibleType(parameterValue, memberType, memberInfo) : TypeManipulation.ChangeToCompatibleType(parameterValue, memberType, parameterInfo); return(parseValue); } } } return(null); } catch (Exception ex) { throw new DependencyResolutionException($"Value set error,can not resolve class type:{classType.FullName} =====>" + $" {(parameterInfo == null?memberType.Name:parameterInfo.Name)} " + (!string.IsNullOrEmpty(this.value) ? $",with value:[{this.value}]" : ""), ex); } }
public Result <bool> EditUser(User u) { Result <bool> rlt = new Result <bool>(); try { var rptrlt = IsRepeat(u); if (rptrlt.Entities) { rlt.Entities = false; rlt.Msg = rptrlt.Msg; } else { //判断图片发生变化 bool imgChange = false; var old = Db.Users.AsNoTracking().First(p => p.Id == u.Id); if (old.ImagePath != u.ImagePath) { imgChange = true; } var entity = Db.Entry(u); entity.State = System.Data.Entity.EntityState.Modified; Db.SaveChanges(); if (!string.IsNullOrEmpty(u.ImagePath) && imgChange) { try { if (System.IO.File.Exists(u.ImagePath)) { string imgPath = System.IO.Path.Combine(ConfigurationUtil.GetConfiguration("ImageDir"), Guid.NewGuid() + ".jpg"); System.IO.File.Copy(u.ImagePath, imgPath); //查询用户是否存在 string result = FaceInit.test_get_user_info(u.Id); var faceRlt = JsonConvert.DeserializeObject <FaceResut>(result); if (faceRlt.errno == 0) { if (faceRlt.data.result == null || faceRlt.data.result.Count == 0) { result = FaceInit.test_user_add(u.Id.ToString(), imgPath); } else { result = FaceInit.test_user_update(u.Id.ToString(), imgPath); } faceRlt = JsonConvert.DeserializeObject <FaceResut>(result); if (faceRlt.errno == 0)//成功 { try { System.IO.File.Delete(old.ImagePath); } catch (Exception ex) { } u.ImagePath = imgPath; u.FaceToken = faceRlt.data.face_token; } else//失败 { u.ImagePath = ""; rlt.HasError = true; rlt.Msg = "人脸识别信息更新失败,请使用【用户编辑】功能重新录入人脸信息!\r\n" + FaceErrors.GetFaceError(faceRlt.errno); } } else { u.ImagePath = ""; rlt.HasError = true; rlt.Msg = "人脸识别信息更新失败,请使用【用户编辑】功能重新录入人脸信息!\r\n" + FaceErrors.GetFaceError(faceRlt.errno); } Db.SaveChanges(); } } catch (Exception ex) { LogUtil.WriteLog(ex); rlt.HasError = true; rlt.Msg = "人脸识别信息更新失败,请使用【用户编辑】功能重新录入人脸信息!\r\n" + ex.Message; } } } } catch (Exception ex) { LogUtil.WriteLog(ex); rlt.HasError = true; rlt.Msg = ex.Message; } return(rlt); }
public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { name = "NHibernateMembershipProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "NHibernate Membership Provider"); } base.Initialize(name, config); application = SystemApplicationWrapper.CreateOrLoadApplication(SystemApplicationWrapper.BaseSystemApplicationName); requiresQuestionAndAnswer = Convert.ToBoolean(ConfigurationUtil.GetConfigValue(config["requiresQuestionAndAnswer"], "False")); requiresUniqueEmail = Convert.ToBoolean(ConfigurationUtil.GetConfigValue(config["requiresUniqueEmail"], "True")); enablePasswordRetrieval = Convert.ToBoolean(ConfigurationUtil.GetConfigValue(config["enablePasswordRetrieval"], "True")); enablePasswordReset = Convert.ToBoolean(ConfigurationUtil.GetConfigValue(config["enablePasswordReset"], "True")); maxInvalidPasswordAttempts = Convert.ToInt32(ConfigurationUtil.GetConfigValue(config["maxInvalidPasswordAttempts"], "5")); passwordAttemptWindow = Convert.ToInt32(ConfigurationUtil.GetConfigValue(config["passwordAttemptWindow"], "10")); minRequiredPasswordLength = Convert.ToInt32(ConfigurationUtil.GetConfigValue(config["minRequiredPasswordLength"], "7")); minRequiredNonAlphanumericCharacters = Convert.ToInt32(ConfigurationUtil.GetConfigValue(config["minRequiredAlphaNumericCharacters"], "1")); passwordStrengthRegularExpression = Convert.ToString(ConfigurationUtil.GetConfigValue(config["passwordStrengthRegularExpression"], string.Empty)); string configValue = ConfigurationUtil.GetConfigValue(config["passwordFormat"], "Hashed"); if (configValue != null) { if (!(configValue == "Hashed")) { if (configValue == "Encrypted") { passwordFormat = MembershipPasswordFormat.Encrypted; goto Label_01FB; } if (configValue == "Clear") { passwordFormat = MembershipPasswordFormat.Clear; goto Label_01FB; } } else { passwordFormat = MembershipPasswordFormat.Hashed; goto Label_01FB; } } throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this, "password format not supported"); Label_01FB: Configuration configuration = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath); machineKey = (MachineKeySection)configuration.GetSection("system.web/machineKey"); if ("Auto".Equals(machineKey.Decryption)) { machineKey.DecryptionKey = CryptographyUtil.CreateKey(0x18); machineKey.ValidationKey = CryptographyUtil.CreateKey(0x40); } }
public static void Main(string[] args) { ConfigurationUtil.InitializeProperties(); CreateHostBuilder(args).Build().Run(); }