我正在使用由班次组成的护士日历:
public interface IShift
{
ShiftType ShiftType { get; } //enum {Day, Early, Late, Night}
DateTime Day { get; }
bool IsNightShift();
bool IsWeekendShift();
}
Run Code Online (Sandbox Code Playgroud)
护士日历是IEnumerable<IShift>.从那时起,我选择自己的shift(IEnumerable<IShift> selectedShifts)一段较短的时间来检查一些约束.
我试图计算多个条件,例如星期五的夜班:
var countFridayNight = selectedShifts.Count(s => s.IsNightShift()
&& s.Day.DayOfWeek == DayOfWeek.Friday);
Run Code Online (Sandbox Code Playgroud)
我正在努力的是多天计算多件事.例如,周五晚班和下周一早班.我试过这个,但VS似乎不喜欢语法:
var countFridayLateAndMondayEarly =
selectedShifts.Count(
(r, s) => s.ShiftType == ShiftType.Late && s.Day.DayOfWeek == DayOfWeek.Friday
&& r.Day.DayOfWeek == DayOfWeek.Monday && r.Day.AddDays(-2).DayOfYear == s.Day.DayOfYear && r.ShiftType == ShiftType.Early
);
Run Code Online (Sandbox Code Playgroud)
编辑:删除最后一个lambda表达式中的花括号.
Edit2:有两条评论说Count不能在lambda表达式中使用多个变量.我怎样才能做我需要使用LINQ的东西?
编辑3:澄清问题 - 我需要计算周五晚班制的变化,同时,还有另一个变化,即下周一早些时候.
我试图从今天的 UTC 日期找出下一个光明节的日期。我已经发现 C# 有HebrewCalendar类,并且我能够使用GetYear(),GetMonth()和获取当前的犹太日期GetDayOfMonth()。但是真的不知道如何使用这些信息来获取当前日期下一个将要发生的犹太日期。
光明节的日期是基斯流月 25 日(犹太历的第 3 个月)。
我正在尝试为 jquery-select2 多选创建一个重置按钮。我不知道为什么我的解决方案不起作用。
网址:
<select id="workload-selector" class="js-source-states-2" multiple="multiple" style="width: 100%">
<option value="haha">haha</option>
<option value="haha2">haha2</option>
<option value="haha3">haha3</option>
</select>
<button id="reset">
Reset
</button>
Run Code Online (Sandbox Code Playgroud)
Javascript:
$("#workload-selector").select2();
$("#reset").click(function(){
$("#workload-selector option:selected").removeAttr("selected");
});
Run Code Online (Sandbox Code Playgroud)
我在 jsFiddle 上制作的:https ://jsfiddle.net/DTcHh/41975/
我有一个MVVM应用程序,我试图通过LinQ工作过滤我的ObservableCollection,它是从基于Entity Framework的数据库获得的.
在View Model我有这个:
public class MenuListViewModel : BaseViewModelCollection<Menu>
{
private string filterString;
public string FilterString
{
get { return filterString; }
set
{
if (Equals(value, filterString)) return;
filterString = value;
RaisePropertyChanged();
}
}
//TODO problems with notification, filter doesn't work
public ObservableCollection<Menu> FilteredItems
{
get
{
if (filterString == null) return Items; //Items is Observable Collection that contains every Item
var query = Items.Where(x => x.Time.ToString().StartsWith(filterString));
return new ObservableCollection<Menu>(query);
}
}
public MenuListViewModel(MenuService menuService)
{
base.Service = menuService; //Using …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个函数,我可以将字符串密钥(我有另一种算法来生成密钥)放入一个消息字符串中。该函数应使用 OpenSSL 库中的 aes256-cbc 加密和解密文本
#define AES_KEYLENGTH 256
string cipher_AES(string key, string message);
int main(int argc, char* argv[])
{
cipher_AES("115792089237316195423570985008687907853269984665640564039457583884239776304164", "Hello, how are you, you mad?");
return 0;
}
// a simple hex-print routine. could be modified to print 16 bytes-per-line
static void hex_print(const void* pv, size_t len)
{
const unsigned char * p = (const unsigned char*)pv;
if (NULL == pv)
printf("NULL");
else
{
size_t i = 0;
for (; i<len;++i)
printf("%02X ", *p++);
}
printf("\n");
}
/* computes …Run Code Online (Sandbox Code Playgroud) 我正在使用JQuery DataTables并尝试添加滚动条以适应屏幕以及标题中的列搜索。它正在破坏标题(如果我点击排序,那么我的自定义标题就会消失)并且搜索不起作用(仅在滚动条存在时发生)。
我的代码(不要更改 html,因为我正在动态添加所有数据):
var table = $('#example').DataTable({
"scrollX": true,
});
$('#example thead th').each(function() {
var title = $(this).text();
$(this).html('<input type="text" placeholder="' + title + '" />');
});
table.columns().every(function() {
var that = this;
$('input', this.header()).on('keyup change', function() {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="example" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead> …Run Code Online (Sandbox Code Playgroud)c# ×3
html ×2
javascript ×2
jquery ×2
linq ×2
.net ×1
c++ ×1
cryptography ×1
datatables ×1
date ×1
datetime ×1
encryption ×1
lambda ×1
mvvm ×1
wpf ×1