MS Project VSTO - vsto

I am using Project 2016 to integrate with an ERP. My goal is to read Project's Resource Information.
To do that I save the database in an mdb file.
The line that do this trick is:
projApp.VisualReportsSaveDatabase(FileNameCompleteMdb, PjVisualReportsDataLevel.pjLevelDays)
Everything works fine, but some of my users, they are using Project with Portuguese Language. When the Access mdb file is created, many table fields have their names in Portuguese which causes all my SQL Statements to fail.
My question is:
Is there any way to force Project to export always the mdb file in English.
Best Regards

After a little research I got to this solution. It isn't the best solution, but works.
First Step, declare all fields as strings
Dim _Code As String
Dim _Name As String
Dim _Start As String
Dim _Finish As String
Dim _Work As String
Dim _ActualWork As String
Second step:
Set your strings with the FieldName read from your project application. At this point , project will return its FieldNames according to the language that it is set.
_Code = projApp.FieldConstantToFieldName(PjField.pjResourceCode)
_Name = projApp.FieldConstantToFieldName(PjField.pjResourceName)
_Start = projApp.FieldConstantToFieldName(PjField.pjResourceStart)
_Finish = projApp.FieldConstantToFieldName(PjField.pjResourceFinish)
_Work = projApp.FieldConstantToFieldName(PjField.pjResourceWork)
_ActualWork = projApp.FieldConstantToFieldName(PjField.pjResourceActualWork)
Dim qryResource As String = "Select [ResourceUID], [Code], [Name], [Start], [Finish], [Work], [Actual Work] From MSP_EpmResource Where [Code] >'0';"
Step 3:
With your sql statement in English, simply replace the original FieldNames with your variables:
qryResource = qryResource.Replace("Code", _Code)
qryResource = qryResource.Replace("Name", _Name)
qryResource = qryResource.Replace("Start", _Start)
qryResource = qryResource.Replace("Finish", _Finish)
qryResource = qryResource.Replace("Actual Work", _ActualWork)
qryResource = qryResource.Replace("Work", _Work)
Finally , you gonna have a valid sql statement, depending on your application language.
tks

Related

View content from the database sqlserver within the project visual basic

I have a database that contains the data as in the following picture
Notes:
Collation Database ('SQL_Latin1.General_CP1_CI_AS').
I have no right to change Collation to Araic_CI_AS.
In case you change Collation to Araic_CI_AS, the data display from the database is displayed in the new program, but the program has a problem and it appears in the old program in the form of ????? Where the old program.
I can not modify the old program because there is no source code for it.
This database is outdated and may not be modified by anyone ( Collation [rows] or Collation [databases])
When you link the database to a new standalone program through Visual Basic 2015 to use some data from the database, the following format appears as in the picture...
What I want is to display the content of the database to change the (ãßÇÆä æÂáÇÊ) sentence to the default language which is Arabic.
I hope to find a solution through the Visual Basic code and not through the amendment to the database.
Thanks to all
The problem has been solved in the process of converting the encoding characters by the following code:
Private Function conv1256(ByVal txt As String) As String
Dim dic As New Dictionary(Of String, String)
Const _1256 As String = "ÐÏÌÍÎåÚÛÝÞËÕÖØßãäÊÇáÈíÓÔÙÒæÉìÑÄÁÆøºÅñõðó¡ÜÃòö¿Âú"
Const _utf8 As String = "ذدجحخهعغفقثصضطكمنتالبيسشظزوةىرؤءئّ؛إًٌَُ،ـأٍِ؟آْ"
For i = 0 To (_1256.Length) - 1
dic.Add(_1256.Chars(i), _utf8.Chars(i))
Next i
For Each ch In txt
conv1256 &= If(dic.ContainsKey(ch), dic.Item(ch), ch)
Next
End Function
To be used this way:
MsgBox(conv1256("ÈÓãö Çááå ÇáÑøÍãä ÇáÑøÍíã"))
Good luck and thank you all

.ASHX file need to do a IF ELSE Statement within it

I am using an Upload script (http://www.uploadify.com/demos/ ) Converted to VB.NET for uploading multiple images. This script I have been using for years. It is very robust and works well. However, when I am working on it locally, I have to go inside of the ASHX file and comment out the LIVE database and uncomment the Local Database server.
My question is the following: Is there a way to do an IF ELSE statement inside of the ASHX file? I have tried and it errors out.
What I would like to do is something like this.
if Request.ServerVariables("SERVER_NAME")="192.168.2.12" then
'local connection here
else
'live server connection here
end if
This will make it so I can work on the scripts, without having to change this ALL THE TIME... It is right annoying.
Any idea's?
There is an IsLocal property you can read, which will tell you if the current request is being called locally. Assuming you are running within the ProcessRequest of the .ASHX
Dim isLocal As Boolean = context.Request.IsLocal
If isLocal Then
'local connection here
Else
'live server connection here
End If
OK, I figured it out. I used another method that I am using in an aspx.vb file. And I changed it up a little to work within the ASHX file. Works like a charm.
dim ipAdd as string
dim dbName as string
dim UN as string
dim PW as string
dim theLocal as string = Httpcontext.Current.Request.ServerVariables("SERVER_NAME")
if theLocal="192.168.2.12" then
ipAdd = "LOCAL_SERVER_NAME\INSTANCE_NAME"
dbName = "LOCAL_DB_NAME"
UN = "LOCAL_USERNAME"
PW = "LOCAL_PASSWORD"
else
ipAdd = "00.00.00.00"
dbName = "LIVE_DB_NAME"
UN = "SERVER_USERNMAE"
PW = "SERVER_PASSWORD"
end if
Dim cn As New System.Data.SqlClient.SqlConnection("Data Source="+ipAdd+"; Initial Catalog="+dbName+";User ID="+UN+";Password="+PW+";")
cn.Open()
Thanks for the attempted assistance from Malcor.
This is a wrap all.
Wayne

How do I trim all text up to and including a \ in a VB.net string

I'm sure if I knew the correct terminology I may have been able to search an answer... But my Visual Studio VB skills are somewhat n00bish.
My VB runs a dos batch, that dumps the DOMAIN\USERNAME of the current logged on user for a given IP address to a text file (GETUSER.txt)
What I need to do with this string (taken from the txt file created above), is create two strings, one that is the DOMAIN, one that is the USERNAME and to drop the \ entirely.
The problem is that my work environment consists of multiple domains, and varying username styles. The only constant is the \ separating the DOMAIN and USERNAME.
I've looked at the REPLACE and various STRING functions, but I'm struggling folks.
The below is the section of VB code that runs when you click OK on the dialogue box (after entering an IP). "MAIN" is the name of the parent window that has the Public VARs in it.
Public Shared IPADDRESS As String
Public Shared USERNAME As String
^ are the Public VARS used.
Dim GETUSER As New ProcessStartInfo("TOOLS\GETUSER.bat")
Dim fileReader As System.IO.StreamReader
Dim stringReader As String
MAIN.IPADDRESS = NEW_IP_ADD.Text
MAIN.IP_DISPLAY.Text = MAIN.IPADDRESS
GETUSER.WindowStyle = ProcessWindowStyle.Hidden
GETUSER.Arguments = MAIN.IPADDRESS
Process.Start(GETUSER)
fileReader =
My.Computer.FileSystem.OpenTextFileReader("TOOLS\GETUSER.txt")
stringReader = fileReader.ReadLine()
MAIN.USERNAME = stringReader
MAIN.USER_NAME.Text = MAIN.USERNAME
I hope this makes sense, and isn't too impossible to decipher... I look forward to your responses....
Please remember, I'm VERY new at VB, and Visual Studio... also... I'm more than happy if people post links to places that know I can get my answer, or help me with function names or anything designed to help me find the answer myself... it's the only way to learn... I just think I need a nudge in the right direction...
Cheers,
Tim.
It sounds like what you want to do is to split the string. And handily, there's a Split method:
Returns a string array that contains the substrings...
So you'd do something like:
Dim parts = MAIN.USERNAME.Split("\"C)
Dim domain = parts(0)
Dim userNameWithoutDOmain = parts(1)

VB.net file reading tricks?

I'm rather new to VB and I was wondering if you could help me out with something. I've got a file that I need to read and edit, looks something like this:
Name|Ted
SetAttackBaseDamage(251,1)
{2|73|10|-1|20,40}
I need to be able to load the data here (What will be changing at least) into a variable so that I can change it, almost like what happens in XML except with this. The way the file is set up can't be changed as I'm edit files that are produced by another program, also written in VB.net though it isn't open source.
Assumed that you've 3 line by readline the file .. L1, L2, L3
dim sTmp as String
dim sName as String = L1.Split("|")(1) '--> this Name var
sTmp = L2.Split("(")(1)
dim sSA = split(sTmp.Replace(")", ""),",")
dim sSA1 as String = sSA(0) '---> this SetAttackBaseDamage - 1
dim sSA2 as String = sSA(1) '---> this SetAttackBaseDamage - 2
just wanna try to help you .. you have to de the rest ............

How to create a dynamic excel link in VB.NET? (not .dll)

VB.NET level: Beginner
I made a .exe using VB.NET. In this program there are many links to excel files (There are specific folders for excel files).
My problem:
Consider an excel file named as abc.xlsx, which is on my home pc. Link to this file is as follows,
D:\work\data\abc.xlsx
now for obvious reasons, this link will not be valid when I run the .exe on my work pc.
(Later I want to run this .exe on multiple pc's)
How to solve this issue?
My thinking is to create a dynamic link which will update itself based on pc in use or to create a constant link which is independent of pc in use.
Help will be really appreciated.
Thanks in advance
so make the path relative to the .exe
C:\myapp\myapp.exe
c:\myapp\data\abc.xslx
...
So no matter where you app is, you can get to your data like this
Dim dataFolder As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly(‌​).Location)
dataFolder = System.IO.Path.Combine(dataFolder,"data")
Dim theFileIwant as String = System.IO.Path.Combine(datafolder,"abc.xslx")
Try something like this:
Public Function GetDynamicFilename(p_filename As String) As String
Dim tempPath As String
Select Case My.Computer.Name.ToUpper
Case "COMPUTER1"
tempPath = "c:\work\data"
Case "COMPUTER2"
tempPath = "d:\work\files"
End Select
Return String.Format("{0}\{1}", tempPath, p_filename)
End Function