|
Thanks! I'll give it a try. It seems like it will work with adding a conversion from DateTime to integer.
int mfgDate_mo_int = mfg.Month;
|
|
|
|
|
Why don't you just do binary serialization to a byte array? It'll be a little bigger then what you are doing because of the meta data, but if you want it really light weight, I don't really get the hex step. Just store the month, day and year?? Also, don't store just the 2 digit yr or you'll have Y2K issues.
|
|
|
|
|
I have to convert to hex and do 2-digits because of system requirements.
|
|
|
|
|
Are the requirements fixed? A DateTime is really a long internally (Ticks), which of course can be stored in/retrieved from 8 bytes very easily.
|
|
|
|
|
Yes, the requirements are fixed. This is related to a chip layout that a contractor designed years ago. Thanks for the suggestions, though!
|
|
|
|
|
No problem. Did you get it working?
|
|
|
|
|
Yes. I still have to try writing the data to the chip to test it, but hopefully all is good (encoding) when I do.
|
|
|
|
|
Hello,
I wanted to use a (flag) enum as index to access the single flag values.
Instead of
<CheckBox IsChecked="{Binding Obj[1]}" ...
I hoped that I could use something like
<CheckBox IsChecked="{Binding Obj[TestEnum.Enum1]}" ...
with some helper object providing an index operator. The first works, the second does not...
Additionally: Can I use an expression (for example an extension method
TestEnum.Enum1.DoSomething()
(which returns a different enum item of the same type) instead of the enum item name for the Binding?
Alex
|
|
|
|
|
Alex, in order to use an enum, you actually need to provide some instance information to WPF for it to be able to "understand" it. To do that, you need to set up an ObjectDataSource that binds in the enum. There's an example here[^] that shows how to do this.
You might also want to look at this[^] handy article.
BTW - you really should have asked this in the WPF forum. This has nothing to do with C#.
|
|
|
|
|
Sorry, I missed that there is an WPF forum (hidden behind Silverlight...).
Indeed, the samples shown in your links do it the other way round - get the string from the enum value. I needed the value from the string.
My error was simply to use the full name
"{Binding Obj[TestEnum.Enum1]}"
instead of simply
"{Binding Obj[Enum1]}"
The latter works now.
Alex
|
|
|
|
|
I'm glad you've got it working.
|
|
|
|
|
And for the expression
{Binding Obj[Enum1.DoSomething()]}
I found a simple workaround for my case.
I simply use multiple properties:
{Binding ObjDoSomething[Enum1]}
{Binding ObjDoSomethingElse[Enum1]}
which internally call the extension method.
Alex
|
|
|
|
|
I dunno anything about WPF, but to answer the question; yes to all. To answer the questions in reverse order;
LionAM wrote:
Additionally: Can I use an expression (for example an extension method
TestEnum.Enum1.DoSomething()
Yes, see example-code below (tested under Mono);
public enum TestEnum: int
{
Enum1 = 3,
EnumZwei = 9
}
public static class MyExt
{
public static TestEnum DoSomething(this TestEnum e)
{
return TestEnum.EnumZwei;
}
}
class Program
{
public static void Main (string[] args)
{
Console.WriteLine(TestEnum.Enum1.DoSomething());
}
}
LionAM wrote: I hoped that I could use something like
<CheckBox IsChecked="{Binding Obj[TestEnum.Enum1]}" ...
with some helper object providing an index operator. The first works, the second does not...
With a little helper you can. Add the method below;
public static class MyExt
{
public static string Parse(this string SomeString)
{
foreach (var enumVal in Enum.GetValues(typeof(TestEnum)))
{
string enumValAsString = String.Format("{0}.{1}",
enumVal.GetType().Name, enumVal);
int enumValAsInt = (int)enumVal;
if (SomeString.Contains(enumValAsString))
{
SomeString = SomeString.Replace(enumValAsString, enumValAsInt.ToString());
}
}
return SomeString;
}
}
class Program
{
public static void Main (string[] args)
{
string s = "{Binding Obj[TestEnum.Enum1]}";
Console.WriteLine(s);
Console.WriteLine(s.Parse());
}
}
Enjoy
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for your answer.
However, I have to admit that the C# forum was the wrong forum to ask my question. The Binding expression is not used within C# code but within a (static) .xaml file - although it should in principle be possible to assign the Binding string dynamically, I would avoid it for coding style reasons.
Alex
|
|
|
|
|
You're welcome
|
|
|
|
|
HI Friends,
I am working on smart device application development using .net compact framework 3.5 (for windows mobile 6.5) .
In my mobile UI, used typed dataset to View/Edit/remove etc.
I would like to synchronize the data only few selected table data to server using web service.
Anyone has how to/best way to synchronize with typed dataset?
please help with any link or idea. highly appreciated.
thanks in advance
Ramana
modified 20-Aug-12 5:25am.
|
|
|
|
|
Well, I would probably use Microsoft Sync Framework to do this. There's a basic sample here[^] that should give you some idea.
You can get more information about the Sync Framework here[^].
|
|
|
|
|
|
I Know how to Authenticate a web service like( [SoapHeader("Authentication", Required = true)]) before the class we need to do this..
How to acheive the same kind of Authentication in WCF Service any ideas or references will be greatly appreciated.
Thanks in Advance..!
|
|
|
|
|
Hi all,
I'm trying to create an app that lets people upload their resume to my database. I've seen tutorials for doing this and they all say the same thing. Number 1 save the original name and file type of the file to be uploaded and convert the file to byte array. Number 2 upload to database. However there is a problem, they all seem to assume one thing and that is, they assume the path of the file to be uploaded is known. Just to show you what I'm talking about below is one of the methods I've found that let you upload a file to the database.
protected void InsertDoc_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("APP_DATA/TestDoc.docx");
string filename = Path.GetFileName(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
string strQuery = "insert into tblFiles(Name, ContentType, Data) values (@Name, @ContentType, @Data)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value = "application/vnd.ms-word";
cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
InsertUpdateData(cmd);
}
The line
string filePath = Server.MapPath("APP_DATA/TestDoc.docx");
is supposed to give you the file path but it assumes you already know what it is. I tried to get around this problem by using a FileUpload control and use fileupload1.PostedFile.FileName, but it only returns the file name and extension, not the full path. I have also tried Path.GetFileName( fileupload1.FileName) with no luck. How do I get around this problem? Thanks in advance for replying.
modified 18-Aug-12 23:30pm.
|
|
|
|
|
What file upload control are you using?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard, thanks for replying. I'm using asp.net FileUpload control.
|
|
|
|
|
Well, the documentation for that control says the following:
Quote: The FileContent property gets a Stream object that points to a file to upload. Use this property to access the contents of the file as bytes. For example, you can use the Stream object that is returned by the FileContent property to read the contents of the file as bytes and store them in a byte array. Alternatively, you can use the FileBytes property to retrieve all the bytes in the file.
I would use the FileContent property to get a stream object that reads the bytes of the file.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
File upload controls don'#t give you any path information (because the device originating the file may not support paths, and the path to the original file would give you information about the client machine - which is not allowed for security reasons).
But that's ok, - you don't need it. You need the file name and extension - which all upload controls will give you - and you need the file content as a byte stream - which all upload controls will also give you. You don't need to read it any further to get the data you need, since you can't specific the destination location when any user uploads it anyway!
This is the method I use: it's probably a bit overkill for you since it handles versioning as well, but...
private string SaveUpload(FileUpload fl)
{
if (fl.HasFile)
{
try
{
int version = 0;
string filename = Path.GetFileName(fl.FileName);
byte[] filedata = fl.FileBytes;
string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DownloadDatabase"].ConnectionString;
using (SqlConnection con = new SqlConnection(strCon))
{
con.Open();
using (SqlCommand ver = new SqlCommand("SELECT MAX(version) FROM dlContent WHERE fileName=@FN", con))
{
ver.Parameters.AddWithValue("@FN", filename);
object o = ver.ExecuteScalar();
if (o != null && o != System.DBNull.Value)
{
version = (int) o + 1;
}
}
using (SqlCommand ins = new SqlCommand("INSERT INTO dlContent (iD, fileName, description, dataContent, version, uploadedOn) " +
"VALUES (@ID, @FN, @DS, @DT, @VS, @UD)", con))
{
ins.Parameters.AddWithValue("@ID", Guid.NewGuid());
ins.Parameters.AddWithValue("@FN", filename);
ins.Parameters.AddWithValue("@DS", "");
ins.Parameters.AddWithValue("@DT", filedata);
ins.Parameters.AddWithValue("@VS", version);
ins.Parameters.AddWithValue("@UD", DateTime.Now);
ins.ExecuteNonQuery();
}
}
return string.Format("{0} uploaded, version = {1}", filename, version);
}
catch (Exception ex)
{
return "The file could not be uploaded. The following error occured: " + ex.Message;
}
}
return "Please select a file.";
}
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thank you so much for replying. Can you please do me one more favor, can you show me how to retrieve the file after it is stored and display it in the browser. None of the tutorials I'm I've looked at worked, I did not get any errors using the code from the tutorials, they just don't do anything. I've been at this for days and I really need to know how to retrieve and display a word doc in the browser as soon as possible. Thanks again for your help.
|
|
|
|