Using IF statement in vb with database material - sql

So I'm trying to use an If statement based on criteria in my database and I'm not sure how I'm new to vb. The viewaccess, editaccess, and approveaccess are bits in my database.
If (Session("ViewAccess") = 1) And Session("EditAccess") = 0 And (Session("ApproveAccess") = 0) Then
btnSaveTop.Visible = False
btnSaveBottom.Visible = False
btnApproveTop.Visible = False
btnApproveBottom.Visible = False
btnRequestUnapproveTop.Visible = False
btnRequestUnapproveBottom.Visible = False
RequiredData.FreightWBS.ReadOnly = True
RequiredData.GemFeeWBS.ReadOnly = True
RequiredData.Approver.ReadOnly = True
End If

When you get values from the database they are not anymore 1 or 0 (bit type). They are true or false (boolean), change that. No idea how you're filling session but it looks like an SqlDataReader if that's your case, doing that will fix your problem. (Be more explicit)

Related

How can I remove the cell selection from a checkbox column ? VB.NET

Greetings to the community.
I am trying to modify a checkbox column of a DataGridView in VB.NET. I hope you can help me.
I am looking to go from this:
To this:
That is, even if I click or double click on the cell, the checkbox is not selected.
Part of the code where the columns are added to DataGridView (DvgNeumaticos):
If BtnVistaPorFacturar.Checked Then
For i As Integer = 0 To DgvNeumaticos.Columns.Count - 1
DgvNeumaticos.Columns(i).Visible = False
Next
DgvNeumaticos.Columns("ColChk").Visible = True
DgvNeumaticos.Columns("CodOS").Visible = True
DgvNeumaticos.Columns("Tipo").Visible = True
DgvNeumaticos.Columns("NroOrden").Visible = True
DgvNeumaticos.Columns("NroOrden").DisplayIndex = 0
DgvNeumaticos.Columns("FechaOS").Visible = True
DgvNeumaticos.Columns("F.Cierre").Visible = True
DgvNeumaticos.Columns("Observacion").Visible = True
DgvNeumaticos.Columns("CodNeumatico").Visible = True
DgvNeumaticos.Columns("Externo").Visible = True
DgvNeumaticos.Columns("CodTercero").Visible = True
DgvNeumaticos.Columns("CodProducto").Visible = True
DgvNeumaticos.Columns("Producto").Visible = True
DgvNeumaticos.Columns("Trabajo").Visible = True
DgvNeumaticos.Columns("NroDocRecepcion").Visible = True
DgvNeumaticos.Columns("FechaRecepcion").Visible = True
New Edit:
If BtnVistaPorFacturar.Checked Then
Dim chkCol As New DataGridViewCheckBoxColumn
chkCol.Name = "ColChk"
chkCol.HeaderText = "Chk"
DgvNeumaticos.Columns.Add(chkCol)
dt = WFOrdServicioNeumaticos.Instancia.fdu_NEUM_ORDSERV_VerOrdenesPorFacturar(.Cells("IDAgente").Value)
End If
Thanks for the replies.

How to return data from database

I have the next code for return a value from database
If Not IsDBNull(rsObtenerDatosNit("porteria").Value) AndAlso CBool(rsObtenerDatosNit("porteria").Value) = False Then
porteria = False
nPorteria.Checked = False
Else
porteria = True
nPorteria.Checked = True
End If
The field "porteria" in database it is bit and is with a value of 0 but does not enter to the first condition Where a checkbox with a false value is assigned if not that is entering the Else condition.
If Not IsDBNull(rsObtenerDatosNit("porteria")) Then
If CBool(rsObtenerDatosNit("porteria").Value) = False Then
porteria = False
nPorteria.Checked = False
Else
porteria = True
nPorteria.Checked = True
End If
End If
You could even add an Else statement to the first If logic, where you show an error stating the field does not exist. But you need to be doing the IsDbNull check on the field itself, not the value of the field.

displayindex datatable/dgv columns not working

I set up some datatables via the Visual Studio table/columns collection editor. Sadly, it appears MS didn't include any way to re-order the data columns in the collection editor once you've done (no up/down facility). Thus, I'm having to programmatically re-order my columns (as out of order in the collection).
Done a lot of reading on this and for the life of me, can't locate the source of the problem. Basically, despite the code below, the datacolumns still show out-of-order on the datagridview. Code (abridged):
Private Sub LoadTextStylesDGV()
With _TextStylesDGV
.DefaultCellStyle.Padding = New Padding(0, 5, 0, 5)
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToResizeColumns = True
.Columns.Add(New DataGridViewComboBoxColumn With {.DataPropertyName = "TextAlign", .Visible = True,
.Name = "TextAlign",
.HeaderText = "TextAlign",
.DataSource = MarqueeEditor._EnumDDContentAlign,
.FlatStyle = FlatStyle.Flat,
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells})
' And other column setups similar to above
' ....
.DataSource = Global.CPWBAdmin.MarqueeEditor.MarqueeData.Tables("TextStyles")
.MultiSelect = False
.AllowUserToDeleteRows = False
With .Columns("ID")
.ReadOnly = True
.DefaultCellStyle.BackColor = Color.LightGray
.Visible = False
.DisplayIndex = 0
.Frozen = True
End With
With .Columns("Name")
.DisplayIndex = 1
.Frozen = True
.DefaultCellStyle.BackColor = Color.Linen
End With
.Columns("RandomStyle?").DisplayIndex = 2
With .Columns("Font")
.ReadOnly = True
.DefaultCellStyle.BackColor = Color.LightBlue
.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
.DisplayIndex = 3
End With
'.... other column display index settings
.Columns("Stroke3LineJoin").DisplayIndex = 49
.Columns("Stroke3Wrap").DisplayIndex = 50
.Columns("TextAutoFit").DisplayIndex = 51
'Sort:
.Sort(_TextStylesDGV.Columns("Name"), System.ComponentModel.ListSortDirection.Ascending)
End With
End Sub
I'm wondering whether the DGV columns are getting re-ordered elsewhere in the code. Of course - no way to check this with step-by-step debugging as happens before form show. Have trawled through the code but can't see anything obvious. Does anyone have any ideas as this one is killing me! If only MS had allowed column collection re-ordering. :(
Oooops. Didn't search hard enough! Finally found the solution:
dgvReservedStalls.AutoGenerateColumns = True
dgvReservedStalls.DataSource = clsReservedStalls.LoadDataTable()
dgvReservedStalls.AutoGenerateColumns = False
auto generates the columns from the DT, then frees it for re-ordering the columns. A little obscure, MS... :)
From here

Assign value to checkboxes

Hye there, I new with vba here.
I want to use checkboxes to link with the series collections of a chart. I put the check boxes in a sheet which contain the chart altogether. I have a lot of checkboxes here to be assigned to "true" value.
Private Sub Controls_Initialize()
'Make default for checkboxes
CheckBox1.Value = True
CheckBox2.Value = True
CheckBox3.Value = True
CheckBox4.Value = True
CheckBox5.Value = True
CheckBox6.Value = True
CheckBox7.Value = True
CheckBox8.Value = True
CheckBox9.Value = True
CheckBox10.Value = True
CheckBox11.Value = True
CheckBox12.Value = True
CheckBox13.Value = True
CheckBox14.Value = True
CheckBox15.Value = True
CheckBox16.Value = True
CheckBox17.Value = True
CheckBox18.Value = True
CheckBox19.Value = True
CheckBox20.Value = True
CheckBox21.Value = True
CheckBox22.Value = True
CheckBox23.Value = True
CheckBox24.Value = True
End Sub
I have tried this code but can't
For i = 1 to 24
Controls("CheckBox" & i).Value = True
Next i
The questions are
1. Is there any other code that can make it simple?
2. How to link the check boxes with the series collection in the activechart? Example, if the checkbox return value false, the series collection will be deleted/hide(perhaps?). And when it returns value true, the series collection of the same data will be added back in the chart. I would like to make the chart interactive.
If there is any reference that I can reviewed, do tell me.
Thanks in advance.
Regards.
Alright, so assuming from what you've given, I'd think the problem is that the interpreter doesn't know i is an integer.
To fix this, we can implement something along the lines of Dim i As Integer to implement i as an integer.
We could try this:
Dim i As Integer
For i = 1 to 24
Controls("CheckBox" & i).Value = True
Next i

TIDYCom Deletes the missing tags during cleanup?

HTML TidyCom Removes Unclosed tags during cleanup?
eg: tag with missing closing is wiped off when compared with source file .So can any one let me know how can this be retained. Following is a code snippet that i am using for my program.
Dim tid As New TidyObject()
tid.Options.Doctype = "strict"
tid.Options.OutputXml = True
tid.Options.AddXmlDecl = True
tid.Options.Clean = False
tid.Options.DropEmptyParas = True
tid.Options.DropFontTags = False
tid.Options.CharEncoding = CharEncoding.utf8
tid.Options.QuoteAmpersand = True
tid.Options.QuoteMarks = False
tid.Options.QuoteNbsp = True
tid.Options.TidyMark = False
tid.Options.LogicalEmphasis = True
tid.Options.BreakBeforeBr = False
tid.Options.FixBackslash = True
tid.Options.FixBadComments = True
tid.Options.Wrap = True
tid.Options.UppercaseAttributes = False
tid.Options.UppercaseTags = False
tid.Options.Indent = True
tid.Options.IndentSpaces = 4
tid.Options.IndentAttributes = True
tid.Options.Word2000 = False
Waiting for a quick reply.Thanks in advance
You can have reference at this link http://w3c.github.io/tidy-html5/quickref.html#drop-empty-paras
as you have set it to true, this might be causing problem.