我正在生成带有沿X轴的日期的多系列图.
问题是并非图中的所有系列在日期范围内都具有相同的日期.这意味着,如果我选择2月1日到4月30日,那么一个系列可能有数据从2月1日开始,但只持续到3月底,但另一个系列可能有整个日期范围的数据.
这会扭曲我需要创建的图表.去,给定在查询开始时采用的日期范围,我想生成一个日期列表并填充要绘制的数据,用那些没有数据的日期填充0的系列.
有人可以解释为什么这不起作用?无论数字类型如何,我都试图能够添加两个值.
public static T Add<T> (T number1, T number2)
{
return number1 + number2;
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我收到以下错误:
Operator '+' cannot be applied to operands of type 'T' and 'T'
Run Code Online (Sandbox Code Playgroud) 我无法确定仅基于月份和年份比较SQL中日期的最佳方法.
我们根据日期进行计算,并且由于按月计费,因此该月的日期会造成更多障碍.
例如
DECLARE @date1 DATETIME = CAST('6/15/2014' AS DATETIME),
@date2 DATETIME = CAST('6/14/2014' AS DATETIME)
SELECT * FROM tableName WHERE @date1 <= @date2
Run Code Online (Sandbox Code Playgroud)
上面的示例不会返回任何行,因为@ date1大于@ date2.所以我想找到一种方法来摆脱这个等式.
同样,以下情况也让我悲伤同样的原因.
DECLARE @date1 DATETIME = CAST('6/14/2014' AS DATETIME),
@date2 DATETIME = CAST('6/15/2014' AS DATETIME),
@date3 DATETIME = CAST('7/1/2014' AS DATETIME)
SELECT * FROM tableName WHERE @date2 BETWEEN @date1 AND @date3
Run Code Online (Sandbox Code Playgroud)
我已完成日期的内联转换,以获得指定日期的第一天和最后一天.
SELECT *
FROM tableName
WHERE date2 BETWEEN
DATEADD(month, DATEDIFF(month, 0, date1), 0) -- The first day of the month for date1
AND …Run Code Online (Sandbox Code Playgroud) 我正在寻找更新我的一个查询,因为搜索的要求已经改变.最初,用户要输入单个SKU和制造商.日期范围以搜索产品目录.所以这就是我用过的东西.
DateTime startDate = ...;
DateTime endDate = ...;
string prodSKU = TextSKU.Text.Trim();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
&& c.sku.StartsWith(prodSKU)
select c;
Run Code Online (Sandbox Code Playgroud)
现在要求说用户可以在文本框中输入逗号分隔的SKU列表进行搜索.我很难过的是如何在制造商中找到所有产品.以skuList中的任何SKU开头的日期范围(没有使用fornext循环).
string prodSKU = TextSKU.Text.Trim();
List<string> skuList = prodSKU.Split(new char[] { ', ' }).ToList();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
// && c.sku.StartsWith(prodSKU)
select c;
Run Code Online (Sandbox Code Playgroud)
任何想法将不胜感激!
我需要将几个(阅读:大量)PDF文件发布到网上,但其中许多都有硬编码的文件://链接和非公共位置的链接.我需要阅读这些PDF并更新指向正确位置的链接.我已经开始使用itextsharp编写应用程序来读取目录和文件,找到PDF并遍历每个页面.我接下来要做的是找到链接,然后更新不正确的链接.
string path = "c:\\html";
DirectoryInfo rootFolder = new DirectoryInfo(path);
foreach (DirectoryInfo di in rootFolder.GetDirectories())
{
// get pdf
foreach (FileInfo pdf in di.GetFiles("*.pdf"))
{
string contents = string.Empty;
Document doc = new Document();
PdfReader reader = new PdfReader(pdf.FullName);
using (MemoryStream ms = new MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(doc, ms);
doc.Open();
for (int p = 1; p <= reader.NumberOfPages; p++)
{
byte[] bt = reader.GetPageContent(p);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
坦率地说,一旦我获得了页面内容,我就相当迷失于iTextSharp.我已经阅读了sourceforge上的itextsharp示例,但实际上并没有找到我想要的内容.
任何帮助将不胜感激.
谢谢.
我试图找出一种在我的数据模型中查询对象的方法,并且只包括那些非空的参数.如下所示:
public List<Widget> GetWidgets(string cond1, string cond2, string cond3)
{
MyDataContext db = new MyDataContext();
List<Widget> widgets = (from w in db.Widgets
where
... if cond1 != null w.condition1 == cond1 ...
... if cond2 != null w.condition2 == cond2 ...
... if cond3 != null w.condition3 == cond3 ...
select w).ToList();
return widgets;
}
Run Code Online (Sandbox Code Playgroud)
由于小部件表可能变得非常大,我想避免这样做:
public List<Widget> GetWidgets(string cond1, string cond2, string cond3)
{
MyDataContext db = new MyDataContext();
List<Widget> widgets = db.Widgets.ToList();
if(cond1 != null)
widgets = widgets.Where(w …Run Code Online (Sandbox Code Playgroud) 这是一个小小的拼字游戏项目,我正在修修补补,希望得到一些关于我可能做错的事情.我有一个字母"字典"和各自的分数以及单词列表.我的想法是找到每个单词中的字母并将得分加在一起.
// Create a letter score lookup
var letterScores = new List<LetterScore>
{
new LetterScore {Letter = "A", Score = 1},
// ...
new LetterScore {Letter = "Z", Score = 10}
};
// Open word file, separate comma-delimited string of words into a string list
var words = File.OpenText("c:\\dictionary.txt").ReadToEnd().Split(',').ToList();
// I was hoping to write an expression what would find all letters in the word (double-letters too)
// and sum the score for each letter to get the word score. …Run Code Online (Sandbox Code Playgroud) 无法弄清楚如何读取startup.cs之外的appsettings.json值.我想做的是,例如,在_Layout.cshtml中,从配置中添加站点名称:
例如:
ViewData["SiteName"] = Configuration.GetValue<string>("SiteSettings:SiteName");
Run Code Online (Sandbox Code Playgroud)
甚至更好:
public class GlobalVars {
public static string SiteName => Configuration.GetValue<string>("SiteSettings:SiteName");
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码:
[appsettings.json]
"SiteSettings": {
"SiteName": "MySiteName"
}
Run Code Online (Sandbox Code Playgroud)
[startup.cs]
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
var siteName = Configuration.GetValue<string>("SiteSettings:SiteName");
}
public IConfigurationRoot Configuration { get; }
Run Code Online (Sandbox Code Playgroud)
也许我正在阅读文档错误,但我似乎无法在Startup类之外公开Configuration对象.
我一直在尝试和尝试学习JQuery,使用AJAX来使用我之前写过的SOAP Web服务.以下是我使用的代码:
<script type="text/javascript">
var webServiceURL = 'http://local_server_name/baanws/dataservice.asmx?op=GetAllCategoryFamilies';
var soapMessage = '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><GetAllCategoryFamilies xmlns="http://tempuri.org/" /></soap12:Body></soap12:Envelope';
function CallService()
{
$.ajax({
url: webServiceURL,
type: "POST",
dataType: "xml",
data: soapMessage,
contentType: "text/xml; charset=\"utf-8\"",
success: OnSuccess,
error: OnError
});
return false;
}
function OnSuccess(data, status)
{
alert(data.d);
}
function OnError(request, status, error)
{
alert('error');
}
$(document).ready(function() {
jQuery.support.cors = true;
});
</script>
<form method="post" action="">
<div>
<input type="button" value="Call Web Service" onclick="CallService(); return false;" />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
目前,在Web服务中调用的方法返回包含类别代码和类别描述的类别系列数组.由于该方法返回XML,因此我相应地设置了ajax查询.但是,当我运行应用程序时,我收到一个"错误"警告框 - 我确定会导致问题的原因.我知道Web服务有效,我写的其他.NET Web应用程序每天都会调用几百次.
任何帮助将不胜感激. …
从平面文件导入数据时,我注意到有些行嵌入了非中断空格(Hex:A0).
我想删除这些,但标准的string.replace似乎不起作用,并考虑使用正则表达式替换字符串,但不知道正则表达式将搜索删除它.
而不是将整个字符串转换为十六进制并检查它,是否有更好的方法?
c# ×6
c#-4.0 ×3
linq ×2
ajax ×1
appsettings ×1
asp.net ×1
date ×1
generics ×1
hex ×1
itextsharp ×1
jquery ×1
linq-to-sql ×1
list ×1
soap ×1
sql ×1
sql-server ×1
startswith ×1
string ×1