|
Greetings,
I wanna make a form that is used to search for something in a database and I wanna make it as a general search from, means I wanna use it with all project forms each one appear different data and dealing with different table in the database, this is not the case, the case is, I will call that search form from another one. I made a constructour which take 3 arguments when called that define the table name on which the search will be made the selection/condition columns in that search form so when I make an instance from another form I pass to that instance the specified arguments and on the search form I made fields that are of the same type as the arguments so when the instance is made it initialize those fields which will be used by the method of search when that form comes in action. I wanna provide the user with options to search by name or by code and of course, with each choice the selection/condition columns will be changed one with the other, and this is my case now. For example, I have a form that displays, saves, deletes records of resources in the factory I will, when clicking mouse right button, make a search form instance.
(searchform) [instance] = new searchform(argTable, argSelectionCol, argConditionCol);
call the search form [instance].show();
So I will give it the table but in the search form itself I wanna make a code/name selection choice for searching process and that will not apply as I already passed, when I made the instance, the selection/condition column.
I wanna know how to made such form and if anyone have another better way/idea about makng such search form based on my requirement I described above I will be grateful for that
Sorry about so lengthy
|
|
|
|
|
This is my search form code if any one have a better way to tell it to me.
Note: There might be some arabic words clearly show in MessageBox.Show() methods
public partial class FrmFind : Form
{
string seacrhChoice = "";
// Create a Connection String
string connectionString = @"Data Source=TOSHIBA-PC;Initial Catalog=smart2012;User ID=sa;
Password=Str0ngP@ssw0rd;Integrated Security=True";
private string tableName;
private string returnTableField
{
set { tableName = value; }
get { return tableName; }
}
private string column1;
private string returnColumn1
{
set { column1 = value; }
get { return column1; }
}
private string column2;
private string returnColumn2
{
set { column2 = value; }
get { return column2; }
}
public FrmFind()
{
InitializeComponent();
}
public FrmFind(string table, string argColumn1, string argColumn2)
{
InitializeComponent();
returnTableField = table;
returnColumn1 = argColumn1;
returnColumn2 = argColumn2;
} // end of 3 args constructor
bool validateUserEntry()
{
if (seacrhChoice == "")
{
MessageBox.Show("من فضلك اختر احدى اختيارات البحث");
radioButton1.Focus();
return false;
} // end of if
else if (findValueTextBox.Text.ToString().Trim() == "")
{
MessageBox.Show("من فضلك ادخل قيمة البحث المراد الأستعلام عنها");
findValueTextBox.Focus();
return false;
} // end of esle if
else
{
return true;
} // end of else
}
void search(string findValue)
{
bool validateUserEntryResult = validateUserEntry();
if(validateUserEntryResult == true)
{
string cmdString = "";
// Creat new Connection
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = connectionString;
if (seacrhChoice == "كود")
cmdString = @"SELECT " + returnColumn2 + " FROM " + returnTableField + " WHERE (" + returnColumn1 + "=@Param1)";
else
cmdString = @"SELECT " + returnColumn1 + " FROM " + returnTableField + " WHERE (" + returnColumn2 + "=@Param1)";
// Create the SELECT Command.
SqlCommand cmd = new SqlCommand();
cmd.CommandText = cmdString;
cmd.Connection = sqlConnection;
if (seacrhChoice == "كود")
cmd.Parameters.Add("@Param1", SqlDbType.Int).Value = findValue;
else
cmd.Parameters.Add("@Param1", SqlDbType.NVarChar).Value = findValue;
try
{
// Open Connection
sqlConnection.Open();
if (sqlConnection.State != ConnectionState.Open)
{
MessageBox.Show("فشل فى الأتصال بقاعدة البيانات");
} // end of if
else
{
findResultDataGridView.Rows.Clear();
findResultDataGridView.Rows.Add(99);
SqlDataReader dataReader = cmd.ExecuteReader();
int row = 0;
// Execute Read Query
while (dataReader.Read())
{
findResultDataGridView[0, row].Value = dataReader[0].ToString();
row++;
}
// Release all resources used by dataReader and close it.
dataReader.Dispose();
dataReader.Close();
// Close Connection
sqlConnection.Close();
sqlConnection.Dispose();
} // end of else
} // end of try
catch
{
findValueTextBox.Text = "";
} // end of catch
} // end of if
} // end of search()
private void findValueTextBox_Leave(object sender, EventArgs e)
{
search(findValueTextBox.Text);
} // end of findValueTextBox_Leave
private void radioButton1_Click(object sender, EventArgs e)
{
seacrhChoice = "كود";
findValueTextBox.Text = "";
findResultDataGridView.Rows.Clear();
findValueTextBox.ReadOnly = false;
} // end of radioButton1_Click
private void radioButton2_Click(object sender, EventArgs e)
{
seacrhChoice = "اسم";
findValueTextBox.Text = "";
findResultDataGridView.Rows.Clear();
findValueTextBox.ReadOnly = false;
} // end of radioButton2_Click
private void FrmFind_Load(object sender, EventArgs e)
{
// Creates and initializes the CultureInfo which uses the international sort.
System.Globalization.CultureInfo typeOFLanguage = new System.Globalization.CultureInfo("ar-eg");
// Gets the current input language
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(typeOFLanguage);
findResultDataGridView.Rows.Add(99);
} // end of FrmFind_Load
} // end of public partial class FrmFind : Form
2 problems I have also in that form:
The search method checks for a radio button selection & a search value insertion so first problem is by calling the method validateUserEntry(), however, here comes the problem on the form load the textbox always gets focused and when trying to check a radio button that cause a leave event to the textbox which mean calling the search method which, in turn, call the validateUserEntry() and here is the disaster as I did not select the radio button it message me with error because of not selecting a radio button, and return message me again asking for the search value of the textbox.
Sorry again about so lenghty but trying to explain exactly what the problem is...
|
|
|
|
|
Please use <pre> tags around your code so that it is a little bit more readable.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
Hello,
how can i convert the large files that exceed 2GB in the binary table, I use byte [] data = File.ReadAllBytes (path); and i have exception.
There are another way? thank you very much.
|
|
|
|
|
Stream it rather than attempting to read it all at one time.
|
|
|
|
|
As previously stated, streaming is probably the only way, unless you want to manually read chunks of the file.
.NET has a limit on the maximum size of any one object of 2GB - so no string or array of bytes can exceed this. If you want to read a file bigger than this limit, you have to work in chunks, you cannot read it into any single object in it's entirety.
It should be possible to declare an array like type that provides this chunking, and hides the stream or whatever from the main code. In fact there is an example of this on MSDN: http://msdn.microsoft.com/en-us/library/aa288465(v=vs.71).aspx[^] although their method does seem somewhat inefficient, and I would probably cache a block of data if I did it. Depends on how random-access your data is!
[edit]Typo: "there" for "their" - OriginalGriff[/edit]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi guys, I don't post much, but I seem to be too dense to grasp Lambda expressions fully.
This is the function and logic I'm trying to modify:
static Expression<Func<KnownFields, bool>> GetPredicate(IEnumerable<string> symbols) {
var par = Expression.Parameter(typeof(KnownFields), "row");
var condition = symbols.Select(x => Expression.Equal(Expression.Field(par, "Symbol"), Expression.Constant(x)))
.Aggregate((x, y) => Expression.OrElse(x, y));
return Expression.Lambda<Func<KnownFields, bool>>(condition, par);
}
It is used here. Where GetData takes expressions :
var symbols = new[] { "/AAA", "/BBB" };
var predicate = GetPredicate(symbols);
connection.GetData().Where(predicate).Select(selector);
What I am trying to do is modify the condition, so that each "Symbol" has a corresponding "Date" value to match in the condition. The condition would end up like:
where (row.Symbol == symbol1 && row.Date == date1) || (row.Symbol == symbol2 && row.Date == date2) || () || () ...
Believe me I didn't run to post a question the second I got stuck. Thanks preemptively for all the help.
[EDIT]
I think I got it now. Will post solution later depending on when I have time.
modified 18-Apr-12 14:22pm.
|
|
|
|
|
Through code i need to mimic the click of a desktop shortcut.
I know that in the properties of the shortcut it has the directory of which it is relevant to but this isnt what im after. Any ideas?
|
|
|
|
|
MitchG92_24 wrote: i need to mimic the click of a desktop shortcut.
What do you mean exactly, do you wish to launch the application referred to? Will you know in advance which shortcut you are accessing?
MitchG92_24 wrote: I know that in the properties of the shortcut it has the directory of which it is relevant to but this isnt what im after. Any ideas?
No, perhaps you could explain what you are after.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
|
MitchG92_24 wrote: The desktop icon i am looking for is pre determined so will be hard-coded.
How do you hard code an icon?
MitchG92_24 wrote: I am running code to mimic the user configuring a computer
What has this to do with your question?
MitchG92_24 wrote: so i need to double click the icon or select that icon rather than running a process.
You still have not explained what your application is trying to do. Are you trying to run some program based on a shortcut on the user's desktop? Are you trying to get information from the shortcut to do something else? Will this be run in a separate process ... etc.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
MitchG92_24 wrote: Through code i need to mimic the click of a desktop shortcut.
That's a description that a manager would give.. Ask the user why the shortcut needs to be clicked (ie, what does it do, and what does the user try to achieve?)
So, you need to execute the app that the shortcut points to. That means reading the shortcut, finding out what it points to, and execute that.
There's no generic way of clicking on the desktop. Yes, you can simulate a mouse-click, but chances are huge that users move their icons around. It's either that, or installing AutoHotKey[^].
Bastard Programmer from Hell
|
|
|
|
|
Please don't remove messages in a thread, it prevents other people from following it - and, who knows, one of them may be able to give some useful feedback.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Hi,
I'm using webservices in my project and specified the webservice location in application configuration file. Issue is when I modify service location in app.config file, its not updating the Settings.settings file(in properties folder) and I couldn't able to call the service methods. Its updating only when I double click on the Settings.settings file.
Please guide me to solve this issue without double click on Settings.settings file.
Thanks in advance
|
|
|
|
|
Your settings-class has a Save method. I suggest you call it when you want to persist any changes in the settings.
Bastard Programmer from Hell
|
|
|
|
|
I tried with the below code to save settings . But its not working.
Properties.Settings setting = Properties.Settings.Default;
setting.Save();
|
|
|
|
|
BradNorthA wrote: But its not working
It's working for me.
What does "it's not working" mean? Does it throw an error? Does it not update the settings in the settings file of the IDE (as designed)? Do you get old or new values if you Reload the settings file?
Bastard Programmer from Hell
|
|
|
|
|
It didn't throw any error. its not updating the new values of app.config file.
|
|
|
|
|
Where are you verifying these new values? Are you looking in the app.config file that's part of your solution? It won't update the *default* values
Save, then Reload, then verify. Using code, not using the IDE.
Bastard Programmer from Hell
|
|
|
|
|
My app.config contains the below settings.
<applicationSettings>
<LibClient.Properties.Settings>
<setting name="LibClient_WebReference_CRService" serializeAs="String">
<value>http:
</setting>
</LibClient.Properties.Settings>
</applicationSettings>
I changed the port value in given url. like http://localhost:8080/TestService/services/TestService.TestServiceHttpSoap11Endpoint
When I run the code it is using old port value 8888 not 8080.
Because settings file was not updated with the new value 8080
Hope you understood the issue. I just have to update the settings whenever the config file gets changed. I tried with the below code in my class constructor as suggested by you. Still its not updating.
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
|
|
|
|
|
BradNorthA wrote: Hope you understood the issue. I just have to update the settings whenever the config file gets changed. I tried with the below code in my class constructor as suggested by you. Still its not updating.
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
That's how we do it in WinForms, and it saves the file locally. I just glanced at the documentation for ASP.NET, seems like they use a web.config; so I'm guessing that's something different.
Check if the settings-file that's in the Debug-folder is *not* readonly. Alternatively, store it in a XML file under your direct control (as opposed to relying on the generated stuff).
Bastard Programmer from Hell
|
|
|
|
|
Help Me Out . . . !
A distance calculator ... Or From Google How could I Add Service ....[Solution ....]
Jimmy
|
|
|
|
|
start Google Maps API[^]
Expecting people to provide... being too lazy to type... is unrealistic.
"You get that on the big jobs."
|
|
|
|
|
We are not here to ... Chris Maunder wrote: be surrogates for doing one's own research.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|