剔除Datagridview选中央银行并创新数据库

,当然…

     U层:给实体层传值,实行B层方法
[vb] 
”’ <summary>  
   ”’ 自定义的删除Datagridview记录的措施  
   ”’ </summary>  
   ”’ <remarks></remarks>  
   Public Sub Del() 
 
       Dim k As Integer = Me.DataGridView1.SelectedRows.Count 
       Dim enUserInfo As New Entity.UserInfoEntity 
       Dim DelUserUI As New BLL.AddDelUserBLL 
 
       ‘Datagridview中是还是不是留存数据  
       If DataGridView1.Rows.Count > 0 Then 
 
           ‘从下往上删,防止电火花电磁打点计时器效应  
           For i As Integer = k To 1 Step -1 
 
               ‘获取第N行的首先列的数码  
               Dim usercode As String = DataGridView1.SelectedRows(i –
1).Cells(“用户名”).Value.ToString() 
 
               ‘判别是或不是该行客商是还是不是为当下登陆顾客  
               If frmLogin.txtUserID.Text = usercode Then 
                   MsgBox(“当前顾客不能被去除,请重新选用!”, vbOKOnly +
vbExclamation, “系统提示”) 
                   Exit Sub 
               Else 
                  
‘将usercode传值给enUserInfo实体的UserID属性(即依据客商名删除)  
                   enUserInfo.UserID = usercode 
               End If 
 
               ‘从数据库试行删除操作  
               If DelUserUI.DelUserManager(enUserInfo) Then 
                   MsgBox(“删除成功!”, vbOKOnly + vbInformation,
“系统提示”) 
               Else 
                   MessageBox.Show(“删除战败!”, “系统提示”,
MessageBoxButtons.OK, MessageBoxIcon.[Error]) 
                   Return 
               End If 
               ‘将从数据库中剔除的音讯从Datagridview第11中学去除  
              
Me.DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(i –
1).Index) 
           Next 
       Else 
           DataGridView1.Rows.Clear() 
       End If 
 
   End Sub 

Sub
AddGlowToTitle()  
    Dim myChart As
Chart  
    Set myChart =
ActiveChart  
    myChart.ChartTitle.Format.Line.ForeColor.RGB = RGB(255,
255, 255)  
    myChart.ChartTitle.Format.Line.DashStyle =
msoLineSolid  
    myChart.ChartTitle.Format.Glow.Color.ObjectThemeColor
= msoThemeColorAccent6  
    myChart.ChartTitle.Format.Glow.Radius = 8  
End Sub


Sub
FormatShadow()  
    Dim myChart As
Chart  
    Set myChart =
ActiveChart  
    With myChart.Legend.Format.Shadow  
        .ForeColor.RGB = RGB(0,
0, 128)  
        .OffsetX = 5  
        .OffsetY = -3  
        .Transparency = 0.5  
        .Visible = True  
    End With  
End Sub


Sub
FormatSoftEdgesWithLoop()  
    Dim myChart As
Chart  
    Dim ser As
Series  
    Set myChart =
ActiveChart  
    Set ser =
myChart.SeriesCollection(1)  
    For i = 1 To 6  
        ser.Points(i).Format.SoftEdge.Type = i  
    Next i  
End Sub

    End Property

多多有相爱的人再为使用什么曲线来显示数据发愁,当然有MONEY的心上人除此之外。其实微软一度给大家提供叁个很有力免费的控件,那正是chart
,当然那个控件只可以再vs.二〇〇八以上的本子技能动用。但是相当少有人介绍怎么使用。于是小编花了一天时间,认真拓宽学习。

        ‘选中记录则提示严谨删除,未有当选数据则提示选拔。
        If Me.DataGridView1.SelectedRows.Count > 0 Then

 Chart Lengend

类图

 

                ‘决断是不是该行客商是不是为当下报到客户
                If frmLogin.txtUserID.Text = usercode Then
                    MsgBox(“当前客商不能够被去除,请重新选拔!”, vbOKOnly

    1. 透过VBA成立Chart的三种情势
      动用ChartWizard方法创建Sub
      CreateExampleChartVersionI() 
          Dim ws As
      Worksheet 
          Dim rgChartData As
      Range 
          Dim myChart As
      Chart 

        Set ws =
    ThisWorkbook.Worksheets(“Sheet1”) 
        Set rgChartData =
    ws.Range(“B1”).CurrentRegion 
        Set myChart =
    Charts.Add 
        Set myChart =
    myChart.Location(xlLocationAsObject, ws.Name) 
        With myChart 
            .ChartWizard _ 
                Source:=rgChartData, _ 
                Gallery:=xlColumn, _ 
                Format:=1, _ 
                PlotBy:=xlColumns, _ 
                CategoryLabels:=1, _ 
                SeriesLabels:=1, _ 
                HasLegend:=True,

                Title:=”Version
    I”, _ 
                CategoryTitle:=”Year”, _ 
                ValueTitle:=”GDP in
    billions of $” 
        End With 

        Set myChart = Nothing 
        Set rgChartData = Nothing 
        Set ws = Nothing 
    End Sub

    利用Chart Object方法成立Sub
    CreateExampleChartVersionII() 
        Dim ws As
    Worksheet 
        Dim rgChartData As
    Range 
        Dim myChart As
    Chart 

        Set ws =
    ThisWorkbook.Worksheets(“Basic
    Chart”) 
        Set rgChartData =
    ws.Range(“B1”).CurrentRegion 
        Set myChart =
    Charts.Add 
        Set myChart =
    myChart.Location(xlLocationAsObject, ws.Name) 

        With myChart 
            .SetSourceData rgChartData, xlColumns 
            .HasTitle = True 
            .ChartTitle.Caption = “Version
    II” 
            .ChartType = xlColumnClustered 

            With .Axes(xlCategory) 
                .HasTitle = True 
                .AxisTitle.Caption = “Year” 
            End With 

            With .Axes(xlValue) 
                .HasTitle = True 
                .AxisTitle.Caption = “GDP in
    billions of $” 
            End With 

        End With 

        Set myChart = Nothing 
        Set rgChartData = Nothing 
        Set ws = Nothing 
    End Sub

    动用ActiveWorkbook.Sheets.Add方法创建Sub
    chart()
        Dim myChartSheet As
    Chart
        Set myChartSheet =
    ActiveWorkbook.Sheets.Add _
            (After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count),
    _
            Type:=xlChart)
    End Sub

    利用ActiveSheet.ChartObjects.Add方法创设Sub
    charObj()
        Dim myChartObject As
    ChartObject
        Set myChartObject =
    ActiveSheet.ChartObjects.Add(Left:=200,
    Top:=200, _
            Width:=400,
    Height:=300)
        myChartObject.Chart.SetSourceData Source:= _
            ActiveWorkbook.Sheets(“Chart
    Data”).Range(“A1:E5”)
    End Sub

    不等的始建方法能够选取在分裂的场面,如Sheet中内嵌的图形,一个独立的Chart
    Tab等,读者能够团结商讨。最终一种方式的末段给新创制的图形设定了数据源,那样图表就足以显得出切实的图样了。
    假诺需求内定图表的门类,能够加上那句代码:
    myChartObject.ChartType = xlColumnStacked
    若果急需在现存图表的功底上增加新的series,下面那行代码能够参见:
    myChartObject.SeriesCollection.Add
    Source:=ActiveSheet.Range(“C4:K4”), Rowcol:=xlRows
    依旧通过下边那行代码对已部分series实行扩充:
    myChartObject.SeriesCollection.Extend Source:=Worksheets(“Chart
    Data”).Range(“P3:P8”)

    1. 三个争辨完整的通过VBA成立Chart的事例
      ‘Common Excel Chart Types     
      ‘——————————————————————-  

    ‘Chart   |   VBA Constant
    (ChartType property of Chart object)     |
    ‘==================================================================       

    ‘Column  |   xlColumnClustered,
    xlColumnStacked, xlColumnStacked100|        
    ‘Bar     |   xlBarClustered,
    xlBarStacked, xlBarStacked100         |
    ‘Line    |   xlLine,
    xlLineMarkersStacked, xlLineStacked           |
    ‘Pie     |   xlPie,
    xlPieOfPie                                     |
    ‘Scatter |   xlXYScatter,
    xlXYScatterLines                         |
    ‘——————————————————————-

    Public Sub
    AddChartSheet()
        Dim dataRange As
    Range
        Set dataRange =
    ActiveWindow.Selection
        Charts.Add   ‘Create a chart sheet
        With
    ActiveChart    ‘Set chart properties
            .ChartType =
    xlColumnClustered
            .HasLegend = True
            .Legend.Position =
    xlRight

            .Axes(xlCategory).MinorTickMark =
    xlOutside
            .Axes(xlValue).MinorTickMark =
    xlOutside
            .Axes(xlValue).MaximumScale = _
                        Application.WorksheetFunction.RoundUp( _
                        Application.WorksheetFunction.Max(dataRange),
    -1)
            .Axes(xlCategory).HasTitle = True
            .Axes(xlCategory).AxisTitle.Characters.Text = “X-axis
    Labels”
            .Axes(xlValue).HasTitle = True
            .Axes(xlValue).AxisTitle.Characters.Text = “Y-axis”

            .SeriesCollection(1).name
    = “Sample
    Data”
            .SeriesCollection(1).Values
    = dataRange
        End With
    End Sub

    1. 经过甄选的Cells Range的值设置Chart中数量标签的内容
      Sub
      DataLabelsFromRange()
          Dim DLRange As
      range
          Dim myChart As
      Chart
          Dim i As Integer
          
          Set myChart =
      ActiveSheet.ChartObjects(1).Chart
          On Error Resume Next
          Set DLRange =
      Application.InputBox _
            (prompt:=”Range
      for data labels?”, Type:=8)
          If DLRange Is Nothing Then Exit Sub
          On Error GoTo 0
          myChart.SeriesCollection(1).ApplyDataLabels Type:=xlDataLabelsShowValue, AutoText:=True,
      LegendKey:=False
          Pts = myChart.SeriesCollection(1).Points.Count
          For i = 1 To Pts
              myChart.SeriesCollection(1). _
                Points(i).DataLabel.Characters.Text =
      DLRange(i)
          Next i
      End Sub

    虚拟上面那个情形,当使用下表的数量生成图表Chart4时,私下认可的作用如下图。
    图片 1
    图片 2   
    能够手动给该图片增加Data Labels,方法是选中肆意的series,右键选取Add
    Data Labels。要是想要为富有的series增加Data
    Labels,则须求各种选拔不相同的series,然后再度该操作。
        Excel中可以因此VBA将内定Cells Range中的值设置到Chart的Data
    Labels中,上面包车型客车代码就是八个事例。程序实施的时候会首先弹出一个提示框,供给客商通过鼠标去挑选三个单元格区域以博取到Cells集合(恐怕直接输入地点),如下图:
    图片 3   
    注意VBA中输入型对话框Application.InputBox的行使。在循环上将Range中的值增加到Chart的Data
    Labels中。

    1. 一个采纳VBA给Chart增多Data Labels的例证
      Sub AddDataLabels()
          Dim seSales As Series
          Dim pts As Points
          Dim pt As Point
          Dim rngLabels As range
          Dim iPointIndex As Integer

        Set rngLabels = range(“B4:G4”)

        Set seSales = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
        seSales.HasDataLabels = True

        Set pts = seSales.Points

        For Each pt In pts
            iPointIndex = iPointIndex + 1
            pt.DataLabel.text = rngLabels.cells(iPointIndex).text
            pt.DataLabel.font.bold = True
            pt.DataLabel.Position = xlLabelPositionAbove
        Next pt
    End Sub

    End Sub

摘自 wl58796351的专栏

    3、数据库变化

Sub
AssignBevel()  
    Dim myChart As
Chart  
    Dim ser As
Series  
    Set myChart =
ActiveChart  
    Set ser =
myChart.SeriesCollection(1)  
    ser.Format.ThreeD.Visible = True  
    ser.Format.ThreeD.BevelTopType =
msoBevelCircle  
    ser.Format.ThreeD.BevelTopInset = 16  
    ser.Format.ThreeD.BevelTopDepth = 6  
End Sub

               cmd = Nothing

  • (Rand.NextDouble() * 2 – 1) 
        End If 
     
        If newVal < 0 Then 
            newVal = 0 
        End If 
     
        ‘ Add new data point to its series. 
        ptSeries.Points.AddXY(timeStamp.ToOADate, pValue) 
     
        ‘ remove all points from the source series older than 1.5
    minutes. 
        Dim removeBefore As Double = timeStamp.AddSeconds((CDbl(90) *
    -1)).ToOADate() 
        ‘remove oldest values to maintain a constant number of data
    points 
        While ptSeries.Points(0).XValue < removeBefore 
            ptSeries.Points.RemoveAt(0) 
        End While 
     
        Dim ptA As ChartArea 
        For Each ptA In Chart1.ChartAreas 
            ptA.AxisX.Minimum = ptSeries.Points(0).XValue 
            ptA.AxisX.Maximum =
    DateTime.FromOADate(ptSeries.Points(0).XValue).AddMinutes(2).ToOADate() 
        Next 
       
        Chart1.Invalidate() 
    End Sub 
     
    ‘ Clean up any resources being used. 
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 
        If (addDataRunner.ThreadState And ThreadState.Suspended) =
    ThreadState.Suspended Then 
            addDataRunner.Resume() 
        End If 
        addDataRunner.Abort() 
     
        If disposing Then 
            If Not (components Is Nothing) Then 
                components.Dispose() 
            End If 
        End If 
        MyBase.Dispose(disposing) 
    End Sub ‘Dispose 
     
     
     
    Private Sub startTrending_Click(sender As System.Object, e As
    System.EventArgs) Handles startTrending.Click 
        ‘ 最早开关状态 www.2cto.com  
        startTrending.Enabled = False 
        ‘ 停止开关状态 
        stopTrending.Enabled = True 
     
        ‘ Predefine the viewing area of the chart 
        minValue = DateTime.Now 
        ‘2分钟预览区域 
        maxValue = minValue.AddSeconds(120) 
     
        Chart1.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 
        Chart1.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate() 
     
        Chart1.ChartAreas(1).AxisX.Minimum = minValue.ToOADate() 
        Chart1.ChartAreas(1).AxisX.Maximum = maxValue.ToOADate() 
     
        ‘ Reset number of series in the chart. 
        Chart1.Series.Clear() 
     
        ‘ create a line chart series 
        Dim newSeries1 As New Series(“Series1”) 
        With newSeries1 
            .LegendText = “曲线一” 
            .ChartType = SeriesChartType.Line 
            .BorderWidth = 1 
            .Color = Color.Red 
            .XValueType = ChartValueType.Time 
        End With 
        newSeries1.ChartArea = “ChartArea1” 
     
        Dim newSeries2 As New Series(“Series2”) 
        With newSeries2 
            .LegendText = “曲线二” 
            .ChartType = SeriesChartType.Line 
            .BorderWidth = 1 
            .Color = Color.Blue 
            .XValueType = ChartValueType.Time 
        End With 
        newSeries2.ChartArea = “ChartArea2” 
     
        Chart1.Series.Add(newSeries1) 
        Chart1.Series.Add(newSeries2) 
     
        ‘ start worker threads. 
        If addDataRunner.IsAlive = True Then 
            addDataRunner.Resume() 
        Else 
            addDataRunner.Start() 
        End If 
    End Sub 
     
    Private Sub stopTrending_Click_1(sender As System.Object, e As
    System.EventArgs) Handles stopTrending.Click 
        If addDataRunner.IsAlive = True Then 
            addDataRunner.Resume() 
        End If 
     
        ‘ Enable all controls on the form 
        startTrending.Enabled = True 
        ‘ and only Disable the Stop button 
        stopTrending.Enabled = False 
    End Sub 

    B层:
[vb] 
Public Function DelUserManager(ByVal enUserInfo As
Entity.UserInfoEntity) As Boolean 
 
    Dim DelUser As New DAL.UserDataDAL 
    Return DelUser.DelUser(enUserInfo) 
 
End Function 

图片 4
再次来到目录

”’ </summary>

[vb]
Private AddDataRunner As Thread 
Private Rand As New Random() 
Public Delegate Sub AddDataDelegate()  ‘定义几个线程委托 
Public AddDataDel As AddDataDelegate 
Private minValue, maxValue As DateTime 
 
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs)
Handles MyBase.Load 
    ‘定义四个新的线程举办循环施行 
    Dim addDataThreadStart As New ThreadStart(AddressOf
AddDataThreadLoop) 
    ‘把线程交给公家线程来管理 
    AddDataRunner = New Thread(addDataThreadStart) 
    ‘委托交付管理 
    addDataDel = New AddDataDelegate(AddressOf AddData) 
 
End Sub 
 
”’ <summary> 
”’ 主线程每秒循环叁遍,并经过信托,将数据发给你 CHART 
”’ </summary> 
”’ <remarks></remarks> 
Private Sub AddDataThreadLoop() 
    While True 
        chart1.Invoke(addDataDel) 
 
        Thread.Sleep(1000) 
    End While 
End Sub ‘AddDataThreadLoop 
 
Public Sub AddData() 
    Dim timeStamp As DateTime = DateTime.Now 
 
    Dim ptA As ChartArea 
    For Each ptA In Chart1.ChartAreas 
        Dim ptSeries As Series 
        ‘对每series举行多少扫描 
        For Each ptSeries In Chart1.Series 
            Dim k As Single 
            k = Rand.Next(10, 50) 
            AddNewPoint(timeStamp, k, ptSeries) 
        Next ptSeries 
    Next 
End Sub ‘AddData 
 
 
”’ <summary> 
”’ x轴为时间,y轴为数量,并依据随意数据进行填写; 
”’ </summary> 
”’ <param name=”timeStamp”></param> 
”’ <param name=”ptSeries”></param> 
”’ <remarks></remarks> 
Public Sub AddNewPoint(timeStamp As DateTime, ByVal pValue As Single,
ptSeries As System.Windows.Forms.DataVisualization.Charting.Series) 
    Dim newVal As Double = 0 
 
    If ptSeries.Points.Count > 0 Then 
        newVal = ptSeries.Points((ptSeries.Points.Count – 1)).YValues(0)

    End Sub

图片 5
重临目录

        End Set

详尽的主次如下,中间笔者一度作了无尽证明,呵呵

        strSql = “Delete From T_User Where
[email protected]”                              
‘删除客商sql语句
        param = New SqlParameter() {New SqlParameter(“@ID”,
enUserInfo.UserID)}      ‘给参数ID传值
        bln = DBHelper.ExecuteUID(strSql, CommandType.Text,
param)                   ‘调用SqlHelper,执行sql语句
        Return bln

    1. 操作Chart对象。给多少个用VBA操作Excel
      Chart对象的例证,读者能够和睦去品尝一下。
      Public Sub
      ChartInterior()
          Dim myChart As
      Chart
          ‘Reference embedded chart
          Set
      myChart = ActiveSheet.ChartObjects(1).Chart
          With myChart   ‘Alter
      interior colors of chart components
             
      .ChartArea.Interior.Color = RGB(1,
      2, 3)
              .PlotArea.Interior.Color = RGB(11,
      12, 1)
              .Legend.Interior.Color = RGB(31,
      32, 33)
              If .HasTitle Then
                  .ChartTitle.Interior.Color = RGB(41,
      42, 43)
              End If
          End With
      End Sub

 

 图片 6

   

    1. 经过VBA增加图表的标题Sub
      chartTitle()
          Dim myChartObject As
      ChartObject
          Set myChartObject =
      ActiveSheet.ChartObjects.Add(Left:=200,
      Top:=200, _
              Width:=400,
      Height:=300)
          
          myChartObject.Chart.SetSourceData Source:= _
              ActiveWorkbook.Sheets(“Chart
      Data”).Range(“A1:E5”)
          
          myChartObject.SeriesCollection.Add Source:=ActiveSheet.Range(“C4:K4”),
      Rowcol:=xlRows
          myChartObject.SeriesCollection.NewSeries
          myChartObject.HasTitle = True
      End Sub

    假使要设置标题展现的岗位,能够在上述代码的末端加上:
    With myChartObject.ChartTitle
       .Top = 100
       .Left = 150
    End With
    一经要同一时间设置标题字体,能够在上述代码的末尾加上:
    myChartObject.ChartTitle.Font.Name = “Times”

    1. 经过VBA修改图表的题目Sub
      charTitleText()
          ActiveChart.ChartTitle.Text = “Industrial Disease in North
      Dakota”
      End Sub
    1. 多少个经过题目寻找图表的例证
      Function GetChartByCaption(ws As
      Worksheet, sCaption As String)
      As Chart
          Dim myChart As
      ChartObject
          Dim myChart As
      Chart
          Dim sTitle As String

        Set myChart = Nothing
        For Each
    myChart In ws.ChartObjects
            If myChart.Chart.HasTitle Then
                sTitle = myChart.Chart.ChartTitle.Caption
                If StrComp(sTitle, sCaption, vbTextCompare)
    = 0 Then
                    Set myChart =
    myChart.Chart
                    Exit For
                End If
            End If
        Next
        Set GetChartByCaption =
    myChart
        Set myChart = Nothing
        Set myChart = Nothing
    End Function
    Sub TestGetChartByCaption()
        Dim myChart As
    Chart
        Dim ws As
    Worksheet
        Set ws =
    ThisWorkbook.Worksheets(“Sheet1”)
        Set myChart =
    GetChartByCaption(ws, “I am the
    Chart Title”)

        If Not
    myChart Is Nothing Then
            Debug.Print “Found
    chart”
        Else
            Debug.Print “Sorry –
    chart not found”
        End If

        Set ws = Nothing
        Set myChart = Nothing
    End Sub

顾客查询时序图

   
达成的效率:能够去除一行只怕多行数据,并在剔除前提醒是不是明显进行删除!

Public Sub
SetXAxis()  
    Dim myAxis As Axis  
    Set myAxis =
ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory, xlPrimary)  
    With myAxis    'Set
properties of x-axis  
        .HasMajorGridlines
= True  
        .HasTitle = True  
        .AxisTitle.Text = "My
Axis"  
        .AxisTitle.Font.Color = RGB(1,
2, 3)  
        .CategoryNames =
Range("C2:C11")  
        .TickLabels.Font.Color = RGB(11,
12, 13)  
    End With  
End Sub


Public Sub
TestSeries()  
    Dim mySeries As
Series  
    Dim seriesCol As
SeriesCollection  
    Dim I As Integer  
    I = 1  
    Set seriesCol =
ActiveSheet.ChartObjects(1).Chart.SeriesCollection  
    For Each
mySeries In seriesCol  
        Set mySeries =
ActiveSheet.ChartObjects(1).Chart.SeriesCollection(I)  
        With mySeries  
            .MarkerBackgroundColor = RGB(1,
32, 43)  
            .MarkerForegroundColor = RGB(11,
32, 43)  
            .Border.Color = RGB(11,
12, 23)  
        End With  
        I = I + 1  
    Next  
End Sub


Public Sub
TestPoint()  
    Dim myPoint As
Point  
    Set myPoint =
ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Points(3)  
    With myPoint  
        .ApplyDataLabels xlDataLabelsShowValue  
        .MarkerBackgroundColor = RGB(1,
2, 3)  
        .MarkerForegroundColor = RGB(11,
22, 33)  
    End With  
End Sub


Sub
chartAxis()  
    Dim myChartObject As
ChartObject  
    Set myChartObject =
ActiveSheet.ChartObjects.Add(Left:=200,
Top:=200, \_  
        Width:=400,
Height:=300)  
      
    myChartObject.Chart.SetSourceData Source:= \_  
        ActiveWorkbook.Sheets("Chart
Data").Range("A1:E5")  
      
    myChartObject.SeriesCollection.Add Source:=ActiveSheet.Range("C4:K4"),
Rowcol:=xlRows  
    myChartObject.SeriesCollection.NewSeries  
    myChartObject.HasTitle = True  
      
    With myChartObject.Axes(Type:=xlCategory, AxisGroup:=xlPrimary)  
        .HasTitle = True  
        .AxisTitle.Text = "Years"  
        .AxisTitle.Font.Name = "Times
New Roman"  
        .AxisTitle.Font.Size = 12  
        .HasMajorGridlines = True  
        .HasMinorGridlines = False  
    End With  
End Sub


Sub
FormattingCharts()  
    Dim myChart As
Chart  
    Dim ws As
Worksheet  
    Dim ax As Axis  

    Set ws =
ThisWorkbook.Worksheets("Sheet1")  
    Set myChart =
GetChartByCaption(ws, "GDP")  

    If Not
myChart Is Nothing Then  
        Set ax =
myChart.Axes(xlCategory)  
        With ax  
            .AxisTitle.Font.Size = 12  
            .AxisTitle.Font.Color = vbRed  
        End With  
        Set ax =
myChart.Axes(xlValue)  
        With ax  
            .HasMinorGridlines = True  
            .MinorGridlines.Border.LineStyle =
xlDashDot  
        End With  
        With myChart.PlotArea  
            .Border.LineStyle =
xlDash  
            .Border.Color = vbRed  
            .Interior.Color =
vbWhite  
            .Width = myChart.PlotArea.Width + 10  
            .Height =
myChart.PlotArea.Height + 10  
        End With  
        myChart.ChartArea.Interior.Color =
vbWhite  
        myChart.Legend.Position =
xlLegendPositionBottom  
    End If  

    Set ax = Nothing  
    Set myChart = Nothing  
    Set ws = Nothing  
End Sub  
Function GetChartByCaption(ws As
Worksheet, sCaption As String)
As Chart  
    Dim myChart As
ChartObject  
    Dim myChart As
Chart  
    Dim sTitle As String  

    Set myChart = Nothing  
    For Each
myChart In ws.ChartObjects  
        If myChart.Chart.HasTitle Then  
            sTitle = myChart.Chart.ChartTitle.Caption  
            If StrComp(sTitle, sCaption, vbTextCompare)
= 0 Then  
                Set myChart =
myChart.Chart  
                Exit For  
            End If  
        End If  
    Next  
    Set GetChartByCaption =
myChart  
    Set myChart = Nothing  
    Set myChart = Nothing  
End Function

地方是在数据库表中插入一条记下,其余的删除和改换,查询类似,就是DAL和BLL层重返值或许两样。

    End Sub   

图片 7
重返目录

           userPwd = value

        Dim DelUser As New DAL.UserDataDAL
        Return DelUser.DelUser(enUserInfo)

 Chart Format

        Dim cmd As SqlCommand = NewSqlCommand(sql, conn)

                ‘从数据库施行删除操作
                If DelUserUI.DelUserManager(enUserInfo) Then
                    Msg博克斯(“删除成功!”, vbOKOnly + vbInformation,
“系统提醒”)
                Else
                    Message博克斯.Show(“删除失利!”, “系统提醒”,
MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    Return
                End If
                ‘将从数据库中删除的信息从Datagridview第11中学剔除
               
Me.DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(i –
1).Index)
            Next
        Else
            DataGridView1.Rows.Clear()
        End If

 Chart Protect

    ”’ <summary>

   图片 8

图片 9
再次来到目录

 

    2、选择“是”

图片 10 Chart
Export
图片 11 Chart
Format
图片 12 Chart
Lengend
图片 13 Chart
Protect
图片 14 Chart
Title
图片 15
Chart

        Catch ex As Exception

        Dim strSql As String
        Dim DBHelper As New SqlHelper
        Dim param As SqlParameter()
        Dim bln As Boolean

图片 16
再次来到目录

               cmd.Dispose()

   
图片 17

    1. 将Excel中的图表导出成gif格式的图纸保存到硬盘上
      Sub
      ExportChart()
          Dim myChart As
      Chart
          Set myChart =
      ActiveChart
          myChart.Export Filename:=”C:\Chart.gif”,
      Filtername:=”GIF”
      End Sub

    反驳上海图书馆片能够被保留成任何类型的图片文件,读者能够自身去尝尝。

    1. 将Excel中的图表导出成可互相的页面保存到硬盘上
      Sub
      SaveChartWeb()
          ActiveWorkbook.PublishObjects.Add _
              SourceType:=xlSourceChart, _
              Filename:=ActiveWorkbook.Path & “\Sample2.htm”, _
              Sheet:=ActiveSheet.name, _
              Source:=” Chart
      1″, _
              HtmlType:=xlHtmlChart

        ActiveWorkbook.PublishObjects(1).Publish (True)
    End Sub

           Return cmd.ExecuteNonQuery() > 0

    
大家常见会遇见删除dataGridview中当选的一和或都多行数据,在网络查了大多方法,有个别只可以删除dataGridview中的数据,而无法去除数据库中的源数据,也许稍微只好删除选中的一行,而无法何况删除多行,经过一番尝试,终于消除了这几个题材:

    1. 使用VBA在Excel中加多图表
      Public Sub
      AddChartSheet()
        Dim aChart As
      Chart

      Set aChart =
    Charts.Add
      With aChart
        .Name = “Mangoes”
        .ChartType = xlColumnClustered
        .SetSourceData Source:=Sheets(“Sheet1”).Range(“A3:D7”),
    PlotBy:=xlRows
        .HasTitle = True
        .ChartTitle.Text = “=Sheet1!R3C1”
      End With
    End Sub

    1. 遍历并更换Chart对象中的图表类型
      Sub
      ChartType()
          Dim myChart As
      ChartObject
          For Each
      myChart In ActiveSheet.ChartObjects
              myChart.Chart.Type =
      xlArea
          Next myChart
      End Sub
    1. 遍历并更动Chart对象中的Legend
      Sub
      LegendMod()
          Dim myChart As
      ChartObject
          For Each
      myChart In ActiveSheet.ChartObjects
              With myChart.Chart.Legend.font
                  .name = “Calibri”
                  .FontStyle = “Bold”
                  .Size = 12
              End With
          Next myChart
      End Sub
    1. 一个格式化Chart的例子
      Sub
      ChartMods()
          ActiveChart.Type =
      xlArea
          ActiveChart.ChartArea.font.name = “Calibri”
          ActiveChart.ChartArea.font.FontStyle = “Regular”
          ActiveChart.ChartArea.font.Size = 9
          ActiveChart.PlotArea.Interior.ColorIndex =
      xlNone
          ActiveChart.Axes(xlValue).TickLabels.font.bold = True
          ActiveChart.Axes(xlCategory).TickLabels.font.bold = True
          ActiveChart.Legend.Position =
      xlBottom
      End Sub
    1. 通过VBA更改Chart的Title
      Sub
      ApplyTexture()
          Dim myChart As
      Chart
          Dim ser As
      Series
          Set myChart =
      ActiveChart
          Set ser =
      myChart.SeriesCollection(2)
          ser.Format.Fill.PresetTextured (msoTextureGreenMarble)
      End Sub
    1. 在VBA中应用自定义图片填充Chart对象的series区域
      Sub
      FormatWithPicture()
          Dim myChart As
      Chart
          Dim ser As
      Series
          Set myChart =
      ActiveChart
          Set ser =
      myChart.SeriesCollection(1)
          MyPic = “C:\Title.jpg”
          ser.Format.Fill.UserPicture (MyPic)
      End Sub

    Excel中的Chart允许客户对中间选定的区域自定义样式,个中包蕴动用图片选中样式。在Excel的Layout菜单下有二个Format
    Selection,首先在Chart对象中选定要格式化的区域,比如series,然后选用该菜单,在弹出的对话框中就能够对所选的区域实行格式化。如series选项、填充样式、边框颜色和体制、阴影以及3D效果等。上边再付许多个在VBA中使用渐变色填充Chart对象的series区域的例证。
    Sub
    TwoColorGradient()
        Dim myChart As
    Chart
        Dim ser As
    Series
        Set myChart =
    ActiveChart
        Set ser =
    myChart.SeriesCollection(1)
        MyPic = “C:\Title1.jpg”
        ser.Format.Fill.TwoColorGradient msoGradientFromCorner,
    3
        ser.Format.Fill.ForeColor.ObjectThemeColor =
    msoThemeColorAccent6
        ser.Format.Fill.BackColor.ObjectThemeColor =
    msoThemeColorAccent2
    End Sub

    1. 通过VBA格式化Chart对象中series的趋向线样式
      Sub
      FormatLineOrBorders()
          Dim myChart As
      Chart
          Set myChart =
      ActiveChart
          With myChart.SeriesCollection(1).Trendlines(1).Format.Line
              .DashStyle = msoLineLongDashDotDot
              .ForeColor.RGB = RGB(50,
      0, 128)
              .BeginArrowheadLength =
      msoArrowheadShort
              .BeginArrowheadStyle =
      msoArrowheadOval
              .BeginArrowheadWidth =
      msoArrowheadNarrow
              .EndArrowheadLength =
      msoArrowheadLong
              .EndArrowheadStyle =
      msoArrowheadTriangle
              .EndArrowheadWidth =
      msoArrowheadWide
          End With
      End Sub

    Excel允许顾客为Chart对象的series增添趋势线(trendline),首先在Chart中选中要安装的series,然后选择Layout菜单下的trendline,采取一种trendline样式。

    1. 一组选拔VBA格式化Chart对象的例证
      Sub
      FormatBorder()
          Dim myChart As
      Chart
          Set myChart =
      ActiveChart
          With myChart.ChartArea.Format.Line
              .DashStyle = msoLineLongDashDotDot
              .ForeColor.RGB = RGB(50,
      0, 128)
          End With
      End Sub

               conn = Nothing

 ”’ <summary>
    ”’ 自定义的删除Datagridview记录的不二秘技
    ”’ </summary>
    ”’ <remarks></remarks>
    Public Sub Del()

 Chart

图片 18

    ”’ <summary>
    ”’ 删除客户音讯
    ”’ </summary>
    ”’ <param name=”enUserInfo”>客户新闻实体</param>
    ”’ <returns>布尔值类型</returns>
    ”’ <remarks></remarks>
    Public Function DelUser(ByVal enUserInfo As Entity.UserInfoEntity)
As Boolean

Chart Export

ImportsSystem.Data.SqlClient

  • vbExclamation, “系统提示”)
                        Exit Sub
                    Else
                       
    ‘将usercode传值给enUserInfo实体的UserID属性(即依据客商名删除)
                        enUserInfo.UserID = usercode
                    End If

 Chart Title

        sqlParam.Value = EntityUserInfo.UserID

   

    1. 安装Lengend的职位和ChartArea的颜色
      Sub
      FormattingCharts()
          Dim myChart As
      Chart
          Dim ws As
      Worksheet
          Dim ax As Axis

        Set ws =
    ThisWorkbook.Worksheets(“Sheet1”)
        Set myChart =
    GetChartByCaption(ws, “GDP”)

        If Not
    myChart Is Nothing Then
            myChart.ChartArea.Interior.Color =
    vbWhite
            myChart.Legend.Position =
    xlLegendPositionBottom
        End If

        Set ax = Nothing
        Set myChart = Nothing
        Set ws = Nothing
    End Sub
    Function GetChartByCaption(ws As
    Worksheet, sCaption As String)
    As Chart
        Dim myChart As
    ChartObject
        Dim myChart As
    Chart
        Dim sTitle As String

        Set myChart = Nothing
        For Each
    myChart In ws.ChartObjects
            If myChart.Chart.HasTitle Then
                sTitle = myChart.Chart.ChartTitle.Caption
                If StrComp(sTitle, sCaption, vbTextCompare)
    = 0 Then
                    Set myChart =
    myChart.Chart
                    Exit For
                End If
            End If
        Next
        Set GetChartByCaption =
    myChart
        Set myChart = Nothing
        Set myChart = Nothing
    End Function

    1. 通过VBA给Chart添加Lengend
      Sub
      legend()
          Dim myChartObject As
      ChartObject
          Set myChartObject =
      ActiveSheet.ChartObjects.Add(Left:=200,
      Top:=200, _
              Width:=400,
      Height:=300)
          
          myChartObject.Chart.SetSourceData Source:= _
              ActiveWorkbook.Sheets(“Chart
      Data”).Range(“A1:E5”)
          
          myChartObject.SeriesCollection.Add Source:=ActiveSheet.Range(“C4:K4”),
      Rowcol:=xlRows
          myChartObject.SeriesCollection.NewSeries
          With myChartObject.Legend
              .HasLegend = True
              .Font.Size = 16
              .Font.Name = “Arial”
          End With
      End Sub

    Public Property UserActor() As String

                ‘获取第N行的首先列的多少
                Dim usercode As String = DataGridView1.SelectedRows(i –
1).Cells(“用户名”).Value.ToString()

    1. 在VBA中对Chart对象应用3D效果
      Sub
      Assign3DPreset()
          Dim myChart As
      Chart
          Dim shp As
      Shape
          Set myChart =
      ActiveChart
          Set shp =
      myChart.Shapes(1)
          shp.ThreeD.SetPresetCamera msoCameraIsometricLeftDown
      End Sub

        Dim cmd As SqlCommand = NewSqlCommand(sql, conn)

    Private Sub btnDelUser_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnDelUser.Click

    1. 保卫安全图表
      Sub
      ProtectChart()
          Dim myChart As
      Chart
          Set myChart =
      ThisWorkbook.Sheets(“Protected Chart”)
          myChart.Protect “123456”,
      True, True, ,
      True
          myChart.ProtectData = False
          myChart.ProtectGoalSeek = True
          myChart.ProtectSelection = True
      End Sub

    Excel中的Chart能够和Sheet同样被保卫安全,读者能够选中图表所在的Tab,然后经过Review菜单下的Protect
    Sheet菜单来对图片举办保险装置。代码中的Protected
    Chart123456是安装保险时的密码,有关Protect函数的参数和安装保险时的另外性质读者能够查阅Excel自带的帮扶文书档案。

    1. 撤消图表珍重Sub
      UnprotectChart()
          Dim myChart As
      Chart
          Set myChart =
      ThisWorkbook.Sheets(“Protected Chart”)
          myChart.Unprotect “123456”
          myChart.ProtectData = False
          myChart.ProtectGoalSeek = False
          myChart.ProtectSelection = False
      End Sub

    与敬爱图表的身体力行相对应,能够经过VBA打消对图片的珍重装置。 

           Return userRegDate

        Dim k As Integer = Me.DataGridView1.SelectedRows.Count
        Dim enUserInfo As New Entity.UserInfoEntity
        Dim DelUserUI As New BLL.AddDelUserBLL

目录

    Public Function BLLUserAdd(ByValEntityUserInfo As Entity.UserInfo)
As Boolean

图片 19
再次来到目录

 

            ‘从下往上删,防止停车放大计时器效应
            For i As Integer = k To 1 Step -1

Public Class BLLUser

    End Function  

           Return userID

    Public Function DelUserManager(ByVal enUserInfo As
Entity.UserInfoEntity) As Boolean

               MsgBox(“输入的挂号日期请为日期XXXX-XX-XX格式!”)

    D层:肩负更新数据库
[vb] 
”’ <summary>  
”’ 删除客户消息  
”’ </summary>  
”’ <param name=”enUserInfo”>顾客音讯实体</param>  
”’ <returns>布尔值类型</returns>  
”’ <remarks></remarks>  
Public Function DelUser(ByVal enUserInfo As Entity.UserInfoEntity) As
Boolean 
 
    Dim strSql As String 
    Dim DBHelper As New SqlHelper 
    Dim param As SqlParameter() 
    Dim bln As Boolean 
 
    strSql = “Delete From T_User Where
[email protected]”                              
‘删除顾客sql语句  
    param = New SqlParameter() {New SqlParameter(“@ID”,
enUserInfo.UserID)}      ‘给参数ID传值  
    bln = DBHelper.ExecuteUID(strSql, CommandType.Text,
param)                   ‘调用SqlHelper,执行sql语句  
    Return bln 
 
End Function 

    End Function

   

           End If

   图片 20

    ”'<returns>全体顾客的DataSet集合</returns>

        ‘Datagridview中是还是不是存在数量
        If DataGridView1.Rows.Count > 0 Then

    End Property

 

 

   图片 21

    End Function

    效果如下:

        Else

            If
MessageBox.Show(“明确要删减选中的客户吗?删除后将不得恢复!”, “提醒”,
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes
Then
                Del()
            End If
        Else
            Message博克斯.Show(“请采用要去除的客商!”, “提醒”,
MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If

 

    1、选中两行,点击删除按键

界面层。

    实今世码如下:

    ”’ <remarks></remarks>

    End Function

           conn = Nothing

[vb] 
Private Sub btnDelUser_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelUser.Click 
 
    ‘选中记录则提示审慎删除,未有当选数据则提示选取。  
    If Me.DataGridView1.SelectedRows.Count > 0 Then 
 
        If Message博克斯.Show(“明确要去除选中的客商吗?删除后将不得复苏!”,
“提醒”, Message博克斯Buttons.YesNo, MessageBoxIcon.Question) =
DialogResult.Yes Then 
            Del() 
        End If 
    Else 
        MessageBox.Show(“请选拔要去除的客商!”, “提醒”,
Message博克斯Buttons.OK, MessageBoxIcon.Warning) 
        Return 
    End If 
 
End Sub 

 

    ”’ 顾客注册,并对客商的输入加以判断。

        sqlParam.Value =EntityUserInfo.UserRegDate

Imports DAL

               cmd = Nothing

    ‘数据库连接字符串

        sqlParam.Value =EntityUserInfo.UserFlag

               EntityUserInfo.UserID =txtUserID.Text

”’ <summary>

    ”’ <returns>一个顾客的对象</returns>

      

        End Try

        Try

           Return DALEntityUserinfo

               DALEntityUserinfo.UserName =sdr.GetString(0)

    ‘顾客合法标致

 

        End Set

           userActor = value

代码:

    ”’ <remarks></remarks>

        If Not IsNothing(conn) Then

        Dim DALEntityUserinfo As NewEntity.UserInfo

        Dim sqlParam As New SqlParameter

    ”’ <remarks></remarks>

               EntityUserInfo.UserRegDate =txtUserRegDate.Text

    Private userID As Integer

 

        Dim sqlParam As NewSqlParameter(“@UserID”, SqlDbType.Int)

           End If

    End Property

        sqlParam.Value =EntityUserInfo.UserName

        Dim ds As New DataSet

        End Set

    Private Sub RegisterBut_Click(ByVal senderAs System.Object, ByVal e
As System.EventArgs) Handles RegisterBut.Click

‘DAL包中的DALuser类。

    Private userPwd As String

        End If

               Dim EntityUserInfo As NewEntity.UserInfo

Public Class DALUser

 

           End If

    ”’ </summary>

客商修改时序图

    Public Property UserFlag

发表评论

电子邮件地址不会被公开。 必填项已用*标注