首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MonthCalendar事件

MonthCalendar事件
EN

Stack Overflow用户
提问于 2017-02-02 10:36:27
回答 1查看 96关注 0票数 0

我有一个项目用于为特定的dates.My项目保存病人约会,该项目拥有一个与sqlserver database.The网格链接的数据视图,其中包含一个名为"Time".I的列,该列在sqlserver.When中为该列分配了“时间”.I赋值。我输入了datagridview包含10行空行的表单,以便用户可以以特定的times.The形式保存患者,其中还包含一个monthcalendar.What,它将显示每个月日历日期的空行,并将约会保存在不同的日期。

我在下面看到了这个,但是他使用了dataset,我和实体模型一起工作,我不知道如何实现它,请帮助我。

代码语言:javascript
复制
Public Function connect()

    Dim sql As String = "Data Source=RINOR-PC\SQLEXPRESS;Initial Catalog=Ordinanca;Integrated Security=True"
    Return New Sqlconnection(sql)
End Function

Public Function search(pmtData As Date) As DataTable

    Using con As SqlConnection = connect()

        Dim dt As Datatable = New Datatable()
        Try

            Dim query As String = "SELECT * FROM CLIENTS WHERE DT='" + pmtData + "'"
            Dim cmd As SqlCommand = New sqlCommand(query, con)
            Dim da As SqldataAdapter = New sqlDataadapter(cmd)
            da.Fill(dt)

        Catch ex As Exception

            Messagebox.show(ex.Message)
        Finally
            con.close()
        End Try

        Return dt

    End Using
End Function

Private Sub monthcalendar1_datechanged(sender As Object, e As DateRangeEventArgs) Handles monthcalendar1.datechanged

    Dim datatable As datatable
    Dim pmtdata As Date
    pmtdata = monthcalendar1.selectionstart
    datatable = search(pmtdata)
    gridview.datasource = datatable

End Sub

我的代码:

代码语言:javascript
复制
Public Class Form1
  Dim db As New OrdinancaEntities
  Dim pacienti As New Pacientet
  Dim isEditing As Boolean = True
  Dim selectedPacient As Int16

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    BindingDatagridView()
    FillData("")
  End Sub

  Sub BindingDatagridView()
    dgvPacientet.DataSource = db.Pacientets.ToList()
  End Sub

  Sub FillData(searchText As String)
    Dim data As List(Of Pacientet)
    Dim context As New OrdinancaEntities
    If searchText = "" Then
        data = context.Pacientets.OrderBy(Function(t) t.Id).ToList()
    Else
        data = context.Pacientets.Where(Function(t) t.Emri.StartsWith(searchText) Or t.Mbiemri.StartsWith(searchText)).OrderBy(Function(t) t.Id).ToList()
    End If
    dgvPacientet.AutoGenerateColumns = False
    dgvPacientet.DataSource = data
    SelectClient()
  End Sub

  Sub EnableButton(bPërditëso As Boolean)
    btnPërditëso.Enabled = bPërditëso
  End Sub

  Sub SelectClient()
    If dgvPacientet.SelectedRows.Count > 0 Then
        selectedPacient = CInt(dgvPacientet.SelectedRows.Item(0).Cells("Id").Value.ToString())

        txtEmri.Text = dgvPacientet.SelectedRows.Item(0).Cells("Emri").Value.ToString()
        txtMbiemri.Text = dgvPacientet.SelectedRows.Item(0).Cells("Mbiemri").Value.ToString()

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Emri_prindit").Value) Then
            txtEmri_prindit.Text = dgvPacientet.SelectedRows.Item(0).Cells("Emri_prindit").Value.ToString()
        Else
            txtEmri_prindit.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Datelindja").Value) Then
            txtDatelindja.Text = dgvPacientet.SelectedRows.Item(0).Cells("Datelindja").Value.ToString()
        Else
            txtDatelindja.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Numri_telefonit").Value) Then
            txtNumri.Text = dgvPacientet.SelectedRows.Item(0).Cells("Numri_telefonit").Value.ToString()
        Else
            txtNumri.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Diagnoza").Value) Then
            txtDiagnoza.Text = dgvPacientet.SelectedRows.Item(0).Cells("Diagnoza").Value.ToString()
        Else
            txtDiagnoza.Text = ""
        End If
        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Tretmani_planifikuar").Value) Then
            txtTretmani_planifikuar.Text = dgvPacientet.SelectedRows.Item(0).Cells("Tretmani_planifikuar").Value.ToString()
        Else
            txtTretmani_planifikuar.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Tretmani_kryer").Value) Then
            txtTretmani_kryer.Text = dgvPacientet.SelectedRows.Item(0).Cells("Tretmani_kryer").Value.ToString()
        Else
            txtTretmani_kryer.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Pagesa").Value) Then
            txtPagesa.Text = dgvPacientet.SelectedRows.Item(0).Cells("Pagesa").Value.ToString()
        Else
            txtPagesa.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Pagoi").Value) Then
            txtPagoi.Text = dgvPacientet.SelectedRows.Item(0).Cells("Pagoi").Value.ToString()
        Else
            txtPagoi.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Doktori").Value) Then
            cboDoktori.Text = dgvPacientet.SelectedRows.Item(0).Cells("Doktori").Value.ToString()
        Else
            cboDoktori.Text = ""
        End If

        If Not IsNothing(dgvPacientet.SelectedRows.Item(0).Cells("Dt_terminit").Value) Then
            Me.MonthCalendar1.SelectionStart = dgvPacientet.SelectedRows.Item(0).Cells("Dt_terminit").Value.ToString()
        Else
            Me.MonthCalendar1.SelectionStart = Date.Now
        End If
    End If
  End Sub

  Private Sub btnPërditëso_Click(sender As Object, e As EventArgs) Handles btnPërditëso.Click

    If isEditing Then
        Dim context As New OrdinancaEntities
        Dim client As Pacientet = (From c In context.Pacientets
                               Where c.Id = selectedPacient
                                  Select c).FirstOrDefault()
        client.Emri = txtEmri.Text
        client.Mbiemri = txtMbiemri.Text
        client.Emri_prindit = txtEmri_prindit.Text
        client.Datelindja = txtDatelindja.Text
        client.Numri_telefonit = txtNumri.Text
        client.Diagnoza = txtDiagnoza.Text
        client.Tretmani_planifikuar = txtTretmani_planifikuar.Text
        client.Tretmani_kryer = txtTretmani_kryer.Text
        client.Pagesa = txtPagesa.Text
        client.Pagoi = txtPagoi.Text
        client.Doktori = cboDoktori.SelectedItem
        client.Dt_terminit = Me.MonthCalendar1.SelectionStart
        context.SaveChanges()
        BindingDatagridView()
    End If
    isEditing = True
    FillData("")
    MessageBox.Show("Të dhënat u insertuan me sukses.")
  End Sub

  Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
    ClearText()
  End Sub

  Sub ClearText()
    txtEmri.Clear()
    txtMbiemri.Clear()
    txtNumri.Clear()
    txtDiagnoza.Clear()
    txtPagesa.Clear()
    txtPagoi.Clear()
    cboDoktori.Text = "Zgjedh doktorin"
    txtEmri.Focus()
    txtTretmani_planifikuar.Clear()
    txtTretmani_kryer.Clear()
    txtDatelindja.Clear()
    txtEmri_prindit.Clear()
  End Sub

  Private Sub txtKerko_TextChanged(sender As Object, e As EventArgs) Handles txtKerko.TextChanged
    FillData(txtKerko.Text)
  End Sub

  Private Sub dgvPacientet_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPacientet.RowEnter
    SelectClient()
  End Sub
End Class
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-03 09:43:14

我觉得这和你想要的差不多。它简单地将"search“函数中与DataTable相关的所有功能替换为对实体框架类的简单调用:

代码语言:javascript
复制
Private Sub monthcalendar1_datechanged(sender As Object, e As DateRangeEventArgs) Handles monthcalendar1.datechanged
  Dim pmtdata As Date
  pmtdata = monthcalendar1.selectionstart
  Dim records = db.Pacientets.Where(Function(p)  p.dt_terminit.Equals(pmtdata)).ToList()

  'add extra rows if not all rows populated
  If (records.Count() < 10) Then
    Dim timeSlots = db.TimeSlots 'get the list of all possible appointment times in one day, this is a new table you must create and populate in advance

    For Each(slot in timeSlots)
      'here, check that the slots's time is not in any of the items in the "records" list
      'if it's not, add it to the Pacientes table with only time and date completed.
    Next

    'requery the DB
    records = db.Pacientets.Where(Function(p)  p.dt_terminit.Equals(pmtdata)).ToList()
  End If

  gridview.datasource = records
End Sub

显然,您必须将任何变量或字段名(如月历或网格视图)更改为所使用的任何内容。我也使用了Time.Date,因为您的时间列将包含特定的时间,而月份日历则包含没有时间的日期。

另外,我不知道"Pacientets“是否是这里要查询的正确实体。我不会说你的语言,但听起来像一张病人名单。如果你在给时间,大概你有另一个实体,它描述了一个与特定时间有关的预约列表,以及一个特定的病人?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41999936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档