17
2013
01

c#利用反射,实现将model类变成字符串、再还原成mode对象的功能

处理类:

public string ToString(UserGiftCardModel model)
        {
            if (model == null) return "";
            string sb = "";
            Type type =model.GetType() ;//assembly.GetType("Reflect_test.PurchaseOrderHeadManageModel", true, true); //命名空间名称 + 类名  
            //创建类的实例  
            //object obj = Activator.CreateInstance(type, true);
            //获取公共属性  
            PropertyInfo[] Propertys = type.GetProperties();


15
2013
01

C#批量去掉文件前缀,最近用动软代码生成器,文件名在代码里改不了。

code:

 

         static void Main(string[] args)
        {
            Console.WriteLine("本程序去掉当前目录及子目录下的文件前缀");
            Console.Write("请输入要去掉的前缀:");
            string stringFront = Console.ReadLine();
            if (stringFront != "")
            {
                string dir = AppDomain.CurrentDomain.BaseDirectory;
                RenameFile(dir, stringFront);
            }
            else Console.WriteLine("请输入要去掉的前缀!");
            Console.WriteLine("操作已完成");
            Console.ReadKey();
        }
        public static void RenameFile(string ParentDir,string stringFront)
        {
            string[] files = Directory.GetFiles(ParentDir, "*.cs", SearchOption.TopDirectoryOnly);
            foreach (string file in files)
            {
                string filename = Path.GetFileName(file);
                string pathname = Path.GetDirectoryName(file);
                if (filename.StartsWith(stringFront, true, null))
                {
                    filename = filename.Substring(stringFront.Length);
                    FileInfo fi = new FileInfo(file);
                    fi.MoveTo(Path.Combine(pathname,filename));
                }
            }
            string[] dirs = Directory.GetDirectories(ParentDir);
            foreach(string dir in dirs)
            {
                RenameFile(dir,stringFront);
            }
        }


27
2012
12

js行背景变色、显示提示层的代码

JS代码:

function showHelp(id) {  

    var obj = document.getElementById(id);  

    obj.style.display = "";  

26
2012
12

网页中js弹出模式窗口并传值的问题

js代码:

    <script type="text/javascript">  

        //父窗体中打开模式窗口  

        function SelectClient(ctlName) {  

27
2012
10

linux下练习 gcc 静态库/动态库 编译示例

//iotool.c

#include <stdio.h>
int inputInt(const char *info)
{
int r;
printf("%s:",info);
scanf("%d",&r);
return r;
}


graphic.c

27
2012
10

c#程序片段,替换所有同名文件

code:

 

  class Program
    {
        static void Main(string[] args)
        {
            try
            {
                replacefile rf = new replacefile();
                rf.doReplace(@"F:\c1");
                rf.doReplace(@"F:\c2");
                rf.doReplace(@"F:\c3");
                Console.WriteLine("替换完成!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
    public class replacefile
    {
        public string sourceFilejs = @"F:\frmleftdown.js";//源文件
        public string sourceFilexml = @"F:\frmleftdown.xml";//源文件
        public void doReplace(string parentPath)
        {
            string[] files = Directory.GetFiles(parentPath);
            foreach (string f in files)
            {
                if (f=="frmleftdown.js") File.Copy(sourceFilejs, f, true);//替换目录下所有的同名文件
                if (f=="frmleftdown.xml") File.Copy(sourceFilexml, f, true);
            }
            string[] subdirs = Directory.GetDirectories(parentPath);
            foreach (string subdir in subdirs)
            {
                doReplace(subdir);
            }
        }
    }


26
2012
10

linux下练习 c++ 输入输出迭代器

iterator.cpp

/*
迭代器
输入:可读,不一定可改值
输出:可改,不一定可读值
前向:可读可改
双向:支持 --
随机:支持--、+n、-n、下标访问
*/
#include<iterator>
#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include "print.h"
#include<fstream>
int main()
{
//输入迭代
istream_iterator<int> in(cin);//输入流cin,也可以是文件输入流
istream_iterator<int> end;
vector<int> vi;
copy(in,end,back_inserter(vi));//一直输入,按ctrl+D结束
print(vi.begin(),vi.end());
//输出迭代
ofstream fo("out.txt");
ostream_iterator<int> o(cout,",");
ostream_iterator<int> ofile(fo," ");
copy(vi.begin(),vi.end(),o);
copy(vi.begin(),vi.end(),ofile);
fo.close();
cout<<endl;
}


26
2012
10

linux下练习 c++ 特殊容器、特殊函数的使用

//specialcontainer.cpp

/*一般容器:stack,queue
特殊容器:priority_queue
.push(element),.pop(),.empty()
stack:.top()
queue:.front(),.back()
priority_queue:.top()
没有迭代器
*/
#include<iostream>
#include<queue>
using namespace std;
int main()
{
priority_queue<int> pq;
pq.push(40);
pq.push(20);
pq.push(10);
pq.push(50);
pq.push(90);
while(!pq.empty())
{
cout<<pq.top()<<' ';
pq.pop();
}
cout<<endl;
return 0;
}


26
2012
10

linux下练习 c++ 容器set、multimset的特性

print.h

//print.h
#include <iostream>
using namespace std;
#ifndef print_fun
#define print_fun
template<typename T>
///显示序列数据
void print(T b,T e,char c=' ')
{
bool isExit=false;
while (b!=e)
{
cout<<*b++<<c;
isExit=true;
}
if(isExit) cout<<endl;
}
template<typename K,typename V>
ostream& operator<<(ostream& o,const pair<K,V>& p)//重载输出map类型元素
{
return o<<p.first<<':'<<p.second;
}
#endif


25
2012
10

html代码弹出固定大小的窗口


//js弹出固定大小窗口

<SCRIPT language=javascript> 
function openScript(url, width, height) {
        var Win = window.open(url,"openScript",'width=' + width + ',height=' + 
height + ',resizable=0,scrollbars=yes,menubar=no,status=n0' );
}
</SCRIPT>
<body>
 <a href='javascript:openScript("http://www.baidu.com",300,400)' >1234324</>
</body>