简陋的会计凭证金额输入控件(加强)

      上次一时兴起,做了一个仿金蝶的凭证金额输入的控件,今天使用了下,真的奇陋无比,所以花了几个小时加强了点功能
主要有增加以下功能
1、实现整数和小数位的分开
2、在得到焦点的时候能控制在整数位
3、在输入“.”的时候可以自动跳转到小数位(红线后)
4、能设置和获得原始的数据
以下是示意图

代码如下
None.gif using  System;
None.gif
using  System.ComponentModel;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
namespace  Voucher
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [DefaultProperty(
"jText")]
InBlock.gif    [ToolboxData(
@"<{0}:VoucherInput jText = ''  
InBlock.gif    runat='server'></{0}:VoucherInput>
")
InBlock.gif    ]
InBlock.gif    
//设置默认的属性
InBlock.gif
    public class VoucherInput : WebControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      
InBlock.gif        
private TextBox _TextBox;    //整数位
InBlock.gif
        private TextBox _PTextBox;   //小数位
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
属性#region 属性
InBlock.gif        [
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
""),
InBlock.gif        Description(
"金额")
InBlock.gif        ]
InBlock.gif        
public string jText
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                EnsureChildControls();
InBlock.gif                
return _TextBox.Text + "." + _PTextBox.Text;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                EnsureChildControls();
InBlock.gif                
if (value == "" || value == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                   
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
string[] Allstring = value.Split('.');
InBlock.gif                    _TextBox.Text 
= Allstring[0];
InBlock.gif                    _PTextBox.Text 
= Allstring[1]; 
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion
 Properties delegated to child controls
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
方法#region 方法
InBlock.gif        
protected override void CreateChildControls()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Controls.Clear();
InBlock.gif            _TextBox 
= new TextBox();
InBlock.gif            _TextBox.ID 
= "TextBox1";
InBlock.gif            _TextBox.MaxLength 
= 13;
InBlock.gif            _TextBox.Width 
= 120;
InBlock.gif            _TextBox.Height 
= 20;
InBlock.gif            _TextBox.Attributes.Add(
"onkeypress""keyPress()");
InBlock.gif            _TextBox.Style.Add(HtmlTextWriterStyle.BackgroundImage, 
"url(Images/text.gif)");
InBlock.gif            _TextBox.Style.Add(HtmlTextWriterStyle.Direction, 
"rtl");
InBlock.gif            _TextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, 
"0");            
InBlock.gif
InBlock.gif            _PTextBox 
= new TextBox();
InBlock.gif            _PTextBox.Width 
= 15;
InBlock.gif            _PTextBox.Height 
= 20;
InBlock.gif            _PTextBox.MaxLength 
= 2;
InBlock.gif            _PTextBox.ID 
= "PTextBox";
InBlock.gif            _PTextBox.Style.Add(HtmlTextWriterStyle.BackgroundImage, 
"url(Images/textPoint.gif)");
InBlock.gif
InBlock.gif            _PTextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, 
"0");
InBlock.gif
InBlock.gif
InBlock.gif            
this.Controls.Add(_TextBox);
InBlock.gif            
this.Controls.Add(_PTextBox);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            AddAttributesToRender(writer);
InBlock.gif            _TextBox.RenderControl(writer);
InBlock.gif            _PTextBox.RenderControl(writer);
InBlock.gif            writer.Write(
"<script language=javascript>function keyPress(){if(!(event.keyCode>=48&&event.keyCode<=57 ||event.keyCode==46 || event.keyCode==45)){event.keyCode = 0;}if(event.keyCode==46){event.keyCode = 0;document.getElementById('PTextBox').focus();}}</script>");   //对字符的控制
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockEnd.gif        
#endregion
 Overriden methods
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif
None.gif
None.gif
总结
现在还是不满意,比如删数据的时候还是小数位和整数位分开发删除,目前还没有具体的想法

转载于:https://www.cnblogs.com/jiekeng/archive/2006/10/27/541887.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值