public virtual string EnsureDatabaseObjectSeName(string type, int id)
        {
            if (id == 0)
            {
                return(string.Empty);
            }

            using (var connection = new SqlConnection(DB.GetDBConn()))
            {
                connection.Open();

                string name, seName;
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = string.Format("select Name, SEName from [{0}] with(nolock) where {0}ID = @id", type);
                    command.Parameters.AddWithValue("id", id);

                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(string.Empty);
                        }

                        name   = reader.FieldByLocale("Name", Localization.GetUSLocale());                       // SENames are ALWAYS from U.S locale
                        seName = reader.Field("SEName");
                    }
                }

                if (!string.IsNullOrEmpty(seName))
                {
                    return(CommonLogic.Left(GenerateSeName(seName), 90));
                }

                // Update the SEName field since it's empty
                var newSeName = CommonLogic.Left(GenerateSeName(name), 90);
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = string.Format("update [{0}] set SEName = @seName where {0}ID = @id", type);
                    command.Parameters.AddWithValue("seName", newSeName);
                    command.Parameters.AddWithValue("id", id);
                    command.ExecuteNonQuery();
                }

                return(newSeName);
            }
        }
Ejemplo n.º 2
0
        public static String GetEntitySEName(String EntityName, int EntityID)
        {
            String uname = String.Empty;

            if (EntityID != 0)
            {
                if (EntityName == "Product" || EntityName == "ProductVariant")
                {
                    using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
                    {
                        con.Open();
                        using (IDataReader rs = DB.GetRS("Select Name,SEName from [" + EntityName.Replace("]", "") + "]  with (NOLOCK)  where " + EntityName + "ID=" + EntityID.ToString(), con))
                        {
                            if (rs.Read())
                            {
                                uname = DB.RSField(rs, "SEName");
                                if (uname.Length == 0)
                                {
                                    uname = DB.RSFieldByLocale(rs, "Name", Localization.GetUSLocale());                           // SENames are ALWAYS from U.S locale
                                    //update the SEName Field since it's empty
                                    DB.ExecuteSQL(String.Format("update [" + EntityName.Replace("]", "") + "] set SEName={0} where " + EntityName + "ID={1}", DB.SQuote(CommonLogic.Left(SE.MungeName(uname), 90)), EntityID));
                                }
                            }
                        }
                    }
                }
                else
                {
                    using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
                    {
                        con.Open();
                        using (IDataReader rs = DB.GetRS("select SEName,Name from [" + EntityName.Replace("]", "") + "]  with (NOLOCK)  where " + EntityName + "ID=" + EntityID.ToString(), con))
                        {
                            if (rs.Read())
                            {
                                uname = DB.RSField(rs, "SEName");
                                if (uname.Length == 0)
                                {
                                    uname = DB.RSFieldByLocale(rs, "Name", Localization.GetUSLocale());
                                    //update the SEName Field since it's empty
                                    DB.ExecuteSQL(String.Format("update [" + EntityName.Replace("]", "") + "] set SEName={0} where " + EntityName + "ID={1}", DB.SQuote(CommonLogic.Left(SE.MungeName(uname), 90)), EntityID));
                                }
                            }
                        }
                    }
                }
            }
            return(CommonLogic.Left(SE.MungeName(uname), 90));
        }