我有两个int型List像List A和List B.我要检查多少项目List A是那里List B.我能够做到这一点,但是foreach因为优化是我的代码中的主要目标,所以我可以避免这种有效方式.
List<int> A = new List<int>;
List<int> B = new List<int>;
// Some logic....item added in both lists. Then
foreach(var item in A)
{
if (B.Contains(item))
{
// Subtract number of duplicates
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用Intersect和Any,但是返回bool所以我无法完全应用它们.
我发布了一个我的疑问:有没有办法我们可以使用一个查询的结果,然后像我们在SQL中那样进一步加入:
SELECT Applications.* , ApplicationFees.ApplicationNo, ApplicationFees.AccountFundDate1,ApplicationFees.AccountFundDate2 ,ApplicationFees.AccountFundDate3 , ApplicationFees.AccountCloseDate1, ApplicationFees.AccountCloseDate2,ApplicationFees.AccountCloseDate3,
isnull(SUBQRY11.AMNT ,0) as SCMSFEE1R,
isnull(SUBQRY12.AMNT,0) as SCMSFEE2R,
Left Join
(
SELECT ApplicationNo,COUNT(ApplicationNo) AS CNT, SUM(Amount) as AMNT
FROM Payments where (FEETYPE=1 AND FeePosition=1) and (FeeDate>='2011-01-01')
and (FeeDate<='2012-01-01')
GROUP BY ApplicationNo
)SUBQRY11
ON ApplicationFees.ApplicationNo= SUBQRY11.ApplicationNo
Left Join
(
SELECT ApplicationNo,COUNT(ApplicationNo) AS CNT2, SUM(Amount) as AMNT
FROM Payments where (FEETYPE=1 AND FeePosition=2) and (FeeDate>='2011-01-01')
and (FeeDate<='2012-01-01')
GROUP BY ApplicationNo )SUBQRY12 ON ApplicationFees.ApplicationNo=SUBQRY12.ApplicationNo
Run Code Online (Sandbox Code Playgroud)
我想避免在查询的foreach中使用相同的内容,因为这将非常耗时.
我有大约10个word文档,我使用open xml和其他东西生成.现在我想创建另一个word文档,我想逐个加入到这个新创建的文档中.我希望使用open xml,任何提示都会很明显.以下是我的代码:
private void CreateSampleWordDocument()
{
//string sourceFile = Path.Combine("D:\\GeneralLetter.dot");
//string destinationFile = Path.Combine("D:\\New.doc");
string sourceFile = Path.Combine("D:\\GeneralWelcomeLetter.docx");
string destinationFile = Path.Combine("D:\\New.docx");
try
{
// Create a copy of the template file and open the copy
//File.Copy(sourceFile, destinationFile, true);
using (WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true))
{
// Change the document type to Document
document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
//Get the Main Part of the document
MainDocumentPart mainPart = document.MainDocumentPart;
mainPart.Document.Save();
}
}
catch
{
}
}
Run Code Online (Sandbox Code Playgroud)
更新(使用AltChunks):
using (WordprocessingDocument myDoc = WordprocessingDocument.Open("D:\\Test.docx", true)) …Run Code Online (Sandbox Code Playgroud) 我必须创建一个SP,如果它有效,则返回一个值.但它不返回任何东西,我不知道,为什么?
CREATE DEFINER=`root`@`localhost` PROCEDURE `validar_egreso`(
IN codigo_producto VARCHAR(100),
IN cantidad INT,
OUT valido INT(11)
)
BEGIN
DECLARE resta INT(11);
SET resta = 0;
SELECT (s.stock - cantidad) INTO resta
FROM stock AS s
WHERE codigo_producto = s.codigo;
IF (resta > s.stock_minimo) THEN
SET valido = 1;
ELSE
SET valido = -1;
END IF;
SELECT valido;
END
Run Code Online (Sandbox Code Playgroud) 我已经从word模板创建了一个docx文件,现在我正在访问复制的docx文件,并希望用某些其他数据替换某些文本.
我无法获得如何从doument主要部分访问文本的提示?
任何帮助都会很明显.
以下是我的代码到现在为止.
private void CreateSampleWordDocument()
{
//string sourceFile = Path.Combine("D:\\GeneralLetter.dot");
//string destinationFile = Path.Combine("D:\\New.doc");
string sourceFile = Path.Combine("D:\\GeneralWelcomeLetter.docx");
string destinationFile = Path.Combine("D:\\New.docx");
try
{
// Create a copy of the template file and open the copy
File.Copy(sourceFile, destinationFile, true);
using (WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true))
{
// Change the document type to Document
document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
//Get the Main Part of the document
MainDocumentPart mainPart = document.MainDocumentPart;
mainPart.Document.Save();
}
}
catch
{
}
}
Run Code Online (Sandbox Code Playgroud)
现在如何查找某些文本并替换相同的文本?我无法通过链接,所以一些代码提示将是可观的.
与Linq to SQL一起使用时,FirstOrDefault()的默认行为是什么?
例如
int value = (from p in context.tableX
select p.Id).FirstOrDefault() // Value will initialized here or
if(value > 0) // query will be executed here????
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我的存储过程中有一个nvarchar(MAX),它包含int值列表,我这样做是因为无法将int列表传递给我的存储过程,但是,现在我遇到问题,因为我的数据类型是int我想比较字符串列表.有没有办法可以做同样的事情?
---myquerry----where status in (@statuslist)
Run Code Online (Sandbox Code Playgroud)
但是statuslist现在包含字符串值而不是int,那么如何将它们转换为INT?
更新:
USE [Database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP]
(
@FromDate datetime = 0,
@ToDate datetime = 0,
@ID int=0,
@List nvarchar(MAX) //This is the List which has string ids//
)
Run Code Online (Sandbox Code Playgroud)
AS SET FMTONLY OFF; DECLARE @sql nvarchar(MAX),@ paramlist nvarchar(MAX)
SET @sql = 'SELECT ------ and Code in(@xList)
and -------------'
SELECT @paramlist = '@xFromDate datetime,@xToDate datetime,@xId int,@xList nvarchar(MAX)'
EXEC sp_executesql @sql, @paramlist,
@xFromDate = @FromDate ,@xToDate=@ToDate,@xId=@ID,@xList=@List …Run Code Online (Sandbox Code Playgroud) 这是我的代码,我正在尝试下载docx文件.但没有成功.在哪里我可能会滞后,需要一点点暗示.
if (File.Exists(sTempPath + sCreateFileName))
{
FileInfo file =new FileInfo(sTempPath + sCreateFileName);
Response.ClearContent();
// LINE1: Add the file name and attachment, which will force the open/cancel/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", file.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(file.Extension.ToLower());
// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(sTempPath + sCreateFileName);
// …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的元素数组:
messages[i],messages[i]可能只存在某些值的i.例如messages[0],messages[2]可能存在但不存在messages[1].
现在我想将具有连续索引的元素组合在一起,例如,如果存在消息的索引是:
2, 3, 4, 5, 8, 9, 12, 13, 14, 15, 16, 17, 20
我想像他们这样分组:
2, 3, 4, 5
8, 9
12, 13, 14, 15, 16, 17
20
使用Javascript这样做的有效方法是什么?
编辑:
for (i = 0; i < messages.length; i++) {
if (messages[i].from_user_id == current_user_id) {
// group the continuous messages together
} else {
//group these continuous messages together
}
}
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我试图通过鼠标滚轮缩放图像。但是代码不能正常工作,它只是刷新面板但没有调整它的大小。实际上,我正在从另一个称为解密的类创建的内存流中获取图像。完整图像显示正确,但我无法使用鼠标滚轮事件执行图像缩放。请帮助我。
private void Form2_Load(object sender, EventArgs e)
{
this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.CenterToScreen();
PicturePanel= new PictureBox();
PicturePanel.Dock = DockStyle.Fill;
//PicturePanel.SizeMode = PictureBoxSizeMode.AutoSize;
//PicturePanel.SizeMode = PictureBoxSizeMode.CenterImage;
PicturePanel.Focus();
//PicturePanel.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.OnMouseWheel);
this.Controls.Add(PicturePanel);
View_codee v = new View_codee();
try
{
PicturePanel.Image = Image.FromStream(Decrypt.ms1);
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
this.Name = "";
}
protected override void OnMouseWheel(MouseEventArgs mea)
{
// Override OnMouseWheel event, for zooming in/out with the scroll wheel
if (PicturePanel.Image != null)
{
// If the mouse …Run Code Online (Sandbox Code Playgroud) c# ×4
linq ×3
c#-4.0 ×2
docx ×2
list ×2
openxml ×2
sql ×2
arrays ×1
casting ×1
count ×1
download ×1
intersect ×1
javascript ×1
join ×1
linq-to-sql ×1
merge ×1
mousewheel ×1
mysql ×1
openxml-sdk ×1
return-value ×1
string ×1
templates ×1
zooming ×1