小编zSy*_*sis的帖子

用Ifs重构帮助

我一直在研究这段代码,出于某种原因,所有的if都让我疯狂了,还有一堆重复的代码.有更好的清洁方法吗?

public Program(string[] args)
    {
        try
        {
            WriteToLogFile("Starting ImportTask");
            if (args.Length == 0)
            {
                Import(DateTime.Now,DateTime.Now);
                MarkRecordsAsDeleted();
            }
            else if (args.Length == 1)
            {
                DateTime dateToImport;
                bool isValidDate = DateTime.TryParse(args[0], out dateToImport);
                if (isValidDate)
                {
                    Import(dateToImport,dateToImport);
                    MarkRecordsAsDeleted();
                }
                else
                    WriteToLogFile(String.Format("The Import date specified was invalid. - {0}", args[0]));
            }
            else if (args.Length == 2)
            {
                DateTime importStartDate;
                bool isValidStartDate = DateTime.TryParse(args[0], out importStartDate);
                DateTime importEndDate;
                bool isValidEndDate = DateTime.TryParse(args[0], out importEndDate);
                if (isValidStartDate && isValidEndDate)
                {
                    if (importStartDate > importEndDate)
                    { …
Run Code Online (Sandbox Code Playgroud)

refactoring .net-2.0

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

类设计输入

我目前的服务类看起来像这样

public class UserService : IUserService 
{
    private IAssignmentService _assignmentService;
    private ILocationService _locationService;
    private IUserDal _userDal;
    private IValidationDictionary _validationDictionary;
    public UserService(IAssignmentService assignmentService, ILocationService locationService, IValidationDictionary validationDictionary)
    {
        this._assignmentService = assignmentService;
        this._locationService = locationService;
        this._userDAL = new UserDal();
        this._validationDictionary = validationDictionary;
    }

    .....

    private void ValidateUser(IUser user)
    {
       if (_locationService.GetBy(user.Location.Id) == null)
          _validationDictionary.AddError("....");
       if (_assignmentService.GetBy(user.Assignment.Id) == null)
          _validationDictionary.AddError("....");
       .....
    }
}
Run Code Online (Sandbox Code Playgroud)

和DAL类看起来像这样

public class UserDal: IUserDal
{
    private IAssignmentDal _assignmentDal;
    private ILocationDAL _locationDAL

    public UserDal()
    {
        this_assignmentDal = new AssignmentDal();
        this._locationDal …
Run Code Online (Sandbox Code Playgroud)

c# class-design

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

Oracle 8i查询帮助

我有一个看起来像这样的表:

     ID    |     STATUS    |     TYPE
----------------------------------------
x123       |      A        | High School
x122       |      I        | High School
x124       |      F        | High School
x125       |      A        | College
x126       |      I        | College
x127       |      F        | College
x128       |      F        | College
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我提出一个oracle 8i的查询,显示这样的表

Type             |    Count A    |    Count I    |  Count F
------------------------------------------------------------
High School      |     1         |     1         |  1
College          |     1         |     1         |  2
Run Code Online (Sandbox Code Playgroud)

谢谢!

sql oracle

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

循环遍历类的属性并获取非空属性的计数

我想知道是否有更简单的方法来做这样的事情?

    public int NonNullPropertiesCount(object entity)
    {
        if (entity == null) throw new ArgumentNullException("A null object was passed in");


        int nonNullPropertiesCount = 0;
        Type entityType = entity.GetType();

        foreach (var property in entityType.GetProperties())
        {
            if (property.GetValue(entity, null) != null)
                nonNullPropertiesCount = nonNullPropertiesCount+ 1;
        }


        return nonNullPropertiesCount;
    }
Run Code Online (Sandbox Code Playgroud)

c#-4.0

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

Threadpool内存不足异常

我继续在下面的代码中得到一个内存不足的例外,我想知道是否有什么东西可以阻止这种情况发生.

  private static List<string> MyIds { get; set; }
  private static object LockObject { get; set; }
  private static int Counter { get; set; }
  private static readonly NumOfThreads = 5;

  static void Main(string[] args)
  {
      try
      {
          Console.Clear();
          LockObject = new object();
          // Pull id's into memory (A list of around 1 million ids)
          MyIds = _repository.GetIds();
          for (int i = 0; i < NumOfThreads ; i++)
                ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), (object)i);

       }
       catch (Exception ex)
       {
           Console.WriteLine(ex.StackTrace);
       }
   }

   public …
Run Code Online (Sandbox Code Playgroud)

.net c# out-of-memory threadpool

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

使用 JAX-WS 在 java 中返回原始肥皂响应

我有一个程序,我在其中调用 jax-ws wsimport 函数生成的代码。它看起来是这样的:

HolidayService2 service = new HolidayService2();
HolidayService2Soap proxy = service.getHolidayService2Soap();
ArrayOfCountryCode countries = proxy.GetCountriesAvailable("USA");
Run Code Online (Sandbox Code Playgroud)

proxy.GetCountriesAvailable 方法调用 Web 服务并返回国家/地区代码数组。有什么方法可以在我的应用程序中显示原始肥皂响应吗?

谢谢你的帮助

java web-services jax-ws

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

CSS3PIE与ASP.NET MVC3

我正在尝试使用css3pie与asp.net mvc一起工作,但由于某种原因它不起作用.

我有一个包含内联css的视图,如下所示:

@{
    ViewBag.Title = "Home Page";
}

<div>


    <div class="contentWrapper" style="width:600px;margin:25px auto;">
        Hello World
        <input name="button" value="Button" class="button" type="button" />
    </div>
</div>


@section BreadCrumb {
    <div class="breadcrumb">
    </div>
    <div class="pageTitle">
        <h1></h1>
    </div>
} 

@section HeaderContent {

<style type="text/css"> 

    .contentWrapper  
    {
        border: 1px solid #ddd; 
        padding: 30px 40px 20px 40px; 
        background: #fff;
        /* -- CSS3 - define rounded corners for the form -- */  
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;        

        /* -- CSS3 - create a background graident -- …
Run Code Online (Sandbox Code Playgroud)

razor css3pie asp.net-mvc-3

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

使用quartz.net xml作业定义文件中的参数配置作业

我有一个作业,该作业的构造函数包含参数,并且我想知道是否可以通过传递作业配置文件中定义的参数来配置石英以实例化对象。我试过使用job-data-map元素,但这似乎不起作用。这是可能吗?

谢谢

c# .net-4.0 quartz.net

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

重构DAL代码以支持存储过程

    private static readonly string dataProvider = ConfigurationManager.AppSettings.Get("Provider");
    private static readonly DbProviderFactory factory = DbProviderFactories.GetFactory(dataProvider);
    private static readonly string connectionString = ConfigurationManager.ConnectionStrings[dataProvider].ConnectionString;
    /// <summary>
    /// Executes Update statements in the database.
    /// </summary>
    /// <param name="sql">Sql statement.</param>
    /// <returns>Number of rows affected.</returns>
    public static int Update(string sql)
    {
        using (DbConnection connection = factory.CreateConnection())
        {
            connection.ConnectionString = connectionString;

            using (DbCommand command = factory.CreateCommand())
            {
                command.Connection = connection;
                command.CommandText = sql;

                connection.Open();
                return command.ExecuteNonQuery();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我需要帮助重写这个,以便它可以使用存储过程.(通过sproc名称和params)有没有人知道我应该怎么做呢?编辑:我遇到问题的区域是试图找出填写参数的方法.

谢谢

c# refactoring data-access-layer

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

来自2个表的SQL查询

我目前有两个表看起来像这样:

表格1

Id | AddressNumber | AddressStreet | AddressZip
------------------------------------------------
1   | 50           | Fake          | 60101
2   | 300          | Fake          | 60101
3   | 50           | Fake2         | 60101
4   | 50           | Fake          | 60103
Run Code Online (Sandbox Code Playgroud)

表2

AddressLowRange | AddressHighRange | AddressStreet | AddressZip
---------------------------------------------------------------
50             | 200              | Fake          | 60101
20             | 50               | Other Fake    | 70102
Run Code Online (Sandbox Code Playgroud)

我需要从表1中找到一个Ids列表,其中地址不在表2中.因此,对于上面的示例数据,我将返回ID 2,3和4.

sql oracle10g

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