Exemplo n.º 1
0
        public static bool InsertTirePatternConfig(SqlConnection conn, TirePatternConfig config)
        {
            string sql      = @"INSERT Tuhu_productcatalog.[dbo].[TirePatternConfig] (   CP_Brand ,
                                                         Tire_Pattern ,
                                                         Pattern_EN ,
                                                         Pattern_CN ,
                                                         CreateDateTime ,
                                                         LastUpdateDateTime
                                                     )
                           VALUES ( @brand ,
                                    @pattern ,
                                    @patternEN ,
                                    @patternCN ,
                                    @createTime ,
                                    @updateTime
                                  );";
            var    sqlParam = new[]
            {
                new SqlParameter("@brand", config.CP_Brand),
                new SqlParameter("@pattern", config.Tire_Pattern),
                new SqlParameter("@patternEN", config.Pattern_EN),
                new SqlParameter("@patternCN", config.Pattern_CN),
                new SqlParameter("@createTime", config.CreateDateTime),
                new SqlParameter("@updateTime", config.LastUpdateDateTime),
            };

            return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, sqlParam) > 0 ? true : false);
        }
 public bool UpdateTirePatternConfig(TirePatternConfig oldConfig, TirePatternConfig newConfig)
 {
     try
     {
         return(handler.UpdateTirePatternConfig(oldConfig, newConfig));
     }
     catch (TuhuBizException)
     {
         throw;
     }
     catch (Exception ex)
     {
         var exception = new DownloadAppException(1, "UpdateTirePatternConfig", ex);
         Logger.Log(Level.Error, exception, "UpdateTirePatternConfig");
         throw ex;
     }
 }
 public bool InsertTirePatternConfig(TirePatternConfig config)
 {
     try
     {
         return(handler.InsertTirePatternConfig(config));
     }
     catch (TuhuBizException)
     {
         throw;
     }
     catch (Exception ex)
     {
         var exception = new DownloadAppException(1, "InsertTirePatternConfig", ex);
         Logger.Log(Level.Error, exception, "InsertTirePatternConfig");
         throw ex;
     }
 }
Exemplo n.º 4
0
        public static bool UpdateTirePatternConfigExpectPattern(SqlConnection conn, TirePatternConfig config)
        {
            string sql      = @"UPDATE Tuhu_productcatalog.[dbo].[TirePatternConfig]  WITH (ROWLOCK)
                           SET    CP_Brand = @brand ,
                                  Pattern_EN = @patternEN ,
                                  Pattern_CN = @patternCN ,
                                  LastUpdateDateTime = @updateTime
                           WHERE  Tire_Pattern = @pattern;";
            var    sqlParam = new[]
            {
                new SqlParameter("@brand", config.CP_Brand),
                new SqlParameter("@pattern", config.Tire_Pattern),
                new SqlParameter("@patternEN", config.Pattern_EN),
                new SqlParameter("@patternCN", config.Pattern_CN),
                new SqlParameter("@updateTime", config.LastUpdateDateTime),
            };

            return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, sqlParam) > 0 ? true : false);
        }
        public bool UpdateTirePatternConfig(TirePatternConfig oldConfig, TirePatternConfig newConfig)
        {
            Func <SqlConnection, bool> action = (connecttion) => DalTirePatternConfig.UpdateTirePatternConfig(connecttion, oldConfig, newConfig);

            return(dbManager.Execute(action));
        }
        public bool UpdateTirePatternConfigExpectPattern(TirePatternConfig config)
        {
            Func <SqlConnection, bool> action = (connecttion) => DalTirePatternConfig.UpdateTirePatternConfigExpectPattern(connecttion, config);

            return(dbManager.Execute(action));
        }
        public bool InsertTirePatternConfig(TirePatternConfig config)
        {
            Func <SqlConnection, bool> action = (connecttion) => DalTirePatternConfig.InsertTirePatternConfig(connecttion, config);

            return(dbManager.Execute(action));
        }
Exemplo n.º 8
0
        public static bool UpdateTirePatternConfig(SqlConnection conn, TirePatternConfig oldConfig, TirePatternConfig newConfig)
        {
            string Sql_DisableOldPattern = @"UPDATE Tuhu_productcatalog.[dbo].[TirePatternConfig] WITH (ROWLOCK)
                                             SET    IsDelete = 1 ,
                                                    LastUpdateDateTime = GETDATE()
                                             WHERE  Tire_Pattern = @pattern;";
            string Sql_NewPatternExist   = @"SELECT *
                                           FROM   Tuhu_productcatalog.[dbo].[TirePatternConfig] WITH ( NOLOCK )
                                           WHERE  Tire_Pattern = @pattern;";
            string Sql_InsertNewPattern  = @"INSERT Tuhu_productcatalog.[dbo].[TirePatternConfig] (    CP_Brand ,
                                                         Tire_Pattern ,
                                                         Pattern_EN ,
                                                         Pattern_CN ,
                                                         CreateDateTime ,
                                                         LastUpdateDateTime
                                                    )
                                            VALUES ( @brand ,
                                                     @pattern ,
                                                     @patternEN ,
                                                     @patternCN ,
                                                     GETDATE() ,
                                                     GETDATE() );";
            string Sql_EnableNewPattern  = @"UPDATE Tuhu_productcatalog.[dbo].[TirePatternConfig] WITH (ROWLOCK)
                                            SET    IsDelete = 0 ,
                                                   CP_Brand = @brand ,
                                                   Pattern_EN = @patternEN ,
                                                   Pattern_CN = @patternCN ,
                                                   LastUpdateDateTime = GETDATE()
                                            WHERE  Tire_Pattern = @pattern;";
            string Sql_UpdateCatalog     = @"UPDATE Tuhu_productcatalog.dbo.[CarPAR_zh-CN_Catalog] WITH (ROWLOCK)
                                         SET    CP_Tire_Pattern = @newPattern
                                         WHERE  CP_Tire_Pattern = @oldPattern;";

            using (var disableCmd = new SqlCommand(Sql_DisableOldPattern))
                using (var existCmd = new SqlCommand(Sql_NewPatternExist))
                    using (var insertCmd = new SqlCommand(Sql_InsertNewPattern))
                        using (var enableCmd = new SqlCommand(Sql_EnableNewPattern))
                            using (var updateCmd = new SqlCommand(Sql_UpdateCatalog))
                                using (var dbHelper = DbHelper.CreateDefaultDbHelper())
                                {
                                    dbHelper.BeginTransaction();
                                    try
                                    {
                                        disableCmd.Parameters.AddWithValue("@pattern", oldConfig.Tire_Pattern);
                                        var result_disable = dbHelper.ExecuteNonQuery(disableCmd);
                                        if (result_disable <= 0)
                                        {
                                            dbHelper.Rollback();
                                            return(false);
                                        }

                                        existCmd.Parameters.AddWithValue("@pattern", newConfig.Tire_Pattern);
                                        var result_exist = dbHelper.ExecuteDataTable(existCmd).ConvertTo <TirePatternConfig>().ToList();
                                        if (result_exist == null || !result_exist.Any())
                                        {
                                            insertCmd.Parameters.AddWithValue("@brand", newConfig.CP_Brand);
                                            insertCmd.Parameters.AddWithValue("@pattern", newConfig.Tire_Pattern);
                                            insertCmd.Parameters.AddWithValue("@patternEN", newConfig.Pattern_EN);
                                            insertCmd.Parameters.AddWithValue("@patternCN", newConfig.Pattern_CN);
                                            var result_insert = dbHelper.ExecuteNonQuery(insertCmd);
                                            if (result_insert <= 0)
                                            {
                                                dbHelper.Rollback();
                                                return(false);
                                            }
                                        }
                                        else
                                        {
                                            enableCmd.Parameters.AddWithValue("@brand", newConfig.CP_Brand);
                                            enableCmd.Parameters.AddWithValue("@patternEN", newConfig.Pattern_EN);
                                            enableCmd.Parameters.AddWithValue("@patternCN", newConfig.Pattern_CN);
                                            enableCmd.Parameters.AddWithValue("@pattern", newConfig.Tire_Pattern);
                                            var result_enable = dbHelper.ExecuteNonQuery(enableCmd);
                                            if (result_enable <= 0)
                                            {
                                                dbHelper.Rollback();
                                                return(false);
                                            }
                                        }

                                        updateCmd.Parameters.AddWithValue("oldPattern", oldConfig.Tire_Pattern);
                                        updateCmd.Parameters.AddWithValue("newPattern", newConfig.Tire_Pattern);

                                        var result_update = dbHelper.ExecuteNonQuery(updateCmd);
                                        if (result_update < 0)
                                        {
                                            dbHelper.Rollback();
                                            return(false);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        dbHelper.Rollback();
                                        return(false);
                                    }
                                    dbHelper.Commit();
                                    return(true);
                                }
        }