Catsou55 发表于 2018-4-25 10:11:14

SpreadAsp.Net版整数型Cell最大最小值Check

本帖最后由 Catsou55 于 2018-4-25 10:26 编辑

整数型单元格的默认可以输入任何字符,为了实现只能输入数字的功能,需要结合InputMan的验证控件GcCharacterTypeValidator。代码如下所示,数字输入功能实现了,可是数值1~999的范围check失效了。麻烦帮看看问题出在哪里。

      Dim intCell As New IntegerCellType
      intCell.MinimumValue = 1
      intCell.MaximumValue = 999

      Dim GcCharacterTypeValidator1 As New GcCharacterTypeValidator
      GcCharacterTypeValidator1.ID = "dataTypeValidator1"
      GcCharacterTypeValidator1.ValidateOnInput = True
      GcCharacterTypeValidator1.CharacterSet = "9"
      GcCharacterTypeValidator1.ValidatorActionID = "GcValidatorAction1"

      Dim valProc As New ValueProcess
      valProc.ValueProcessOption = ValueProcessOption.Restore
      GcValidatorAction1.DefaultActions.Add(valProc)

      intCell.Validators.Add(GcCharacterTypeValidator1)

dexteryao 发表于 2018-4-25 12:31:06

建议您直接发可直接运行的Demo,这样处理快很多。

Catsou55 发表于 2018-4-25 13:53:54

<%@ Page Language="VB" Inherits="System.Web.UI.Page" %>

<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMValidators" tagprefix="im_validator" %>

<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMExtenders" tagprefix="im_extenders" %>

<!DOCTYPE html>
<script language="VB" type="text/VB" runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
      InitVaSpread1()
    End Sub

    Private Sub InitVaSpread1()
      FpSpread1.EditModeReplace = True
      FpSpread1.ProcessTab = True

      FpSpread1.HorizontalScrollBarPolicy = ScrollBarPolicy.Never
      FpSpread1.VerticalScrollBarPolicy = ScrollBarPolicy.Always

      FpSpread1.ActiveSheetView.DefaultRowHeight = 37

      FpSpread1.ActiveSheetView.RowCount = 4
      FpSpread1.ActiveSheetView.ColumnCount = 2

      FpSpread1.ColumnHeader.Cells(0, 0).Value = "Col1"
      FpSpread1.ColumnHeader.Cells(0, 1).Value = "Col2"

      FpSpread1.ActiveSheetView.Columns(0).Width = 100
      FpSpread1.ActiveSheetView.Columns(1).Width = 100

      FpSpread1.ActiveSheetView.Columns(0).BackColor = Drawing.Color.Yellow
      FpSpread1.ActiveSheetView.Columns(0).CellType = New TextCellType With {.AllowWrap = True}

      Dim intCell As New IntegerCellType
      intCell.MinimumValue = 1
      intCell.MaximumValue = 999

      GcCharacterTypeValidator1.ID = "dataTypeValidator1"
      GcCharacterTypeValidator1.ValidateOnInput = True
      GcCharacterTypeValidator1.CharacterSet = "9"
      GcCharacterTypeValidator1.ValidatorActionID = "GcValidatorAction1"

      Dim valProc As New ValueProcess
      valProc.ValueProcessOption = ValueProcessOption.Restore
      GcValidatorAction1.DefaultActions.Add(valProc)

      intCell.Validators.Add(GcCharacterTypeValidator1)

      FpSpread1.ActiveSheetView.Columns(1).CellType = intCell
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
      <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400">
            <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark">
            </CommandBar>
            <Sheets>
                <FarPoint:SheetView SheetName="Sheet1">
                </FarPoint:SheetView>
            </Sheets>
      </FarPoint:FpSpread>
      <im_validator:GcCharacterTypeValidator ID="GcCharacterTypeValidator1" runat="server" ErrorMessage="GcCharacterTypeValidator" HasLoadFromXml="True"></im_validator:GcCharacterTypeValidator>
      <im_extenders:GcValidatorAction ID="GcValidatorAction1" runat="server"></im_extenders:GcValidatorAction>
    </form>
</body>
</html>

Catsou55 发表于 2018-4-25 13:55:01

下面是全的文件:

<%@ Page Language="VB" Inherits="System.Web.UI.Page" %>

<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMValidators" tagprefix="im_validator" %>

<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMExtenders" tagprefix="im_extenders" %>

<!DOCTYPE html>
<script language="VB" type="text/VB" runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
      InitVaSpread1()
    End Sub

    Private Sub InitVaSpread1()
      FpSpread1.EditModeReplace = True
      FpSpread1.ProcessTab = True

      FpSpread1.HorizontalScrollBarPolicy = ScrollBarPolicy.Never
      FpSpread1.VerticalScrollBarPolicy = ScrollBarPolicy.Always

      FpSpread1.ActiveSheetView.DefaultRowHeight = 37

      FpSpread1.ActiveSheetView.RowCount = 4
      FpSpread1.ActiveSheetView.ColumnCount = 2

      FpSpread1.ColumnHeader.Cells(0, 0).Value = "Col1"
      FpSpread1.ColumnHeader.Cells(0, 1).Value = "Col2"

      FpSpread1.ActiveSheetView.Columns(0).Width = 100
      FpSpread1.ActiveSheetView.Columns(1).Width = 100

      FpSpread1.ActiveSheetView.Columns(0).BackColor = Drawing.Color.Yellow
      FpSpread1.ActiveSheetView.Columns(0).CellType = New TextCellType With {.AllowWrap = True}

      Dim intCell As New IntegerCellType
      intCell.MinimumValue = 1
      intCell.MaximumValue = 999

      GcCharacterTypeValidator1.ID = "dataTypeValidator1"
      GcCharacterTypeValidator1.ValidateOnInput = True
      GcCharacterTypeValidator1.CharacterSet = "9"
      GcCharacterTypeValidator1.ValidatorActionID = "GcValidatorAction1"

      Dim valProc As New ValueProcess
      valProc.ValueProcessOption = ValueProcessOption.Restore
      GcValidatorAction1.DefaultActions.Add(valProc)

      intCell.Validators.Add(GcCharacterTypeValidator1)

      FpSpread1.ActiveSheetView.Columns(1).CellType = intCell
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
      <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400">
            <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark">
            </CommandBar>
            <Sheets>
                <FarPoint:SheetView SheetName="Sheet1">
                </FarPoint:SheetView>
            </Sheets>
      </FarPoint:FpSpread>
      <im_validator:GcCharacterTypeValidator ID="GcCharacterTypeValidator1" runat="server" ErrorMessage="GcCharacterTypeValidator" HasLoadFromXml="True"></im_validator:GcCharacterTypeValidator>
      <im_extenders:GcValidatorAction ID="GcValidatorAction1" runat="server"></im_extenders:GcValidatorAction>
    </form>
</body>
</html>

dexteryao 发表于 2018-4-25 15:18:03

我试着重现问题

dexteryao 发表于 2018-4-26 09:33:21

测试了,使用validator后原有验证就失效了,需要您在Validator里实现所有验证

Catsou55 发表于 2018-4-26 09:56:27

谢谢您的回答。
InputMan只提供了下面六种验证控件,没有提供最大最小值的验证。
GcCharacterTypeValidator,GcDataTypeValidator,GcDateDifferenceValidator,
GcDateRangeValidator,GcForbiddenTextValidator,GcTextLengthValidator
需要实现自定义验证控件才能实现吗?
如何实现自定义验证控件能提供些帮助吗?
麻烦再帮忙看看,万分感激。

dexteryao 发表于 2018-4-26 17:43:13

也可以看看微软本身提供的一些Validator。 结合一起使用

Catsou55 发表于 2018-5-11 19:49:41

日期时间型单元格(DateTimeCellType)也有同样的问题。绑定了InputMan的检证控件GcCharacterTypeValidator之后,
时间最大值最小值Check也会失效。还有没有别的解决方案。

dexteryao 发表于 2018-5-14 09:01:50

这个没有了,这个和之前一样,结合使用。
页: [1]
查看完整版本: SpreadAsp.Net版整数型Cell最大最小值Check