开发大型的MIS系统,肯定是离不开第三方控件的,同时也要根据项目需要自己写几个。
MicroERP共用了以下几个控件:
第三方商业控件:
vsFlexGrid:大名鼎鼎的表格控件,不用多说,配合vsPrinter使用
开源的基础上修改和自己写的:
button按钮
cash会计凭证用的金额线
MDITabs MDI窗体
LeftMenu手风琴导航菜单
这里着重说一下vsFlexGrid、scriptControl的使用,以工资模块来说明表格运算及脚本编程示例。
这个控件也不是万能的,比如单元格没有change事件,很淡疼
在工资发放中,最难的就是工资表的自定义字段,某些成熟的软件用了内置上百个字段,然后由用户修改字段属性方式来完成,这里我用了“行转列”的方式,具体实现效果请参见MicroERP中的工资管理模块。
实现原理就是把预设的工资结构在填制工资表时,将表中的行转为工资表中的发放字段,某工资表数据行如下:
基本工资
岗位工资
养老保险
应发工资
应发工资=基本工资+岗位工资-养老保险
实发工资表时,显示为:
员工姓名|基本工资|岗位工资|养老保险|应发工资
员工一.......................
员工二.......................
以VB为例,实现代码如下,其它语言类似
'行转列
Public Sub SetFrame(frameID As Long)
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset, sql As String
Dim i As Long
btnSelectEmployee.Enabled = True
sql = "SELECT tbGZItem.ItemName "
sql = sql & "FROM (tbGZFrame INNER JOIN tbGZFrameDetail ON tbGZFrame.ID = tbGZFrameDetail.FrameID) INNER JOIN tbGZItem ON tbGZFrameDetail.ItemID = tbGZItem.ID "
sql = sql & "where tbGZFrameDetail.FrameID=" & frameID & " order by tbGZFrameDetail.FOrder"
On Error GoTo err
Set cn = GetConnection
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenStatic, adLockReadOnly
With fg
.Clear
.Rows = 1
.Cols = rs.RecordCount + 3
For i = 3 To .Cols - 1
.ColWidth(i) = 1300
.ColAlignment(i) = flexAlignRightCenter
Next i
.TextMatrix(0, 1) = "EmpID"
.TextMatrix(0, 2) = "员工姓名"
.Cell(flexcpAlignment, 0, 1, 0, .Cols - 1) = flexAlignCenterCenter
.ColWidth(0) = 300
.ColHidden(1) = True
For i = 0 To rs.RecordCount - 1
.TextMatrix(0, i + 3) = rs.Fields("ItemName").Value
.ColKey(i + 3) = rs.Fields("ItemName").Value
rs.MoveNext
Next i
End With
Exit Sub
err:
If rs.State <> adStateClosed Then rs.Close
Set rs = Nothing
If cn.State <> adStateClosed Then cn.Close
Set cn = Nothing
MsgBox err.Description, vbCritical, "SetFrame"
End Sub
注意,.ColKey(i + 3) = rs.Fields("ItemName").Value,这句是重点。
下在是在工资表编辑时,根据字段定义,来自动计算公式列和所得税列的值
Private Sub fg_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
Dim formula As String '公式
Dim funCol As String '需要计算的列
Dim i As Integer
Dim s As Single
Dim q As Single
If Col = 2 Then Cancel = True
On Error GoTo err
If Row <> 0 Then
If GetEditMode(fg.ColKey(Col)) = "公式计算" Then
funCol = "fg.TextMatrix(" & Row & "," & Col & ")="
formula = GetFormula(mFrameID, GetItemID(fg.ColKey(Col)))
'例:基本工资+补贴-保险
'将公式替换成行列索引
For i = 3 To fg.Cols - 1
formula = Replace(formula, fg.ColKey(i), "fg.ValueMatrix(" & Row & ", " & fg.colIndex(fg.ColKey(i)) & ")")
Next i
formula = funCol & formula
ScriptControl1.Reset
ScriptControl1.AddObject "fg", fg
ScriptControl1.ExecuteStatement formula
ElseIf GetEditMode(fg.ColKey(Col)) = "所得税" Then
txtYF.Text = Trim(GetINIstr(gAppPath & "option.ini", "system", "yffield"))
'应发工资
s = Val(fg.TextMatrix(Row, fg.colIndex(txtYF.Text)))
'起征点
q = Val(GetINIstr(gAppPath & "option.ini", "system", "gztax"))
If s <= q Then
fg.TextMatrix(Row, Col) = "0"
Else
'全月应纳税所得额
fg.TextMatrix(Row, Col) = GetTax(s - q)
End If
End If
End If
Exit Sub
err:
MsgBox err.Description, vbExclamation, "fg_BeforeEdit"
End Sub
注意:formula = Replace(formula, fg.ColKey(i), "fg.ValueMatrix(" & Row & ", " & fg.colIndex(fg.ColKey(i)) & ")"),这句是重点。
工资表结构预定义:
工资数据录入,下图的各列除基本工资和岗位工资外,其它列为自动计算出的数值:
看不懂的或需要代码的可以联系我。
http://www.tshuake.com/microerp