以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  设置临时表单元格格式  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=65120)

--  作者:wyd1008
--  发布时间:2015/3/9 17:06:00
--  设置临时表单元格格式

老师,如何设置临时表的单元格的格式?
下面是代码,我想设置“库存差异”列的单元格格式,
格式根据条件来设置,“库存差异”<=0,单元格红色
“库存差异”>0,单元格绿色

请原谅,我真的不会做,请指教



Dim et As Date = e.Form.Controls("ETime3").value

Dim str As String = Format(et,"yyyy年MM月dd日")

Dim g As New GroupTableBuilder("统计表1", DataTables("成品流水账"))
g.Groups.AddDef("产品状态")
g.Groups.AddDef("车")
g.Groups.AddDef("型")
g.Groups.AddDef("产品类型")
g.Groups.AddDef("背番")
g.Groups.AddDef("品番")
g.Groups.AddDef("安全库存","安全库存",str & "_安全库存")
g.Totals.AddDef("库存", "库存",str & "_库存")
g.filter = "日期 <= \'" & cdate(et) & "\'"
g.build
MainTable = Tables("统计表1")

Dim cp As List(of String())
cp = DataTables("成品流水账").GetValues("产品状态|车|型|产品类型|品番|背番|安全库存", "品番 not in (\'" & DataTables("统计表1").GetComboListString("品番").Replace("|", "\',\'") & "\')")
For i As Integer = 0 To cp.Count - 1
    Dim nr As Row = Tables("统计表1").AddNew
    nr("产品状态") = cp(i)(0)
    nr("车") = cp(i)(1)
    nr("型") = cp(i)(2)
    nr("产品类型") = cp(i)(3)
    nr("背番") = cp(i)(4)
    nr("品番") = cp(i)(5)
nr("安全库存") = cp(i)(6)
Next

For Each r As Row In Tables("统计表1").Rows
    Dim filter = " 日期 <= \'" & cdate(et) & "\' and 品番 = \'" & r("品番") & "\'"
    Dim kc As Double = DataTables("成品流水账").Compute("sum(入库)",filter) - DataTables("成品流水账").Compute("sum(出库)",filter)
    r("库存") = kc
Next

With DataTables("统计表1").DataCols  \'用表达式列计算库存数据
    .Add("库存差异",Gettype(Double),"(isnull([库存],0) - isnull([安全库存],0))",str & "_库存差异")
End With


With Forms("统计返回")
    .OpenTo("统计表1")
    .Controls("Label1").Text = "统计"
    .Controls("TextBox1").Value = "此统计为起始日期至截止日期的成品统计"
    .Controls("Button1").Text = "返回成品流水账表"
End With
MainTable.Focus()

--  作者:Bin
--  发布时间:2015/3/9 17:07:00
--  
利用DrawCell事件
--  作者:有点甜
--  发布时间:2015/3/9 17:10:00
--  

 你要开启一下全局事件,然后去编写全局的drawcell事件

 

http://www.foxtable.com/help/topics/0671.htm

 


--  作者:wyd1008
--  发布时间:2015/3/10 9:00:00
--  

甜老师,昨天下班了,

回复昨天的问题,今天我用在项目事件中的

Initialize写入代码:

For Each kq As DataTable In DataTables
    kq.GlobalHandler.drawcell = True
Next

然后在Drawcell写入代码:

Select Case e.Table.Name
    Case "统计表1"
        If e.Col.IsNumeric AndAlso e.Col.Name = "库存差异" Then
            If e.Row.IsNull(e.Col.Name) = False \'且该列已经输入内容
                If e.Row(e.Col.Name) <= 0 Then \'如果该列的值小于等于0
                    e.Style = "库存不足" \'那么用"库存不足"样式绘制单元格
                ElseIf e.Row(e.Col.Name) > 0 Then \'如果单元格的值大于0
                    e.Style = "库存安全" \'那么用"库存安全"样式绘制单元格
                End If
            End If
        End If
End Select

 

自定义样式中,设置了“库存不足”“库存安全”2个样式

但是执行了后,临时“统计表1”中的库存差异列没反应,

这是什么问题?


--  作者:Bin
--  发布时间:2015/3/10 9:01:00
--  
上个例子看看.
--  作者:wyd1008
--  发布时间:2015/3/10 9:08:00
--  

老师这个用完删除,有我们公司内部数据恩
[此贴子已经被作者于2015/3/10 9:10:10编辑过]

--  作者:Bin
--  发布时间:2015/3/10 9:11:00
--  
没有数据源,打不开,  或者你做个内部数据源的简单例子
--  作者:wyd1008
--  发布时间:2015/3/10 9:12:00
--  
恩,忘记了是外部的数据源了,好的
--  作者:有点甜
--  发布时间:2015/3/10 9:12:00
--  

1、请带上数据源别人才能打开啊;

 

2、Build统计表出来之后,在加入开启的代码

 

MainTable = Tables("统计表1")

DataTables("统计表1").GlobalHandler.drawcell = True

DataTables("统计表1").AddUserStyle("库存不足", Color.Red, Color.White)

DataTables("统计表1").AddUserStyle("库存安全", Color.Green, Color.White)


--  作者:wyd1008
--  发布时间:2015/3/10 9:26:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.rar

老师这个应该可以了