2010-12-7

2010-6-25

81. 各种面向编程

1、什么是面向对象编程 (Object-Oriented Programming)

面向对象编程(Object-Oriented Programming)简称OOP技术,是开发计算机应用程序的一种新方法、新思想。过去的面向过程编程常常会导致所有的代码都包含在几个模块中,使程序难以阅读和维护。在做一些修改时常常牵一动百,使以后的开发和维护难以为继。而使用OOP技术,常常要使用许多代码模块,每个模块都只提供特定的功能,它们是彼此独立的,这样就增大了代码重用的几率,更加有利于软件的开发、维护和升级。

在面向对象中,算法与数据结构被看做是一个整体,称作对象,现实世界中任何类的对象都具有一定的属性和操作,也总能用数据结构与算法两者合一地来描述,所以可以用下面的等式来定义对象和程序:

对象=(算法+数据结构),程序=(对象+对象+……)。

从上面的等式可以看出,程序就是许多对象在计算机中相继表现自己,而对象则是一个个程序实体。

 

2、什么是面向组件编程(Component-Oriented Programming)

组件不是一个新的概念,Java中的javaBean规范和EJB规范都是典型的组件。组件的特点在于他定义了一种通用的处理方式。例如,JavaBean 拥有内视的特性,这样就可以通过工具来实现JAVABean的可视化。而EJB规范定义了企业服务中的一些特性,使得EJB容器能够为符合EJB规范的代码增添企业计算所需要的能力,例如事务、持久化、池等。

所以,组件比起对象来的进步就在于通用的规范的引入。通用规范往往能够为组件添加新的能力(就像上面所讨论的),但也给组件添加了限制,例如你需要实现EJB的一些接口

COP比OOP更进一步。通常OOP将数据对象组织到实体中。这种方法具有很多优点。但是,OOP有一个大的限制:对象之间的相互依赖关系。去掉这个限制的一个好的想法就是组件。组件和一般对象之间的关键区别是组件是可以替代的。

 

3、什么是面向方面编程(ASPect-Oriented Programming)

将通用需求功能从不相关类之中分离出来;同时,能够使得很多类共享一个行为,一旦行为发生变化,不必修改很多类,只要修改这个行为就可以。

AOP就是这种实现分散关注的编程方法,它将“关注”封装在“方面”中。

 

4、什么是面向服务编程(Service-Oriented Programming) 

SOA是一种体系结构,目标是在软件代理交互中获得松散耦合。一个服务是一个服务提供者为一个服务消费者获得其想要的最终结果的一个工作单元。服务者与消费者都以软件代理代表他们自己的角色。

    这听起来有些太抽象,但是SOA确实无处不在。让我们在你的住房中找到一个SOA的例子。例如播放一个CD,你可以将要播放的CD放入CD机中,CD机将为你播放这张CD,CD机提供了一个CD播放服务。这里的好处就是你可以用不同的CD机去播放同一张CD。他们能提供同样的CD播放服务,但是服务质量是不同的。

SOA的思想明显不同于面向对象的编程,面向对象编程强烈的建议你应该将数据与其操作绑定。因此在面向对象编程风格中,每张CD 有它自己的CD播放机,他们之间不能被拆开。这听起来很奇怪,但是这就是我们建立许多已存软件系统的方式

 

5、什么是面向过程编程

面向过程编程就是分析待解决的问题所涉及的步骤,然后通过函数来逐一把每一步骤实现。它是以事件(问题)为中心的。代表语言有C……

    其实质是按照计算机处理问题的过程来进行程序设计:输入——操作——输出。这样设计者需要变更思维的习惯来完成涉及工作。面向过程程序设计所具有的流的工作性质,试图通过信息流及其转换来认识系统,不仅加大了程序设计的难度,亦使得程序的可理解性比较差。这种程序设计思维同样为软件的后期维护升级或是修改留下了较大的麻烦——可复用性差。

   面向过程程序设计方法一种普遍采用的优化方法是自上而下的程序设计思路。要求设计开始就得全面系统了解整个工程的架构。

 

 

2010-7-21

82.Sql判断表中是否存在某一列

if not exists (select * from syscolumns

where id = (select id from sysobjects where name ='con_productbill' ) and name = 'descript')

alter table con_productbill add descript varchar(60)

 

2010-7-28

83.DataTableReader累计加数据

DataTableReader dtr = entity.con_paymentapply.CreateDataReader();

(this.ActiveWrapper.BusinessDataSet as PaymentApplyEntity).con_paymentapply.Load(dtr);

 

2010-8-5

84.IndexOf()用法

找不到相匹配的返回-1

 

2010-8-16

85.Sql删除主键,修改字段,增加主键

declare @pk varchar(80);

select @pk=Name  from sysobjects where parent_obj = object_id('con_contract_bk') and xtype = 'pk';

if @pk is not null

exec('alter table con_contract_bk drop ' + @pk)

 

alter table con_contract_bk alter column vary_num numeric(18, 2);

 

alter table con_contract_bk alter column vary_num numeric(18, 2) not null;

 

alter table con_contract_bk add constraint pkName primary key (con_systemcode,vary_num);

 

2010-8-18

86.判断小数点后2位

this.currentForm.txtWidth.Text.ToString().Substring(this.currentForm.txtWidth.Text.ToString().IndexOf(".") + 1).Length > 2

 

2010-8-30

87.字符串中去掉中文

toAddress = Regex.Replace(toAddress,@"[/u4e00-/u9fa5]","");

 

2010-9-6

88.过滤文件类型

currentForm.openFileDialog1.Filter = @"文件类型(*.txt *.jpg *.gif *.bmp *.jpeg *.png *.rar *.zip *.pdf *.eml *.doc *.docx *.ppt *.pptx *.xls *.xlsx)                                                      |*.txt;*.jpg;*.gif;*.bmp;*.jpeg;*.png;*.rar;*.zip;*.pdf;*.eml;                                                          *.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx";

 

89. ToolStripMenuItem 弹出选项弹出事件

    menuCatalog.DropDownItemClicked += new ToolStripItemClickedEventHandler(menuCatalog_DropDownItemClicked);                      

                  

2010-10-14

90. sqlserver类型转换

cast(id as varchar)

 

2010-10-19

91.加载整个数据集

DataTableReader dtr = null;

dtr = new DataTableReader(currentManagerForm.BusinessDataSet.Tables["con_mainbody"]);

this.Bk1DataSet.Tables["con_mainbody_bk"].Clear();                   this.Bk1DataSet.Tables["con_mainbody_bk"].Load(dtr);

 

2010-10-22

92.分段读二进制文件

using (fs)

            {

                int startPosition = 0;

                int stepCount = 0;

                int stepValue = 1 * 1024 * 1024;

 

                buffer = new byte[fs.Length];

                stepCount = buffer.Length / stepValue + 1;

 

                byte[] ByteArray = null;

 

                if (stepCount == 1)

                {

                    ByteArray = new byte[fs.Length];

                    fs.Read(ByteArray, startPosition, Convert.ToInt32(fs.Length));

                    this.CreateRow(maxsysno, ByteArray);

                }

                if (stepCount > 1)

                {

                    for (int i = 0; i < stepCount; i++)

                    {

                        if (i == stepCount - 1)

                        {

                            ByteArray = new byte[fs.Length - (i * stepValue)];

                            fs.Position = startPosition;

                            fs.Read(ByteArray, 0, Convert.ToInt32(fs.Length) - (i * stepValue));

                            this.CreateRow(maxsysno, ByteArray);

                        }

                        else

                        {

                            ByteArray = new byte[stepValue];

                            fs.Position = startPosition;

                            fs.Read(ByteArray, 0, stepValue);

                            startPosition = stepValue * (i == 0 ? 1 : (i + 1));

                            this.CreateRow(maxsysno, ByteArray);

 

                        }

                    }

                }

 

93.二进制分段

if (newEntity.attachment_object.Rows.Count > 0)

                {

                    foreach (DataRow dr in newEntity.attachment_object.Rows)

                    {

                        int id = 0;

                        int startPosition = 0;

                        int stepCount = 0;

                        int stepValue = 2 * 1024 * 1024;

 

                        if (dr["att_object"] == null || dr["att_object"] == DBNull.Value)

                        { continue; }

 

                        byte[] att_objectByte = (byte[])dr["att_object"];

                        string att_objectSysno = dr["sysno"].ToString();

 

                        if (att_objectByte != null)

                        {

                            byte[] byteTotal = att_objectByte;

 

                            if (byteTotal.Length > 0)

                            {

                                stepCount = byteTotal.Length / stepValue + 1;

                                if (stepCount == 1)

                                {

                                    dr_byte = dt.NewRow();

                                    dr_byte["id"] = id++;

                                    dr_byte["sysno"] = att_objectSysno;

                                    dr_byte["byte"] = byteTotal;

                                    dt.Rows.Add(dr_byte);

                                }

                                if (stepCount > 1)

                                {

                                    for (int i = 0; i < stepCount; i++)

                                    {

                                        if (i == stepCount - 1)

                                        {

                                            byte[] ByteArray = new byte[byteTotal.Length - (i * stepValue)];

                                            System.Array.Copy(byteTotal, startPosition, ByteArray, 0, ByteArray.Length);

 

                                            dr_byte = dt.NewRow();

                                            dr_byte["id"] = id++;

                                            dr_byte["sysno"] = att_objectSysno;

                                            dr_byte["byte"] = ByteArray;

                                            dt.Rows.Add(dr_byte);

 

                                        }

                                        else

                                        {

                                            byte[] ByteArray = new byte[stepValue];

                                            System.Array.Copy(byteTotal, startPosition, ByteArray, 0, ByteArray.Length);

                                            startPosition = stepValue * (i == 0 ? 1 : (i + 1));

 

                                            dr_byte = dt.NewRow();

                                            dr_byte["id"] = id++;

                                            dr_byte["sysno"] = att_objectSysno;

                                            dr_byte["byte"] = ByteArray;

                                            dt.Rows.Add(dr_byte);

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

 

2010-11-3

94.重设控件位置

private void SetControlSize()

{

      this.currentForm.gdApplyDetail.Location = new System.Drawing.Point(this.currentForm.ngGroup3.Left, 385);

            this.currentForm.gdApplyDetail.Size = new System.Drawing.Size(this.currentForm.ngGroup3.Width, 150);

            this.currentForm.ngXtraPanel2.Location = new System.Drawing.Point(this.currentForm.gdApplyDetail.Left, 540);

            this.currentForm.ngXtraPanel2.Size = new System.Drawing.Size(this.currentForm.gdApplyDetail.Width, 50);

}

 

95.Sql exists 用法

from

con_contract,

uv_con_baseinfo

WHERE    con_contract.con_systemcode = uv_con_baseinfo.con_systemcode and

exists(

SELECT    *  FROM    uv_con_baseinfo

WHERE    con_contract.con_systemcode = uv_con_baseinfo.con_systemcode  

 

96.建立索引查询优化

create nonclustered index CI_contract_non

on con_contract(createdate,affixtounit,handover,historyflag)

 

2010-11-10

97.利用游标实现sql循环

set nocount on

declare @con_systemcode varchar(250)

declare @vary_num numeric(18, 2)

declare UpdateVary_num cursor

forward_only read_only

for select con_systemcode,vary_num from con_contract

where vary_num > 0 and con_systemcode

in ((select  con_systemcode from con_managercontract

where con_systemcode = con_systemcode_new))

 

open UpdateVary_num

fetch next

from UpdateVary_num

into @con_systemcode,@vary_num

 

while @@FETCH_STATUS = 0

begin

 

update con_mainbody set vary_num = @vary_num

where con_systemcode = @con_systemcode and vary_num = 0

 

fetch next

from UpdateVary_num

into @con_systemcode,@vary_num

end

 

close UpdateVary_num

deallocate UpdateVary_num

 

 

2010-11-15

98.过滤表中重复数据

DataView dv = dt.DefaultView;

DataTable dd = dv.ToTable(true, "content");

 

2010-11-30

99.Sqlserver分页:

  sql = " select distinct top 20 logid,u_name FROM secuser, fg_orgpop where secuser.logid = fg_orgpop.ug_code  " +

                      " and ocode in (select ocode FROM fg_orgpop where u_soft = '01' and ug_code = '" + i6.DataAccess.Common.AppSessionConfig.LoginID + "') " +

                      " and  logid not in ( select  distinct top " + num.ToString() +

               " logid FROM secuser, fg_orgpop " +

               " where secuser.logid = fg_orgpop.ug_code  " +

               " and ocode in (select ocode FROM fg_orgpop where u_soft = '01' and ug_code = '" + i6.DataAccess.Common.AppSessionConfig.LoginID + "'))";

oracle分页:

sql = " select distinct logid,u_name FROM secuser, fg_orgpop where Rownum <= 20 and secuser.logid = fg_orgpop.ug_code  " +

                     " and ocode in (select ocode FROM fg_orgpop where u_soft = '01' and ug_code = '" + i6.DataAccess.Common.AppSessionConfig.LoginID + "') " +

                     " and  logid not in ( select  distinct " +

              " logid FROM secuser, fg_orgpop " +

              " where Rownum <= " + num.ToString() +

              " and secuser.logid = fg_orgpop.ug_code and ocode in (select ocode FROM fg_orgpop where u_soft = '01' and ug_code = '" + i6.DataAccess.Common.AppSessionConfig.LoginID + "'))";

        

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值