我有一个包含文件名列表的目录.
VAH007157100-pic1.jpg
VAH007157100-pic2.jpg
VAH007157100-pic3.jpg
WAZ009999200-pic1.jpg
WAZ009999200-pic2.jpg
WAZ009999200-pic3.jpg
我想知道子串的独特计数(0,12).
由于某种原因,这不起作用:
string[] originalFiles = Directory.GetFiles(SelectedDirectory);
private int GetDistinctPolicyCountInDirectory()
{
var prefixes = originalFiles
.GroupBy(x => x.Substring(0, 12))
.Select(y => new { Policy = y.Key, Count = y.Count() });
return prefixes.Count();
}
Run Code Online (Sandbox Code Playgroud)
我一直都是0.我在这里错过了什么?
请注意,我不想进行拆分以将数字分开.我想通过子串来做到这一点.
更新 -
private int GetDistinctPolicyCountInDirectory(string[] originalFiles)
{
var count = originalFiles.Distinct(x => Path.GetFileName(x).Substring(0, 12)).Count();
return Convert.ToInt32(count);
}
Run Code Online (Sandbox Code Playgroud)
我在这里遇到错误,它说:错误1无法将lambda表达式转换为类型'System.Collections.Generic.IEqualityComparer',因为它不是委托类型
txtTest.text = DateTime.Now.ToString();
Run Code Online (Sandbox Code Playgroud)
结果在文本框中:
8/14/2012 10:06:48 AM
什么是最有效的方式使它看起来像这样?
8142012100648
我知道替换/删除功能,但我认为必须有一个更简单的方法来做到这一点.
顺便说一句,这样做的目的是生成唯一的文件名.
private void btnUpload_Click(object sender, EventArgs e)
{
progressbar.value = 10;
RunLongProcess();
progressbar.value = 20;
RunAnotherLongProcess();
progressbar.value = 50;
RunOneMoreLongProcess();
progressbar.value = 100;
}
Run Code Online (Sandbox Code Playgroud)
上面代码的问题是应用程序冻结,我看不到进度条正常运行。
处理这种情况的正确方法是什么?考虑到我不想同时运行两件事,我不确定为什么会发生这种情况。一次只做一件事。我需要刷新应用程序或类似的东西吗?
后台工作程序完成其过程后,我想更改表单上某些标签上的文本.
这是触发后台工作者的按钮:
private void btnProcessImages_Click(object sender, EventArgs e)
{
DialogResult processImagesWarnMsg = MessageBox.Show("You're about to process images, are you sure?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if (processImagesWarnMsg == DialogResult.Yes)
{
DisableAllButtons();
if (!processImagesWorker.IsBusy)
{
processImagesWorker.RunWorkerAsync();
}
//The problem here is that the below will run BEFORE the worker is complete. Where should I place the below method in my code?
//ResetDirectoryStatistics();
}
}
Run Code Online (Sandbox Code Playgroud)
这是更改表单上标签文本的方法:
private void ResetDirectoryStatistics()
{
lblSelectedDirectory.Text = "N/A";
lblTotalNumberOfFilesInDirectory.Text = "N/A";
lblTotalNumberOfSupportedFilesInDirectory.Text = "N/A";
lblTotalNumberOfUnsupportedFilesInDirectory.Text = "N/A";
lblTotalNumberOfPoliciesInDirectory.Text …Run Code Online (Sandbox Code Playgroud) 基本上我正在创建一个复制应用程序,我只需要弄清楚数据库大小以及D:\驱动器上有多少可用空间.
如果数据库大小大于可用空间,那么我需要提醒用户.
这是我到目前为止:
首先,我找出D驱动器中有多少可用空间.
DriveInfo di = new DriveInfo(@"D:\");
if (di.IsReady)
{
freeSpace = di.TotalFreeSpace;
}
Run Code Online (Sandbox Code Playgroud)
然后我得到了我要复制的数据库的大小:
dbSize = Database.GetDatabaseSize(ddlPublisherServer.Text, ddlPublisherDatabase.Text);
Run Code Online (Sandbox Code Playgroud)
这是获取数据库大小的方法.我不知道是否有更好的方法来做到这一点,但是大小带有"MB"字符串,所以我需要删除它.
public static long GetDatabaseSize(string server, string database)
{
string finalConnString = Properties.Settings.Default.rawConnectionString.Replace("<<DATA_SOURCE>>", server).Replace("<<INITIAL_CATALOG>>", database);
using (SqlConnection conn = new SqlConnection(finalConnString))
{
using (SqlCommand cmd = new SqlCommand("sp_spaceused", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
using (DataSet ds = new DataSet())
{
da.Fill(ds);
var spaceAvailable = ds.Tables[0].Rows[0][1].ToString();
string freeSpace = spaceAvailable.Remove(spaceAvailable.Length - …Run Code Online (Sandbox Code Playgroud) 我不能使用公用表表达式:
WITH cte
AS (SELECT [StationID],
[LastDistribution]
FROM [DB1].[dbo].[ProcessingStations]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB2].[dbo].[ProcessingStations]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB3].[dbo].[ProcessingStations]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB4].[dbo].[ProcessingStations]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB5].[dbo].[ProcessingStations]
ORDER BY [StationID]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB6].[dbo].[ProcessingStations]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB7].[dbo].[ProcessingStations]
UNION ALL
SELECT [StationID],
[LastDistribution]
FROM [DB8].[dbo].[ProcessingStations])
SELECT *
FROM cte
ORDER BY StationID
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
sql sql-server sql-order-by common-table-expression sql-server-2008
connectionString=Data Source=SERVER1;Initial Catalog=DATABASE1;Integrated Security=True
Run Code Online (Sandbox Code Playgroud)
我想捕捉"="右边的所有内容.
我该怎么做呢?
Console.WriteLine(connectionString);
Data Source=SERVER1;Initial Catalog=DATABASE1;Integrated Security=True
Run Code Online (Sandbox Code Playgroud)
我试过了:
variable = string.Split('=')[1]
Run Code Online (Sandbox Code Playgroud)
但它只给了我"数据源"
$.ajax({
url: '../api/notifications/deleteNotification?userId=' + userId + '¬ificationId=' + notificationId,
type: 'DELETE',
success: function()
{
CreateNotificationTree(userId);
alert('Delete successful.');
},
failure: function()
{
alert('Delete failed.');
}
});
Run Code Online (Sandbox Code Playgroud)
功能CreateNotificationTree(userId);上面是Ajax调用成功函数内会被触发.但是,警报并未触发.有人知道为什么吗?我也试过使用多个浏览器.
编辑 - 发现我在执行AJAX调用时遇到此错误:
Uncaught TypeError: Cannot read property 'uid' of undefined kendo.web.min.js:23
(anonymous function) kendo.web.min.js:23
p.extend.each jquery.min.js:2
p.fn.p.each jquery.min.js:2
g.extend._attachUids kendo.web.min.js:23
g.extend.init kendo.web.min.js:22
(anonymous function) kendo.web.min.js:9
p.extend.each jquery.min.js:2
p.fn.p.each jquery.min.js:2
$.fn.(anonymous function) kendo.web.min.js:9
CreateNotificationTree NotificationsTreeView.js:17
(anonymous function) NotificationsTreeView.js:60
k jquery.min.js:2
l.fireWith jquery.min.js:2
y jquery.min.js:2
d
Run Code Online (Sandbox Code Playgroud) 向下滚动到OUTPUT部分.它给了我一个红色的下划线.我想在InsertedCreditDebitAdjustmentIDs表格中插入@CreditDebitAdjustment与InvoiceNum一起插入的ID .我该怎么做呢?
DECLARE @InsertedCreditDebitAdjustmentIDs TABLE
(
ID INT,
InvoiceNumber VARCHAR(50)
)
INSERT INTO @CreditDebitAdjustment ( col1, col2, ...)
SELECT @ImportedFileID AS '@ImportedFileID',
tbl.col.value('(Purpose/text())[1]', 'VARCHAR(500)') AS Purpose,
etc.
FROM @XML.nodes('/CreditDebitAdjustments/CreditDebitAdjustment') AS tbl (col)
OUTPUT INSERTED.CreditDebitAdjustmentID, etc. INTO @InsertedCreditDebitAdjustmentIDs
Run Code Online (Sandbox Code Playgroud) 我有一个来自一个地方的字符串:
"06/02/2000"
我有另一个来自不同地方的字符串:
"6/2/2000"
我需要比较这两个来做一些处理.
比较这两者时,它不应该是不同的.
如何将第二个从"6/2/2000"更改为"06/02/2000"?这是一个字符串.
我试着这样做:
DateTime dt = DateTime.ParseExact(data[i].contract_dt, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
但是因为"6/2/2000"而轰炸