|
And what is the problem?
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
using System;
using System.IO;
namespace MyApplication
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
if(File.Exists("output.txt"))
{
File.Delete("output.txt");
}
StreamReader streamReader = new StreamReader("input.txt");
StreamWriter streamWriter = new StreamWriter("output.txt");
while(true)
{
try
{
string[] texts = streamReader.ReadLine().Split(' ');
int[] numbers = new int[texts.Length];
for(int i = 0; i < texts.Length; i++)
{
numbers[i] = Int32.Parse(texts[i]);
}
Array.Sort(numbers);
string newString = "";
for(int i = 0; i < numbers.Length; i++)
{
newString += numbers[i].ToString();
if(i != numbers.Length - 1)
{
newString += " ";
}
}
streamWriter.WriteLine(newString);
}
catch
{
break;
}
}
streamReader.Close();
streamWriter.Close();
}
}
}
|
|
|
|
|
I'm trying to get the document properties: Title, Author, etc of a document. I can find great documentation on Microsoft Office documents, but I need to do it for all documents. I think the solution will use the MODI library. Any help is greatly appreciated.
|
|
|
|
|
I'm in the process of building my first n-tier software package. However I'm kind of stuck on a design decision. I posted in the C# forum since this is the language I am using, however the responses will most likely be algorithmic and language agnostic.
So here is the issue (VERY basic) I'm sure...
Each user needs to be logged into the program in order to use it. I'm going to use a basic username/password authentication scheme however, how would I implement this? I've never done anything like this before and I am not a professional. My first idea was to keep a SQL2005 table of users with information for each user such as password and other personal information. I was going to use SqlCommand() to do a select query where the username and password match on a character by character basis. Is this the best, or at least an "ok" way to do this? How is authentication "normally" implemented using .NET?
Thanks,
John
|
|
|
|
|
I am not sure I would say anything is the normal way.
Username/Password is common, but never store or send the password in clear text. Encrypt it in some way, MD5 hash is common but can be broken (as most methods can be. Another option is if all machines are on the same domain. Use windows authentication, this fails if users leave and do not password lock their machines however. In some cases I have also read machine information (mac address, etc.) and allow user X to only come via machine y. Depends on what you are looking for.
In any event, along with the username/password fields have fields for last login time/date and number of login failures. If unused for x days, lock the account or if x unsuccessful attempts also lock the account.
"Every new day begins with possibilities. It's up to us to fill it with things that move us toward progress and peace.” (Ronald Reagan)
|
|
|
|
|
|
Why not just require they log into their Windows account and assume they are therefore authenticated?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
I have a ListBox bound to a DataTable in a Win Form (DataTable populated from a MS Access database). I want the user to be able to change the position of the items in the ListBox and then save back to database in the updated order (or maybe tagged for a sort order).
Would the first step of resorting the items in the ListBox be to change the order of the rows in the DataTable? If so, how would this be done?
Would the second step (saving the list back to the database file), be to delete all rows in the MS Access table and then Insert the complete updated DataSet (achieving the correct order)?
Or, should I be adding a new column like "SortOrder" and populating this with the ListBox's index numbering? I guess this column (for all rows) would have to be updated every time an item is moved or deleted in the ListBox(DataTable).
Any ideas on how to work this out would be appreciated.
Ron
|
|
|
|
|
myNameIsRon wrote: Or, should I be adding a new column like "SortOrder" and populating this with the ListBox's index numbering? I guess this column (for all rows) would have to be updated every time an item is moved or deleted in the ListBox(DataTable).
That sounds like the way to go. Since the list is bound, you can't really mess around with the order that the items appear, unless you change the sort order. Also, when storing rows in the DB you should not depend on the physical order of the rows to preserve the sort order. Keeping that information in a separate column is the best way to keep track it.
Josh
-- modified at 7:30 Tuesday 2nd May, 2006
|
|
|
|
|
Thanks Josh!
Ya, you don't really want to muck with the original ID's.
Ron
|
|
|
|
|
I am experimenting with the datagrid and have not found two issues (they are related so if I find one, I may have a working solution.)
One is I can not find what keydown event I need to handle to capture the arrow keys. The left and right arrows are events in the individual cells if you are moving the cursor along the characters (in a textbox) but the up and down or the left and right are not captured when moving which cell is selected. They are also not key events of the datagrid. What item/component are the arrow key down events associated with?
Alternately I could handle the current cell changing and keep track of the last and next cells. For then moving over a row I do not want selected I can set the selected row by using the datagrid.CurrentRowIndex. Which works fine for rows, but I find no equivalent for columns. Any suggestions on setting the current column?
Thanks for the help. Here is my sample dialg box code if any one can make use of the handling I have so far.
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace TestDlg<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Button PressMe;<br />
private System.Windows.Forms.DataGrid m_dataGrid;<br />
private System.Data.DataSet m_dataSet;<br />
private System.Data.DataTable m_dataTable;<br />
<br />
private System.Windows.Forms.DataGridCell m_CurCell;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
m_dataTable = new DataTable("test");<br />
m_dataTable.Columns.Add("Name");<br />
m_dataTable.Columns.Add("Col-1");<br />
m_dataTable.Columns.Add("Col-2");<br />
this.SetTableStyle(m_dataGrid,m_dataTable);<br />
<br />
string[] row = new string[3] {"R-name","11111","22222"};<br />
<br />
m_dataTable.Rows.Add(row);<br />
m_dataTable.Rows.Add(row);<br />
m_dataTable.Rows.Add(row);<br />
m_dataTable.Rows.Add(row);<br />
m_dataTable.Rows.Add(row);<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.PressMe = new System.Windows.Forms.Button();<br />
this.m_dataGrid = new System.Windows.Forms.DataGrid();<br />
((System.ComponentModel.ISupportInitialize)(this.m_dataGrid)).BeginInit();<br />
this.SuspendLayout();<br />
this.PressMe.Location = new System.Drawing.Point(608, 24);<br />
this.PressMe.Name = "PressMe";<br />
this.PressMe.Size = new System.Drawing.Size(80, 64);<br />
this.PressMe.TabIndex = 0;<br />
this.PressMe.Text = "PressMe";<br />
this.m_dataGrid.DataMember = "";<br />
this.m_dataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;<br />
this.m_dataGrid.Location = new System.Drawing.Point(16, 16);<br />
this.m_dataGrid.Name = "m_dataGrid";<br />
this.m_dataGrid.Size = new System.Drawing.Size(552, 312);<br />
this.m_dataGrid.TabIndex = 1;<br />
this.m_dataGrid.KeyDown += new System.Windows.Forms.KeyEventHandler(this.m_dataGrid_KeyDown);<br />
this.m_dataGrid.MouseDown += new System.Windows.Forms.MouseEventHandler(this.m_dataGrid_MouseDown);<br />
this.m_dataGrid.Click += new System.EventHandler(this.m_dataGrid_Click);<br />
this.m_dataGrid.CurrentCellChanged += new System.EventHandler(this.m_dataGrid_CurrentCellChanged);<br />
<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(696, 341);<br />
this.Controls.Add(this.m_dataGrid);<br />
this.Controls.Add(this.PressMe);<br />
this.Name = "Form1";<br />
this.Text = "TestDlg";<br />
((System.ComponentModel.ISupportInitialize)(this.m_dataGrid)).EndInit();<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
private void SetTableStyle(DataGrid dg, DataTable dt)<br />
{<br />
try<br />
{<br />
DataGridTableStyle ts = new DataGridTableStyle();<br />
ts.HeaderForeColor = Color.Black; <br />
ts.HeaderFont = new Font("Verdana", (float)8.25); <br />
ts.MappingName = dt.TableName;<br />
ts.BackColor = Color.Linen;<br />
ts.AlternatingBackColor = Color.Aquamarine;<br />
<br />
DataGridColumnStyle cs;<br />
DataGridTextBoxColumn tbc;<br />
<br />
foreach (System.Data.DataColumn col in dt.Columns)<br />
{<br />
if(col.ColumnName.CompareTo("Name")==0)<br />
{<br />
cs = new DataGridTextBoxColumn();<br />
tbc = (DataGridTextBoxColumn) cs;<br />
cs.ReadOnly=true;<br />
}<br />
else if(col.DataType.ToString().CompareTo("System.String")==0)<br />
{<br />
cs = new DataGridTextBoxColumn();<br />
tbc = (DataGridTextBoxColumn) cs;<br />
tbc.TextBox.KeyDown += new KeyEventHandler(m_curCell_KeyDown);<br />
tbc.TextBox.MouseDown += new MouseEventHandler(m_curCell_MouseDown);<br />
tbc.TextBox.Click += new EventHandler(m_curCell_Click);<br />
}<br />
else if(col.DataType.ToString().CompareTo(DbType.Boolean.ToString())==0)<br />
{<br />
cs = new DataGridBoolColumn();<br />
((DataGridBoolColumn)cs).AllowNull = false;<br />
}<br />
else <br />
{<br />
cs = new DataGridTextBoxColumn();<br />
tbc = (DataGridTextBoxColumn) cs;<br />
}<br />
cs.HeaderText = col.ColumnName;<br />
cs.MappingName = col.ColumnName;<br />
ts.GridColumnStyles.Add(cs);<br />
if(col.ColumnName.CompareTo("Name")==0) cs.ReadOnly=true;<br />
}<br />
<br />
dg.TableStyles.Clear();<br />
dg.TableStyles.Add(ts);<br />
dg.DataSource = dt;<br />
<br />
}<br />
catch ( Exception e )<br />
{<br />
throw e;<br />
}<br />
}<br />
<br />
<br />
private void m_dataGrid_Click(object sender, System.EventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
}<br />
<br />
private void m_dataGrid_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
}<br />
<br />
private void m_dataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
}<br />
<br />
private void m_dataGrid_CurrentCellChanged(object sender, System.EventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
curr = m_dataGrid.CurrentCell.RowNumber;<br />
if(curr==0) m_dataGrid.CurrentRowIndex = 1;<br />
int curc = m_dataGrid.CurrentCell.ColumnNumber;<br />
<br />
m_CurCell = m_dataGrid.CurrentCell;<br />
}<br />
<br />
private void m_curCell_Click(object sender, System.EventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
<br />
}<br />
<br />
private void m_curCell_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
}<br />
<br />
private void m_curCell_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
int curr = m_dataGrid.CurrentRowIndex;<br />
<br />
}<br />
<br />
<br />
}<br />
}
"Every new day begins with possibilities. It's up to us to fill it with things that move us toward progress and peace.” (Ronald Reagan)
|
|
|
|
|
Okay, this may sound silly but I've never had to create a DLL in c# until now. I've written a C# dialog app and I want to run some crystal reports from a dll. So can someone point me to a tutorial that shows how to create dll's and how to call them from my C# app? Oh and in my dll I will need to pop up a dialog showing the report in it. Is this doable? I've done it plenty times in MFC.
Thanks
Tom Wright
tawright915@yahoo.com
-- modified at 18:12 Monday 1st May, 2006
|
|
|
|
|
If you need Win32 dll - you can't create it in c#. You have to make it in c++ or any other native language. About using Win32 dlls from c# - search for Platform Invoke (p/invoke). This can be useful, for example
If you need .net dll - just set in project properties, on Application tab, "output type" property to "Class library".
Using .net dlls on design-time is very easy - add reference to needed dll and use it through Namespace.Class.Function system. For example, if your dll contains function ShowReport() in class Report in namespace MyReportNamespace, you just have to call for MyReportNamespace.Report.ShowReport().
About showing dialog - I don't know what about CrystalReport, but I've used a lot of forms, called from dlls.
____________________________________________
Robin Panther http://www.robinland.com
|
|
|
|
|
I've tried to use this method just as I see it after Googling every way I can find, and the usage is all the same:
string strCompressed = PassportIdentity.Compress(strToCompress);
But when I try to use it, I get an exception: "Unable to load dll (aspnet_isapi.dll)". I added a reference to System.Web and a using directive for System.Web.Security, and it just won't work. Any clues as to what I'm screwing up?
My Music | My Pics | My Articles
BlackDice
|
|
|
|
|
1) Are you trying to use it in ASP.NET with Microsoft IIS installed?
2) How are you trying to use it?
--
I've killed again, haven't I?
|
|
|
|
|
I've found out I'm using the wrong thing. What I need to use is System.IO.Compression to achieve what I'm trying to do (compress a long string that is sent both ways from client and server using sockets on specific ports)
My Music | My Pics | My Articles
BlackDice
|
|
|
|
|
Long time Java programmer running into a C# issue I can not figure out.
I have a class that contains a List. Other classes need iterate through the list. What I have below is not working. I get an excpetion at runtime about Current being outofRange.
Should I just return an Enumerator from the List or is there a way to do it like this that I'm missing.
thanks for the help.
Class Foo<br />
{<br />
List<Bar> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator : IEnumerator<br />
{<br />
protected int lastVisited;<br />
<br />
public FooIterator ()<br />
{<br />
lastVisited = -1;<br />
<br />
}<br />
<br />
#region IEnumerator Members<br />
<br />
public object Current<br />
{<br />
get<br />
{<br />
<br />
return list[lastVisited].thisBar;<br />
<br />
}<br />
}<br />
<br />
public bool MoveNext()<br />
{<br />
return ++lastVisited < list.Count - 1;<br />
}<br />
<br />
public void Reset()<br />
{<br />
throw new Exception("The method or operation is not implemented.");<br />
}<br />
<br />
#endregion<br />
}<br />
}<br />
<br />
}
|
|
|
|
|
You might as well just return the List's enumerator (accessed via GetEnumerator()) if you are not doing any special/custom processing in your enumerator.
Josh
|
|
|
|
|
Just tried this and got an InvalidOperationException saying that the enumeration has either not started or finished.
|
|
|
|
|
looks like you get an error when lastVisited is -1.
Probably you have to do something like this:
public object Current<br />
{<br />
get<br />
{<br />
if (lastVisited == -1) return null;<br />
return list[lastVisited].thisBar;<br />
}<br />
}
____________________________________________
Robin Panther http://www.robinland.com
|
|
|
|
|
Tried this but did not work. See following post for why and a new question.
|
|
|
|
|
I think I figured out why I'm having the problem but I still can not figure a way around it yet.
FooIterator in an inner class so it can only acess list if list is a static attribute. So I made changes like so:
<br />
<br />
public object Current<br />
{<br />
get<br />
{<br />
<br />
return Foo.list[lastVisited].thisBar;<br />
<br />
}<br />
But when checking the degugger, when I load Foo.list is is fine. When I access it via the Iterator inner class it is empty.
I tried to get rid of the inner class and return the static list and that did not work.
What I need to do is immitate the Java Iterator but this seems impossible because of the static attribute contrate on inner classes.
|
|
|
|
|
The problem is more complex than I wrote here but I will show my solution to this problem.
Here is what we had.
Class Foo<br />
{<br />
protected static List<T> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator : IEnumerator<br />
{<br />
protected int lastVisited;<br />
<br />
public FooIterator ()<br />
{<br />
lastVisited = -1;<br />
<br />
more enumeration code....<br />
}
The FooIterator was neede by other class to enumerate through the List<>. The inner class was not working because the List has to be static.
Class Bar is an object that contains 2 other objects.
Here is the change:
Class Foo<br />
{<br />
protected List<Bar> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator <br />
{<br />
private List<Bar> list;<br />
public FooIterator (List<Bar> anotherList)<br />
{<br />
list = anotherList;<br />
}<br />
public IEnumerator<FeFiFoe> GetEnumerator()<br />
{<br />
foreach (Bar b in list)<br />
{<br />
yield return b.thisFeFiFoe;<br />
<br />
}<br />
}<br />
<br />
}
Hope this helps someone else.
|
|
|
|
|
I have an ActiveX control that is wrapped as an AxHost class. It draws an image when certain properties are input to it. Is there any way that I could draw that control to an image instead of on a form? I tried using this:
<br />
using System;<br />
using System.Drawing;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
public class ControlPainter<br />
{<br />
private const int<br />
WM_PRINT = 0x317, PRF_CLIENT = 4,<br />
PRF_CHILDREN = 0x10, PRF_NON_CLIENT = 2,<br />
COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;<br />
<br />
[DllImport("USER32.DLL")]<br />
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);<br />
<br />
public static void PaintControl(Graphics graphics, Control control)<br />
{
IntPtr hWnd = control.Handle;<br />
IntPtr hDC = graphics.GetHdc();<br />
SendMessage(hWnd, WM_PRINT, hDC, COMBINED_PRINTFLAGS);<br />
graphics.ReleaseHdc(hDC);<br />
}<br />
}<br />
and it paints everything besides the ActiveX control. Does anyone know how to do this?
|
|
|
|
|