GVKun编程网logo

织梦(今日更新等)经常用到的统计代码SQL调用语句(织梦系统基本参数)

8

如果您对织梦(今日更新等)经常用到的统计代码SQL调用语句和织梦系统基本参数感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解织梦(今日更新等)经常用到的统计代码SQL调用语句的各种细节,并对织梦

如果您对织梦(今日更新等)经常用到的统计代码SQL调用语句织梦系统基本参数感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解织梦(今日更新等)经常用到的统计代码SQL调用语句的各种细节,并对织梦系统基本参数进行深入的分析,此外还有关于40个经常用到的java代码块、asp下经常用到的代码、C#程序员经常用到的10个实用代码片段、Dede(织梦)sql调用之代码大全的实用技巧。

本文目录一览:

织梦(今日更新等)经常用到的统计代码SQL调用语句(织梦系统基本参数)

织梦(今日更新等)经常用到的统计代码SQL调用语句(织梦系统基本参数)

 

织梦CMS经常用到的内容统计代码SQL调用语句:

·共有新闻:多少篇

{dede:sql sql="select count(*) as c from idea_archives where channel=1"}·共有新闻:[field:c /]篇{/dede:sql}

·共有图集:多少个

{dede:sql sql="select count(*) as c from idea_archives where channel=2"}·共有图集:[field:c /]个{/dede:sql}

·共有软件:多少个

{dede:sql sql="select count(*) as c from idea_archives where channel=3"}·共有软件:[field:c /]个{/dede:sql}

·共有评论:多少条

{dede:sql sql="select count(*) as c from idea_feedback"}·共有评论:[field:c /]条{/dede:sql}

·共有会员:多少名

{dede:sql sql="select count(mid) as c from idea_member "}·共有会员:[field:c /]名{/dede:sql}

·新闻阅读:多少人次

{dede:sql sql="select sum(click) as c from idea_archives"}新闻阅读:[field:c /]人次{/dede:sql}

·今日更新:多少篇

{dede:sql sql="SELECT count( * ) AS c FROM idea_archives WHERE pubdate & gt; UNIX_TIMESTAMP( CURDATE( ) ) "}今日更新:[field:c /]篇{/dede:sql}

总共留言:{dede:sql sql="select count(*) as cc From idea_guestbook"}[field:cc/]{/dede:sql}条

本文章网址:http://www.ppssdd.com/code/11622.html。转载请保留出处,谢谢合作!

40个经常用到的java代码块

40个经常用到的java代码块

下面是20个非常有用的Java程序片段,期望能对你有用。

  1. 字符串有整型的相互转换

1
2
String a = String.valueOf(2); //integer to numeric string
int i = Integer.parseInt(a);//numeric string to an int

  1. 向文件末尾添加内容

1
2
3
4
5
6
7
8
9
10
11
BufferedWriter out =null;
try {

out =new BufferedWriter(new FileWriter(”filename”,true)); 
out.write(”aString”); 

}catch (IOException e) {

// error processing code 

}finally {

if (out !=null) { 
    out.close(); 
} 

}

  1. 得到当前办法的名字

1
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();

  1. 转字符串到日期

1
java.util.Date = java.text.DateFormat.getDateInstance().parse(date String);
或者是:

1
2
SimpleDateFormat format =new SimpleDateFormat("dd.MM.yyyy" );
Date date = format.parse( myString );

  1. 运用JDBC链接Oracle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class OracleJdbcTest
{

String driver; 

Connection con; 

public void init(FileInputStream fs)throws ClassNotFoundException, SQLException, FileNotFoundException, IOException 
{ 
    Properties props =new Properties(); 
    props.load(fs); 
    String url = props.getProperty("db.url"); 
    String userName = props.getProperty("db.user"); 
    String password = props.getProperty("db.password"); 
    Class.forName(driverClass); 

    con=DriverManager.getConnection(url, userName, password); 
} 

public void fetch()throws SQLException, IOException 
{ 
    PreparedStatement ps = con.prepareStatement("select SYSDATE from dual"); 
    ResultSet rs = ps.executeQuery(); 

    while (rs.next()) 
    { 
        // do the thing you do 
    } 
    rs.close(); 
    ps.close(); 
} 

public static void main(String[] args) 
{ 
    OracleJdbcTest test =new OracleJdbcTest(); 
    test.init(); 
    test.fetch(); 
} 

}

  1. 把 Java util.Date 转成 sql.Date

1
2
java.util.Date utilDate =new java.util.Date();
java.sql.Date sqlDate =new java.sql.Date(utilDate.getTime());

  1. 运用NIO进行快速的文件复制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public static void fileCopy( File in, File out )

        throws IOException 
{ 
    FileChannel inChannel =new FileInputStream( in ).getChannel(); 
    FileChannel outChannel =new FileOutputStream( out ).getChannel(); 
    try
    { 

// inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparently has trouble copying large files on Windows

        // magic number for Windows, 64Mb - 32Kb) 
        int maxCount = (64 *1024 *1024) - (32 *1024); 
        long size = inChannel.size(); 
        long position =0; 
        while ( position < size ) 
        { 
           position += inChannel.transferTo( position, maxCount, outChannel ); 
        } 
    } 
    finally
    { 
        if ( inChannel !=null ) 
        { 
           inChannel.close(); 
        } 
        if ( outChannel !=null ) 
        { 
            outChannel.close(); 
        } 
    } 
}
  1. 创立图片的缩略图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
private void createThumbnail(String filename,int thumbWidth,int thumbHeight,int quality, String outFilename)

    throws InterruptedException, FileNotFoundException, IOException 
{ 
    // load image from filename 
    Image image = Toolkit.getDefaultToolkit().getImage(filename); 
    MediaTracker mediaTracker =new MediaTracker(new Container()); 
    mediaTracker.addImage(image,0); 
    mediaTracker.waitForID(0); 
    // use this to test for errors at this point: System.out.println(mediaTracker.isErrorAny()); 

    // determine thumbnail size from WIDTH and HEIGHT 
    double thumbRatio = (double)thumbWidth / (double)thumbHeight; 
    int imageWidth = image.getWidth(null); 
    int imageHeight = image.getHeight(null); 
    double imageRatio = (double)imageWidth / (double)imageHeight; 
    if (thumbRatio < imageRatio) { 
        thumbHeight = (int)(thumbWidth / imageRatio); 
    }else { 
        thumbWidth = (int)(thumbHeight * imageRatio); 
    } 

    // draw original image to thumbnail image object and 
    // scale it to the new size on-the-fly 
    BufferedImage thumbImage =new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); 
    Graphics2D graphics2D = thumbImage.createGraphics(); 
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 
    graphics2D.drawImage(image,0,0, thumbWidth, thumbHeight,null); 

    // save thumbnail image to outFilename 
    BufferedOutputStream out =new BufferedOutputStream(new FileOutputStream(outFilename)); 
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); 
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage); 
    quality = Math.max(0, Math.min(quality,100)); 
    param.setQuality((float)quality /100.0f,false); 
    encoder.setJPEGEncodeParam(param); 
    encoder.encode(thumbImage); 
    out.close(); 
}
  1. 创立 JSON 格局的数据

请先阅览这篇文章 了解一些细节,

并下面这个JAR 文件:json-rpc-1.0.jar (75 kb)

1
2
3
4
5
6
7
8
9
import org.json.JSONObject;
...
...
JSONObject json =new JSONObject();
json.put("city","Mumbai");
json.put("country","India");
...
String output = json.toString();
...

  1. 运用iText JAR生成PDF

阅览这篇文章 了解更多细节

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class GeneratePDF {

public static void main(String[] args) { 
    try { 
        OutputStream file =new FileOutputStream(new File("C:\\Test.pdf")); 

        Document document =new Document(); 
        PdfWriter.getInstance(document, file); 
        document.open(); 
        document.add(new Paragraph("Hello Kiran")); 
        document.add(new Paragraph(new Date().toString())); 

        document.close(); 
        file.close(); 

    }catch (Exception e) { 

        e.printStackTrace(); 
    } 
} 

}

  1. HTTP 署理设置

阅览这篇 文章 了解更多细节。

1
2
3
4
System.getProperties().put("http.proxyHost","someProxyURL");
System.getProperties().put("http.proxyPort","someProxyPort");
System.getProperties().put("http.proxyUser","someUserName");
System.getProperties().put("http.proxyPassword","somePassword");

  1. 单实例Singleton 示例

请先阅览这篇文章 了解更多信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class SimpleSingleton {

private static SimpleSingleton singleInstance = new SimpleSingleton(); 

//Marking default constructor private 
//to avoid direct instantiation. 
private SimpleSingleton() { 
} 

//Get instance for class SimpleSingleton 
public static SimpleSingleton getInstance() { 

    return singleInstance; 
} 

}
另一种完成

1
2
3
4
5
6
7
8
public enum SimpleSingleton {

INSTANCE; 
public void doSomething() { 
} 

}

//Call the method from Singleton:
SimpleSingleton.INSTANCE.doSomething();

  1. 抓屏程序

阅览这篇文章 获得更多信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

...

public void captureScreen(String fileName)throws Exception {

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle =new Rectangle(screenSize);
Robot robot =new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image,"png",new File(fileName));

}
...

  1. 列出文件和目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
File dir =new File("directoryName");
String[] children = dir.list();
if (children ==null) {

  // Either dir does not exist or is not a directory 

}else {

  for (int i=0; i < children.length; i++) { 
      // Get filename of file or directory 
      String filename = children[i]; 
  } 

}

// It is also possible to filter the list of returned files.
// This example does not return any files that start with `.''.
FilenameFilter filter =new FilenameFilter() {

  public boolean accept(File dir, String name) { 
      return !name.startsWith("."); 
  } 

};
children = dir.list(filter);

// The list of files can also be retrieved as File objects
File[] files = dir.listFiles();

// This filter only returns directories
FileFilter fileFilter =new FileFilter() {

  public boolean accept(File file) { 
      return file.isDirectory(); 
  } 

};
files = dir.listFiles(fileFilter);

  1. 创立ZIP和JAR文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.zip.*;
import java.io.*;

public class ZipIt {

public static void main(String args[])throws IOException { 
    if (args.length <2) { 
        System.err.println("usage: java ZipIt Zip.zip file1 file2 file3"); 
        System.exit(-1); 
    } 
    File zipFile =new File(args[0]); 
    if (zipFile.exists()) { 
        System.err.println("Zip file already exists, please try another"); 
        System.exit(-2); 
    } 
    FileOutputStream fos =new FileOutputStream(zipFile); 
    ZipOutputStream zos =new ZipOutputStream(fos); 
    int bytesRead; 
    byte[] buffer =new byte[1024]; 
    CRC32 crc =new CRC32(); 
    for (int i=1, n=args.length; i < n; i++) { 
        String name = args[i]; 
        File file =new File(name); 
        if (!file.exists()) { 
            System.err.println("Skipping: " + name); 
            continue; 
        } 
        BufferedInputStream bis =new BufferedInputStream( 
            new FileInputStream(file)); 
        crc.reset(); 
        while ((bytesRead = bis.read(buffer)) != -1) { 
            crc.update(buffer,0, bytesRead); 
        } 
        bis.close(); 
        // Reset to beginning of input stream 
        bis =new BufferedInputStream( 
            new FileInputStream(file)); 
        ZipEntry entry =new ZipEntry(name); 
        entry.setMethod(ZipEntry.STORED); 
        entry.setCompressedSize(file.length()); 
        entry.setSize(file.length()); 
        entry.setCrc(crc.getValue()); 
        zos.putNextEntry(entry); 
        while ((bytesRead = bis.read(buffer)) != -1) { 
            zos.write(buffer,0, bytesRead); 
        } 
        bis.close(); 
    } 
    zos.close(); 
} 

}

  1. 解析/读取XML 文件

XML文件


    John
    B
    12


    Mary
    A
    11


    Simon
    A
    18

Java代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package net.viralpatel.java.xmlparser;

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XMLParser {

public void getAllUserNames(String fileName) { 
    try { 
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
        DocumentBuilder db = dbf.newDocumentBuilder(); 
        File file =new File(fileName); 
        if (file.exists()) { 
            Document doc = db.parse(file); 
            Element docEle = doc.getDocumentElement(); 

            // Print root element of the document 
            System.out.println("Root element of the document: "
                    + docEle.getNodeName()); 

            NodeList studentList = docEle.getElementsByTagName("student"); 

            // Print total student elements in document 
            System.out 
                    .println("Total students: " + studentList.getLength()); 

            if (studentList !=null && studentList.getLength() >0) { 
                for (int i =0; i < studentList.getLength(); i++) { 

                    Node node = studentList.item(i); 

                    if (node.getNodeType() == Node.ELEMENT_NODE) { 

                        System.out 
                                .println("====================="); 

                        Element e = (Element) node; 
                        NodeList nodeList = e.getElementsByTagName("name"); 
                        System.out.println("Name: "
                                + nodeList.item(0).getChildNodes().item(0) 
                                        .getNodeValue()); 

                        nodeList = e.getElementsByTagName("grade"); 
                        System.out.println("Grade: "
                                + nodeList.item(0).getChildNodes().item(0) 
                                        .getNodeValue()); 

                        nodeList = e.getElementsByTagName("age"); 
                        System.out.println("Age: "
                                + nodeList.item(0).getChildNodes().item(0) 
                                        .getNodeValue()); 
                    } 
                } 
            }else { 
                System.exit(1); 
            } 
        } 
    }catch (Exception e) { 
        System.out.println(e); 
    } 
} 
public static void main(String[] args) { 

    XMLParser parser =new XMLParser(); 
    parser.getAllUserNames("c:\\test.xml"); 
} 

}

  1. 把 Array 转换成 Map

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Map;
import org.apache.commons.lang.ArrayUtils;

public class Main {

public static void main(String[] args) {

String[][] countries = { {"United States","New York" }, {"United Kingdom","London" }, 
    {"Netherland","Amsterdam" }, {"Japan","Tokyo" }, {"France","Paris" } }; 

Map countryCapitals = ArrayUtils.toMap(countries); 

System.out.println("Capital of Japan is " + countryCapitals.get("Japan")); 
System.out.println("Capital of France is " + countryCapitals.get("France")); 

}
}

  1. 发送邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public void postMail( String recipients[ ], String subject, String message , String from)throws MessagingException
{

boolean debug =false; 

 //Set the host smtp address 
 Properties props =new Properties(); 
 props.put("mail.smtp.host","smtp.example.com"); 

// create some properties and get the default Session 
Session session = Session.getDefaultInstance(props,null); 
session.setDebug(debug); 

// create a message 
Message msg =new MimeMessage(session); 

// set the from and to address 
InternetAddress addressFrom =new InternetAddress(from); 
msg.setFrom(addressFrom); 

InternetAddress[] addressTo =new InternetAddress[recipients.length]; 
for (int i =0; i < recipients.length; i++) 
{ 
    addressTo[i] =new InternetAddress(recipients[i]); 
} 
msg.setRecipients(Message.RecipientType.TO, addressTo); 

// Optional : You can also set your custom headers in the Email if you Want 
msg.addHeader("MyHeaderName","myHeaderValue"); 

// Setting the Subject and Content Type 
msg.setSubject(subject); 
msg.setContent(message,"text/plain"); 
Transport.send(msg); 

}

  1. 发送代数据的HTTP 恳求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {

public static void main(String[] args)  { 
    try { 
        URL my_url =new URL("http://coolshell.cn/"); 
        BufferedReader br =new BufferedReader(new InputStreamReader(my_url.openStream())); 
        String strTemp =""; 
        while(null != (strTemp = br.readLine())){ 
        System.out.println(strTemp); 
    } 
    }catch (Exception ex) { 
        ex.printStackTrace(); 
    } 
} 

}

asp下经常用到的代码

asp下经常用到的代码

点击提示“确定”与“取消”提示框
onclick=''{if(confirm("您确定删除吗?此操作将不能恢复!")){return true;}return false;}''


删除.LDB文件
<%
Application.Contents.Removeall()
%>

将HTML格式转换为纯文本格式
<%  
Function RemoveHTML(strHTML)  
 Dim objRegExp, Match, Matches     
 Set objRegExp = New Regexp  

 objRegExp.IgnoreCase = True  
 objRegExp.Global = True  
 ''取闭合的<>  
 objRegExp.Pattern = "<.+?>"  
 ''进行匹配  
 Set Matches = objRegExp.Execute(strHTML)  

 '' 遍历匹配集合,并替换掉匹配的项目  
 For Each Match in Matches     
     strHtml=Replace(strHTML,Match.Value,"")  
 Next  
 RemoveHTML=strHTML  
 Set objRegExp = Nothing  
End Function  

%>
调用
<%=RemoveHTML(你的字段)%>


25、当前页地址
<% 
response.write "http://"&Request.ServerVariables("server_name")&Request.ServerVariables("script_name") 
%>

C#程序员经常用到的10个实用代码片段

C#程序员经常用到的10个实用代码片段

 1 读取操作系统和CLR的版本

OperatingSystem os = System.Environment.OSVersion;
Console.WriteLine(“Platform: {0}”, os.Platform);
Console.WriteLine(“Service Pack: {0}”, os.ServicePack);
Console.WriteLine(“Version: {0}”, os.Version);
Console.WriteLine(“VersionString: {0}”, os.VersionString);
Console.WriteLine(“CLR Version: {0}”, System.Environment.Version);
登录后复制

  在我的windows 7系统中,输出以下信息

  Platform: Win32NT
  Service Pack:
  Version: 6.1.7600.0
  VersionString: Microsoft Windows NT 6.1.7600.0
  CLR Version: 4.0.21006.1

  2 读取CPU数量,内存容量

  可以通过Windows Management Instrumentation (WMI)提供的接口读取所需要的信息。

private static UInt32 CountPhysicalProcessors()
{
     ManagementObjectSearcher objects = new ManagementObjectSearcher(
        “SELECT * FROM Win32_ComputerSystem”);
     ManagementObjectCollection coll = objects.Get();
     foreach(ManagementObject obj in coll)
    {
        return (UInt32)obj[“NumberOfProcessors”];
    } 
    return 0;
}
private static UInt64 CountPhysicalMemory()
{
   ManagementObjectSearcher objects =new ManagementObjectSearcher(
      “SELECT * FROM Win32_PhysicalMemory”);
   ManagementObjectCollection coll = objects.Get();
   UInt64 total = 0;
   foreach (ManagementObject obj in coll)
   {
       total += (UInt64)obj[“Capacity”];
    }
    return total;
}
登录后复制

请添加对程序集System.Management的引用,确保代码可以正确编译。

点击下载“修复打印机驱动工具”;

Console.WriteLine(“Machine: {0}”, Environment.MachineName);
Console.WriteLine(“# of processors (logical): {0}”, Environment.ProcessorCount);
Console.WriteLine(“# of processors (physical): {0}”  CountPhysicalProcessors());
Console.WriteLine(“RAM installed: {0:N0} bytes”,  CountPhysicalMemory());
Console.WriteLine(“Is OS 64-bit? {0}”,   Environment.Is64BitOperatingSystem);
Console.WriteLine(“Is process 64-bit? {0}”,  Environment.Is64BitProcess);
Console.WriteLine(“Little-endian: {0}”, BitConverter.IsLittleEndian);
foreach (Screen screen in  System.Windows.Forms.Screen.AllScreens)
{
     Console.WriteLine(“Screen {0}”, screen.DeviceName);
     Console.WriteLine(“\tPrimary {0}”, screen.Primary);
     Console.WriteLine(“\tBounds: {0}”, screen.Bounds);
     Console.WriteLine(“\tWorking Area: {0}”,screen.WorkingArea);
     Console.WriteLine(“\tBitsPerPixel: {0}”,screen.BitsPerPixel);
}
登录后复制

  3 读取注册表键值对

using (RegistryKey keyRun = Registry.LocalMachine.OpenSubKey(@”Software\Microsoft\Windows\CurrentVersion\Run”))
{
    foreach (string valueName in keyRun.GetValueNames())
    {
     Console.WriteLine(“Name: {0}\tValue: {1}”, valueName, keyRun.GetValue(valueName));
    }
}
登录后复制

  请添加命名空间Microsoft.Win32,以确保上面的代码可以编译。

  4 启动,停止Windows服务

  这项API提供的实用功能常常用来管理应用程序中的服务,而不必到控制面板的管理服务中进行操作。

ServiceController controller = new ServiceController(“e-M-POWER”);      
controller.Start();      
if (controller.CanPauseAndContinue)      
{      
    controller.Pause();      
    controller.Continue();      
}      
controller.Stop();
登录后复制

  .net提供的API中,可以实现一句话安装与卸载服务

if (args[0] == "/i")
 {
       ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
 }
 else if (args[0] == "/u")
 {
   ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
 }
登录后复制

如代码所示,给应用程序传入i或u参数,以表示是卸载或是安装程序。

  5 验证程序是否有strong name (P/Invoke)

  比如在程序中,为了验证程序集是否有签名,可调用如下方法

[DllImport("mscoree.dll", CharSet=CharSet.Unicode)]
static extern bool StrongNameSignatureVerificationEx(string wszFilePath, bool fForceVerification, ref bool  pfWasVerified);
bool notForced = false;
bool verified = StrongNameSignatureVerificationEx(assembly, false, ref notForced);
Console.WriteLine("Verified: {0}\nForced: {1}", verified, !notForced);
登录后复制

  这个功能常用在软件保护方法,可用来验证签名的组件。即使你的签名被人去掉,或是所有程序集的签名都被去除,只要程序中有这一项调用代码,则可以停止程序运行。

  6 响应系统配置项的变更

  比如我们锁定系统后,如果QQ没有退出,则它会显示了忙碌状态。

  请添加命名空间Microsoft.Win32,然后对注册下面的事件。

  . DisplaySettingsChanged (包含Changing) 显示设置
  . InstalledFontsChanged 字体变化
  . PaletteChanged
  . PowerModeChanged 电源状态
  . SessionEnded (用户正在登出或是会话结束)
  . SessionSwitch (变更当前用户)
  . TimeChanged 时间改变
  . UserPreferenceChanged (用户偏号 包含Changing)

  我们的ERP系统,会监测系统时间是否改变,如果将时间调整后ERP许可文件之外的范围,会导致ERP软件不可用。

7 运用Windows7的新特性

  Windows7系统引入一些新特性,比如打开文件对话框,状态栏可显示当前任务的进度。

Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog ofd = new  Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();
ofd.AddToMostRecentlyUsedList = true;
ofd.IsFolderPicker = true;
ofd.AllowNonFileSystemItems = true;
ofd.ShowDialog();
登录后复制

  用这样的方法打开对话框,与BCL自带类库中的OpenFileDialog功能更多一些。不过只限于Windows 7系统中,所以要调用这段代码,还要检查操作系统的版本要大于6,并且添加对程序集Windows API Code Pack for Microsoft®.NET Framework的引用,请到这个地址下载 http://code.msdn.microsoft.com/WindowsAPICodePack

  8 检查程序对内存的消耗

  用下面的方法,可以检查.NET给程序分配的内存数量

long available = GC.GetTotalMemory(false);
Console.WriteLine(“Before allocations: {0:N0}”, available);
int allocSize = 40000000;
byte[] bigArray = new byte[allocSize];
available = GC.GetTotalMemory(false);
Console.WriteLine(“After allocations: {0:N0}”, available);
登录后复制

  在我的系统中,它运行的结果如下所示

Before allocations: 651,064
After allocations: 40,690,080
登录后复制

  使用下面的方法,可以检查当前应用程序占用的内存

Process proc = Process.GetCurrentProcess();
Console.WriteLine(“Process Info: “+Environment.NewLine+
登录后复制
“Private Memory Size: {0:N0}”+Environment.NewLine +
“Virtual Memory Size: {1:N0}” + Environment.NewLine +
登录后复制
“Working Set Size: {2:N0}” + Environment.NewLine +
“Paged Memory Size: {3:N0}” + Environment.NewLine +
“Paged System Memory Size: {4:N0}” + Environment.NewLine +
登录后复制
“Non-paged System Memory Size: {5:N0}” + Environment.NewLine,
proc.PrivateMemorySize64,   proc.VirtualMemorySize64,  proc.WorkingSet64,  proc.PagedMemorySize64, proc.PagedSystemMemorySize64,  proc.NonpagedSystemMemorySize64 );
登录后复制
9 使用记秒表检查程序运行时间

  如果你担忧某些代码非常耗费时间,可以用StopWatch来检查这段代码消耗的时间,如下面的代码所示

System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
Decimal total = 0;
int limit = 1000000;
for (int i = 0; i < limit; ++i)
{
      total = total + (Decimal)Math.Sqrt(i);
}
timer.Stop();
Console.WriteLine(“Sum of sqrts: {0}”,total);
Console.WriteLine(“Elapsed milliseconds: {0}”,
timer.ElapsedMilliseconds);
Console.WriteLine(“Elapsed time: {0}”, timer.Elapsed);
登录后复制

  现在已经有专门的工具来检测程序的运行时间,可以细化到每个方法,比如dotNetPerformance软件。

  以上面的代码为例子,您需要直接修改源代码,如果是用来测试程序,则有些不方便。请参考下面的例子。

class AutoStopwatch : System.Diagnostics.Stopwatch, IDisposable
{
   public AutoStopwatch()
   { 
       Start();
   }
   public void Dispose()
   {
       Stop();
       Console.WriteLine(“Elapsed: {0}”, this.Elapsed);
   }
}
登录后复制

  借助于using语法,像下面的代码所示,可以检查一段代码的运行时间,并打印在控制台上。

using (new AutoStopwatch())
{
    Decimal total2 = 0;
    int limit2 = 1000000;
    for (int i = 0; i < limit2; ++i)
    {
       total2 = total2 + (Decimal)Math.Sqrt(i);
    }
}
登录后复制

  10 使用光标

  当程序正在后台运行保存或是册除操作时,应当将光标状态修改为忙碌。可使用下面的技巧。

class AutoWaitCursor : IDisposable
{
private Control _target;
private Cursor _prevCursor = Cursors.Default;
public AutoWaitCursor(Control control)
{
   if (control == null)
   {
     throw new ArgumentNullException(“control”);
   }
   _target = control;
   _prevCursor = _target.Cursor;
   _target.Cursor = Cursors.WaitCursor;
}
public void Dispose()
{
   _target.Cursor = _prevCursor;
}
}
登录后复制

  用法如下所示,这个写法,是为了预料到程序可能会抛出异常

using (new AutoWaitCursor(this))
{
...
throw new Exception();
}
登录后复制

  如代码所示,即使抛出异常,光标也可以恢复到之间的状态。

Dede(织梦)sql调用之代码大全

Dede(织梦)sql调用之代码大全

在Dede系统里面,可以使用sql语句来配合织梦标签进行更多的个性化调用,今天毛仔整理了一些Dede(织梦)系统利用sql语句调用相关标签的代码,现在分享给大家,有错误的请尽管指正,有遗漏的也欢迎大家补上~

调用的代码基本格式为:

	

{dede:sql sql='select  字段 From 数据库名.表名称 where 条件语句'}
[field:字段名/]
{/dede:sql}

举例,调用文档列表的代码

	

{dede:sql sql='select  * From dede_archives where typeid=1 limit 10'}
PHP?aid=[field:id/]">[field:title/] {/dede:sql}
说明:如果是在相同数据库内不需要加数据库名称,否则就要在表名称前面加"数据库名.",比如“Dedecms.dede_archives”;如果不指定调用哪个栏目的文章则去掉“where typeid=1”;如果调用多个栏目的文章则代码格式为“where typeid='1' or typeid='2'   ”;用order by id desc 可以设列表排序,by id表示按id从大到小排列,这个语句用的时候加在 表名称后面, limit 10表示调用最新的10条文档,可以自由设定调用的数量。

以上调用出来的文档的链接为动态链接,如果调用静态链接地址,代码格式为:

	

{dede:sql sql="SELECT * FROM dede_archives limit 10"}
etoneArchive($id);@me=$url['arcurl'];[/field:id]'  title="[field:title/]" target="_blank">[field:title function=cn_substr(@me,30,0)/]sql}

以上代码经毛仔测试过能够调用处本系统内的文章以及静态调用地址,但是如果是多个dede系统嵌套的话,可以调用处文章标题,但是调不出静态地址,不晓得大家有什么其他好主意不?不过能够调出来了文章的id,只要你的文章命名命的好,可以通过id调用处静态地址。

调用提问标题和提问内容

	

{dede:sql sql='Select * from dede_ask where status=1 order by id desc limit 0,3'}
PHP?id=[field:id/]">[field:title function="cn_substr(@me,10)"/] [field:content function="cn_substr(@me,10)"/]…
{/dede:sql}
 

调用提问标题和最佳答案

	

{dede:sql sql='Select q.id,q.title,a.askid,a.ifanswer,a.content from dede_ask as q,dede_askanswer as a where q.status=1 and a.ifanswer=1 and q.id=a.askid and q.bestanswer=a.id order by q.id desc limit 0,3'}
PHP?id=[field:id/]">[field:title function="cn_substr(@me,10)"/] {/dede:sql}

毛仔还从网上找了一些其他标签调用的代码

共有文章:** 篇

	

 {dede:sql sql="select count(*) as c from dede_archives where channel=1"}·共有文章:[field:c /]篇{/dede:sql}

共有图集:** 个

	

{dede:sql sql="select count(*) as c from dede_archives where channel=2"}·共有图集:[field:c /]个{/dede:sql}

共有软件:** 个

	

{dede:sql sql="select count(*) as c from dede_archives where channel=3"}·共有软件:[field:c /]个{/dede:sql}

共有评论:**条

	

{dede:sql sql="select count(*) as c from dede_Feedback"}·共有评论:[field:c /]条{/dede:sql}

共有会员:**名

	

{dede:sql sql="select count(mid) as c from dede_member "}·共有会员:[field:c /]名{/dede:sql}

文章阅读:** 人次

	

{dede:sql sql="select sum(click) as c from dede_archives"}文章阅读:[field:c /]人次{/dede:sql}

今日更新:**篇

	

{dede:sql sql="SELECT count( * ) AS c FROM dede_archives WHERE pubdate > UNIX_TIMESTAMP( CURDATE( ) ) "}今日更新:[field:c /]篇{/dede:sql}

总共留言:

	

{dede:sql sql="select count(*) as cc From dede_guestbook"}[field:cc/]{/dede:sql}条

调用某个特定会员发布的文章内容

	

{dede:sql sql='Select * from dede_archives where mid=1'}
PHP?aid=[field:id/]" target="_blank" >[field:title="" ]<="" a> {/dede:sql}

关于织梦(今日更新等)经常用到的统计代码SQL调用语句织梦系统基本参数的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于40个经常用到的java代码块、asp下经常用到的代码、C#程序员经常用到的10个实用代码片段、Dede(织梦)sql调用之代码大全等相关内容,可以在本站寻找。

本文标签: