我一直在阅读有关Unity(依赖注入,控制反转)的MSDN文章,但我认为我需要用简单的术语(或简单的例子)来解释它.我熟悉MVPC模式(我们在这里使用它),但我还不能真正掌握这个Unity的东西,我认为这是我们应用程序设计的下一步.
c# dependency-injection inversion-of-control unity-container
除了我正在做的事情,因为它似乎不起作用,这样做有可能吗?我希望能够拥有一个类下的子类,专门为该class.subclass使用CSS.
CSS
.area1
{
border:1px solid black;
}
.area1.item
{
color:red;
}
.area2
{
border:1px solid blue;
}
.area2.item
{
color:blue;
}
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="area1">
<table>
<tr>
<td class="item">Text Text Text</td>
<td class="item">Text Text Text</td>
</tr>
</table>
</div>
<div class="area2">
<table>
<tr>
<td class="item">Text Text Text</td>
<td class="item">Text Text Text</td>
</tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用class ="item"作为父css类"area1","area2"下的元素.我知道我可以使用class ="area1 item"来实现这一点,但我不明白为什么它必须如此冗长.css子类不应该查看它所在的父类以便定义它吗?
注意:这适用于IE(现在使用7),但在FF中它没有,所以我假设这不是CSS标准的做事方式.
我经常不得不将多个项目加载到数据库中的特定记录.例如:网页显示要包含在单个报表中的项目,所有这些都是数据库中的记录(报表是报表中的记录,项目是项目表中的记录).用户通过Web应用程序选择要包含在单个报告中的项目,并假设他们选择3个项目并提交.通过将记录添加到名为ReportItems(ReportId,ItemId)的表中,该过程将这3个项添加到此报告中.
目前,我会在代码中执行以下操作:
public void AddItemsToReport(string connStr, int Id, List<int> itemList)
{
Database db = DatabaseFactory.CreateDatabase(connStr);
string sqlCommand = "AddItemsToReport"
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
string items = "";
foreach (int i in itemList)
items += string.Format("{0}~", i);
if (items.Length > 0)
items = items.Substring(0, items.Length - 1);
// Add parameters
db.AddInParameter(dbCommand, "ReportId", DbType.Int32, Id);
db.AddInParameter(dbCommand, "Items", DbType.String, perms);
db.ExecuteNonQuery(dbCommand);
}
Run Code Online (Sandbox Code Playgroud)
这在存储过程中:
INSERT INTO ReportItem (ReportId,ItemId)
SELECT @ReportId,
Id
FROM fn_GetIntTableFromList(@Items,'~')
Run Code Online (Sandbox Code Playgroud)
函数返回一列整数表.
我的问题是:有没有更好的方法来处理这样的事情?注意,我不是在询问数据库规范化或类似的事情,我的问题与代码有关.
Web服务和Windows服务之间有什么区别?
我的经验主要是Windows服务,我从未创建过Web服务.
Web服务的行为与Windows服务类似吗?
他们可以安排,在某些时间运行等吗?
当您使用Web服务代替Windows服务时,反之亦然?
我很想知道处理层次结构的最佳方法(最佳实践)是关于数据库设计的.这是我通常如何处理它们的一个小例子.
节点表
NodeId int PRIMARY KEY
NodeParentId int NULL
DisplaySeq int NOT NULL
Title nvarchar(255)
Run Code Online (Sandbox Code Playgroud)
祖先表
NodeId int
AncestorId int
Hops int
Run Code Online (Sandbox Code Playgroud)
使用NodeId上的索引,AncestorId,Hops
表格如下所示:
节点表
NodeId NodeParentId DisplaySeq Title
1 NULL 1 'Root'
2 1 1 'Child 1'
3 1 2 'Child 2'
4 2 1 'Grandchild 1'
5 2 2 'Grandchild 2'
Run Code Online (Sandbox Code Playgroud)
祖先表
NodeId AncestorId Hops
1 NULL 0
1 1 0
2 1 1
2 2 0
3 1 1
3 3 0
4 1 2
4 2 …Run Code Online (Sandbox Code Playgroud) 我知道WebForms有一个RadioButtonList控件,但我找不到一个WinForms.我需要的是将3个RadioButton组合在一起,这样一次只能选择1个.我发现我必须通过代码执行此操作,这很痛苦.我只是没有看到RadioButtonList某个地方,或者它真的不存在WinForms?
我正在与OpenXmlSDK一起玩,看看它是否可以满足我们Powerpoint的需求。所需的一件事是在Powerpoint中定位形状的能力。我一直在寻找一种获取Shape位置的方法,但只遇到了MSDN“操作方法” http://msdn.microsoft.com/zh-cn/library/cc850828.aspx和一个位置类(但无法从Shape中获取它)http://msdn.microsoft.com/zh-cn/library/office/documentformat.openxml.wordprocessing.position%28v=office.14%29.aspx。
我该怎么做:
PresentationDocument presentationDocument = PresentationDocument.Open("C:\\MyDoc.pptx", true);
IdPartPair pp = presentationDocument.PresentationPart.SlideParts.First().Parts.FirstOrDefault();
var shape = pp.OpenXmlPart;
// How do I get the position and dimensions?
Run Code Online (Sandbox Code Playgroud) 指针存储指向值的存储器地址,因此指针包含的存储器地址与值的存储器地址相同.因此,向这两个内存地址添加1应该会产生相同的结果,这是不会发生的.为什么?这是代码
int main()
{
int ages[] = {23, 43, 12, 89, 2};
int *cur_ages = ages;
printf("\n&cur_ages=%p, &cur_ages+1=%p", &cur_ages, &cur_ages+1);
printf("\n&ages=%p, &ages+1=%p", &ages, &ages+1);
printf("\ncur_ages=%p, cur_ages+1=%p", cur_ages, cur_ages+1);
printf("\n*cur_ages=%d, *cur_ages+1=%d", *cur_ages, *(cur_ages+1));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是
&cur_ages=0x1ffff85f3d0, &cur_ages+1=0x1ffff85f3d8
&ages=0x1ffff85f3dc, &ages+1=0x1ffff85f3f0
cur_ages=0x1ffff85f3dc, cur_ages+1=0x1ffff85f3e0
*cur_ages=23, *cur_ages+1=43
Run Code Online (Sandbox Code Playgroud)
&age + 1不等于cur_ages + 1.为什么?
我在尝试调试检查两个值是否相等的排序例程时发现了这个问题。获取值只是对两个双变量进行一些加法:0.31 + 0.27。
当排序将这两个的总和与另一个对象的总和也等于 0.58 进行比较时,它告诉我比较不相等。查看第一个对象的总和,我看到它列为 0.58000000000000007。想知道它是否与我的代码有关,我创建了一个简单的控制台应用程序来测试它:
static void Main(string[] args)
{
double val1 = .31;
double val2 = .27;
Console.WriteLine("Value 1: " + val1);
Console.WriteLine("Value 2: " + val2);
double added = val1 + val2;
if (!added.Equals(.58))
Console.WriteLine("Added value is not .58!");
else
Console.WriteLine("Added value is .58");
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
在我的机器上运行它,它又是 0.58000000000000007。我有一个同事做同样的事情,并提出了相同的输出。
有没有人遇到过这个?我们都运行 64 位 Windows 7,这是在 C# 中完成的 - 我没有在其他场景中测试过。
c# ×4
sql ×2
64-bit ×1
c ×1
css ×1
math ×1
openxml ×1
openxml-sdk ×1
pointers ×1
powerpoint ×1
radio-button ×1
sql-server ×1
t-sql ×1
web-services ×1
winforms ×1