我有一个使用jQuery UI排序的列表.第一个列表项是"项目1",第二个是"项目2".我的要求是必须根据存储在数组"arrValuesForOrder"中的顺序初始化列表项.我们如何初始化它呢?
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/themes/sunny/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function ()
{
var arrValuesForOrder = ["3", "1", "4", "2"];
$("#myUnorderedList").sortable({
axis:'y',
handle: '.handle',
update: function ()
{
var order = $('#myUnorderedList').sortable('serialize');
alert(order);
}
});
});
</script>
<style>
#myUnorderedList li img.handle
{
margin-right: 20px;
cursor: move;
}
#myUnorderedList li
{
display: block;
margin-bottom: 3px;
height:30px;
background-color: #efefef;
}
</style>
</head>
<body>
<div>
<ul id="myUnorderedList">
<li id="listItem_1">
<img src="images/arrow.png" alt="move" class="handle" />
<strong>Item 1</strong>
</li>
<li …Run Code Online (Sandbox Code Playgroud) 我有一个银行帐户域名,如下所示.可以有SavingsAccount,LoanAccount,FixedAccount等.一个用户可以拥有多个帐户.我需要添加一个新功能 - 为用户获取所有帐户.应该写的功能在哪里以及如何?
如果解决方案遵循SOLID原则(开放 - 封闭原则,......)和DDD,那将是很好的.
任何可以使代码更好的重构都是受欢迎的.
注意:AccountManipulator将由网站客户端通过Web服务使用.
namespace BankAccountBL
{
public class AccountManipulator
{
//Whether it should beprivate or public?
private IAccount acc;
public AccountManipulator(int accountNumber)
{
acc = AccountFactory.GetAccount(accountNumber);
}
public void FreezeAccount()
{
acc.Freeze();
}
}
public interface IAccount
{
void Freeze();
}
public class AccountFactory
{
public static IAccount GetAccount(int accountNumber)
{
return new SavingsAccount(accountNumber);
}
}
public class SavingsAccount : IAccount
{
public SavingsAccount(int accountNumber)
{
}
public void Freeze()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
读: …
业务:
我有一个支付系统,可以通过GiftCoupon,ClubMembershipCard等支付.一个支付本身可以有多个支付组件
课程:
我有一个付款类.它有支付组件,如GiftCouponPayment,ClubMembershipCardPayment,CashPayment等.每种组件类型都满足通用接口IPaymentComponent.我使用有关现有类型的知识实现了它.
问题
1)如何以抽象的方式实现这个功能- 不知道存在哪些类型?这意味着它需要适用于实现IPaymentComponent接口的所有类型.
2)如果在LINQ to SQL中无法实现它,是否可以在Entity Framework中实现?
3)当LINQ to SQL在Payment对象中生成GiftCouponPayment实体时,它是关联/聚合还是组合?
注意:我使用LINQ to SQL作为ORM.GiftCouponPayment和Payment是自动生成的类,这些对象由ORM创建.我通过使用部分类为这些类添加了更多功能.
注意:在数据库中,每个PaymentComponent(例如GiftCouponPayment)都有自己的属性(例如CouponValue,CardValue等).因此,按层次结构表将不会很好.我们需要单独的表格.那条线路有解决方案吗?
注意:此付款之前,数据库中已存在GiftCouponPayment.我们需要使用客户提供的GiftCouponPaymentID来识别GiftCouponPayment对象.我们只需要更新此表中的PaymentID列.
泄漏抽象是指任何已实现的抽象,旨在减少(或隐藏)复杂性,其中底层细节未被完全隐藏
LINQ to SQL Diagram

参考:
C#代码
public interface IPaymentComponent
{
int MyID { get; set; }
int MyValue { get; set; }
int GetEffectiveValue();
}
public partial class GiftCouponPayment : IPaymentComponent
{
public int MyID
{
get
{
return this.GiftCouponPaymentID;
}
set
{
this.GiftCouponPaymentID = …Run Code Online (Sandbox Code Playgroud) 我已经提到了Stack Overflow问题有没有一种简单的方法来检查.NET Framework版本?.但是那里给出的建议并不适用于以下目的.
我们如何识别C#控制台应用程序正在使用的.NET版本?
环境:
码
using System;
using System.Globalization;
using Microsoft.Win32;
namespace TESTConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//.NET version: Approach 1
RegistryKey installed_versions = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
string[] version_names = installed_versions.GetSubKeyNames();
double latestFramework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture);
int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]).GetValue("SP", 0));
Console.WriteLine(latestFramework);
//Approach 2
string versionval = Environment.Version.ToString();
Console.WriteLine(versionval);
//Approach 3
string systemVersionVal = System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion().ToString();
Console.WriteLine(systemVersionVal);
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
产量

版本设置

我正在添加来自三个字段的计算列。它将是一个 VARCHAR 字段。我需要指定计算列的最大长度。我们如何指定这一点。
ALTER TABLE [MyTable] ADD CustomNumber AS [PGM]+'-'+[GRP]+'-'+[PGMGRPSEQ]
Run Code Online (Sandbox Code Playgroud)
有什么办法可以限制我吗?如果长度超过 10 个字符,我需要提出错误
参考:指定表中的计算列
我有一个Kendo UI Grid,如下所示.有记录时出现水平滚动条.但是当没有记录时它就不会出现.即使没有记录,如何使用滚动条.
格
<div class="GridSearch">
@(Html.Kendo().Grid<Topco.TopMapp.MVC.Models.TransactionHistoryModel>()
.Name("TransactionHistroyGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.UserId);
model.Field(p => p.Comment).Editable(true);
})
.PageSize(25)
.ServerOperation(true)
.Read(read => read
.Action("TransactionHistorySearch_Read", "Home")
.Data("additionalData")
)
)
.Columns(columns =>
{
columns.Command(c => c.Custom("Edit").Click("editDetails")).HeaderTemplate("Action").HeaderHtmlAttributes(new { style = "text-align: center;" }).Width(90);
columns.Command(c => { c.Custom("Save").Click("saveDetails"); c.Custom("Cancel").Click("cancelDetails"); }).Hidden();
columns.Bound(p => p.UserId).Filterable(false).Title("UserID").HeaderHtmlAttributes(new { style = "text-align: center;" }).Width(90);
columns.Bound(p => p.Status).Filterable(false).Title("Status").HeaderHtmlAttributes(new { style = "text-align: center;" }).Width(70);
columns.Bound(p => p.Reviewed).HeaderHtmlAttributes(new { style = "text-align: center;" }).Template(@<text></text>).ClientTemplate("<input id='checkbox' class='chkbx' type='checkbox' …Run Code Online (Sandbox Code Playgroud) 我在SQL Server中有一个存储过程
CREATE PROCEDURE ParseXML (@InputXML xml)
Run Code Online (Sandbox Code Playgroud)
输入参数的数据类型是"xml".
在LINQ to SQL生成的存储过程代码中,输入参数是System.Xml.Linq.XElement
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.ParseXML")]
public ISingleResult<ParseXMLResult> ParseXML([global::System.Data.Linq.Mapping.ParameterAttribute(Name="InputXML", DbType="Xml")] System.Xml.Linq.XElement inputXML)
Run Code Online (Sandbox Code Playgroud)
现在,如何将以下List传递给ParseXML方法以使存储过程正常工作?
编辑:
阅读答案后 - 下面列出了另一种解决方案
XElement root = new XElement("ArrayOfBankAccountDTOForStatus",
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"));
foreach (var element in bankAccountDTOList)
{
XElement ex= new XElement("BankAccountDTOForStatus",
new XElement("BankAccountID", element.BankAccountID),
new XElement("Status", element.Status));
root.Add(ex);
}
Run Code Online (Sandbox Code Playgroud)
问题代码
string connectionstring = "Data Source=.;Initial Catalog=LibraryReservationSystem;Integrated Security=True;Connect Timeout=30";
var theDataContext = new DBML_Project.MyDataClassesDataContext(connectionstring);
List<DTOLayer.BankAccountDTOForStatus> bankAccountDTOList = new List<DTOLayer.BankAccountDTOForStatus>();
DTOLayer.BankAccountDTOForStatus presentAccount1 = new …Run Code Online (Sandbox Code Playgroud) 我有一个Report对象,它具有Recipients属性(String数据类型)."收件人"属性将保留所有收件人的电子邮件地址comma separated string.我需要从逗号分隔的字符串创建电子邮件对象的" 集合 ".我有以下代码使用字符串列表 来获取电子邮件地址.然后我创建了一个电子邮件对象的集合.
有没有更好的方法来避免冗余的List和Collection使用LINQ?
Report report = new Report();
report.Recipients = "test@test.com, demo@demo.com";
List<string> emailAddressList = new List<string>( report.Recipients.Split(',') );
Collection<Email> emailObjectCollection = new Collection<Email>();
foreach (string emailAddress in emailAddressList)
{
Email email = new Email();
email.EmailAddress = emailAddress;
emailObjectCollection.Add(email);
}
Run Code Online (Sandbox Code Playgroud)
参考文献:
CA1002:不要公开通用列表.System.Collections.Generic.List是一个通用集合,专为性能而非继承而设计,因此不包含任何虚拟成员.http://msdn.microsoft.com/en-us/library/ms182142(v=vs.80).aspx
我有以下代码AddTicks方法.datetime对象的Ticks属性在AddTick方法之前和之后返回相同的值.为什么表现如此?
一毫秒内有10,000个刻度.
刻度:此属性的值表示自0001年1月1日午夜12:00:00起经过的100纳秒间隔的数量,表示DateTime.MinValue.
AddTicks:将指定数量的刻度添加到此实例的值.
注意:我正在使用.Net 4.0框架
码
static void Main()
{
DateTime dt2 = new DateTime(2010, 5, 7, 10, 11, 12, 222);
long x = dt2.Ticks;
dt2.AddTicks(9999);
long y = dt2.Ticks;
bool isSame = false;
if (x == y)
{
isSame = true;
}
Console.WriteLine(isSame);
System.Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud) 我们有一个如下所列的类结构
public class ItemDTO
{
public int ItemID { get; set; }
}
public class CostPageDTO
{
public string CostPageNumber { get; set; }
public List<ItemDTO> Items { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
有两个列表 - 1)数据库中存在的Costpage和Items列表2)用户选择的costpages
题
我们需要比较这两个列表,并得到一个结果列表,其中包含成本页面,实际集合和选定集合中不同项目的计数相同.
什么是best performingLINQ(链式方法)?
预期结果
基于以下场景的预期结果是仅包含1个成本页的列表 - "C2"(项目匹配)

码
static void Main(string[] args)
{
List<CostPageDTO> selectedCostPageAndItems = GetSelectedCostPageAndItems();
List<CostPageDTO> actualItems = GetActualItems();
//LINQ code to get the matching count costPages
}
private static List<CostPageDTO> GetSelectedCostPageAndItems()
{
ItemDTO i1 = new ItemDTO();
i1.ItemID = …Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×2
linq ×2
linq-to-sql ×2
sql-server ×2
cqrs ×1
jquery ×1
jquery-ui ×1
kendo-grid ×1
kendo-ui ×1
oop ×1
telerik ×1
xml ×1