毕业设计超市系统(六)界面的设计

这是一个界面设计的用于保存用户配置信息的可序列化类

 

SerializeInfo序列化用户信息
Imports System.Runtime.Serialization
Imports System.Drawing
''' <summary>
''' 可序列化的用户配置信息
''' </summary>
''' <remarks></remarks>
<Serializable()> _
Public Class SerializeInfo
    
''' <summary>
    
''' 构造方法加载默认配置
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub New()
        _AlterRowBackColorName 
= Color.Silver.Name
        _ReadOnlyBackColorName 
= Color.LightGray.Name
        _DefaultCellBackColorName 
= Color.White.Name
        _SingCellForeColorName 
= Color.Red.Name
        _SignRowOkForeColorName 
= Color.Green.Name
    
End Sub
    
Private _AlterRowBackColorName As String
    
''' <summary>
    
''' 交替行背景色名字
    
''' </summary>
    
''' <returns>交替行背景色名字</returns>
    
''' <remarks></remarks>
    Public Property AlterRowBackColorName() As String
        
Get
            
Return _AlterRowBackColorName
        
End Get
        
Set(ByVal value As String)
            _AlterRowBackColorName 
= value
        
End Set
    
End Property
    
Private _SingCellForeColorName As String
    
''' <summary>
    
''' 标记前景色名字
    
''' </summary>
    
''' <returns>标记前景色名字</returns>
    
''' <remarks></remarks>
    Public Property SingCellForeColorName() As String
        
Get
            
Return _SingCellForeColorName
        
End Get
        
Set(ByVal value As String)
            _SingCellForeColorName 
= value
        
End Set
    
End Property
    
Private _SignRowOkForeColorName As String
    
''' <summary>
    
''' 标记通过行前景色名字
    
''' </summary>
    
''' <returns>标记通过行前景色名字</returns>
    
''' <remarks></remarks>
    Public Property SignRowOkForeColorName() As String
        
Get
            
Return _SignRowOkForeColorName
        
End Get
        
Set(ByVal value As String)
            _SignRowOkForeColorName 
= value
        
End Set
    
End Property
    
Private _ReadOnlyBackColorName As String
    
''' <summary>
    
''' 只读行背景色名字
    
''' </summary>
    
''' <returns>只读行背景色名字</returns>
    
''' <remarks></remarks>
    Public Property ReadOnlyBackColorName() As String
        
Get
            
Return _ReadOnlyBackColorName
        
End Get
        
Set(ByVal value As String)
            _ReadOnlyBackColorName 
= value
        
End Set
    
End Property
    
Private _DefaultCellBackColorName As String
    
''' <summary>
    
''' 默认背景色名字
    
''' </summary>
    
''' <returns>默认背景色名字</returns>
    
''' <remarks></remarks>
    Public Property DefaultCellBackColorName() As String
        
Get
            
Return _DefaultCellBackColorName
        
End Get
        
Set(ByVal value As String)
            _DefaultCellBackColorName 
= value
        
End Set
    
End Property

    
Private _SelectionBackColorName As String
    
''' <summary>
    
''' 选中先背景色名字
    
''' </summary>
    
''' <returns>选中先背景色名字</returns>
    
''' <remarks></remarks>
    Public Property SelectionBackColorName() As String
        
Get
            
Return _SelectionBackColorName
        
End Get
        
Set(ByVal value As String)
            _SelectionBackColorName 
= value
        
End Set
    
End Property
End Class

 

 

把可序列化类型的信息转换为具体的可用信息

 

转化为可用配置信息
Imports System.Runtime.Serialization
Imports System.Drawing
''' <summary>
''' 可序列化的用户配置信息
''' </summary>
''' <remarks></remarks>
<Serializable()> _
Public Class SerializeInfo
    
''' <summary>
    
''' 构造方法加载默认配置
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub New()
        _AlterRowBackColorName 
= Color.Silver.Name
        _ReadOnlyBackColorName 
= Color.LightGray.Name
        _DefaultCellBackColorName 
= Color.White.Name
        _SingCellForeColorName 
= Color.Red.Name
        _SignRowOkForeColorName 
= Color.Green.Name
    
End Sub
    
Private _AlterRowBackColorName As String
    
''' <summary>
    
''' 交替行背景色名字
    
''' </summary>
    
''' <returns>交替行背景色名字</returns>
    
''' <remarks></remarks>
    Public Property AlterRowBackColorName() As String
        
Get
            
Return _AlterRowBackColorName
        
End Get
        
Set(ByVal value As String)
            _AlterRowBackColorName 
= value
        
End Set
    
End Property
    
Private _SingCellForeColorName As String
    
''' <summary>
    
''' 标记前景色名字
    
''' </summary>
    
''' <returns>标记前景色名字</returns>
    
''' <remarks></remarks>
    Public Property SingCellForeColorName() As String
        
Get
            
Return _SingCellForeColorName
        
End Get
        
Set(ByVal value As String)
            _SingCellForeColorName 
= value
        
End Set
    
End Property
    
Private _SignRowOkForeColorName As String
    
''' <summary>
    
''' 标记通过行前景色名字
    
''' </summary>
    
''' <returns>标记通过行前景色名字</returns>
    
''' <remarks></remarks>
    Public Property SignRowOkForeColorName() As String
        
Get
            
Return _SignRowOkForeColorName
        
End Get
        
Set(ByVal value As String)
            _SignRowOkForeColorName 
= value
        
End Set
    
End Property
    
Private _ReadOnlyBackColorName As String
    
''' <summary>
    
''' 只读行背景色名字
    
''' </summary>
    
''' <returns>只读行背景色名字</returns>
    
''' <remarks></remarks>
    Public Property ReadOnlyBackColorName() As String
        
Get
            
Return _ReadOnlyBackColorName
        
End Get
        
Set(ByVal value As String)
            _ReadOnlyBackColorName 
= value
        
End Set
    
End Property
    
Private _DefaultCellBackColorName As String
    
''' <summary>
    
''' 默认背景色名字
    
''' </summary>
    
''' <returns>默认背景色名字</returns>
    
''' <remarks></remarks>
    Public Property DefaultCellBackColorName() As String
        
Get
            
Return _DefaultCellBackColorName
        
End Get
        
Set(ByVal value As String)
            _DefaultCellBackColorName 
= value
        
End Set
    
End Property

    
Private _SelectionBackColorName As String
    
''' <summary>
    
''' 选中先背景色名字
    
''' </summary>
    
''' <returns>选中先背景色名字</returns>
    
''' <remarks></remarks>
    Public Property SelectionBackColorName() As String
        
Get
            
Return _SelectionBackColorName
        
End Get
        
Set(ByVal value As String)
            _SelectionBackColorName 
= value
        
End Set
    
End Property
End Class

 

 

处理用户样式的基类

 

样式个性化基类
Imports System.Windows.Forms
Imports System.Drawing
''' <summary>
''' 控件样式基类
''' </summary>
''' <remarks></remarks>
Public Class ViewStyleBase
    
Protected _localview As DataGridView
    
Protected _localrow As DataGridViewRow
    
''' <summary>
    
''' 标记的前景色
    
''' </summary>
    
''' <returns></returns>
    
''' <remarks>这里并不多余,目的是让前台只用SetUpGridViewCellStyle就可以对表现层进行处理</remarks>
    Public Shared ReadOnly Property SignForeColor() As Color
        
Get
            
Return SetUpInfo.SignCellForeColor
        
End Get
    
End Property
    
''' <summary>
    
''' 默认的前景色
    
''' </summary>
    
''' <value></value>
    
''' <returns></returns>
    
''' <remarks></remarks>
    Public Shared ReadOnly Property DefaultForeColor() As Color
        
Get
            
Return SetUpInfo.DefaultCellBackColor
        
End Get
    
End Property
    
''' <summary>
    
''' 要被设置的DataGridView
    
''' </summary>
    
''' <value></value>
    
''' <remarks></remarks>
    Public WriteOnly Property LocalView() As DataGridView
        
Set(ByVal value As DataGridView)
            _localview 
= value
        
End Set
    
End Property
    
''' <summary>
    
''' 要被设置的DataGridViewRow
    
''' </summary>
    
''' <value></value>
    
''' <remarks></remarks>
    Public WriteOnly Property LocalViewRow() As DataGridViewRow
        
Set(ByVal value As DataGridViewRow)
            _localrow 
= value
        
End Set
    
End Property
End Class

 

 

设置datagridview的样式的类

 

设置样式
Imports System.Windows.Forms
Imports System.Drawing

Imports Microsoft.Office.Interop.Excel
''' <summary>
''' 设置数据视图样式
''' </summary>
''' <remarks></remarks>
Public Class SetUpGridViewCellStyle
    
Inherits ViewStyleBase
    
''' <summary>
    
''' 设置要显示的样式
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub New()
        SetUpInfo.SeriaInfo 
= UserSetUpManger.LoadSetUpInfo()
    
End Sub
    
''' <summary>
    
''' 标记选中的单元格
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub SignSelectedCell()
        
If _localview Is Nothing Then
            
Exit Sub
        
End If
        
If _localview.SelectedCells.Count > 0 Then
            
For Each c As DataGridViewCell In _localview.SelectedCells
                c.Style.ForeColor 
= SetUpInfo.SignCellForeColor
            
Next
        
End If
    
End Sub
    
''' <summary>
    
''' 对通过行标记
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub SignRowOk()
        
If _localrow Is Nothing Then
            
Exit Sub
        
End If
        
For Each c As DataGridViewCell In _localrow.Cells
            c.Style.ForeColor 
= SetUpInfo.SignRowOkForeColor
        
Next
    
End Sub
    
''' <summary>
    
''' 标记行错误
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub SignRowError()
        
If _localrow Is Nothing Then
            
Exit Sub
        
End If
        
For Each c As DataGridViewCell In _localrow.Cells
            c.Style.ForeColor 
= SetUpInfo.SignCellForeColor
        
Next
    
End Sub
    
''' <summary>
    
''' 反向设置标记
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub UnSignCell()
        
For Each c As DataGridViewCell In _localview.SelectedCells
            
If c.Style.ForeColor <> SetUpInfo.SignCellForeColor Then
                c.Style.ForeColor 
= SetUpInfo.SignCellForeColor
            
Else
                c.Style.ForeColor 
= Color.Black
            
End If
        
Next
    
End Sub
    
''' <summary>
    
''' 清除标记
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub ClearViewSign()
        
For Each r As DataGridViewRow In _localview.Rows
            
For Each c As DataGridViewCell In r.Cells
                c.Style.ForeColor 
= Color.Black
            
Next
        
Next
    
End Sub
    
''' <summary>
    
''' 设置只读列的背景色
    
''' </summary>
    
''' <remarks></remarks>
    Private Sub SetUpReadOnlyStyle()
        
For Each c As DataGridViewColumn In _localview.Columns
            
If c.ReadOnly Then
                c.DefaultCellStyle.BackColor 
= SetUpInfo.ReadOnlyBackColor
            
End If
        
Next
    
End Sub
    
''' <summary>
    
''' 设置样式
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub SetUpViewStyle()
        SetUpReadOnlyStyle()
        SetUpAlterRowStyle()
        _localview.DefaultCellStyle.BackColor 
= SetUpInfo.DefaultCellBackColor
        _localview.DefaultCellStyle.SelectionBackColor 
= SetUpInfo.SelectionBackColor
    
End Sub
    
''' <summary>
    
''' 设置交替行的样式
    
''' </summary>
    
''' <remarks></remarks>
    Private Sub SetUpAlterRowStyle()
        _localview.AlternatingRowsDefaultCellStyle.BackColor 
= SetUpInfo.AlterRowBackColor
    
End Sub
    
''' <summary>
    
''' 导出被标记的行
    
''' </summary>
    
''' <remarks></remarks>
    Public Sub ExportSignRow() 'ByVal title As String
        Dim saved As New SaveFileDialog
        saved.Title 
= "保存到本地磁盘的位置"
        saved.Filter 
= "Excel文件(.xls)|*.xls"
        saved.FileName 
= "超市导出Excel的文件.xls"
        
Dim filename As String
        
If saved.ShowDialog() = DialogResult.OK Then
            filename 
= saved.FileName
        
Else
            
Exit Sub
        
End If
        
Dim app As Microsoft.Office.Interop.Excel.Application

        app 
= CreateObject("Excel.Application")
        
Dim wb As Workbook
        app.Visible 
= False
        wb 
= app.Workbooks.Add
        
Dim ws As Worksheet
        ws 
= wb.Sheets(1)
        ws.Cells(
11= "打印时间:" + DateTime.Now.ToString
        
For Each c As DataGridViewColumn In _localview.Columns
            ws.Cells(
2, c.Index + 1= c.HeaderText
            ws.Cells(
2, c.Index + 1).Font.Bold = True
        
Next
        
'添加到表格数据
        Dim signed As Boolean = False
        
For Each r As DataGridViewRow In _localview.Rows
            
For Each c As DataGridViewCell In r.Cells
                
If c.Style.ForeColor = SetUpInfo.SignCellForeColor Then
                    signed 
= True
                    
Exit For
                
End If
            
Next
            
If signed Then
                
For Each c As DataGridViewCell In r.Cells
                    ws.Cells(c.RowIndex 
+ 3, c.ColumnIndex + 1= c.Value
                
Next
                signed 
= False
            
End If
        
Next
        app.Workbooks(
1).SaveAs(filename)
        app.ActiveWorkbook.Close(SaveChanges:
=True)
        app.Quit()
        app 
= Nothing
        wb 
= Nothing
    
End Sub
End Class

 

 

别的不多说了如有问题可看前面的uml图

posted @ 2010-05-27 20:51  gege_s  Views(621)  Comments(0)    收藏  举报