Sunday, February 22, 2015

WPF 实现sql server连接

首先创建一个新的wpf项目
在reference 下点击manage nuget package
安装entity framework

然后在项目下添加一个item,ado.net entity data model,连接到你的sqlserver服务
然后在界面下添加一个datagrid,一个query的button

在主界面程序文件下先实例化数据服务,
AdventureWorks2012Entities data = new AdventureWorks2012Entities();
AdventureWorks2012是微软自带sample database
再建立button的点击方法

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            var query =
           from person in data.Person
           where person.FirstName == textbox1.Text && person.LastName == textbox2.Text
           orderby person.LastName
           select new { person.FirstName, person.LastName, person.PersonType, person.Title };

            datagrid1.ItemsSource = query.ToList();
        }



Monday, February 9, 2015

一个简单 javascript计算器的实现

<input id="kkk" />

<br />
<button id="1" onclick="reply_click(this.value)" value="1">1</button>
<button id="2" onclick="reply_click(this.id)">2</button>
<button id="3" onclick="reply_click(this.id)">3</button>
<button id="4" onclick="reply_click(this.id)">4</button>
<button id="5" onclick="reply_click(this.id)">5</button>
<button id="6" onclick="reply_click(this.id)">6</button>
<button id="7" onclick="reply_click(this.id)">7</button>
<button id="8" onclick="reply_click(this.id)">8</button>
<button id="9" onclick="reply_click(this.id)">9</button>
<button id="0" onclick="reply_click(this.id)">0</button>
<br />
<button id="equal" onclick="compute()">=</button>
<button onclick="reply_click(this.value)" value="+">+</button>
<button onclick="reply_click(this.value)" value="-">-</button>
<button onclick="reply_click(this.value)" value="*">*</button>
<button onclick="reply_click(this.value)" value="/">/</button>
<button onclick="reset()">C</button>


<script type="text/javascript">
function reply_click(clicked_id)
{
    document.getElementById("kkk").value+=clicked_id;
}
function compute()
{
document.getElementById("kkk").value = eval(document.getElementById("kkk").value);
}
function reset()
{
document.getElementById("kkk").value="";
}

</script>

效果见

Sunday, February 8, 2015

mysql的一些有用操作

source d:/create-company-data-for-MySQL.sql       // 导入sql源文件

下载安装
http://dev.mysql.com/downloads/connector/
打开Eclipse,创建一个项目,

操作:右键点击--->build Path--->add external Archiver...选择jdbc驱动,点击确定。

新建java文件测试
import java.sql.*;

public class DBTest {
    static Connection conn = null;
      
        public static void main(String[] args) {

            // Initialize variables for fields by data type
            String ssn;
            String firstName;
            String lastName;
            String address;
            int dno;

            int linect = 0;

        try {
            // Create a connection to the local MySQL server, with the "company" database selected.
            //        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "mypassword");
            // Create a connection to the local MySQL server, with the NO database selected.
                    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "");
    
            // Create a SQL statement object and execute the query.
            Statement stmt = conn.createStatement();
        
            // Set the current database, if not already set in the getConnection
            // Execute a SQL statement
//   String chooseDatabase = "use company;"
            stmt.execute("use company;");

            // Execute a SQL query using SQL as a String object
            ResultSet rs = stmt.executeQuery("SELECT ssn, fname, lname, dno FROM employee;");

            // Iterate through the result set using ResultSet class's next() method
            while (rs.next()) {
                // Keep track of the line/tuple count
                linect++;
                // Populate field variables
                
                firstName = rs.getString("fname");
                lastName = rs.getString("lname");
//                dno = rs.getInt("dno");
    ssn = rs.getString("ssn");
    dno = Integer.parseInt(rs.getString("dno"));
            
                // Do something with the data
                System.out.print(linect + ".\t");
                System.out.print(ssn + "\t");
                System.out.print(firstName + "\t");
                System.out.print(lastName + "\t");
                System.out.print(dno + "\t");
                System.out.println();
            } // End while(rs.next())

            // Always close the recordset and connection.
            rs.close();
            conn.close();
            System.out.println("Success!!");
        } 
        catch(SQLException ex) {
            System.out.println("Error in connection: " + ex.getMessage());
        }
    }

   
    }
}

ubuntu的一些有用操作

apt-get remove openjdk*  remove openjdk
java安装在哪里了 通过whereis java命令不能知道java真是的安装路径
可以通过 update-alternatives --config java 命令察看

Saturday, February 7, 2015

git 简易操作指南

首先 download git 软件http://msysgit.github.io/
在github上新建repository
在git bash命令行下

【建立账号】

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com


【新建git项目】在某目录下

$ git init

【克隆项目】

$ git clone git://github.com/schacon/grit.git

【check status】

$ git status

【commit】可以copy文件进来

$ git commit (-v)  (:wq 保存退出)

$ git commit –m “write message” (不弹出编辑界面)

$ git commit –am “write message” (修改的不用重新add)

【remove files】

$ rm file.py (硬盘删除linux,unstaged)

$ git rm (-f) file.py (登记删除,同时硬盘删除)

然后git push 可以推送
git push origin master
可以把 master 换成你想要推送的任何分支


$ git log (查看commit历史)
git reset --hard   可强制下载pull


$ git branch name (只是建立分支,仍在master分支上)

$ git checkout name (转到分支上,转分支时文件自动改变!!)






asp.net MVC 对数据库进行操作

using EntityFramework.Extensions;
//外界扩展库+ 需要在PM里 Install-Package EntityFramework.Extended


//删除时间超过12小时的信息
            db.channel.Delete(item => DbFunctions.DiffHours(item.Date,newTime) > 12);

linux服务器任务自动执行

crontab -e执行schedule task

*/30 * * * * /home/004/wget.sh    每30分钟执行wget.sh程序

参考:
基本格式 :
*  *  *  *  *  command
分 时 日 月 周 命令

第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
crontab文件的一些例子:
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重启apache。
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每月1、10、22日的4 : 45重启apache。
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每周六、周日的1 : 10重启apache。
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每星期六的11 : 00 pm重启apache。
* */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小时重启apache
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11点到早上7点之间,每隔一小时重启apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4号与每周一到周三的11点重启apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一号的4点重启apache