/// <summary>
        /// 同步并保存
        /// </summary>
        /// <param name="model">产品信息</param>
        /// <param name="diffs">差别产品数据</param>
        /// <returns></returns>
        public static Tuple <int, Guid> SyncSave(QiangGouModel model, List <QiangGouDiffModel> diffs)
        {
            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                dbHelper.BeginTransaction();
                try
                {
                    var syncResult = SyncDiffActivity(model, diffs, dbHelper);

                    if (syncResult < 0)
                    {
                        if (model.ActivityID != null)
                        {
                            return(new Tuple <int, Guid>(syncResult, model.ActivityID.Value));
                        }
                    }

                    var result = DALQiangGou.CreateOrUpdateQianggou(dbHelper, model);

                    dbHelper.Commit();
                    return(result);
                }
                catch (Exception e)
                {
                    dbHelper.Rollback();
                    throw new Exception(e.Message);;
                }
            }
        }
        public bool DeleteShareConfigByLocation(string location, string specialParam, int jumpId)
        {
            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                try
                {
                    dbHelper.BeginTransaction();
                    if (!handler.DeleteShareConfigByLocation(location, specialParam))
                    {
                        dbHelper.Rollback();
                        return(false);
                    }

                    if (!handler.DeleteShareSConfigByJumpId(jumpId))
                    {
                        dbHelper.Rollback();
                        return(false);
                    }
                    dbHelper.Commit();
                    return(true);
                }
                catch (TuhuBizException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    var exception = new DownloadAppException(1, "DeleteShareConfigByLocation", ex);
                    Logger.Log(Level.Error, exception, "DeleteShareConfigByLocation");
                    throw ex;
                }
            }
        }
 public static int SaveAddMany(TirePatternModel model)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         dbHelper.BeginTransaction();
         var result = -99;
         foreach (var brand in model.Patterns)
         {
             foreach (var pattern in brand.Patterns.Split(','))
             {
                 TirePatternModel tempModel = new TirePatternModel()
                 {
                     Image       = model.Image,
                     Title       = model.Title,
                     Describe    = model.Describe,
                     Author      = model.Author,
                     Date        = model.Date,
                     ArticleLink = model.ArticleLink,
                     IsShow      = false,
                     IsActive    = model.IsActive,
                     Brand       = brand.Brand,
                     Pattern     = pattern
                 };
                 result = Insert(dbHelper, tempModel);
                 if (result <= 0)
                 {
                     dbHelper.Rollback();
                 }
             }
         }
         dbHelper.Commit();
         return(result);
     }
 }
        public static int DeleteProductAllInfo(int pkid, string userName)
        {
            var result = 0;
            var conn   = ConfigurationManager.ConnectionStrings["Gungnir"].ConnectionString;

            if (SecurityHelp.IsBase64Formatted(conn))
            {
                conn = SecurityHelp.DecryptAES(conn);
            }
            using (var dbhelper = new SqlDbHelper(conn))
            {
                dbhelper.BeginTransaction();
                result = DeleteProductModuleItem(dbhelper, pkid, userName);
                if (result > 0)
                {
                    if (DeleteProductConfigItem(dbhelper, pkid, userName) > 0)
                    {
                        dbhelper.Commit();
                        return(result);
                    }
                    else
                    {
                        dbhelper.Rollback();
                        return(-1);
                    }
                }
                else
                {
                    dbhelper.Rollback();
                    return(-1);
                }
            }
        }
        public static int SaveMany(IEnumerable <VehicleTireRecommend> list)
        {
            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                var result = -99;
                dbHelper.BeginTransaction();
                var Postions = list.Where(c => !string.IsNullOrWhiteSpace(c.PID)).Select(C => C.Postion);

                //删
                DeleteDatasByPostion(dbHelper, list.FirstOrDefault(), string.Join(",", Postions));

                foreach (var item in list)
                {//批量只插入PID不为空的
                    if (!string.IsNullOrWhiteSpace(item.PID))
                    {
                        foreach (var vehicle in item.VehicleIDS)
                        {
                            result = InsertDataToRecommend(dbHelper, item, vehicle);
                        }
                    }
                }
                dbHelper.Commit();
                return(result);
            }
        }
        public static int BitchOn(IEnumerable <InstallNowModel> list)
        {
            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                dbHelper.BeginTransaction();
                foreach (var model in list)
                {
                    var countSame = SelectSameCitySameTireSizeStatusOnCount(dbHelper, model.CityId, model.PID);
                    if (countSame > 4)
                    {
                        dbHelper.Rollback();
                        return(-99);
                    }
                    else
                    {
                        var rowCount = SingleOn(dbHelper, model.PKID);
                        if (rowCount <= 0)
                        {
                            dbHelper.Rollback();

                            return(-101);
                        }
                    }
                }
                dbHelper.Commit();
                return(1);
            }
        }
 public static int ApproveBack(string acid)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         dbHelper.BeginTransaction();
         try
         {
             //var result1 = DalSeckill.DeleteFlashSaleTempByAcid(acid);
             //if (result1 <= 0)
             //{
             //    dbHelper.Rollback();
             //    return -1;
             //}
             //var result2 = DalSeckill.DeleteFlashSaleProductsTempByAcid(acid);
             //if (result2 <= 0)
             //{
             //    dbHelper.Rollback();
             //    return -1;
             //}
             var result3 = DalSeckill.UpdateSeckillToToApprove(acid, 2);
             if (result3 <= 0)
             {
                 dbHelper.Rollback();
                 return(-1);
             }
             dbHelper.Commit();
             return(1);
         }
         catch (Exception e)
         {
             dbHelper.Rollback();
             throw new Exception(e.Message);;
         }
     }
 }
 public static int SaveQZTJMany(List <QZTJModel> list)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         var result = -99;
         dbHelper.BeginTransaction();
         //var pids = list.Select(C => C.PID);
         //List<int> Postion = new List<int>();
         //if (list.FirstOrDefault().Products.Any(C => C.Postion == 1))
         //    Postion.Add(1);
         //else if (list.FirstOrDefault().Products.Any(C => C.Postion == 2))
         //    Postion.Add(2);
         //else if (list.FirstOrDefault().Products.Any(C => C.Postion == 3))
         //    Postion.Add(3);
         //DeleteQZTJMany(string.Join(";",pids), string.Join(";", Postion));
         foreach (var item in list)
         {
             foreach (var model in item.Products)
             {
                 DeleteQZTJByPIDAndPostion(dbHelper, item.PID, model.Postion);
                 result = InsertQZTJ(dbHelper, model, item.PID);
                 if (result <= 0)
                 {
                     dbHelper.Rollback();
                 }
             }
         }
         dbHelper.Commit();
         return(result);
     }
 }
        public static int DelFlashSale(Guid aid)
        {
            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                const string sql  = @"Delete FROM  Activity..tbl_FlashSale WITH(ROWLOCK) where ActivityID='{0}'";
                var          sql1 = string.Format(sql, aid);

                dbHelper.BeginTransaction();
                var result = dbHelper.ExecuteNonQuery(sql1);
                if (result > 0)
                {
                    const string sql2 = @"Delete FROM  Activity..tbl_FlashSaleProducts WITH(ROWLOCK) where ActivityID='{0}'";
                    var          sql3 = string.Format(sql2, aid);
                    result = dbHelper.ExecuteNonQuery(sql3);
                    if (result > 0)
                    {
                        dbHelper.Commit();
                        return(result);
                    }
                    else
                    {
                        dbHelper.Rollback();
                    }
                }
                else
                {
                    dbHelper.Rollback();
                }
                return(result);
            }
        }
        public async Task <bool> SaveGeneralBeautyServerCodeProductRegions(IEnumerable <ThirdPartyBeautyPackageProductRegionConfigModel> models)
        {
            #region SQL
            string del = @"Update    [Tuhu_groupon].[dbo].[ThirdPartyBeautyPackageRegion] WITH(ROWLOCK) 
   SET IsDeleted=1 ,UpdatedDateTime=GetDate() 
    WHERE PackageProductId=@PackageProductId AND IsDeleted=0";
            string sql = @"Insert into [Tuhu_groupon].[dbo].[ThirdPartyBeautyPackageRegion]
  ([PackageProductId]
   ,[ProvinceId]
   ,[CityIds]
   ,[IsAllCitys]
   ,[IsDeleted]
   ,[CreatedDateTime]
   ,[UpdatedDateTime])
   values(
    @PackageProductId
   ,@ProvinceId
   ,@CityIds
   ,@IsAllCitys
   ,0
   ,GetDate()
   ,GetDate()
   )";
            #endregion
            List <ThirdPartyBeautyPackageProductRegionConfigModel> result = new List <ThirdPartyBeautyPackageProductRegionConfigModel>();
            using (var dbhelper = new SqlDbHelper(strConn_Write))
            {
                dbhelper.BeginTransaction();
                dbhelper.ExecuteNonQuery(del,
                                         CommandType.Text,
                                         new[] { new SqlParameter("PackageProductId", models.FirstOrDefault()?.PackageProductId), });

                bool success = true;
                foreach (var item in models)
                {
                    var sqlPara = new[]
                    {
                        new SqlParameter("PackageProductId", item.PackageProductId),
                        new SqlParameter("ProvinceId", item.ProvinceId),
                        new SqlParameter("CityIds", item.CityIds),
                        new SqlParameter("IsAllCitys", item.IsAllCitys),
                    };
                    if (dbhelper.ExecuteNonQuery(sql, CommandType.Text, sqlPara) <= 0)
                    {
                        success = false;
                        break;
                    }
                }
                if (success)
                {
                    dbhelper.Commit();
                }
                else
                {
                    dbhelper.Rollback();
                }
                return(await Task.FromResult(success));
            }
        }
Exemple #11
0
        /// <summary>
        /// 添加建议反馈信息
        /// </summary>
        /// <param name="typeId">问题类型Id</param>
        /// <param name="userPhone">用户手机号</param>
        /// <param name="feedbackContent">反馈内容</param>
        /// <param name="versionNum">版本号</param>
        /// <param name="phoneModels">手机型号</param>
        /// <param name="networkEnvironment">网络环境</param>
        /// <param name="images">图片,>=0张</param>
        /// <returns></returns>
        public async Task <int> AddFeedbackInfo(int typeId, string userPhone, string feedbackContent, string versionNum, string phoneModels, string networkEnvironment, List <string> images)
        {
            int result = 0;

            using (var sqlHelper = new SqlDbHelper())
            {
                sqlHelper.BeginTransaction();
                try
                {
                    var        sql = @"INSERT INTO Tuhu_profiles..Feedback
                        (TypeId
                        ,CreateTime
                        ,UserPhone
                        ,FeedbackContent
                        ,VersionNum
                        ,PhoneModels
                        ,NetworkEnvironment)
                  VALUES
                        (@TypeId
                        ,GETDATE()
                        ,@UserPhone
                        ,@FeedbackContent 
                        ,@VersionNum
                        ,@PhoneModels 
                        ,@NetworkEnvironment)";
                    SqlCommand cmd = new SqlCommand(sql + ";SELECT @@identity as Id");
                    cmd.Parameters.AddWithValue("@TypeId", typeId);
                    cmd.Parameters.AddWithValue("@UserPhone", userPhone);
                    cmd.Parameters.AddWithValue("@FeedbackContent", feedbackContent);
                    cmd.Parameters.AddWithValue("@VersionNum", versionNum);
                    cmd.Parameters.AddWithValue("@PhoneModels", phoneModels);
                    cmd.Parameters.AddWithValue("@NetworkEnvironment", networkEnvironment);
                    result = Convert.ToInt32(await sqlHelper.ExecuteScalarAsync(cmd));
                    if (images != null && images.Any())
                    {
                        foreach (var imgurl in images)
                        {
                            var        imgsql = @"INSERT INTO Tuhu_profiles..FeedbackImg
                                      (ImgUrl
                                      ,FeedbackId)
                                    VALUES
                                       (@ImgUrl
                                       ,@FeedbackId)";
                            SqlCommand cmd1   = new SqlCommand(imgsql);
                            cmd1.Parameters.AddWithValue("@ImgUrl", imgurl);
                            cmd1.Parameters.AddWithValue("@FeedbackId", result);
                            await sqlHelper.ExecuteNonQueryAsync(cmd1);
                        }
                    }
                    sqlHelper.Commit();
                    return(result);
                }
                catch (Exception e)
                {
                    sqlHelper.Rollback();
                    throw new Exception(e.Message);
                }
            }
        }
Exemple #12
0
        public static bool UsertEnterpriseUserConfig(EnterpriseUserViewModel data, string user)
        {
            var result = false;

            try
            {
                using (var dbhelper = new SqlDbHelper(BeautyServicePackageDal.GetTuhuGrouponWriteConnstr()))
                {
                    dbhelper.BeginTransaction();
                    var userConfig   = BeautyServicePackageDal.SelectEnterpriseUserConfigByUserId(dbhelper, data.UserId);
                    var moduleConfig = BeautyServicePackageDal.SelectEnterpriseUserModuleConfigByUserId(dbhelper, data.UserId);
                    if (userConfig != null && userConfig.Any())
                    {
                        BeautyServicePackageDal.DeleteEnterpriseUserConfigByUserId(dbhelper, data.UserId);
                    }
                    if (moduleConfig != null && moduleConfig.Any())
                    {
                        BeautyServicePackageDal.DeleteEnterpriseModuleConfigByUserId(dbhelper, data.UserId);
                    }
                    if (data.PackageDetailIds != null && data.PackageDetailIds.Any())
                    {
                        foreach (var item in data.PackageDetailIds)
                        {
                            BeautyServicePackageDal.InsertEnterpriseUserConfig(dbhelper, data.UserId, item, data.Remark);
                        }
                    }
                    else
                    {
                        BeautyServicePackageDal.InsertEnterpriseUserConfig(dbhelper, data.UserId, 0, data.Remark);//允许不配服务模板
                    }
                    if (data.UserModuleDetails != null && data.UserModuleDetails.Any())
                    {
                        foreach (var item in data.UserModuleDetails)
                        {
                            BeautyServicePackageDal.InsertEnterpriseUserModuleConfig(dbhelper, data.UserId, item.ModuleType);
                        }
                    }
                    dbhelper.Commit();
                    result = true;
                    var log = new BaoYangOprLog
                    {
                        LogType     = "EnterpriseUserConfig",
                        IdentityID  = data.UserId.ToString(),
                        OldValue    = "[]",
                        NewValue    = JsonConvert.SerializeObject(data),
                        Remarks     = $"发码服务权限修改 {data.UserMobile}",
                        OperateUser = user,
                    };
                    LoggerManager.InsertLog("BeautyOprLog", log);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }

            return(result);
        }
        public static bool InsertVipCardModelAndDetails(List <VipCardDetailModel> details, string activityName, int clientId)
        {
            bool result;

            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                try
                {
                    dbHelper.BeginTransaction();
                    var clientName   = GetBatchesByClientId(clientId).Select(r => r.ClientName).FirstOrDefault();
                    var activityId   = Guid.NewGuid();
                    var vipCardModel = new VipCardModel()
                    {
                        ActivityId   = activityId,
                        ActivityName = activityName,
                        Url          = UrlPrfex + activityId
                    };
                    var insertResult = DalVipCard.InsertVipCardModel(vipCardModel, dbHelper);
                    result = insertResult > 0;
                    if (insertResult <= 0)
                    {
                        dbHelper.Rollback();
                    }
                    else
                    {
                        var list = new List <VipCardDetailModel>();
                        if (details != null)
                        {
                            list = details.Select(r =>
                            {
                                r.ClientName = clientName;
                                r.ClientId   = clientId;
                                return(r);
                            }).ToList();
                        }
                        var insertDetail = DalVipCard.InsertVipCardDetailsModel(list, insertResult, dbHelper);
                        result = result && insertDetail;
                        if (!insertDetail)
                        {
                            dbHelper.Rollback();
                        }
                        else
                        {
                            OpertionLogs(OpertionType.Add, "", "", activityId.ToString());
                            dbHelper.Commit();
                        }
                    }
                }
                catch (Exception ex)
                {
                    dbHelper.Rollback();
                    result = false;
                    logger.Error(ex.Message, ex);
                }
            }
            return(result);
        }
        public static bool UpsertYxArticle(YouXuanArticle article, string user)
        {
            var result    = false;
            var articleId = 0;

            try
            {
                var conn = ConfigurationManager.ConnectionStrings["Tuhu_Discovery_Db"].ConnectionString;
                if (SecurityHelp.IsBase64Formatted(conn))
                {
                    conn = SecurityHelp.DecryptAES(conn);
                }
                using (var dbhelper = new SqlDbHelper(conn))
                {
                    dbhelper.BeginTransaction();
                    if (article.PKID > 0)
                    {
                        articleId = article.PKID;
                        ArticleDal.UpdateYxArticle(dbhelper, article);
                    }
                    else
                    {
                        articleId = ArticleDal.InsertYxArticle(dbhelper, article);
                    }
                    article.CoverConfig.ArticleId = articleId;
                    ArticleDal.DeleteYxArticleCoverConfig(dbhelper, articleId);
                    ArticleDal.DeleteArticleCategoryTag(dbhelper, articleId);
                    if (!string.IsNullOrEmpty(article.CategoryTags))
                    {
                        var categoryIds = JsonConvert.DeserializeObject <List <JObject> >(article.CategoryTags).Select(t => t.Value <int>("key"));
                        foreach (var id in categoryIds)
                        {
                            ArticleDal.InsertArticleCategoryTag(dbhelper, articleId, id);
                        }
                    }
                    ArticleDal.InsertYxArticleCoverConfig(dbhelper, article.CoverConfig);
                    dbhelper.Commit();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            if (result)
            {
                if (article.PKID > 0)
                {
                    LoggerManager.InsertOplog(user, "ArticleTblNew", articleId, "新增优选文章,文章状态:" + article.Status);
                }
                else
                {
                    LoggerManager.InsertOplog(user, "ArticleTblNew", articleId, "修改优选文章,文章状态:" + article.Status);
                }
            }
            return(result);
        }
        /// <summary>
        /// 更新广告产品
        /// </summary>
        /// <param name="dbhelper"></param>
        /// <param name="products"></param>
        /// <returns></returns>
        //public static int UpdateProducts(SqlDbHelper dbhelper, AdProductModel products)
        //{
        //    using (var cmd = new SqlCommand("Gungnir..[Advertise_UpdateProducts]"))
        //    {
        //        cmd.CommandType = CommandType.StoredProcedure;
        //        cmd.Parameters.AddWithValue("@AdvertiseID", products.AdvertiseID);
        //        cmd.Parameters.AddWithValue("@AdColumnID", products.AdColumnID);
        //        cmd.Parameters.AddWithValue("@PID", products.PID);
        //        cmd.Parameters.AddWithValue("@Position", products.Position);
        //        cmd.Parameters.AddWithValue("@LastUpdateDateTime", DateTime.Now);
        //        return dbhelper.ExecuteNonQuery(cmd);
        //    }
        //}
        /// <summary>
        /// 更新广告位信息   (默认图片和链接)
        /// </summary>
        /// <param name="AdcModel"></param>
        /// <returns></returns>
        public static int UpdateAdColumn(AdColumnModel AdcModel)
        {
            var conn = ConfigurationManager.ConnectionStrings["Gungnir"].ConnectionString;

            if (SecurityHelp.IsBase64Formatted(conn))
            {
                conn = SecurityHelp.DecryptAES(conn);
            }
            using (var dbhelper = new SqlDbHelper(conn))
            {
                dbhelper.BeginTransaction();
                var cmd = new SqlCommand("Gungnir..[Advertise_UpdateAdColumn]");
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ID", AdcModel.ID);
                cmd.Parameters.AddWithValue("@DefaultImage", AdcModel.DefaultImage);
                cmd.Parameters.AddWithValue("@Name", AdcModel.ADCName);
                cmd.Parameters.AddWithValue("@DefaultbgColor", AdcModel.DefaultbgColor);
                cmd.Parameters.AddWithValue("@DefaultUrl", AdcModel.DefaultUrl);
                cmd.Parameters.AddWithValue("@Remark", AdcModel.Remark);
                var result = dbhelper.ExecuteNonQuery(cmd);
                if (result > 0)
                {
                    if (AdcModel.Products != null && AdcModel.Products.Count() > 0)
                    {
                        if (DeleteProducts(AdcModel.ID, "0") > 0)
                        {
                            foreach (var p in AdcModel.Products)
                            {
                                if (InsertProducts(dbhelper, p) <= 0)
                                {
                                    dbhelper.Rollback();
                                    return(-2);
                                }
                            }
                        }
                        else
                        {
                            dbhelper.Rollback();
                            return(-3);
                        }
                    }
                    else if (AdcModel.Remark == "product")
                    {
                        dbhelper.Rollback();
                        return(-98);//一个产品都没有无需保存
                    }
                }
                else
                {
                    dbhelper.Rollback();
                    return(-1);
                }
                dbhelper.Commit();
                return(result);
            }
        }
        /// <summary>
        /// 新增广告信息
        /// </summary>
        /// <param name="ad"></param>
        /// <returns></returns>
        public static int InsertAdvertiseDetail(AdvertiseModel ad, IEnumerable <AdProductModel> products)
        {
            var conn        = ConfigurationManager.ConnectionStrings["Gungnir"].ConnectionString;
            var AdvertiseID = 0;

            if (SecurityHelp.IsBase64Formatted(conn))
            {
                conn = SecurityHelp.DecryptAES(conn);
            }
            using (var dbhelper = new SqlDbHelper(conn))
            {
                dbhelper.BeginTransaction();
                var cmd = new SqlCommand("Gungnir..[Advertise_InsertAdvertiseDetail]");
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@AdColumnID", ad.AdColumnID);
                cmd.Parameters.AddWithValue("@AdName", ad.AdName);
                cmd.Parameters.AddWithValue("@BeginDateTime", ad.BeginDateTime);
                cmd.Parameters.AddWithValue("@EndDateTime", ad.EndDateTime);
                cmd.Parameters.AddWithValue("@Position", ad.Position);
                cmd.Parameters.AddWithValue("@Image", ad.Image);
                cmd.Parameters.AddWithValue("@State", ad.State);
                cmd.Parameters.AddWithValue("@Url", ad.Url);
                cmd.Parameters.AddWithValue("@bgColor", ad.bgColor);
                cmd.Parameters.Add(new SqlParameter
                {
                    ParameterName = "@Result",
                    DbType        = DbType.Int32,
                    Direction     = ParameterDirection.Output
                });
                dbhelper.ExecuteNonQuery(cmd);
                AdvertiseID = Convert.ToInt32(cmd.Parameters["@Result"].Value);
                if (AdvertiseID > 0)
                {
                    if (products != null && products.Count() > 0)
                    {
                        foreach (var p in products)
                        {
                            p.AdvertiseID = AdvertiseID;
                            var result = InsertProducts(dbhelper, p);
                            if (result < 0)
                            {
                                dbhelper.Rollback();
                                return(-2);
                            }
                        }
                    }
                }
                else
                {
                    dbhelper.Rollback();
                    return(-1);
                }
                dbhelper.Commit();
                return(AdvertiseID);
            }
        }
Exemple #17
0
        public bool UpdateQuestionList(List <Question> questionList)
        {
            bool   updatesuccess = true;
            string conn          = ConnectionHelper.GetDecryptConn("Gungnir");

            using (var db = new SqlDbHelper(conn))
            {
                try
                {
                    db.BeginTransaction();
                    string questionUpdateSql = string.Empty;
                    foreach (var question in questionList)
                    {
                        if (question.AnswerYes != 0)
                        {
                            question.QuestionConfirm = 1;
                        }
                        questionUpdateSql += "update Activity..Question WITH(ROWLOCK) set QuestionTitle=" + "N\'" + question.QuestionTitle + "\'" + ",QuestionTextResult=" + "N\'" + question.QuestionTextResult + "\'" + ",QuestionConfirm=" + question.QuestionConfirm + ",LastUpdateDateTime=" + "\'" + DateTime.Now + "\'" + " where PKID=" + question.PKID;
                        questionUpdateSql += "\n";
                        if (question.AnswerYes == 1)
                        {
                            questionUpdateSql += "update Activity..QuestionOption WITH(ROWLOCK) set IsRightValue=1,LastUpdateDateTime=getdate() where QuestionID=" + question.PKID + " and OptionContent=N'是'";
                            questionUpdateSql += "\n";
                            questionUpdateSql += "update Activity..QuestionOption WITH(ROWLOCK) set IsRightValue=0,LastUpdateDateTime=getdate() where QuestionID=" + question.PKID + " and OptionContent=N'否'";
                        }
                        if (question.AnswerYes == -1)
                        {
                            questionUpdateSql += "update Activity..QuestionOption WITH(ROWLOCK) set IsRightValue=1,LastUpdateDateTime=getdate() where QuestionID=" + question.PKID + " and OptionContent=N'否'";
                            questionUpdateSql += "\n";
                            questionUpdateSql += "update Activity..QuestionOption WITH(ROWLOCK) set IsRightValue=0,LastUpdateDateTime=getdate() where QuestionID=" + question.PKID + " and OptionContent=N'是'";
                        }
                    }

                    var result = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, questionUpdateSql);
                    if (result < 0)
                    {
                        db.Rollback();
                        return(false);
                    }
                    else
                    {
                        db.Commit();
                        return(true);
                    }
                }

                catch (Exception ex)
                {
                    db.Rollback();
                    return(false);
                }
            }
        }
Exemple #18
0
        public bool DeleteQuestionWithOptionList(DateTime enddatetime)
        {
            var    operationsuccess = true;
            string conn             = ConnectionHelper.GetDecryptConn("Gungnir");

            using (var db = new SqlDbHelper(conn))
            {
                try
                {
                    db.BeginTransaction();
                    string strSql = @"update Activity..Question set IsDeleted=1,LastUpdateDateTime=getdate() where datediff(dd,EndTime,@EndTime)=0 and QuestionnaireID in 
                                      (
                                       select PKID from Activity..Questionnaire where QuestionnaireType = 5
                                      )";
                    List <SqlParameter> sqlparams = new List <SqlParameter>();
                    sqlparams.Add(new SqlParameter("@EndTime", enddatetime));
                    int rowaffected = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, sqlparams.ToArray());
                    if (rowaffected >= 0)
                    {
                        string updatequestionoptionSql = @"update Activity..QuestionOption set IsDeleted = 1,LastUpdateDateTime=getdate() where QuestionID in (
                           select distinct(pkid) from Activity..Question where
                           datediff(dd, EndTime, @EndTime)= 0)";
                        int    rowoptionaffected       = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, updatequestionoptionSql, sqlparams.ToArray());
                        if (rowoptionaffected < 0)
                        {
                            operationsuccess = false;
                            db.Rollback();
                        }
                    }
                    else
                    {
                        operationsuccess = false;
                        db.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    operationsuccess = false;
                    db.Rollback();
                }
                if (operationsuccess)
                {
                    db.Commit();
                }
                return(operationsuccess);
            }
        }
Exemple #19
0
        public static bool UpdateBeautyServicePackage(BeautyServicePackage package)
        {
            bool result = false;

            try
            {
                var oldValue = GetBeautyServicePackage(package.PKID);
                var writeStr = BeautyServicePackageDal.GetTuhuGrouponWriteConnstr();
                using (var dbhelper = new SqlDbHelper(writeStr))
                {
                    dbhelper.BeginTransaction();
                    var updateBeautyServicePackageResult = BeautyServicePackageDal.UpdateBeautyServicePackage(dbhelper, package);
                    BeautyServicePackageDal.UpdateBeautyServicePackageDetailCooperateIdByPackageId(dbhelper, package.PKID, package.CooperateId);
                    if (!updateBeautyServicePackageResult)
                    {
                        throw new Exception("更新兑换码配置失败");
                    }
                    if (package.IsPackageCodeGenerated && (package.PackageCodeStartTime != oldValue.PackageCodeStartTime ||
                                                           package.PackageCodeEndTime != oldValue.PackageCodeEndTime))
                    {
                        var updateBeautyServicePackageCodeTimeResult = BeautyServicePackageDal.UpdateBeautyServicePackageCodeTime(dbhelper, package.PKID, package.PackageCodeStartTime, package.PackageCodeEndTime);
                        if (!updateBeautyServicePackageCodeTimeResult)
                        {
                            throw new Exception("更新兑换码时间失败");
                        }
                    }
                    dbhelper.Commit();
                    result = true;
                    var log = new BeautyOprLog
                    {
                        LogType     = "UpdateBeautyServicePackage",
                        IdentityID  = $"{package.PKID}",
                        OldValue    = JsonConvert.SerializeObject(oldValue),
                        NewValue    = JsonConvert.SerializeObject(package),
                        Remarks     = $"修改集团客户礼包,礼包ID为:{package.PKID}",
                        OperateUser = package.UpdateUser,
                    };
                    LoggerManager.InsertLog("BeautyOprLog", log);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            };

            return(result);
        }
Exemple #20
0
        /// <summary>
        /// 编辑兑换码批次记录
        /// </summary>
        /// <param name="codeBatch"></param>
        /// <returns></returns>
        public static int UpdateBatches(ThirdPartyCodeBatch codeBatch)
        {
            const string sql    = @"UPDATE  Configuration.dbo.ThirdPartyCodeBatchConfig
                                 SET     BatchName = @BatchName ,
                                         LimitQty = @LimitQty ,
                                         StartDateTime = @StartDateTime ,
                                         EndDateTime = @EndDateTime ,
                                         Instructions = @Instructions ,
                                         UpdateDateTime = @UpdateDateTime ,
                                         Modifier = @Modifier
                                         WHERE BatchGuid=@BatchGuid
                                    ;";
            int          result = -1;

            using (var dbhelper = new SqlDbHelper(ConnectionStringConfig))
            {
                try
                {
                    dbhelper.BeginTransaction();
                    var cmd = new SqlCommand(sql);
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@BatchGuid", codeBatch.BatchGuid);
                    cmd.Parameters.AddWithValue("@BatchName", codeBatch.BatchName);
                    cmd.Parameters.AddWithValue("@LimitQty", codeBatch.LimitQty);
                    cmd.Parameters.AddWithValue("@Instructions", codeBatch.Instructions);
                    cmd.Parameters.AddWithValue("@StartDateTime", codeBatch.StartDateTime);
                    cmd.Parameters.AddWithValue("@EndDateTime", codeBatch.EndDateTime);
                    cmd.Parameters.AddWithValue("@Modifier", codeBatch.Modifier);
                    cmd.Parameters.AddWithValue("@UpdateDateTime", codeBatch.UpdateDateTime);
                    var i = dbhelper.ExecuteNonQuery(cmd);
                    if (i > 0)
                    {
                        DalThirdPartyExchangeCode.UpdateExchangeCodeTime(codeBatch.StartDateTime, codeBatch.EndDateTime, codeBatch.BatchGuid);
                    }
                    dbhelper.Commit();
                    result = 1;
                }
                catch (Exception ex)
                {
                    dbhelper.Rollback();
                    return(-1);
                }
            }

            return(result);
        }
        public static bool UpsertDaoGouArticle(YouXuanArticle article, string user)
        {
            var result    = false;
            var articleId = 0;

            try
            {
                var conn = ConfigurationManager.ConnectionStrings["Tuhu_Discovery_Db"].ConnectionString;
                if (SecurityHelp.IsBase64Formatted(conn))
                {
                    conn = SecurityHelp.DecryptAES(conn);
                }
                using (var dbhelper = new SqlDbHelper(conn))
                {
                    dbhelper.BeginTransaction();
                    if (article.PKID > 0)
                    {
                        articleId = article.PKID;
                        ArticleDal.UpdateDaoGouArticle(dbhelper, article);
                    }
                    else
                    {
                        articleId = ArticleDal.InsertDaoGouArticle(dbhelper, article);
                    }
                    dbhelper.Commit();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            if (result)
            {
                if (article.PKID > 0)
                {
                    LoggerManager.InsertOplog(user, "ArticleTblNew", articleId, "新增导购文章,文章状态:" + article.Status);
                }
                else
                {
                    LoggerManager.InsertOplog(user, "ArticleTblNew", articleId, "修改导购文章,文章状态:" + article.Status);
                }
            }
            return(result);
        }
 public static int SaveSingle(IEnumerable <VehicleTireRecommend> list)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         var result = -99;
         dbHelper.BeginTransaction();
         //删
         DeleteDatasByVehicleAndTireSize(dbHelper, list.FirstOrDefault());
         foreach (var item in list)
         {
             //插入
             result = InsertDataToRecommend(dbHelper, item);
             if (result <= 0)
             {
                 dbHelper.Rollback();
             }
         }
         dbHelper.Commit();
         return(result);
     }
 }
 public static int SaveQZTJSingle(QZTJModel model)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         var result = -99;
         dbHelper.BeginTransaction();
         //删
         DeleteQZTJByPID(model.PID);
         foreach (var item in model.Products)
         {
             //插入
             result = InsertQZTJ(dbHelper, item, model.PID);
             if (result <= 0)
             {
                 dbHelper.Rollback();
             }
         }
         dbHelper.Commit();
         return(result);
     }
 }
 public bool InsertShareSConfigs(List <ShareSupervisionConfig> sscList, string location, string author, int newId)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         try
         {
             if (sscList != null && sscList.Any())
             {
                 dbHelper.BeginTransaction();
                 foreach (var ssc in sscList)
                 {
                     ssc.Location       = location;
                     ssc.CreateDateTime = DateTime.Now;
                     ssc.UpdateDateTime = DateTime.Now;
                     ssc.Creator        = author;
                     ssc.JumpId         = newId;
                     if (!handler.InsertShareSConfig(ssc))
                     {
                         dbHelper.Rollback();
                         return(false);
                     }
                 }
                 dbHelper.Commit();
             }
             return(true);
         }
         catch (TuhuBizException)
         {
             throw;
         }
         catch (Exception ex)
         {
             var exception = new DownloadAppException(1, "InsertShareSConfigs", ex);
             Logger.Log(Level.Error, exception, "InsertShareSConfigs");
             throw ex;
         }
     }
 }
 public bool AddAndUpdareTireChangeActInBatch(ActivityItem updateModel, List <string> pkids, List <ActivityItem> activityListToAdd)
 {
     using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
     {
         try
         {
             dbHelper.BeginTransaction();
             if (pkids != null && pkids.Any())
             {
                 if (!DALListActivity.UpdateTireChangedActInBatch(dbHelper, updateModel, pkids))
                 {
                     dbHelper.Rollback();
                     return(false);
                 }
             }
             if (activityListToAdd != null && activityListToAdd.Any())
             {
                 foreach (var actToAdd in activityListToAdd)
                 {
                     if (!DALListActivity.AddTireChangedAct(actToAdd))
                     {
                         dbHelper.Rollback();
                         return(false);
                     }
                 }
             }
             dbHelper.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             dbHelper.Rollback();
             logger.Error("批量生成服务码错误", ex);
             return(false);
         }
     }
 }
Exemple #26
0
        public static async Task <bool> GenerateServiceCodes(int packageDetailId)
        {
            var result = false;
            var hasGenerateServiceCodes = new List <string>();
            var currentProduct          = GetBeautyServicePackageDetail(packageDetailId);
            var package       = GetBeautyServicePackage(currentProduct.PackageId);
            var cooperateUser = new BankMRManager().FetchMrCooperateUserConfigByPKID(currentProduct.CooperateId);

            if ((string.Equals(package?.PackageType, "serviceCode") || currentProduct.PackageId <= 0) && cooperateUser != null)
            {
                var writeStr = BeautyServicePackageDal.GetTuhuGrouponWriteConnstr();
                using (var dbhelper = new SqlDbHelper(writeStr))
                {
                    dbhelper.BeginTransaction();
                    var key = $"ServiceCodeGenerateingRate/{packageDetailId}";
                    try
                    {
                        var waitingGenerateCount = currentProduct.ServiceCodeNum;
                        var betchSize            = 100;
                        while (waitingGenerateCount > 0)
                        {
                            var generateCount = waitingGenerateCount > betchSize ? betchSize : waitingGenerateCount;
                            var serviceCodes  = await GenerateServiceCode(currentProduct.PID, generateCount, currentProduct.Name, 0, currentProduct.ServiceCodeEndTime);

                            if (serviceCodes != null && serviceCodes.Count() == generateCount)
                            {
                                hasGenerateServiceCodes.AddRange(serviceCodes);
                                var rows = BeautyServicePackageDal.InsertBeautyServicePackageDetailCodes(dbhelper, currentProduct, cooperateUser.VipUserId, serviceCodes);
                                if (rows == generateCount)
                                {
                                    waitingGenerateCount -= generateCount;
                                }
                                else
                                {
                                    throw new Exception($"服务码插入数据库的没有成功,rows:{rows},generateCount:{generateCount}");
                                }
                                using (var client = CacheHelper.CreateCacheClient(CacheClientName))
                                {
                                    var process = (currentProduct.ServiceCodeNum - waitingGenerateCount) * 1.0f / currentProduct.ServiceCodeNum;
                                    await client.SetAsync(key, process, TimeSpan.FromMinutes(20));
                                }
                            }
                            else
                            {
                                throw new Exception($"快修服务生成的服务码和请求的数量不相等,PID:{currentProduct.PID},name:{currentProduct.Name}," +
                                                    $"needCount:{generateCount},realCount:{serviceCodes.Count()}");
                            }
                        }
                        if (string.Equals(currentProduct.SettlementMethod, "PreSettled"))
                        {
                            var createOrderResult = await OrderManager.CreateServiceCodeOrderForVip(cooperateUser, currentProduct);

                            if (createOrderResult.OrderId <= 0)
                            {
                                throw new Exception($"创建大客户兑换码订单失败,packageDetailId:{packageDetailId},OrderId{createOrderResult.OrderId}");
                            }
                            else
                            {
                                var setOrderIdResult = BeautyServicePackageDal.SetPackageDetailBuyoutOrderId(dbhelper, packageDetailId, createOrderResult.OrderId);
                                if (!setOrderIdResult)
                                {
                                    throw new Exception("设置买断订单Id字段失败");
                                }
                            }
                        }
                        var setResult = BeautyServicePackageDal.SetServiceCodeIsGenerated(dbhelper, packageDetailId);
                        if (!setResult)
                        {
                            throw new Exception("设置是否生成服务码字段失败");
                        }
                        dbhelper.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        dbhelper.Rollback();
                        using (var client = CacheHelper.CreateCacheClient(CacheClientName))
                        {
                            await client.SetAsync(key, 0, TimeSpan.FromMinutes(20));
                        }
                        await RevertVOLServiceCode(hasGenerateServiceCodes);

                        Logger.Error("批量生成服务码错误", ex);
                    }
                }
            }

            return(result);
        }
Exemple #27
0
        public static async Task <bool> GeneratePackageCodes(int packageId)
        {
            var result  = false;
            var package = GetBeautyServicePackage(packageId);

            if (package != null && package.PackageCodeNum > 0)
            {
                var writeStr = BeautyServicePackageDal.GetTuhuGrouponWriteConnstr();
                using (var dbhelper = new SqlDbHelper(writeStr))
                {
                    dbhelper.BeginTransaction();
                    var key = $"PacakgeCodeGenerateingRate/{packageId}";
                    try
                    {
                        var waitingGenerateCount = package.PackageCodeNum;
                        var batchSize            = 1000;
                        while (waitingGenerateCount > 0)
                        {
                            var generateCount = batchSize < waitingGenerateCount ? batchSize : waitingGenerateCount;
                            var rows          = BeautyServicePackageDal.InsertBeautyServicePackageCodes(dbhelper, package, generateCount);
                            if (generateCount == rows)
                            {
                                waitingGenerateCount -= generateCount;
                            }
                            else
                            {
                                throw new Exception($"兑换码插入数据库的没有成功,rows:{rows},generateCount:{generateCount}");
                            }
                            using (var client = CacheHelper.CreateCacheClient(CacheClientName))
                            {
                                var process = (package.PackageCodeNum - waitingGenerateCount) * 1.0f / package.PackageCodeNum;
                                await client.SetAsync(key, process, TimeSpan.FromMinutes(20));
                            }
                        }
                        if (string.Equals(package.SettlementMethod, "PreSettled"))
                        {
                            var pacakgeDetails    = GetBeautyServicePackageDetails(packageId);
                            var createOrderResult = await OrderManager.CreatePackageCodeOrderForVipUser(package, pacakgeDetails);

                            if (createOrderResult.OrderId <= 0)
                            {
                                throw new Exception($"创建大客户兑换码订单失败,packageId:{packageId},OrderId{createOrderResult.OrderId}");
                            }
                            else
                            {
                                var setOrderIdResult = BeautyServicePackageDal.SetPackageBuyoutOrderId(dbhelper, packageId, createOrderResult.OrderId);
                                if (!setOrderIdResult)
                                {
                                    throw new Exception("设置买断订单Id字段失败");
                                }
                            }
                        }
                        var setResult = BeautyServicePackageDal.SetPackageCodeIsGenerated(dbhelper, packageId);
                        if (!setResult)
                        {
                            throw new Exception("设置是否兑换字段失败");
                        }
                        dbhelper.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        dbhelper.Rollback();
                        using (var client = CacheHelper.CreateCacheClient(CacheClientName))
                        {
                            await client.SetAsync(key, 0, TimeSpan.FromMinutes(20));
                        }
                        Logger.Error("批量生成兑换码错误", ex);
                    }
                }
            }

            return(result);
        }
Exemple #28
0
        /// <summary>
        /// 根据批次号更新服务码起始时间
        /// </summary>
        /// <param name="user"></param>
        /// <param name="batchCode"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public static async Task <Tuple <bool, string> > UpdateBeautyServiceCodeTimeByBatchCode(string user, string batchCode, DateTime startTime, DateTime endTime)
        {
            var result = false;
            var msg    = string.Empty;

            try
            {
                var writeStr = BeautyServicePackageDal.GetTuhuGrouponWriteConnstr();
                using (var dbhelper = new SqlDbHelper(writeStr))
                {
                    dbhelper.BeginTransaction();
                    var updateCodeResult = BeautyServicePackageDal.UpdateBeautyServicePackageDetailCodeTimeByBatchCode(dbhelper, batchCode, startTime, endTime);
                    if (!updateCodeResult)
                    {
                        throw new Exception("根据批次号更新服务码时间失败,方法UpdateBeautyServicePackageDetailCodeTimeByBatchCode");
                    }
                    var serviceCodes = BeautyServicePackageDal.SelectServiceCodesByBatchCode(batchCode);
                    if (serviceCodes != null && serviceCodes.Any())
                    {
                        if (serviceCodes.Count() > 10000)
                        {
                            throw new Exception("暂时不支持服务码数量大于10000的修改操作");
                        }
                        using (var client = new ServiceCodeClient())
                        {
                            var batchSize = 1000;
                            var index     = 0;
                            while (index < serviceCodes.Count())
                            {
                                var batchCodes            = serviceCodes.Skip(index).Take(batchSize).ToList();
                                var kxChangeCodeTimeModel = new ChangeCodeTimeRequest
                                {
                                    ServiceCodes = batchCodes,
                                    OverdueTime  = endTime
                                };
                                var kxChangeResult = client.ChangeOverdueTime(kxChangeCodeTimeModel);
                                if (!kxChangeResult.Success)
                                {
                                    throw kxChangeResult.Exception;
                                }
                                if (kxChangeResult.Result != null && kxChangeResult.Result.FailServiceCode != null && kxChangeResult.Result.FailServiceCode.Any())
                                {
                                    var serviceCodeFailedLog = new BeautyOprLog
                                    {
                                        LogType     = "ChangeOverdueTimeFailedCodes",
                                        IdentityID  = $"{batchCode}",
                                        OldValue    = null,
                                        NewValue    = JsonConvert.SerializeObject(kxChangeResult.Result.FailServiceCode),
                                        Remarks     = $"根据批次号修改服务码过期时间失败,批次:{batchCode},OverdueTime应该改为:{endTime}",
                                        OperateUser = user,
                                    };
                                    LoggerManager.InsertLog("BeautyOprLog", serviceCodeFailedLog);
                                }
                                index += batchSize;
                            }
                            dbhelper.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Logger.Error(ex.Message, ex);
            }
            return(new Tuple <bool, string>(result, msg));
        }
Exemple #29
0
        public bool UpdateQuestionWithOptionList(List <QuestionWithOption> questionWithOptionList)
        {
            var    operationsuccess = true;
            string conn             = ConnectionHelper.GetDecryptConn("Gungnir");

            using (var db = new SqlDbHelper(conn))
            {
                try
                {
                    long questionaireId = 0;
                    db.BeginTransaction();
                    string questionUpdateSql = string.Empty;
                    foreach (var questionwithOption in questionWithOptionList)
                    {
                        questionUpdateSql = "update Activity..Question set QuestionTitle=" + "N\'" + questionwithOption.QuestionTitle + "\'" + ",StartTime=" + "N\'" + questionwithOption.StartTime + "\'" + ",EndTime=" + "N\'" + questionwithOption.EndTime + "\'" + ",DeadLineTime=" + "N\'" + questionwithOption.DeadLineTime + "\'" + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.PKID;
                        int questionupdateresult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, questionUpdateSql);
                        //  long insertquestionid = 0;
                        if (questionupdateresult >= 0)
                        {
                            #region YesOptionUpdate

                            var    optionAYescontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.YesOptionAUseIntegral, questionwithOption.YesOptionAWinCouponCount);
                            var    optionBYescontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.YesOptionBUseIntegral, questionwithOption.YesOptionBWinCouponCount);
                            var    optionCYescontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.YesOptionCUseIntegral, questionwithOption.YesOptionCWinCouponCount);
                            string yesoptionUpdateSql = string.Empty;
                            yesoptionUpdateSql += "Update Activity..QuestionOption set OptionContent=" + "N\'" + optionAYescontent + "\'" + ",UseIntegral=" + questionwithOption.YesOptionAUseIntegral + ",WinCouponCount=" + questionwithOption.YesOptionAWinCouponCount + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.YesOptionAPKID;
                            yesoptionUpdateSql += "\n";
                            yesoptionUpdateSql += "Update Activity..QuestionOption set OptionContent=" + "N\'" + optionBYescontent + "\'" + ",UseIntegral=" + questionwithOption.YesOptionBUseIntegral + ",WinCouponCount=" + questionwithOption.YesOptionBWinCouponCount + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.YesOptionBPKID;
                            yesoptionUpdateSql += "\n";
                            yesoptionUpdateSql += "Update Activity..QuestionOption set OptionContent=" + "N\'" + optionCYescontent + "\'" + ",UseIntegral=" + questionwithOption.YesOptionCUseIntegral + ",WinCouponCount=" + questionwithOption.YesOptionCWinCouponCount + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.YesOptionCPKID;
                            yesoptionUpdateSql += "\n";
                            int Yesaffectrows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, yesoptionUpdateSql);
                            if (Yesaffectrows < 0)
                            {
                                db.Rollback();
                                operationsuccess = false;
                                return(false);
                            }

                            #endregion
                            #region NoOptionInsert

                            var    optionANocontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.NoOptionAUseIntegral, questionwithOption.NoOptionAWinCouponCount);
                            var    optionBNocontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.NoOptionBUseIntegral, questionwithOption.NoOptionBWinCouponCount);
                            var    optionCNocontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.NoOptionCUseIntegral, questionwithOption.NoOptionCWinCouponCount);
                            string nooptionUpdateSql = string.Empty;
                            nooptionUpdateSql += "Update Activity..QuestionOption set OptionContent=" + "N\'" + optionANocontent + "\'" + ",UseIntegral=" + questionwithOption.NoOptionAUseIntegral + ",WinCouponCount=" + questionwithOption.NoOptionAWinCouponCount + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.NoOptionAPKID;
                            nooptionUpdateSql += "\n";
                            nooptionUpdateSql += "Update Activity..QuestionOption set OptionContent=" + "N\'" + optionBNocontent + "\'" + ",UseIntegral=" + questionwithOption.NoOptionBUseIntegral + ",WinCouponCount=" + questionwithOption.NoOptionBWinCouponCount + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.NoOptionBPKID;
                            nooptionUpdateSql += "\n";
                            nooptionUpdateSql += "Update Activity..QuestionOption set OptionContent=" + "N\'" + optionCNocontent + "\'" + ",UseIntegral=" + questionwithOption.NoOptionCUseIntegral + ",WinCouponCount=" + questionwithOption.NoOptionCWinCouponCount + ",LastUpdateDateTime=" + "N\'" + DateTime.Now + "\'" + " where PKID=" + questionwithOption.NoOptionCPKID;
                            nooptionUpdateSql += "\n";
                            int Noaffectrows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, nooptionUpdateSql);
                            if (Noaffectrows < 0)
                            {
                                db.Rollback();
                                operationsuccess = false;
                                return(false);
                            }
                        }
                        else
                        {
                            db.Rollback();
                            operationsuccess = false;
                            return(false);
                        }
                        #endregion
                    }

                    if (operationsuccess)
                    {
                        db.Commit();

                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    db.Rollback();
                    return(false);
                }
            }
            return(operationsuccess);
        }
Exemple #30
0
        public bool SaveQuestionWithOptionList(List <QuestionWithOption> questionWithOptionList)
        {
            var    operationsuccess = true;
            string conn             = ConnectionHelper.GetDecryptConn("Gungnir");

            using (var db = new SqlDbHelper(conn))
            {
                try
                {
                    long questionaireId = 0;
                    db.BeginTransaction();
                    string sql = "select top 1 PKID from Activity..Questionnaire where QuestionnaireType=5";
                    object questionaireIdObj = SqlHelper.ExecuteScalar(conn, CommandType.Text, sql);
                    if (questionaireIdObj != null)
                    {
                        questionaireId = Convert.ToInt64(questionaireIdObj);
                    }
                    string questionInsertSql = string.Empty;
                    foreach (var questionwithOption in questionWithOptionList)
                    {
                        questionInsertSql = @"insert into Activity..Question(QuestionnaireID,QuestionTitle,QuestionType,IsRequired,IsValidateStartDate,StartTime,IsValidateEndDate,EndTime,DeadLineTime) values(" + questionaireId + "," + "N\'" + questionwithOption.QuestionTitle + "\'" + "," + questionwithOption.QuestionType + "," + "1" + "," + "1" + "," + "N\'" + questionwithOption.StartTime + "\'" + "," + "1" + "," + "N\'" + questionwithOption.EndTime + "\'" + "," + "N\'" + questionwithOption.DeadLineTime + "\'" + "); SELECT SCOPE_IDENTITY();";
                        var  insertquestionidOjb = SqlHelper.ExecuteScalar(conn, CommandType.Text, questionInsertSql);
                        long insertquestionid    = 0;
                        if (insertquestionidOjb != null && long.TryParse(insertquestionidOjb.ToString(), out insertquestionid) && insertquestionid > 0)
                        {
                            questionwithOption.PKID = insertquestionid;
                            #region YesOptionInsert
                            var  yesquestionInsertSql   = @"insert into Activity..QuestionOption(QuestionnaireID, QuestionID, OptionContent) values(" + questionaireId + "," + insertquestionid + "," + "N\'是\'" + "); SELECT SCOPE_IDENTITY();";
                            var  yesinsertquestionidOjb = SqlHelper.ExecuteScalar(conn, CommandType.Text, yesquestionInsertSql);
                            long yesinsertquestionid    = 0;
                            if (yesinsertquestionidOjb != null && long.TryParse(yesinsertquestionidOjb.ToString(), out yesinsertquestionid) && yesinsertquestionid > 0)
                            {
                                var    optionAYescontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.YesOptionAUseIntegral, questionwithOption.YesOptionAWinCouponCount);
                                var    optionBYescontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.YesOptionBUseIntegral, questionwithOption.YesOptionBWinCouponCount);
                                var    optionCYescontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.YesOptionCUseIntegral, questionwithOption.YesOptionCWinCouponCount);
                                string yesoptionInsertSql = string.Empty;
                                yesoptionInsertSql += @"insert into Activity..QuestionOption(QuestionnaireID,QuestionID,OptionContent,QuestionParentID,UseIntegral,WinCouponCount) values(" + questionaireId + "," + insertquestionid + "," + "N\'" + optionAYescontent + "\'" + "," + yesinsertquestionid + "," + questionwithOption.YesOptionAUseIntegral + "," + questionwithOption.YesOptionAWinCouponCount + ")";
                                yesoptionInsertSql += "\n";
                                yesoptionInsertSql += @"insert into Activity..QuestionOption(QuestionnaireID,QuestionID,OptionContent,QuestionParentID,UseIntegral,WinCouponCount) values(" + questionaireId + "," + insertquestionid + "," + "N\'" + optionBYescontent + "\'" + "," + yesinsertquestionid + "," + questionwithOption.YesOptionBUseIntegral + "," + questionwithOption.YesOptionBWinCouponCount + ")";
                                yesoptionInsertSql += "\n";
                                yesoptionInsertSql += @"insert into Activity..QuestionOption(QuestionnaireID,QuestionID,OptionContent,QuestionParentID,UseIntegral,WinCouponCount) values(" + questionaireId + "," + insertquestionid + "," + "N\'" + optionCYescontent + "\'" + "," + yesinsertquestionid + "," + questionwithOption.YesOptionCUseIntegral + "," + questionwithOption.YesOptionCWinCouponCount + ")";
                                yesoptionInsertSql += "\n";
                                int affectrows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, yesoptionInsertSql);
                                if (affectrows < 0)
                                {
                                    db.Rollback();
                                    operationsuccess = false;
                                    return(false);
                                }
                            }
                            else
                            {
                                db.Rollback();
                                operationsuccess = false;
                                return(false);
                            }
                            #endregion
                            #region NoOptionInsert
                            var  noquestionInsertSql   = @"insert into Activity..QuestionOption(QuestionnaireID, QuestionID, OptionContent) values(" + questionaireId + "," + insertquestionid + "," + "N\'否\'" + "); SELECT SCOPE_IDENTITY();";
                            var  noinsertquestionidOjb = SqlHelper.ExecuteScalar(conn, CommandType.Text, noquestionInsertSql);
                            long noinsertquestionid    = 0;
                            if (noinsertquestionidOjb != null && long.TryParse(noinsertquestionidOjb.ToString(), out noinsertquestionid) && noinsertquestionid > 0)
                            {
                                var    optionANocontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.NoOptionAUseIntegral, questionwithOption.NoOptionAWinCouponCount);
                                var    optionBNocontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.NoOptionBUseIntegral, questionwithOption.NoOptionBWinCouponCount);
                                var    optionCNocontent  = string.Format("使用{0}积分,猜对赢{1}兑换券", questionwithOption.NoOptionCUseIntegral, questionwithOption.NoOptionCWinCouponCount);
                                string nooptionInsertSql = string.Empty;
                                nooptionInsertSql += @"insert into Activity..QuestionOption(QuestionnaireID,QuestionID,OptionContent,QuestionParentID,UseIntegral,WinCouponCount) values(" + questionaireId + "," + insertquestionid + "," + "N\'" + optionANocontent + "\'" + "," + noinsertquestionid + "," + questionwithOption.YesOptionAUseIntegral + "," + questionwithOption.YesOptionAWinCouponCount + ")";
                                nooptionInsertSql += "\n";
                                nooptionInsertSql += @"insert into Activity..QuestionOption(QuestionnaireID,QuestionID,OptionContent,QuestionParentID,UseIntegral,WinCouponCount) values(" + questionaireId + "," + insertquestionid + "," + "N\'" + optionBNocontent + "\'" + "," + noinsertquestionid + "," + questionwithOption.YesOptionBUseIntegral + "," + questionwithOption.YesOptionBWinCouponCount + ")";
                                nooptionInsertSql += "\n";
                                nooptionInsertSql += @"insert into Activity..QuestionOption(QuestionnaireID,QuestionID,OptionContent,QuestionParentID,UseIntegral,WinCouponCount) values(" + questionaireId + "," + insertquestionid + "," + "N\'" + optionCNocontent + "\'" + "," + noinsertquestionid + "," + questionwithOption.YesOptionCUseIntegral + "," + questionwithOption.YesOptionCWinCouponCount + ")";
                                nooptionInsertSql += "\n";
                                int affectrows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, nooptionInsertSql);
                                if (affectrows < 0)
                                {
                                    db.Rollback();
                                    operationsuccess = false;
                                    return(false);
                                }
                            }
                            else
                            {
                                db.Rollback();
                                operationsuccess = false;
                                return(false);
                            }
                            #endregion
                        }
                        else
                        {
                            db.Rollback();
                            operationsuccess = false;
                            return(false);
                        }
                    }

                    if (operationsuccess)
                    {
                        db.Commit();

                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    db.Rollback();
                    return(false);
                }
            }
            return(operationsuccess);
        }