public class SharedCacheData : ISharedCacheData
{
private readonly ISharedPetsService mPetsService;
private static ISharedEmployeeService mSharedEmployeeService;
public SharedCacheData(ISharedPetsService petsService, ISharedEmployeeService employeeService)
{
mPetsService = petsService;
mSharedEmployeeService = employeeService;
}
public static string GetUserFullName(string key)
{
Hashtable value = HttpContext.Current.Application[USERFULLNAME_KEY] as Hashtable;
if (value == null)
{
value = new Hashtable();
HttpContext.Current.Application[USERFULLNAME_KEY] = value;
}
if (value.ContainsKey(key))
return value[key] as string;
string name = mSharedEmployeeService.FindOneUser(key);
value[key] = name;
return name;
}
Run Code Online (Sandbox Code Playgroud)
是否在构造函数中初始化静态字段mSharedEmployeeService(service)?
关于在产品集合中使用- > addCategoryFilter.为什么不能按根类别过滤?我有2个商店,都有不同的根类别.我想在我的主页上显示畅销产品列表.但我无法按照根类别过滤产品,只能根据该类别过滤子类别.
因此,在我的主页上,两家商店的所有产品都会显示出来.我可以通过任何子类别过滤ok.例如,我的第二个根类别的ID为35.如果我尝试按此过滤,我会从两个根获得每个产品.但是该根下的第一个子类别是ID 36,并且通过此过滤可以正常工作,仅显示那些产品.我的电话如下(简化):
$_category = Mage::getModel('catalog/category')->load(35);
$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($_category)
->addAttributeToSelect('*');
$_testproductCollection->load();
foreach($_testproductCollection as $_testproduct){
echo $this->htmlEscape($_testproduct->getName())."<br/>";
};
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么这不起作用?或者是否有其他方法可以根据根类别进行过滤?
更新: 我还没有运气.似乎非常错误 - 使用根类别添加类别过滤器有时只能工作,您需要将所有产品添加到根,然后保存,然后删除不应该在该根cat中的任何产品,然后重新保存.但如果你重新索引,你会再次展示所有产品.如果我从上面的集合调用输出sql查询,我得到以下内容:
SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(`price_index`.`tier_price`, LEAST(`price_index`.`min_price`, `price_index`.`tier_price`), `price_index`.`min_price`) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='2' AND cat_index.category_id='35' INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
Run Code Online (Sandbox Code Playgroud)
如您所见,该类别列在那里,为什么过滤器不起作用?
我目前有一个.NET自定义配置部分,如下所示:
<customSection name="My section" />
Run Code Online (Sandbox Code Playgroud)
我想要的是将它写为textnode(我不确定这是否是正确的术语?),如下所示:
<customSection>
<name>My Section</name>
</customSection>
Run Code Online (Sandbox Code Playgroud)
我当前的customSection类看起来像这样:
public class CustomSection: ConfigurationSection {
[ConfigurationProperty("name")]
public String Name {
get {
return (String)this["name"];
}
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能使它成为一个textnode?
我正在尝试理解一些MSBuild概念(我熟悉NAnt).
我尝试初始化目标中的某些属性,然后在另一个中使用它.这是一个例子
<propertygroup>
<MyProp>X</MyProp>
</propertygroup>
<target name="Main">
<message text="$(MyProp)"/> <!-- Display 'X' -->
<CallTarget Target="Sub">
<Output TaskParameter="localProp" PropertyName="MyProp"/>
</CallTarget>
<message text="$(MyProp)"/> <!-- should display 'Y' -->
</target>
<target name="Sub" Outputs=$(localProp)>
<propertygroup>
<localProp>Y</localProp>
</propertygroup>
</target>
Run Code Online (Sandbox Code Playgroud)
它当然不起作用.
我有一个简单的按钮ADD
而ADD_Click代码是:
protected void Add_Click(object sender, EventArgs e)
{
string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;
SqlConnection myConnection = new SqlConnection(strConnectionString);
myConnection.Open();
string hesap = Label1.Text;
string musteriadi = DropDownList1.SelectedItem.Value;
string avukat = DropDownList2.SelectedItem.Value;
SqlCommand cmd = new SqlCommand("INSERT INTO AVUKAT VALUES (@MUSTERI, @AVUKAT, @HESAP)", myConnection);
cmd.Parameters.AddWithValue("@HESAP", hesap);
cmd.Parameters.AddWithValue("@MUSTERI", musteriadi);
cmd.Parameters.AddWithValue("@AVUKAT", avukat);
cmd.Connection = myConnection;
SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
Response.Redirect(Request.Url.ToString());
myConnection.Close();
}
Run Code Online (Sandbox Code Playgroud)
我想要的是,如果有人用相同的HESAP(主键)添加数据我想要一个带有这个词的alert()函数."已经有相同的数据"或任何文字.无所谓.
我怎样才能做到这一点?
注意:我只想获得相同的HESAP值并捕获错误.
《Effective Java #77》规定,我们必须readResolve在序列化过程中使用单例保证。他们已经使用了这个例子。
public class Elvis implements Serializable{
public static final Elvis INSTANCE = new Elvis();
private Elvis() { ... }
public void leaveTheBuilding() { ... }
Run Code Online (Sandbox Code Playgroud)
他们建议使用
如果Elvis类实现了Serialized,下面的readResolve方法足以保证单例属性:
// readResolve for instance control - you can do better!
private Object readResolve() {
// Return the one true Elvis and let the garbage collector
// take care of the Elvis impersonator.
return INSTANCE; }
Run Code Online (Sandbox Code Playgroud)
此方法忽略反序列化的对象,返回类初始化时创建的杰出 Elvis 实例。
当从mysql数据库中提取数据时,符号 显示而不是£
有问题的字段整理为utf8_general_ci
我也有<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />页面的head标签
有什么想法吗?
我试图使用此代码获取Android手机的屏幕分辨率
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
str_ScreenSize = dm.widthPixels + " x " + dm.heightPixels;
str_ScreenSize = "dd" + " x " + dm.heightPixels;
Run Code Online (Sandbox Code Playgroud)
当我在我的Galaxy S手机中尝试此代码时,屏幕分辨率为320x533像素,但实际上Galaxy S的屏幕分辨率为480x800像素.那么代码有什么问题?
如何获得特定设备的实际屏幕分辨率?
我需要改变我在同一行中将开口括号放到新行的编码风格.我需要找到并替换(空格){with(换行符){.我听说使用正则表达式查找和替换,它非常简单.
有人可以帮我吗?
我在NLog库中遇到此方法的问题: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state)
它消耗了太多的CPU时间.我使用Nlog长期运行Windows服务,两天后我的服务消耗超过80%的CPU时间(一个核心几乎是80%,第二个30%).它不是100%的cpu时间,但它正在改变,并且在cca 2小时后它恢复正常.所以我运行了探查器,这个metod可能会导致它:NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(对象状态)
我有10个文件目标都被设置为异步.事实上我在我的应用程序中有很多日志记录,但只在级别Trace上,如果我切换到Info级别它没有帮助.
你能帮我吗,我应该减少我的应用程序中的日志记录吗?