问题列表 - 第8142页

如何使用C#解锁被阻止的网站?

这是从listview中取消阻止任何网站的一些代码,但现在我想要取消阻止之前被阻止的网站.我怎样才能做到这一点?

String path = @"C:\Windows\System32\drivers\etc\hosts";
StreamWriter sw = new StreamWriter(path, true);
String sitetoblock = "\n 127.0.0.1 http://"+listView1.SelectedItems[0].Text+"";
sw.Write(sitetoblock);
sw.Close();
MessageBox.Show(listView1.SelectedItems[0].Text " blocked");
Run Code Online (Sandbox Code Playgroud)

c# file-io hosts

1
推荐指数
1
解决办法
6340
查看次数

使用LINQ to SQL在数据库之间进行复制

鉴于两个相同模式的数据库,有没有简单的方法在两者之间传输记录?我正在使用LINQ to SQL,因为我需要在此过程中执行一些额外的操作,并且使用表示我正在传输的记录的对象使这更容易.这是一个小规模的帮助应用程序,因此SSIS可能有点过分,SQLBulkCopy不允许我在途中轻松查询对象.

我想做的是:

public static void TransferCustomer
                     (DBDataContext DCSource, 
                      DBDataContext DCDest, 
                      int CustomerID)
{
  Customer customer;
  using (DCSource = new DBDataContext(SourceConnStr))
  {
    customer = DCSource.Customers
                       .Where(c => c.CustomerID == CustomerID)
                       .Single();
  }

  using (DCDest = new DBDataContext(DestConnStr))
  {
    DCDest.Customers.InsertOnSubmit(customer);
    DCDest.SubmitChanges();
  }
}
Run Code Online (Sandbox Code Playgroud)

但是由于显而易见的原因,这会引发消息异常:

已尝试附加或添加非新的实体,可能已从另一个DataContext加载.这不受支持.

我可以通过像这样对象的浅拷贝来解决这个问题:

public static Customer Clone(this Customer customer)
{
  return new Customer()
  {
    Name = customer.Name,
    Email = customer.Email
    etc...
  };
}
Run Code Online (Sandbox Code Playgroud)

然后插入克隆的项目.如果我只复制有问题的字段,而不是任何表示表关系的引用,这可以正常工作.然而,它有点啰嗦,我正在做的方式需要我手动分配克隆方法中的每个字段.任何人都可以建议任何使这更容易的方法吗?我想知道的两件事是:

  1. LINQ to SQL能否以更简单的方式执行此操作,
  2. 有没有一种很好的方法可以使用Reflection来制作一个可以插入的浅拷贝?

非常感谢!

c# linq-to-sql

9
推荐指数
1
解决办法
6802
查看次数

SSRS:在每行上重复tablix最左侧的行组值

我在SSRS 2008报告中有一个Tablix.它有两级行分组,我希望最左边分组的值继续显示在每一行上.我知道了:

group1  subgroup1  500.00
        subgroup2  250.00
Run Code Online (Sandbox Code Playgroud)

......但我更喜欢......

group1  subgroup1  500.00
group1  subgroup2  500.00
Run Code Online (Sandbox Code Playgroud)

我似乎无法找到这个选项.想要一件奇怪的事吗?

比尔谢谢你

sql-server reporting-services ssrs-2008

7
推荐指数
3
解决办法
3万
查看次数

HTML中的新闻稿是否应该具有"基于表格"的布局?

我在某处读到,在创建HTML电子邮件时,您应该使用基于表格的布局.您不应该关心创建无表格的基于CSS的布局.真的吗?我必须为我的公司创建一个简报布局,但我不觉得写3个嵌套表很舒服.

html css w3c newsletter

10
推荐指数
3
解决办法
4235
查看次数

为什么不能改变原始类型变量的值?

    public class testtype
{
  private   int a;
  private double b;

   testtype(int a,double b)
  {
    this.a=a;
    this.b=b;
  }

  public void maketoequal(testtype oo)
  {
    oo.a=this.a;
    oo.b=this.b;
  }

  void trytoequal(int c)
  {
    c=this.a;
  }

  public static void main(String[] args)
  {
    testtype t1,t2;
    t1=new testtype(10,15.0);
    t2=new testtype(5,100.0);
    t1.maketoequal(t2);
    System.out.println("after the method is called:"+"\n"+"the value of a for t2 is:"+t2.a
    +"\n"+"the value of b for t2 is :"+t2.b);
    int c=50;
    t1.trytoequal(c);
    System.out.println("the value of c after the method be called is:"+c);
  }
}
Run Code Online (Sandbox Code Playgroud)

为什么c没有改变?

java

-1
推荐指数
2
解决办法
2757
查看次数

Apache FilesMatch - 匹配正则表达式中的文件夹

我正在尝试使用Apache的.htaccess文件缓存一些文件.我想缓存一个特定的文件夹比其他任何东西都长,所以我一直在尝试使用FilesMatch指令,如下所示:

<FilesMatch "skins(.*)\.(jpg|png|gif)">
ExpiresDefault A2592000
</FilesMatch>

我希望能够将所有图像文件缓存在/ skins /目录及其子目录中.但是,我无法完全使用正则表达式--Aracle只是完全忽略它.

如何匹配<FilesMatch>.htaccess文件中的文件夹?

干杯,
马特

regex apache .htaccess mod-expires

12
推荐指数
3
解决办法
3万
查看次数

二进制数学

如果我知道数字y并且知道2 ^ x = y,我该如何计算x?

math

2
推荐指数
1
解决办法
309
查看次数

多态或通用方法更好?C#

我有两个类和一个界面

interface IVehicle
{
    void Drive();
}

class Benz :IVehicle
{
    public void Drive()
    {
        Console.WriteLine("WOW! driving benz");
    }
}

class Ferrari : IVehicle
{
    public void Drive()
    {
        Console.WriteLine("WOW! driving ferrari");
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个使用它的Driver类.

class Driver
{
    public void StartDriving(IVehicle vehicle)
    {
        vehicle.Drive();
    }
}
Run Code Online (Sandbox Code Playgroud)

还有一个通用的驱动程序.

class GenericDriver
{
    public void StartDriving<T>() where T : IVehicle , new()
    {
        T vehicle = new T();
        vehicle.Drive();
    }
}
Run Code Online (Sandbox Code Playgroud)

问题

  1. 与普通驱动程序相比,您认为通用实现有什么优势吗?如果是的话,他们是什么?
  2. 你更倾向哪个?通用的还是普通的?
  3. 有没有更好的方法来实现通用驱动程序?
  4. 我觉得与C++模板相比,C#中的泛型非常有限.真的吗?

有什么想法吗?

c# c++ generics templates

4
推荐指数
1
解决办法
342
查看次数

你如何调试Java Applets?

目前,我所拥有的唯一信息是浏览器状态栏中的单行错误消息.

你知道如何获得堆栈跟踪吗?

java debugging applet

56
推荐指数
2
解决办法
8万
查看次数

协同RegEx开发

我正在寻找Collaborative RegEx网站或软件,在那里可以提交几个"匹配"和"不匹配"的案例,然后其他人可能会重构正则表达式.喜欢refactormycode.com,但有RegEx扭曲.通过这种方式,可以根据给定的匹配测试查看哪些代码执行速度更快,实际上是正确的.

这可以作为任何人都可以编辑(如维基)或团队内的网站非常有用.

我一直在想这个,对我来说很有意义.有这样的网站/软件吗?如果不是,那么,为什么不呢?

regex collaboration refactoring

10
推荐指数
0
解决办法
424
查看次数