I have a view that runs on a model RETLogModel which pulls from an entirely different connection string then a table called RecordsTaskViews. I need to pass information from RecordsTaskViews based on information gathered by my model. Currently my function looks like this:
Function RETLog(model As RETModels.RETLogModel) As ActionResult
Dim id As Integer = model.ActivityIDReturn
Dim id2 As Integer
Dim PS As RecordsTaskView = GlobalVar.db.PS.RecordsTaskViews.Find(id)
If model.ActivityIDReturn > 0 Then
id2 = model.ActivityIDReturn
Else : id2 = PS.RefActionID
End If
If model.ActivityIDError > 0 Then
ViewData("ActivityIDErrorValue") = model.ActivityIDError
Else : ViewData("ActivityIDErrorValue") = PS.RefActionID
End If
Dim PS2 As RecordsTaskView = GlobalVar.db.PS.RecordsTaskViews.Find(id2)
If model.ActivityIDReturn > 0 Then
If PS IsNot Nothing Then
ViewData("QRefActionID") = PS.RefActionID
ViewData("QQutDesc") = PS.QutDesc
ViewData("QTaskDesc") = PS.TaskDesc
ViewData("QClientCode") = PS.CltCode
ViewData("QClientName") = PS.CltDesc
ViewData("QMemberID") = PS.BenIDin
ViewData("QMemberName") = PS.BenNameLast & ", " & PS BenNameFirst
ViewData("QDateStart") = CDate(PS.DateStart).ToString("MM/dd/yyyy")
ViewData("QDateRes") = CDate(PS.DateResolution).ToString("MM/dd/yyyy")
ViewData("QCreateUser") = PS.UserIDCreation
ViewData("QLastChangeUser") = PS.UserIDLastChanged
ViewData("QDateReport") = CDate(PS.DateReport).ToString("MM/dd/yyyy")
Else
ViewData("QQutDesc") = ""
ViewData("QTaskDesc") = ""
ViewData("QClientCode") = ""
ViewData("QClientName") = ""
ViewData("QMemberID") = ""
ViewData("QMemberName") = ""
ViewData("QDateStart") = ""
ViewData("QDateRes") = ""
ViewData("QCreateUser") = ""
ViewData("QLastChangeUser") = ""
ViewData("QDateReport") = ""
End If
If PS2 IsNot Nothing Then
ViewData("ORefActionID") = PS2.RefActionID
ViewData("OQutDesc") = PS2.QutDesc
ViewData("OTaskDesc") = PS2.TaskDesc
ViewData("OClientCode") = PS2.CltCode
ViewData("OClientName") = PS2.CltDesc
ViewData("OMemberID") = PS2.BenIDin
ViewData("OMemberName") = PS2.BenNameLast & ", " & PS.BenNameFirst
ViewData("ODateStart") = CDate(PS2.DateStart).ToString("MM/dd/yyyy")
ViewData("ODateRes") = CDate(PS2.DateResolution).ToString("MM/dd/yyyy")
ViewData("OCreateUser") = PS2.UserIDCreation
ViewData("OLastChangeUser") = PS2.UserIDLastChanged
ViewData("ODateReport") = CDate(PS2.DateReport).ToString("MM/dd/yyyy")
Else
ViewData("ORefActionID") = ""
ViewData("OQutDesc") = ""
ViewData("OTaskDesc") = ""
ViewData("OClientCode") = ""
ViewData("OClientName") = ""
ViewData("OMemberID") = ""
ViewData("OMemberName") = ""
ViewData("ODateStart") = ""
ViewData("ODateRes") = ""
ViewData("OCreateUser") = ""
ViewData("OLastChangeUser") = ""
ViewData("ODateReport") = ""
End If
End If
If ModelState.IsValid Then
End If
Return View(model)
End Function
My issue is this is obviously a boat load of ViewData elements. Being as I already have #ModelType RETModels.RETLogModel specified in the view itself is there a more efficient way to pass the data to the view?
Is there a more efficient way to pass the data to the view?
Yes, use a ViewModel that contains all the relevant (combined) fields and bind that to the View.
And use an automated object mapper, such as AutoMapper, to copy data from your business models to the ViewModel.
Related
I'm using Devexpress Xtragrid TileView module.
Basically I want my code works like this :
user input member ID on the upper left textbox and press load.
If they exists, then a Tile will be appeared.
A tile should contain : Name, Status, member ID and a photo.
If user press load again (either same ID or another ID) a Tile will be added also, and so on. Unless they press Clear & Load, It should be only 1 latest tile left.
So, I'm able to produce up to Step 3.
But I couldn't be able to load the picture.
The picture itself, It's not a byte array. It's a Image path.
e.q : D:/test/1.jpg
So, how do I load the picture?
Protected Overridable Sub InitData()
Try
Dim homesTable = ds.Tables(0)
homesTable.Columns.Add("ImageCol")
For Each row_Renamed As DataRow In homesTable.Rows
Dim img As Image = Image.FromFile(row_Renamed("memberPhoto")) 'I tried this, but didn't work
row_Renamed("ImageCol") = img
Next row_Renamed
GridControl1.DataSource = homesTable
Catch
End Try
End Sub
Private Sub setupTile()
'For i = 0 To j - 1
Try
TileView1.BeginUpdate()
'TileView1.DataSource = ds.Tables(0)
TileView1.OptionsTiles.RowCount = 3
TileView1.OptionsTiles.Padding = New Padding(20)
TileView1.OptionsTiles.ItemPadding = New Padding(10)
TileView1.OptionsTiles.IndentBetweenItems = 20
TileView1.OptionsTiles.ItemSize = New Size(320, 170)
TileView1.Appearance.ItemNormal.ForeColor = Color.White
TileView1.Appearance.ItemNormal.BorderColor = Color.Transparent
'Setup tiles template
Dim leftPanel As New TileViewItemElement()
Dim splitLine As New TileViewItemElement()
Dim nameCaption As New TileViewItemElement()
Dim nameValue As New TileViewItemElement()
Dim statusCaption As New TileViewItemElement()
Dim statusValue As New TileViewItemElement()
Dim RGPCaption As New TileViewItemElement()
Dim RGPvalue As New TileViewItemElement()
Dim imageTile As New TileViewItemElement()
TileView1.TileTemplate.Add(leftPanel)
TileView1.TileTemplate.Add(splitLine)
TileView1.TileTemplate.Add(nameCaption)
TileView1.TileTemplate.Add(nameValue)
TileView1.TileTemplate.Add(statusCaption)
TileView1.TileTemplate.Add(statusValue)
TileView1.TileTemplate.Add(RGPCaption)
TileView1.TileTemplate.Add(RGPvalue)
TileView1.TileTemplate.Add(imageTile)
'
'nameValue.Text = ""
'statusValue.Text = ""
'RGPvalue.Text = ""
'imageTile.Image = Nothing
'
leftPanel.StretchVertical = True
leftPanel.Width = 190
leftPanel.TextLocation = New Point(-10, 0)
leftPanel.Appearance.Normal.BackColor = Color.FromArgb(58, 166, 101)
'
splitLine.StretchVertical = True
splitLine.Width = 3
splitLine.TextAlignment = TileItemContentAlignment.Manual
splitLine.TextLocation = New Point(190, 0)
splitLine.Appearance.Normal.BackColor = Color.White
'
nameCaption.Text = "Name"
nameCaption.TextAlignment = TileItemContentAlignment.TopLeft
nameCaption.Appearance.Normal.FontSizeDelta = -1
'
nameValue.Column = TileView1.Columns("preferredName")
nameValue.AnchorElement = nameCaption
nameValue.AnchorIndent = 2
nameValue.MaxWidth = 200
nameValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'nameValue.Text = ds.Tables(0).Rows(i)("preferredName").ToString
'
statusCaption.Text = "Status"
statusCaption.AnchorElement = nameValue
statusCaption.AnchorIndent = 14
statusCaption.Appearance.Normal.FontSizeDelta = -1
'
statusValue.Column = TileView1.Columns("memberStatus")
statusValue.AnchorElement = statusCaption
statusValue.AnchorIndent = 2
statusValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'statusValue.Text = ds.Tables(0).Rows(i)("memberStatus").ToString
'
RGPCaption.Text = "RGP"
RGPCaption.AnchorElement = nameValue
RGPCaption.AnchorIndent = 65
'RGPCaption.TextLocation
'RGPCaption.Appearance.Normal.FontSizeDelta = -1
RGPCaption.Appearance.Normal.Font = New Font("Segoe UI Semibold", 12.0F, System.Drawing.FontStyle.Regular)
'
RGPvalue.Column = TileView1.Columns("code")
RGPvalue.AnchorElement = RGPCaption
RGPvalue.AnchorIndent = 1
RGPvalue.TextAlignment = TileItemContentAlignment.BottomLeft
RGPvalue.Appearance.Normal.Font = New Font("Segoe UI Semilight", 25.75F, System.Drawing.FontStyle.Regular)
'RGPvalue.Text = ds.Tables(0).Rows(i)("code").ToString
'
imageTile.Column = TileView1.Columns("ImageCol")
imageTile.ImageSize = New Size(120, 170)
imageTile.ImageAlignment = TileItemContentAlignment.MiddleRight
imageTile.ImageScaleMode = TileItemImageScaleMode.Stretch
imageTile.ImageLocation = New Point(12, 0)
Catch ex As Exception
XtraMessageBox.Show(ex.Message)
Finally
TileView1.EndUpdate()
End Try
'Next
End Sub
Private Sub loadBtn_Click(sender As Object, e As EventArgs) Handles loadBtn.Click
initData()
setupTile()
End Sub
Maybe it's too late but in my case only need to read file from disk and assign to a byte() column.
First of all, table column should be byte array so replace:
homesTable.Columns.Add("ImageCol")
for:
homesTable.Columns.Add(New DataColumn("ImageCol", GetType(Byte)))
Then I'd try to replace:
row_Renamed("ImageCol") = img
for:
row_Renamed("ImageCol") = IO.File.ReadAllBytes(row_Renamed("memberPhoto"))
That would load disk file to byte array and shown in tile. I'd check if file exists to avoid exceptions.
That's what I do to load image from disk.
Hope it helps.
Im using following code to input data into orcale database via asp.net web application (vb).
Public Sub SaveRaidDetails()
lblStatus.Text = ""
Dim dt2 As DataTable = CType(ViewState("dt1"), DataTable)
Dim er As Boolean = False
Dim dtRaidDate As Date
If dt2.Rows.Count > 0 Then
Try
dtRaidDate = Convert.ToDateTime(txtRaidDate.Text)
Catch ex As Exception
er = True
End Try
If er = False Then
lblDateEr.Visible = False
Dim intDisID, intMktSeq, intAgID As Integer
Dim dblFine As Double
If ddlDistributor.SelectedValue = "" Then
intDisID = 0
Else
intDisID = ddlDistributor.SelectedValue
End If
If ddlMarkets.SelectedValue = "" Then
intMktSeq = 0
Else
intMktSeq = ddlMarkets.SelectedValue
End If
If ddlAgency.SelectedValue = "" Then
intAgID = 0
Else
intAgID = ddlAgency.SelectedValue
End If
If txtFine.Text = "" Then
dblFine = 0
Else
dblFine = Convert.ToDouble((txtFine.Text))
End If
Dim intUserSeq As Integer = Convert.ToInt32(Session("UserSeq"))
Dim ret As Boolean
Dim rd1 As New RIMS_DATA.Raids
ret = rd1.AddRaid(dtRaidDate, txtCo.Text, txtCa.Text, intDisID, Convert.ToInt32(ddlRegion.SelectedValue), intAgID, intMktSeq, txtTrader.Text, txtTraderAdd.Text, dblFine, txtRemarks.Text, intUserSeq)
If ret = True Then
Dim intRaidID As Integer = rd1.ReadLastRaid()
Dim dtBatchDt As Date
For Each dr As DataRow In dt2.Rows
Try
dtBatchDt = Convert.ToDateTime(dr("BDt"))
Catch ex As Exception
dtBatchDt = Convert.ToDateTime("01/01/2000")
End Try
ret = rd1.AddRaid2(intRaidID, Convert.ToInt32(dr("BID")), Convert.ToInt32(dr("Qty")), dr("BCd"), dtBatchDt)
Next
ClearForm(1)
lblStatus.Text = "Record inserted successfully !"
lblDateEr.Visible = True
End If
End If
End If
Else
lblStatus.Text = "Please enter the raid details !"
End If
But the issue is in the Orcle database the date is saved in wrong format like this.. 20/07/0001 . But the date in the text box which i pass to variable is 2015/07/1. I use date time picker to input date to text box. how can i fix this problem.
Is this enough for answer
In Access 2010.
I have 3 separate groups of fields that can be active based on a combobox selection but I'm trying to get them to be required as well. I've looked everywhere but it doesn't appear to be any VB code to make a field required. Is there anyway I can accomplish this?
The code I have right now to make the selected group of fields active and make the one's not selected blank:
Private Sub Combo109_Click()
If Combo109 = "Germ" Then
cg_moisture.Enabled = True
cg_oil_nir.Enabled = True
extraneous_material.Enabled = True
fines.Enabled = True
cg_moisture.Enabled = True
cg_oil_nir.Enabled = True
extraneous_material.Enabled = True
fines.Enabled = True
Moist_cgm_nir.Enabled = False
prot_cgm_nir.Enabled = False
oil_cgm_nir.Enabled = False
meal_color.Enabled = False
load_out_temp.Enabled = False
moist_cgf_nir.Enabled = False
prot_cgf_nir.Enabled = False
oil_cgf_nir.Enabled = False
profat_nir.Enabled = False
starch_nir.Enabled = False
total_sug_nir.Enabled = False
loadout_temp.Enabled = False
screen_thrus.Enabled = False
screen_thrus.Value = ""
Moist_cgm_nir.Value = ""
prot_cgm_nir.Value = ""
oil_cgm_nir.Value = ""
meal_color.Value = ""
load_out_temp.Value = ""
moist_cgf_nir.Value = ""
prot_cgf_nir.Value = ""
oil_cgf_nir.Value = ""
profat_nir.Value = ""
starch_nir.Value = ""
total_sug_nir.Value = ""
loadout_temp.Value = ""
screen_thrus.Value = ""
screen_thrus.Value = ""
End If
IF all of the controls are in the 'Detail' section of your form, AND if a contrtol is Enabled, you require a value, then the code below should work. If you want more meaningful names to be displayed, either change your control names, or place a better name in the control 'Tag' field and reference that. The following code only checks Textboxes and CheckBoxes - modify to suit your needs.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
Dim blnMissing As Boolean
Dim strMissing As String
For Each ctl In Me.Section("Detail").Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acCheckBox Then
If ctl.Enabled = True Then
'Debug.Print ctl.Name & vbTab & ctl.Value
If ctl.Properties("Enabled") = True Then
If Me(ctl.Name) = "" Or IsNull(Me(ctl.Name)) Then
blnMissing = True
strMissing = strMissing & ctl.Name & "; "
End If
End If
End If
End If
Next ctl
If blnMissing = True Then
MsgBox "You are required to enter data in fields: " & strMissing, vbOKOnly + vbCritical, "Missing Required Data"
Cancel = True
End If
End Sub
The code below works great as is:
dashboard1.Text = charArray(0)
dashboard2.Text = charArray(1)
dashboard3.Text = charArray(2)
dashboard4.Text = charArray(3)
dashboard5.Text = charArray(4)
dashboard6.Text = charArray(5)
dashboard7.Text = ""
dashboard8.Text = ""
dashboard9.Text = ""
dashboard10.Text = ""
If dashboardl >= 7 Then
dashboard7.Text = charArray(6)
End If
If dashboardl >= 8 Then
dashboard8.Text = charArray(7)
End If
If dashboardl >= 9 Then
dashboard9.Text = charArray(8)
End If
If dashboardl >= 10 Then
dashboard10.Text = charArray(9)
End If
However, I would like to convert them to FOR Loop as in example below but I am getting errors.
For i = 1 To (dashboardl)
("dashboard" & CStr(i)) = charArray(i - 1)
Next i
Your assistance is greatly appreciated.
You can try this...
For i = 1 To dashboardl
Dim txtBox As TextBox = FindControl("dashboard" & i)
txtBox.Text = charArray(i - 1)
Next i
Ha, I missed the point. Still not on a real computer, but try this...
For i = 1 To dashboardl
Me.Controls("dashboard" & CStr(i)).Text = charArray(i - 1)
Next i
I have a shopping cart that using 2d array Cart(3, 20) to store user shop in a session.
It storing data like this:
Cart(0,0) = Product_ID
Cart(1,0) = Product_Name
Cart(2,0) = Product_Price
Cart(3,0) = Product_Qty
I want to count Items based on product_id ( we have not repetitive product_id)
I found a function here:
Function UniqueEntryCount(SourceRange)
Dim MyDataset
Dim dic
Set dic=Server.CreateObject("Scripting.Dictionary")
MyDataset = SourceRange
For i = 1 To UBound(MyDataset, 2)
if not dic.Exists(MyDataset(0, i)) then dic.Add MyDataset(0, i), ""
Next
UniqueEntryCount = dic.Count
Set dic = Nothing
End Function
But one problem is remain, When my Cart is empty, it show me 1
How can solved it?
An unitialized fixed array (Dim a(i, j)) contains i * j empty elements; your
if not dic.Exists(MyDataset(0, i)) then dic.Add MyDataset(0, i), ""
will pick up and count the first empty item. Demonstrated in code:
Dim afCart(3, 4)
Dim dicPID : Set dicPID = countPID00(afCart)
Dim aKeys : aKeys = dicPID.Keys
Dim vKey : vKey = aKeys(0)
WScript.Echo "A", dicPID.Count, TypeName(vKey)
Set dicPID = countPID(afCart)
WScript.Echo "B", dicPID.Count
afCart(0, 0) = "ignored"
afCart(0, 1) = 4711
afCart(0, 2) = 4712
afCart(0, 3) = 4711
' afCart(0, 4) = "not initialized/Empty"
Set dicPID = countPID(afCart)
WScript.Echo "C"
For Each vKey In dicPID.Keys
WScript.Echo "", vKey, "=", dicPID(vKey)
Next
Function countPID00(afCart)
Dim dicRVal : Set dicRVal = CreateObject("Scripting.Dictionary")
Dim MyDataset : MyDataset = afCart ' waste of ressources
Dim iRow
For iRow = 1 To UBound(MyDataset, 2)
If Not dicRVal.Exists(MyDataset(0, iRow)) Then
dicRVal(MyDataset(0, iRow)) = "" ' loss of info; will pick up Empty item
End If
Next
Set countPID00 = dicRVal
End Function ' countPID00
Function countPID(afCart)
Dim dicRVal : Set dicRVal = CreateObject("Scripting.Dictionary")
Dim iRow
For iRow = 1 To UBound(afCart, 2)
If Not IsEmpty(afCart(0, iRow)) Then
dicRVal(afCart(0, iRow)) = dicRVal(afCart(0, iRow)) + 1
End If
Next
Set countPID = dicRVal
End Function ' countPID
output:
A 1 Empty
B 0
C
4711 = 2
4712 = 1