Reading task enterprise custom field values from mpp file using mpxj - c#

I'm trying to read task details from a mpp file using net.sf.mpxj library. However, when trying to read custom fields, I get a byte array which I do not know what to do with! It is not the exact value of the custom field from that specific task. Can anyone tell me what to do?
ProjectReader reader = new MPPReader();
ProjectFile project = reader.read(#"C:\EPM\test2.mpp");
foreach (net.sf.mpxj.Task task in project.Tasks)
{
var Value = task.GetFieldByAlias("My Custom Field Name");
}
The "Value" will be a byte array and I do not know how to get the real value from it.

UPDATED ANSWER:
As of MPXJ 10.7.0 you can retrieve correctly typed values for enterprise custom fields. You'll also find a CustomFieldDataType attribute as part of the CustomField class which indicates what type you'll be retrieving.
(One interesting "gotcha" is that if your MPP file contains an enterprise custom field which is based on a lookup table, i.e. the user can only select from a fixed set of values, the user-visible text is NOT stored in the MPP file. You'll only get back a GUID representing the value the user has selected. Microsoft Project itself has this same issue... if you open the MPP file when you're not connected to Project Server, these values will appears as blanks...)
ORIGINAL ANSWER:
The main problem is unfortunately that MPXJ doesn't currently offer the same level of support for Enterprise Custom Fields as it does for other fields. While it is able to identify Enterprise Custom Fields and the aliases they've been given, at the moment it is only able to read the raw bytes representing the field data.
Enterprise Custom Fields are not as commonly used as other field types so there hasn't been as much time invested in locating the definitions of these fields in the MPP file. The field definition will contain the type information necessary to convert from the raw bytes to the expected data type.
Improved support for Enterprise Custom Fields is on the "to do" list for MPXJ.

Related

Storing format information in database for use within a Windows Form Application

I am struggling with how to handle formatting data pulled from a database when every customer may/will want their own formatting for some fields. I have googled around and have found the term data dictionary but no clear explanation of what this is or how I can leverage it in my C# / MSQL Server / Entity Framework windows form application. I feel like this must be a common problem, and therefore must be a standard or common way of handling this type of requirement.
Example:
I have a field called ReferenceRange (FLOAT) in a table. Customer X wants this field to be displayed with an accuracy of 2 decimal points and another would like this to be displayed with 1 decimal point of accuracy.
One way would be to create a parameter in you app.config file or a config table, them store in that place the customer preference.
On every ToString() read the customer preference decimals to create the corresponding format, like:
ToString("#,##0." + dec), where dec would be your stored value.

C# translate database data using resx file

In my project (I am using azure storage) I have some data that I want to translate. I have the resource system in place for translations. I have a table in cloud which has name property. I want to translate it somehow.
One option is to create all the entries in database for each language which I don't prefer as it would create a lot entries along with the name.
Is there a smart way to use the resx mechanism I have in place?
So the table has multiple properties and one is name. Name could be anything like Mud, rock etc. Now I want to translate Mud into different language. Something like Texts.Mud would return me the correct value.
But lets say I get data like this
var data = some query;
string translatedName = Texts.data[0].name; // this won't work
You should instead add more columns in the database, each for a different language and select the column based on the user language.
Other solution is to have a transaltion mechanism (a custom class for example), where you pass the original database result (say data[0].name) to a query and it returns the translated value for you.

How to generate and understand a list of field names in a UniData table

I'm new to both UniData and Uniobjects so if I ask something that obvious I apologize.
I'm trying to write a tool that will let me export contacts from our ERP (Manage2000) that runs on UniData (v. 6.1) and can then import them into AD/Exchange.
The primary issue I'm having is that I don't know which fields (columns?) in the table (file?) are for what. I know that that there is a dictionary that has this information in it but I'm not sure how to get what I want out of it.
I found that there is a command LIST.METADATA in the current UniData documentation from Rocket but it seems that either the version of UniData that we are using is so old that it doesn't have this command in it or it was removed from the VOC file for some unknown reason.
Does anyone know how or have any tips to pull out the structure of a table so that I can know which fields are for what data?
Thanks in advance!
At TCL:
LIST DICT contact.master
Please note that the database file name (EX: contact.master) is case sensitive. I don't have a UniData instance at the moment to provide an example output. However, it should be similar to Universe's output:
Field......... Type & Field........ Conversion.. Column......... Output Depth &
Name.......... Field. Definition... Code........ Heading........ Format Assoc..
Number
AMOUNT.WEBB A 1 MR22 Amt WEBB 10R M
PANDAS.COST A 3 MD2Z Pandass Cost 10R M
CREDIT.EXP.DT A 6 D4/ Cred Exp Date 10R M
For the example above, you can generally tell the "data type" of the field by looking at the conversion code. "D4/" is the conversion code for a date. "MD2Z" is a numeric conversion code, which we can guess is for monetary amounts. I'm glossing over the power of conversion codes, so please make sure to reference Rocket's documentation for these codes to truly understand what these fields would output. If you don't have the documentation in front of you, you can also reference this site:
http://www.koretech.com/kr_help/KU2/30/en/KMK_Prog_Conversions.htm
If you wanted to use UniObjects and C# to retrieve the field names in a file, you could use the following code:
UniCommand fieldSelectCommand = activeSession.CreateUniCommand();
fieldSelectCommand.Command = "SELECT DICT contact.master";
fieldSelectCommand.Execute();
UniSelectList resultList = activeSession.CreateUniSelectList(0);
String[] allFieldNames = resultList.ReadListAsStringArray();
Having answered your question, I would also like to make a recommendation that you check out Rocket's U2 Toolkit for .NET if you're mostly going to be selecting data from the database instead of reading and manipulating individual records:
http://www.rocketsoftware.com/products/rocket-u2-toolkit-net
Not only does it present an ADO.NET way of accessing the database, it also has a better performance version of the UniObjects library under the U2.Data.Client.UO namespace.
The Dictionary, in my opinion, is a recommendation of how the schema should behave. However, there are cases when it's not 100% accurate. You could run "LIST CONTACT.MASTER TOXML TO MYFILE.XML" which would create an xml file what you could parse.
See https://u2devzone.rocketsoftware.com/accelerate/articles/u2-xml/u2-xml#section-0 for more information.

Loading a Null String and Silverlight 4

I maintain a Silverlight 4 application. While I was out of the office, the database structure was changed and a table was dropped and its fields combined into another existing table. Now, I’m receiving the following error after I create a new item and proceed to its "summary" screen:
“Value cannot be null. Parameter name: Text
At System.Windows.Controls.TextBox.set_Text(String value)”
This only happens with newly created entries, not older entries where the information on the next screen is complete (data was converted from an Excel spreadsheet and loaded into the database). So, I’ve narrowed it down this: the child window that is used to create a new record doesn’t have all the fields that were added to the table because some of the information isn’t available when the record is created. A Google search turned up that null strings can’t be passed in Silverlight.
The Summary screen is loaded via ddsSummaryLoadedData domain service. If I don’t include the “new” fields, then the values aren’t loaded for existing entries, but new entries don’t cause an error. If I do include them, older entries load correctly but new ones give the above error.
Is there a workaround to create the empty fields until they’re needed, but still load data if it exists (for older entries)? Or does the child window need to be redesigned? I’m new to Silverlight and still have so much to learn!
It doesn't look like you're using Bindings to render your view otherwise null values will be handled gracefully, so if you are setting the Text property manually in code, use the cascading operator to verify you are not submitting a null value.
myTextBox.Text = myModelValue.FirstName ?? string.Empty;

How to specify data types when dragging content to Excel

I am initiating drag and drop from my WinForms application using this simple
IDataObject data = new DataObject();
string textToExcel = "Hello\tWorld\t1\t2\nHello\tWorld\t1\t2\n"
data.SetData(DataFormats.Text, textToExcel);
I works fine when dropped on Excel, it ends up nicely in columns and rows.
Problem is that Excel does not know that the cells with values 1 and 2 are numerics
and it gets worse when dropping a date value.
How can I tell Excel the data types of the individual cells, is there some richer type that Excel accepts when content is being dropped into it.
All you are able to communicate with Drag-Drop to Excel are strings, which Excel will automatically convert to a date or numeric type if it can. If you don't want it to convert identifable types to a data type then you should begin the value with an appostrophe (') character, such as '100, instead of 100.
If you wish to have full control, you should subscribe to the Excel.Worksheet.Change event which will be triggered at the end of the Drag-Drop action. At that point you can do a custom conversion of your own data. This would be facilitated if you transmit your data as a custom format to begin with, one that would not be automatically converted by Excel. For example, instead of sending a 2x2 block of values such as:
100 Hello
$1.25 10/9/2010
You could send it through as:
<DragDrop:Double>100</Double> <DragDrop:String>Hello</String>
<DragDrop:Currency>1.25</Currency> <DragDrop:Date>2010.10.9</Date>
These values would be received by the cells as strings. But when the Worksheet.Change event fires, it will tell you which cells have been changed, and your routine could process the strings, looking for anything that begins with "<DragDrop:". You could then convert these to the required data types as specified in the strings themselves.
For a detailed example, see the article Adding Drag-and-Drop Functionality using the .NET Framework and Visual Studio 2005 Tools for Office Second Edition. In that article, they use an example that is much more unique than "<DragDrop:" -- they use a GUID at the front of the string to really make sure that the string is unique and identifiable. But the basic strategy is as I described, above.
Hope this helps,
Mike

Categories

Resources