惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
N
News | PayPal Newsroom
V2EX - 技术
V2EX - 技术
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
有赞技术团队
有赞技术团队
S
Schneier on Security
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
IT之家
IT之家
Project Zero
Project Zero
博客园 - 司徒正美
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Security Latest
Security Latest
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity

博客园 - IT-民工

Sqlsever Kill locked process Linked Server Dependencies C# PDF添加水印 Excel Vlookup多条件查询 , 列转行 C# 编写ActiveX Microsoft.Office.Interop.Excel error: 80070005 SQLServer 查询 Excel ISO 纸张尺寸定义 检测SQLSERVER 连接 刷新SQLserver 视图 Sql Server 邮件日志 操作 常用连接 导出Excel Asp.net 多国语言-注意点 SqlServer 行列互转 SqlServer 备份数据库语法 SqlServer To SqlServer 建立 链接服务器 Linked Server sqlserver 根据内容,查询表和列名字 Sqlserver 2005 修改数据库默认排序
C# Linq 分页查询模板
IT-民工 · 2013-06-20 · via 博客园 - IT-民工

1. SQL

 private static string GetAllStocksSql(string branch, string itemNo, string locationName, string lotControl, bool blnAvail, bool blnCount)
        {
            StringBuilder sql = new StringBuilder();

            if (blnCount)
            {
                sql.Append(" SELECT  Count(*) ");
            }
            else
            {
                sql.Append(@"
                            SELECT  ROW_NUMBER() OVER(ORDER BY s.ReceivingTime  ) AS Seq,
                                s.Id ,s.Branch ,s.PDLITM ItemNo ,f.IMDSC1 + f.IMDSC2 [Description] , f.IMUOM1 UM ,  
                                l.Location LocationName ,  s.Qty Quantity ,  s.ReceivingTime ReceivingDate ,  s.LotControl LotControl   ");
            }
            sql.Append(@"   FROM    Stock s
                                LEFT JOIN Location l ON s.Location = l.Id
                                LEFT JOIN F4101 f ON s.PDLITM = f.IMLITM");

            sql.AppendFormat(@" where s.Branch like '%{0}%'  and s.PDLITM like '%{1}%' 
                                and l.Location like '%{2}%' ", branch, itemNo, locationName);
            if (!string.IsNullOrEmpty(lotControl))
            {
                sql.Append(" and s.LotControl like '%" + lotControl + "%'");
            }
            if (blnAvail)
            {
                sql.Append(" and s.Qty >0");//只显示可用库存            
            }
            return sql.ToString();

        }

2. 查询

  public static IList GetAllStocks(string branch, string itemNo, string locationName, string lotControl,bool blnAvail, int startIndex, int endIndex)
        {
            string detailSql = GetAllStocksSql(branch, itemNo, locationName, lotControl,blnAvail, false);

            string sql = @"
            SELECT * FROM 
            (
                {2}
             ) AS TB WHERE Seq>={0} AND Seq<=({1})
            "; 
            sql = string.Format(sql, startIndex, endIndex, detailSql);

            return  WmsDataContext.Instance.ExecuteQuery<StocksTemp>(sql).ToList();
            
        }

3. 总量

public static int GetStocksCount(string branch, string itemNo, string locationName, string lotControl, bool blnAvail)
        {
            
            string sql = GetAllStocksSql(branch, itemNo, locationName, lotControl, blnAvail,true);
            return WmsDataContext.Instance.ExecuteQuery<int>(sql).FirstOrDefault();
        }