|
I figured it out. The key needed to be converted into an 8 byte array.
public static byte[] toBytes(string text)
{
char[] dash = { '-', '\n', '\r' };
String[] values = text.Split(dash);
byte[] keyArray = new byte[8];
for (int i = 0; i < values.Length; i++)
{
int elem = Convert.ToInt32(values[i]);
elem = elem & 0x00FF;
keyArray[i] = (byte)elem;
}
return keyArray;
}
Thanx,
Karl
|
|
|
|
|
Hello all,
Could anyone tell me how to setup orientation to landscape, and datetime , and tabname in footer when user print the excel sheet by default. i am sending my excel code.Could any one tell what i need to do i search in google but no luck I need In C#.
public static void excelprint(DataSet source, string fileName)
{
bool status = false;
try
{
System.IO.StreamWriter excelDoc;
excelDoc = new System.IO.StreamWriter(fileName);
const string startExcelXML = "<xml version>\r\n<Workbook " +
"xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" +
" xmlns =\"urn:schemas-microsoft-com:office:office\"\r\n " +
"xmlns:x=\"urn:schemas- microsoft-com:office:" +
"excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" +
"office:spreadsheet\">\r\n <Styles>\r\n " +
"<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " +
"<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
"\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
"\r\n <Protection/>\r\n </Style>\r\n " +
"<Style ss:ID=\"BoldColumn\">\r\n <Font " +
"x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" +
" ss:Format=\"@\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"Decimal\">\r\n <NumberFormat " +
"ss:Format=\"0.00\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"Integer\">\r\n <NumberFormat " +
"ss:Format=\"0\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"DateLiteral\">\r\n <NumberFormat " +
"ss:Format=\"mm/dd/yyyy;@\"/>\r\n </Style>\r\n " +
"</Styles>\r\n ";
const string endExcelXML = "</Workbook>";
int rowCount = 0;
int sheetCount = 1;
excelDoc.Write(startExcelXML);
for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++)
{
excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">");
excelDoc.Write("<Table>");
excelDoc.Write("<Row>");
for (int x = 0; x < source.Tables[worksheet].Columns.Count; x++)
{
excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");
excelDoc.Write(source.Tables[worksheet].Columns[x].ColumnName);
excelDoc.Write("</Data></Cell>");
}
excelDoc.Write("</Row>");
for (int x = 0; x < source.Tables[worksheet].DefaultView.Count; x++)
{
rowCount++;
if (rowCount == 64000)
{
rowCount = 0;
sheetCount++;
excelDoc.Write("</Table>");
excelDoc.Write(" </Worksheet>");
excelDoc.Write("<Worksheet ss:Name=\"Sheet" + worksheet + "\">");
excelDoc.Write("<Table>");
}
excelDoc.Write("<Row>"); //ID=" + rowCount + "
for (int y = 0; y < source.Tables[worksheet].Columns.Count; y++)
{
System.Type rowType;
rowType = source.Tables[worksheet].DefaultView[x][y].GetType();
switch (rowType.ToString())
{
case "System.String":
//string XMLstring = x[y].ToString();
string XMLstring = source.Tables[worksheet].DefaultView[x][y].ToString();
XMLstring = XMLstring.Trim();
XMLstring = XMLstring.Replace("&", "&");
XMLstring = XMLstring.Replace(">", ">");
XMLstring = XMLstring.Replace("<", "<");
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
excelDoc.Write(XMLstring);
excelDoc.Write("</Data></Cell>");
break;
case "System.DateTime":
// DateTime XMLDate = (DateTime)x[y];
DateTime XMLDate = (DateTime)source.Tables[worksheet].DefaultView[x][y];
string XMLDatetoString = "";
XMLDatetoString = XMLDate.Year.ToString() +
"-" +
(XMLDate.Month < 10 ? "0" +
XMLDate.Month.ToString() : XMLDate.Month.ToString()) +
"-" +
(XMLDate.Day < 10 ? "0" +
XMLDate.Day.ToString() : XMLDate.Day.ToString()) +
"T" +
(XMLDate.Hour < 10 ? "0" +
XMLDate.Hour.ToString() : XMLDate.Hour.ToString()) +
":" +
(XMLDate.Minute < 10 ? "0" +
XMLDate.Minute.ToString() : XMLDate.Minute.ToString()) +
":" +
(XMLDate.Second < 10 ? "0" +
XMLDate.Second.ToString() : XMLDate.Second.ToString()) +
".000";
excelDoc.Write("<Cell ss:StyleID=\"DateLiteral\">" +
"<Data ss:Type=\"DateTime\">");
excelDoc.Write(XMLDatetoString);
excelDoc.Write("</Data></Cell>");
break;
case "System.Boolean":
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
//excelDoc.Write(x[y].ToString());
excelDoc.Write(source.Tables[worksheet].DefaultView[x][y].ToString());
excelDoc.Write("</Data></Cell>");
break;
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Byte":
excelDoc.Write("<Cell ss:StyleID=\"Integer\">" +
"<Data ss:Type=\"Number\">");
// excelDoc.Write(x[y].ToString());
excelDoc.Write(source.Tables[worksheet].DefaultView[x][y].ToString());
excelDoc.Write("</Data></Cell>");
break;
case "System.Decimal":
case "System.Double":
excelDoc.Write("<Cell ss:StyleID=\"Decimal\">" +
"<Data ss:Type=\"Number\">");
// excelDoc.Write(x[y].ToString());
excelDoc.Write(source.Tables[worksheet].DefaultView[x][y].ToString());
excelDoc.Write("</Data></Cell>");
break;
case "System.DBNull":
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
excelDoc.Write("");
excelDoc.Write("</Data></Cell>");
break;
default:
throw (new Exception(rowType.ToString() + " not handled."));
}
}
excelDoc.Write("</Row>");
}
excelDoc.Write("</Table>");
excelDoc.Write(" </Worksheet>");
}
excelDoc.Write(endExcelXML);
excelDoc.Close();
status = true;
// MessageBox.Show("Data exported to excel file successfuly");
}
catch (Exception)
{
status = false;// MessageBox.Show("Error in exporting data to excel file");
}
}
|
|
|
|
|
Hi
I want to use Transactions with TableAdapter class which visual studio dataset designer create for each database objects (tables,...).
i found this article to do this : http://blah.winsmarts.com/2006/06/18/the-definitive-tableadapters--transactions-blog-post.aspx[^]
now u can use transactional tableAdapter like this :
CustomersTableAdapter tableAdap = new CustomersTableAdapter() ;
SqlTransaction tableAdapTran = null ;
SqlConnection tableAdapConn = null ;
try
{
tableAdapConn = tableAdap.OpenConnection() ;
tableAdapTran = tableAdapConn.BeginTransaction() ;
tableAdapTran.Commit() ;
}
catch (Exception)
{
tableAdapTran.Rollback() ;
}
finally
{
tableAdapConn.Close() ;
}
this works fine when u want working with a one TableAdapter. for multuple tableAdapters, u need extend each tableAdapter class for supporting Transactional operation.
In my scenario : i'm dealing with multiple tables (insert,update or delete to/from multiple tables) within a single transaction and i think above method does not correct for this operation. look at this code sample :
CustomersTableAdapter tableAdap = new CustomersTableAdapter() ;
SqlTransaction tableAdapTran = null;
SqlConnection tableAdapConn = null;
OrdersTableAdapter ordersAdapter = new OrdersTableAdapter();
SqlTransaction ordersAdapterTran = null;
SqlConnection ordersAdapterConn = null;
try
{
tableAdapConn = tableAdap.OpenConnection();
tableAdapTran = tableAdapConn.BeginTransaction();
ordersAdapterConn = ordersAdapter.OpenConnection();
ordersAdapterTran = ordersAdapterConn.BeginTransaction();
tableAdapTran.Commit();
}
catch (Exception)
{
tableAdapTran.Rollback();
}
finally
{
tableAdapConn.Close();
}
can anybody help me about this issue ?
Note : i don't want to use TransactionScope class.
thanks
modified on Tuesday, March 3, 2009 11:56 AM
|
|
|
|
|
I'm getting the error message:
Could not load type 'RCH.BL.EMR.PatientEmergencyContacts" from assembly 'BL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
Please bear in mind the reason this is annoying is because every other use of the same assembly BL.dll works perfectly fine and when I document that line the whole things work like clock work.
Any suggestions?
Code:
<br />
Governorates = new RCH.BL.Asclepius.JordanGovernorates().GetAllFromDB();<br />
PatientNationality = new RCH.BL.Asclepius.Nationality().GetAllFromDB();<br />
NumberFormats = new RCH.BL.Asclepius.NumberFormat().GetAllFromDB();<br />
InformationType = new RCH.BL.Asclepius.ContactInformationType().GetAllFromDB();<br />
PatientRateOfStay = new RCH.BL.Accounting.RateOfStay().GetAllFromDB();<br />
EmergencyContactsBL = new RCH.BL.EMR.PatientEmergencyContacts();
|
|
|
|
|
Not much of a suggestion, more wondering why that line breaks the chain.
EmergencyContactsBL = new RCH.BL.EMR.PatientEmergencyContacts().GetAllFromDB(); Shouldn't it read this?
I are troll
|
|
|
|
|
It was that. In fact, to be very precise it was this:
EmergencyContacts = new RCH.BL.EMR.PatientEmergencyContacts().GetAllFromDB();
Out of frustration, I decided to create a BL object and from there carry on, but no go.
|
|
|
|
|
|
Eddy Vluggen wrote: Good hunting
Thanks but I've spent nearly 3 hours and rebooted twice before posting. I'll go and get the hammer...
|
|
|
|
|
Is there any InnerException?
Do you do anything "funky" in the constructor for PatientEmergencyContacts ?
|
|
|
|
|
No exceptions. The moment the load forms (and I found this out by stepping into it) it crashes. The class has an empty constructor.
|
|
|
|
|
Is the assembly GAC'ed? It may have an older version GAC'ed
If this is web app, check temporary asp.net folder if they have the right version.
Yusuf
|
|
|
|
|
No to both and I've manually deleted the bin folder's contents and rebuilt it again but still.
|
|
|
|
|
Brutal!
Last time I'd reference related issue, I was pulling my hair. Finally decided to so system wide search for the assembly and see how many places I can find it. In my case, it turned out to be I'd multiple versions scattered in few places. This was a project I inherited.
Did you search the system where for the assembly? This is brute force and tedious but it may unearth a clue.
Yusuf
|
|
|
|
|
I'll do that but I fail to see how this might be an issue since both projects are part of the same solution.
|
|
|
|
|
Found it.
I have 23 projects so to economize, I unload the ones I'm not working on. Guess what? Loading them, cleaning, rebuilding got things working again 
|
|
|
|
|
So, other projects were referencing the same assembly? this means VS was loading older version of the assembly via other projects. When you rebuild them, they all synchronized.
As my former colleague would say, when you get a problem, first thing do "Clean and rebuild ALL projects"
Yusuf
|
|
|
|
|
Hi all,
I need help with control events. In this specific case I have a panel with another control inside in a Dock.Fill mode.
Now i need to catch the mouse_click event of the panel... Maybe this is a stupid question but I don't know how can I resolve it
Please help me.
Thanks in advance
Cliffer
|
|
|
|
|
You cannot catch mouse click event because you cannot click on the panel. In Dock.Fill mode, your control covers the entire panel. You may catch the click event in the control and pass it to the panel.
Calin
|
|
|
|
|
How do I actually do that?
I tried to call one control's event (forgot which one but that shouldn't matter) and call it inside another control's click event.
Yet the only thing I know how to do is to add a new EventHandler to a control's events and then add some code for it, but not how to call a event without the user explicitly triggering it.
modified on Friday, March 6, 2009 6:01 AM
|
|
|
|
|
Hi All,
I posted this over on the VS forum yesterday but I've not had any reply so I thought I'd try here today.
I'm having real troubles tracking down a referencing problem.
I have been incorporating a new version of one of our DLLs into a client application. When running the application it blows up complaining about not being able to find the old version of one of our DLLs.
The DLL throwing the error has been updated/rebuilt to reference the new DLL as have all the DLLs this DLL references. I've checked the .csproj file and the reference in there is correct.
Running the whole application through NDepend displays a warning on this DLL and Reflector shows this DLL as referencing both versions (which I didn't think was possible!) ...
None of the DLLs have been GAC'd either so its not getting a reference this way.
I've never seen anything like this, I'm totally at a loss as to how this DLL is getting a reference to the old version.
Does anyone have some tips on how to track this rogue reference down?
Cheers,
|
|
|
|
|
Did you try using Fuslogvw[^] ?
To fix the problem try adding a Probing private path See here[^]
Hope this helps.
|
|
|
|
|
Hi Chap,
Indeed I've been using Fuslogvw today with no luck ...
I'll have a look at this Probing path jobby ... thanks!
Cheers,
|
|
|
|
|
Jammer wrote: The DLL throwing the error has been updated/rebuilt to reference the new DLL as have all the DLLs this DLL references. I've checked the .csproj file and the reference in there is correct.
Referencing is what Visual Studio does to build your project, at runtime it's all in the manifest.
|
|
|
|
|
Indeed. The problem has now been fixed. It was a rogue dll in the referencing folder.
The app I'm building is a CAL WPF app so its all decoupled and spread over many solutions meaning that there is more leg work in terms of ensuring that all the references are as they should be.
|
|
|
|
|
Hi there,
I have created an .xsd schema which I want to include in my project (Windows Service). First question is: what is the best way to include it? as a resource? or just by doing "Add existing item"? what is the difference(if any)?
So far, I have added it as a resource (jobs.xsd). Ok, so now I want to validate an xml file, thus I am trying to do as follows:
1. XmlSchemaSet xss = new XmlSchemaSet();
2.
3. xss.Add("http://www.w3.org/2001/XMLSchema",ClassLibrary1.Properties.Resources.jobs);
4. XmlReaderSettings settings = new XmlReaderSettings();
5. settings.ValidationType = ValidationType.Schema;
6. settings.Schemas = xss;
7. settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
8.
9. XmlReader reader = XmlReader.Create(xmlPath, settings);
10.
11. while (reader.Read()){};
This code breaks on line 3, with a System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.Path.GetFullPath(String path)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, String schemaUri)
at ClassLibrary1.ReadXml.ValidateXMLAgainstXSD(String xmlPath) in c:\myproj\ClassLibrary1\GetXml.cs:line 95}
How could I get around this problem?
Cheers
modified on Tuesday, March 3, 2009 6:57 AM
|
|
|
|