|
I must admit, it was the only case I could think of where it was justified (and I racked my brain for maybe 20 seconds).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
It really all depends on several things but this should be the simplest way of breaking it down.
You would have to first order the check boxes with a system.
Example:
checkbox 1
checkbox 2
checkbox 3 checkbox 4
checkbox 5
checkbox 6
checkbox 7 checkbox 8
So as you see first you would have to visually see an order for the checkboxes.
This order can not change when you go thru your logic.
Next you return back to the good ole days and still used binary standard.
for each box in sequence you assign a 1 or a 0 to based off of if they are checked or not.
Now you parse your string accordingly to read each checkboxes value and you combine each check boxes value when writing the string to the sql server.
example (Continue):
Checkbox 1 = checked
Checkbox 2 = not checked
Checkbox 3 = checked
Checkbox 4 = checked
Checkbox 5 = not checked
Checkbox 6 = checked
Checkbox 7 = checked
Checkbox 8 = checked
Using the standard of 1 = Checked and 0 = Not Checked
you would have something like this to store the value to sql server:
string sqlvalueforfield = checkbox1.checked.tostring()+checkbox2.checked.tostring()+checkbox3.checked.tostring()+checkbox4.checked.tostring()+checkbox5.checked.tostring()+checkbox6.checked.tostring()+checkbox7.checked.tostring()+checkbox8.checked.tostring()
then to retrieve the value back to the form
checkbox3.checked = Cint(sqlvalueforfield.Substring(3,1))
let me know if this helps....
|
|
|
|
|
Hey you beat me to the punch
var question = (_2b || !(_2b));
|
|
|
|
|
YEA I win. now if I could get help on my issue of retreiving a image from sql server....
but anyway... PLEASE Understand Really bad idea.
|
|
|
|
|
While technically possible, this is a REALLY bad idea.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Provided, your checkboxlist always looks the same, i.e. it has the same number of checkboxes and they are indexed the same way, if you use a varchar field to store a string of numbers, something like "101100101",
you can then use a stringbuilder to create your string iterating through the collection of your checkboxes.
If the checkbox is checked, set the value to one and zero if it's unchecked.
I do agree that this is not the greatest of designs, but it might just make do.
Another way to do it would be to use an Xml field (provided your using Sql Server), and store the values in there.
var question = (_2b || !(_2b));
|
|
|
|
|
I have done this in the past and I don't see anything wrong with it provided the data values are directly related to one another.
[Serializable(), Flags()]
public enum DayBitFlag
{
None = 0,
Sunday = 1,
Monday = 2,
Tuesday = 4,
Wednesday = 8,
Thursday = 16,
Friday = 32,
Saturday = 64
}
Then create a class that inherits CheckBox, something like this:
public class DayCheckBox : CheckBox
{
private DayBitFlag _dayValue;
public DayBitFlag DayValue
{
get { return _dayValue; }
set { _dayValue = value; }
}
}
I am sure you can work the rest out from here.
Adam
|
|
|
|
|
Thank u
|
|
|
|
|
I am able to store my pictures into the sql server using the following code:
private void pictureBox3_DoubleClick(object sender, EventArgs e)
{
intASUserListSelectedIndex = lbxAssistSuiteUserList.SelectedIndex;
bool FoundUser = false;
FileDialog fldlg = new OpenFileDialog();
//specify your own initial directory
if (lbxAssistSuiteUserList.SelectedIndex > -1)
{
try
{
fldlg.InitialDirectory = @":C\";
//this will allow only those\ file extensions to be added
fldlg.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif|(*.gif)|*.gif|(*.jpg)|*.jpg|(*.jpeg)|*.jpeg|(*.bmp)|*.bmp|(*.wmf)|*.wmf|(*.png)|*.png";
//fldlg.ShowDialog();
if (fldlg.ShowDialog() == DialogResult.OK)
{
imagename = fldlg.FileName;
Bitmap newimg = new Bitmap(imagename);
pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox3.Image =(Image)newimg;
//pictureBox3.Image = System.Drawing.Image.FromFile(openFileDialog1.FileName);
pictureBox3.Refresh();
//Update the SQL Tables.
lbxAssistSuiteUserList.SelectedIndex = intASUserListSelectedIndex;
btnUpdateAssistUsers_Click(sender, e);
lbxAssistSuiteUserList.SelectedIndex = intASUserListSelectedIndex;
updatedata();
}
fldlg = null;
lbxAssistSuiteUserList.SelectedIndex = intASUserListSelectedIndex;
}
catch (System.ArgumentException ae)
{
imagename = " ";
MessageBox.Show(ae.Message.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
private void updatedata()
{
bool FoundMe = false;
int UserIndex = -1;
//use filestream object to read the image.
//read to the full length of image to a byte array.
//add this byte as an oracle parameter and insert it into database.
try
{
//proceed only when the image has a valid path
if (imagename != "")
{
FileStream fs;
fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read);
//a byte array to read the image
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
//open the database using odp.net and insert the data
string connstr = WhatIsMyConnectionString;
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
//Find the index
for (i = 0; i < ApplicationUsersArray.Count; i++)
{
if (((DomainUsersClass)ApplicationUsersArray[i]).WindowsLogonName == lbxAssistSuiteUserList.Items[lbxAssistSuiteUserList.SelectedIndex].ToString())
{
FoundMe = true;
break;
}
}
if (FoundMe = true)
{
UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);
}
else
{
MessageBox.Show("We have a serious problem. This should Never Happen. \n The Array did not find the correct users to grab their index for the Picture. \n The Application will now quit.");
Application.Exit();
Application.ExitThread();
}
string query;
query = "insert into tblApplicationUsersPic(id_image,pic) values(" +
UserIndex.ToString() + "," + " @pic)";
SqlParameter picparameter = new SqlParameter();
picparameter.SqlDbType = SqlDbType.Image;
picparameter.ParameterName = "pic";
picparameter.Value = picbyte;
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.Add(picparameter);
cmd.ExecuteNonQuery();
if (FoundMe = true)
{
SQLUpdate(WhatIsMyConnectionString, "tblApplicationUsers", "tblApplicationUsersPic_idx = (Select idx_tblApplicationUserPic from tblApplicationUsersPic where id_image = '" + UserIndex.ToString() + "') ","delflag = 0 and idx_tblApplicationUsers = '" + UserIndex.ToString() + "' ");
//UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);
}
MessageBox.Show("Image Added");
cmd.Dispose();
conn.Close();
conn.Dispose();
Connection();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Connection()
{
//connect to the database and table
//selecting all the columns
//adding the name column alone to the combobox
try
{
string connstr = WhatIsMyConnectionString;
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
empadap1 = new SqlDataAdapter();
empadap1.SelectCommand = new SqlCommand("SELECT * FROM tblApplicationUsersPic", conn);
dset = new DataSet("dset");
empadap1.Fill(dset);
DataTable dtable;
dtable = dset.Tables[0];
comboBox1.Items.Clear();
foreach (DataRow drow in dtable.Rows)
{
comboBox1.Items.Add(drow[0].ToString());
comboBox1.SelectedIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
But I am unable to retreive the picture from the Sql Server.
Here is my current code to retreive the picture, it keeps erroring saying I do not have something defined and when I define it it still does not work....
Here is the code I use to retreive the image from the database.
//Picture of the User
DataTable dataTable = dset.Tables[0];
if (pictureBox3.Image != null)
{
pictureBox3.Image.Dispose();
}
for (i = 0; i < ApplicationUsersArray.Count; i++)
{
if (((DomainUsersClass)ApplicationUsersArray[i]).WindowsLogonName == lbxAssistSuiteUserList.Items[lbxAssistSuiteUserList.SelectedIndex])
{
break;
}
}
if (((DomainUsersClass)ApplicationUsersArray[i]).PicIndex != "0" || ((DomainUsersClass)ApplicationUsersArray[i]).PicIndex != "")
{
try
{
//using filestream object write the column as bytes and store it as an image
FileStream FS1 = new FileStream("image.jpg", FileMode.Create);
foreach (DataRow dataRow in dataTable.Rows)
{
//if (dataRow[0].ToString() ==
byte[] blob = (byte[])dataRow[1];
FS1.Write(blob, 0, blob.Length);
FS1.Close();
FS1 = null;
pictureBox3.Image = Image.FromFile("image.jpg");
pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox3.Refresh();
}
}
catch
{
MessageBox.Show("Picture retrival Error");
ErrorLogWriter("We have a issue with retreiving the picture stored in the sql server table.");
}
}
|
|
|
|
|
It might help is you gave the error message (in full) simply saying that "it says something is not defined" doesn't help us to pin down the problem.
What is it that you have not defined?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I need a formula to calculate the difference in Hours and Minutes between two times.
Example: Table name = attandance and the fields that need to be calculated are:
[timein] = 1:15 PM
[timeout] = 1:44 PM.
I need the formula create a calculated field which equals 0:29.
I know the fomula that makes this work in Access (=HoursAndMinutes([Shipped]-[Picked]) but I need to write a Crystal report.
Thanks In Advance
|
|
|
|
|
I think that you will be wanting this.
<a href="http://weblogs.sqlteam.com/jeffs/archive/2007/08/29/SQL-Dates-and-Times.aspx">http://weblogs.sqlteam.com/jeffs/archive/2007/08/29/SQL-Dates-and-Times.aspx</a>[<a href="http://weblogs.sqlteam.com/jeffs/archive/2007/08/29/SQL-Dates-and-Times.aspx" target="_blank" title="New Window">^</a>]
From my limited knowledge crystal uses sql language and I believe this will explain how to subtract the 2 time stamps as a date time stamp...
The other way to go about this is to substring the field seperating the hours and minutes into variables and manually do the subtraction into the result.
|
|
|
|
|
this link is not working.
|
|
|
|
|
Hi all,
I am working on Medical transcription voice file format conversion. I need a help on This voice file (.DSS, .DSS2) to WMA or WAV file format conversion. Anybody have an idea feel free to post or share with me.
Thanks in Advance.
pandu
|
|
|
|
|
Hello, I just want to know if its possible to include the delimiter in the string output??
For example:
char[] delim = new char[] {';', ' '};
and the output:
for(int
x=0;
x<5;
x++)
Is there a way without using regex class?
|
|
|
|
|
See String.Split method.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I think you didn't understand what i mean..What i really want to say is if for example i have a semi-colon which is a delimiter, is it possible to still include the semicolon to the splitted string?
For example:
string str = "for(int x=0; x<5; x++) Console.WriteLine("Hello");
in the above example, i want to split the string using the delimiter semi-colon, but at the same time i want it to be included in the splitted string.
For example, instead of this output:
for(int
x=0
x<5
c++)
I want this kind of output:
for(int
x=0;
x<5;
x++)
If you'll notice the semicolon, which is a delimiter is also included in my desired output...Is this possible?
|
|
|
|
|
Good luck with for ( int x = 0 ; x < 5 ; x++ )
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Is there a way on how to ignore or delete the whitespace? I presume that using Trim() method wouldn't do the work.
|
|
|
|
|
The correct way to deal with all the problems you are going to encounter is to write a real lexer and parser.
You can choose not to, and implement some shortcuts; chances are someone will come up with a case you can't handle. Here is one example:
for (int i = 0; i < "this is not a for(; ; ) loop".Length; i++) {...}
proving you need to understand string literals to recognize a for statement.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: chances are someone will come up with a case you can't handle.
You're right about that. We'll be presenting our program next week and defend it like our real thesis. this is only a project that will apply data structures. And when i read about parsing there many ways on how to parse a statement. The one that I think will do our program done is the bottom - up parsing which uses a stack and a parse tree. Now the problem is i don't know where to get the pattern that i'll use to accomplish that. I think the best way is to somehow find a way on how to do that and state to our presentation the scope and limitations of our program.
And also since this is only a simple for loop parser, We can only have a one-line statement, meaning we don't have to include the two curly braces for a block statement.
|
|
|
|
|
gamer1127 wrote: Is there a way without using regex class?
Of course there is. Regex is a tool, a non-essential tool. Anything you can do with a Regex, you can do without Regex too. It will take more code, it may or may not be more readable, and chances are it will be faster without Regex. See this test[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Your right...hehehehe...Now I'm changing the codes on how to verify the entered string using data structures discussed by our professor (stack and tree). Since there is a Stack Collection in C# I think that would make the work a bit easier. Before I changed all the code(That was only yesterday) I was eager to use the Regex class since it has all that i need. But when I can't find a way on how to verify the entered string using Regex I started to look at the harder way which has a long code.
My only problem now is how to verify the entered string..I'm thinking of the way the infix to postfix works using stack. I think that is similar with what i'll be doing to do the job.
Ah..By the way...Can i use the regex class on splitting the strings only? Then apply the stack and parse tree in verifying the string?
|
|
|
|
|
gamer1127 wrote: Can i use the regex class on splitting the strings only?
Not really as my "not a for loop".Length example indicated.
Furthermore, most programming languages can be parsed by an "LALR" parser, meaning you have to backtrack only one token at most, hence you don't need to have all the input at once, which is fine for huge source files (on which a Regex would probably be very slow).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ok then...Can you suggest any good reading materials about parsing that can be found on the web? I already read some in wikipedia but i feel that the explanations there is somewhat incomplete or very hard to understand. I just need to know the basics.
Also should i use the grammar rules(the ones with the terms 'non-terminals' and 'terminals') as my pattern? Or should i use other ways to meet my own criteria in parsing? Right now i'm trying to use the Stack Collection to check the syntax then pass it to a new array, just like how converting from infix to postfix works. What i need are some rules to really come up with that kind of process.
|
|
|
|