从DataGrid添加或删除项目 - vb.net紧凑框架

时间:2014-01-31 10:50:45

标签: vb.net datagrid windows-mobile compact-framework handheld

我正在开发一个项目,允许用户在掌上电脑的餐厅订购,这是Windows移动设备。我使用datagrid显示现有订单,并希望通过单击按钮添加项目,或通过从datagrid中选择以更改订单来删除项目。那么,请你们帮助我找出处理现有数据库项目的最佳方法。提前谢谢。

到目前为止我的代码是,

从数据库获取现有订单

Public Shared Function MenuItems(ByVal groupNo As Integer) As List(Of Menus)
    Dim cmd As New SqlCommand("", Ayar.baglanti)
    Dim menuItem As New List(Of Menus)

    Try
        cmd.CommandText = "SELECT ToppingAutoID, BasePrice, ToppingName, PrinterName, Special, Normal, Irregular," & _
            " NavigationID, ModifiersCharge, taxRate, JustNavigate, Terminator, ItemQuantity, ExtraCharge, TripleCharge, " & _
            " HalfCharge, OneThirdCharge, OneForthCharge, NoDiscountItem FROM MenuToppings WHERE GroupID = @groupID"
        cmd.Parameters.AddWithValue("@groupID", groupNo)
        Dim data As New DataSet
        data.Load(cmd.ExecuteReader, LoadOption.OverwriteChanges, "menuitem")
        Dim dt As DataTable = data.Tables("menuitem")
        ''
        For Each r As DataRow In dt.Rows
            Dim item As New Menus
            item.Toppingautoid = r("ToppingAutoID")
            item.Baseprice = r("BasePrice")
            item.Toppingname = r("ToppingName")
            item.Itemquantity = r("ItemQuantity")
            menuItem.Add(item)
        Next
    Catch ex As Exception
        log.log("MenuItem()fonksiyonunda hata oluştu.", ex.Message)
    End Try
    MenuItems = menuItem
End Function

列出datagrid上的现有订单

  Public Function siparisGoster()        
    Dim isModifed As Boolean = False

    Dim skl As New DataGridTableStyle
    Dim kolon1, kolon2, kolon3 As New DataGridTextBoxColumn
    kolon1.MappingName = "Itemno"
    kolon1.HeaderText = "MADAKAFA"
    kolon1.Width = -1

    kolon2.MappingName = "Itemdesc"
    kolon2.Width = 300

    kolon3.MappingName = "Itemamount"
    kolon3.Width = 10

    skl.GridColumnStyles.Add(kolon1)
    skl.GridColumnStyles.Add(kolon2)
    skl.GridColumnStyles.Add(kolon3)

    If isModifed = False Then
        Dim ord As Order = Order.GetTableOrder(tableNo)

        Dim bs As New BindingSource
        bs.DataSource = ord.GetOrderItems
        skl.MappingName = bs.GetListName(Nothing)
        DataGridItems.BackColor = Color.White
        DataGridItems.ColumnHeadersVisible = False
        DataGridItems.RowHeadersVisible = False

        DataGridItems.TableStyles.Clear()
        DataGridItems.TableStyles.Add(skl)
        DataGridItems.DataSource = bs

    End If

End Function

1 个答案:

答案 0 :(得分:0)

Paul Yao在他的“Compact the Compact Programming”(VB.NET和C#版本可用)一书中描述了一种手动和自动的就地编辑。您可以在http://www.paulyao.com/cfbook/code注册以获取第8章的代码。

摘录:

    Private Sub cmdEdit_Click(ByVal sender As System.Object, _
                             ByVal e As System.EventArgs _
                             ) _
                             Handles cmdEdit.Click
      With dgrdProjects.CurrentCell
         '  Check the DataSource's column's name
         '     If it is "ctTasks", do not update.
         If dgrdProjects.TableStyles("Projects"). _
                           GridColumnStyles(.ColumnNumber). _
                              MappingName = "ctTasks" Then
            MessageBox.Show( _
               "Count of tasks only changes as the " & _
               "result of adding / removing a task.")
            Exit Sub
         End If
         '  Position textEdit for in-place editing.
         textEdit.Bounds = dgrdProjects.GetCellBounds _
                                 (.RowNumber, .ColumnNumber)
         '  Load the CurrentCell's value into textEdit.
         textEdit.Text = dgrdProjects.Item _
                                 (.RowNumber, .ColumnNumber)
         '  Highlight the text.
         textEdit.SelectAll()
         '  Show textEdit and set the focus to it.
         textEdit.Visible = True
         textEdit.Focus()
      End With
      '  Set Form GUI state to "Editing".
      Me.SetEditingState(True)
   End Sub
   ...
   Private Sub cmdUpdate_Click(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs _
                               ) _
                               Handles cmdUpdate.Click
      '  Move the contents of textEdit
      '     into the CurrentCell
      With dgrdProjects
         .Item(.CurrentCell.RowNumber, _
               .CurrentCell.ColumnNumber) = textEdit.Text
      End With
      '  Set Form GUI state to "Not Editing".
      Me.SetEditingState(False)
    End Sub

这本书非常值得购买。这是我最喜欢的CF首发之一。