|
If you want to offer this sort of information then you should write a proper article. The forums are more for technical questions.
|
|
|
|
|
OK! I just thought that amount of information I have at the moment is not enough for a new article
|
|
|
|
|
You can always post it as a Tip if there is not enough for a full article. But either way, it will be more accessible there than in the forums.
|
|
|
|
|
I am having difficulty figuring out how to go about creating a dialog box which, when the user clicks the OK button, if that user hasn't answered all the questions in the dialog, then an error message should appear and reshow the dialog (either with or without the selections made previously).
My original solution was something similar to this:
show dialog box
while (!allAnswered) {
if (OK clicked) {
if all questions have answers then allAnswered=true
else
show error message
show dialog box again
end if
end if
loop
Each of the questions contain a drop-down box with the first choice being empty. So, if the drop-down has the empty string for the result, then I know that it hasn't been answered.
However, I wasn't sure if I was performing the if and while in the correct order because it seemed that it wasn't. Could someone please confirm whether I have the proper algorithm or what I need to do to fix it.
Chris
|
|
|
|
|
I suggest doing the checks within the dialog box so you won't need a loop at all. If it's WinForms then it could look like this:
In the "calling" Form:
private void ShowQuestionsDialog()
{
using (QuestionsForm form = new QuestionsForm())
{
if (form.ShowDialog() == DialogResult.OK)
{
}
else
{
}
}
}
In the "Questions Dialog":
private void OkButton_Click(object sender, EventArgs e)
{
if ()
{
DialogResult = DialogResult.OK;
Close();
}
else
{
MessageBox.Show("Please answer all questions.");
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
A common method is to show the dialog only once (initial) and perform the checks in the OnOK handler.
If all has been answered, close the dialog. Otherwise, show the error message box, optionally reset the selections and return from the handler which should let the dialog stay visible and active.
A more specific answer requires knowing which GUI framework you are using. But those usually provide some kind of OnOK or OnClicked handler which by default call a function to close the dialog. Just don't call that default function and return from the handler to let the dialog be alive.
|
|
|
|
|
Could someone point me to an algorithm or something that might help me solve this problem:
I have 3 tours going to Disneyland, each of these tours need tickets for the passengers to get into Disneyland. In total I have 60 tickets and they can be distributed in this way: I have 20 tickets to share between Tour1 and Tour2. I have another 20 tickets to share between Tour2 and Tour3. I have another 20 tickets for just Tour3.
Image of ticket allocation to tours[^]
For each person that books a tour, the ticket number is reduced by 1.
I want to maximize the availability that is shown to the user when they are attempting to book any of the 3 tours
With no bookings, the Availability for each tour is:
Tour1: 20
Tour2: 40
Tour3: 40
If we now add bookings for each tour:
Tour1 Bookings: 12
Tour2 Bookings: 10
Tour3 Bookings: 10
The availability when looking at each tour INDIVIDUALLY (aka how many tickets can I book), it should return:
Tour1: 8
Tour2: 18
Tour3: 28
Image[^]
As we increase bookings, availability will be adjusted accordingly. Notice in the next example, when there are an additional 10 bookings for Tour1, Availability for all 3 tours change:
Tour1 Bookings: 18
Tour2 Bookings: 10
Tour3 Bookings: 10
The availability when looking at each tour INDIVIDUALLY (aka how many tickets can I book), it should return:
Tour1: 2
Tour2: 12
Tour3: 22
Image[^]
I'm sure someone has already come up with an algorithm for this... could someone point me in the right direction? Please?
modified 5-Oct-17 10:01am.
|
|
|
|
|
I would do it like this :
Assuming that a Tour has more Information/Content than only the Count :
- you have for each Tour an Array (or better a List) with the availible Tours and one with the booked Tours
- if you book one Tour you move it from the Availible_Tours to the Booked_Tours
- the other way round it you free a Tour
If you only need the Count you can work instead of this only with Integer-Variables.
|
|
|
|
|
You need to go "deeper"; and think "allocation" or "reservation" system.
You need "instances" for each ticket (60); tour (3); and "seats" (20;40;40).
A "booking" links a ticket with a passenger / seat.
Iterating over these "lists" of bookings, seats, tours allows you to know at any time what's what.
Draw a picture; or think of a flight seat reservation you make yourself.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
Let's say, I have an XML file that looks like this.
<donors>
<donor>
<donorid>1
<name>abc
<amount>$50
<donor>
....
and I have a table that looks like this:
Relation Name
-------------
Donor
Columns
-------
DonorID - bigint
DonorName - nvarchar(100)
DonationCeiling - float
I want to get all of the donor names and amounts from the xml and compare them against the maximum amount allowed. I want to remove all donors from the xml whose donation has exceed the ceiling.
I can do this.
XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("donor", "www.mydomain.com/xmlns/donor");
nsmanager.PushScope();
XmlDocument doc = new XmlDocument();
doc.Load("donors.xml");
//Select and display the value of all the ISBN attributes.
XmlNodeList donorIds;
XmlNodeList donationAmount ;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/donors/donorid", nsmanager);
Is there a way to retrieve all xml node values from two different xml nodes using one xml path expression into one data structure. For instance, get all donor Ids an donation amount as a key-value list in one data-structure making a single call to root.SelectNodes
Once the donation ids and donations amounts are retrieved, even if they are retrieved as two separate XmlNodeLists, what is the most efficient way to compare these values to the DonationCeiling values returned from the Donor table.
The select query to the Donor table would look like this:
string sql = "Select DonorID, DonationCeiling from Donor where DonorID in ('" + (why can't we just pass the whole XmlNodeList as one data-structure here, without having to loop-through and build the list of DonorId's from the XMLNodeList + "') ;
recordset.ExecuteSQL(sql) ;
After the sql returns the recordset, is there an efficient way to compare the DonationAmounts in the XmlNodeList to the DonationCeiling amounts returned from the Donor table without having two nested loops.
int donorId = Convert.ToInt32(donorIds[0].InnerText) ;
while (!recordset.EOF) {
for (int i=0; i < donorIds.Count;i++) {
if (Convert.ToInt32(donationAmount[i].InnerText) > recordSet.Fields("donationCeiling").Value (should not have to cast to string and then to an integer - the compiler should automatically determine the type based on the returned value from the database column) {
// remove donor node from xml file
}
}
}
Is there a way to do the above without two loops?
Thanks for the time you might spend trying to figure this out. If you can't, that is ok, I have not figured it out so far. Maybe, there is no other way.
Thanks,
Saad
|
|
|
|
|
Upload "both" to "tables" (you admit to at least one) and use SQL.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I've written a 6502 assembler (for Commodore machines) and one of its features is conditional assembly, like this;
ifdef var1
<some code>
else
<some other code>
elseif
So if var1 is defined then <some code=""> is assembled, else <some other="" code="">. However I want to expand this by allowing nested conditional assembly, like this:
ifdef var1
ifdef var2
<some code>
else
<some other code>
endif
else
<yet more code>
endif
Basically the way my assembler works at the moment is if the 'ifdef' condition fails (the variable is not defined) then all of the code following it (until the corresponding 'else' directive) is ignored. It's the 'corresponding else' part which is the problem here. How do I determine which 'else' corresponds with which 'ifdef'? Please note that I can't use the code indentation to determine which 'level' the directives are on. In real life, all of the code will be in the first column (no indentation at all) as my assembler needs directives to be in the first column.
I don't need specific code as such, I'm more interested in an algorithm for this.
In case you're interested, here's my assembler:
www.ajordison.co.uk
modified 28-Sep-17 6:16am.
|
|
|
|
|
The common method for processing such nested commands is using a stack. If you encounter a condition, you push it onto the stack which holds the required information like type (if ) and evaluated result. Upon an else , you modify the current stack value accordingly (e.g. by setting an else flag), and upon an endif you pop (discard).
|
|
|
|
|
Yes this is the approach I tried first, but I still had the same problem when I hit an 'else', i.e. which 'else' is it?
|
|
|
|
|
It is the else for the current (top of stack, recent) if .
|
|
|
|
|
|
Hello,
I have a problem with finiding soultion to my product configurator. I'm looking for algorithms that could help me with matching similar datas. The problem is all of entries might be even unique cause they are insert by different people and they are wishes of different clients. Generaly product has option that client can choose from LOV but each option can be replaced by manualy added text. For example one product can have 70 unique values and other 400 and only 5 are values of the same atribute and only 3 are the same values but only 1 is described in exactly the same words. I'm not looking for exact solution, only for tips what algorithms could be helpfull.
Example values from one contract only(they are not describing the same thing, just wanted to show what different type of values I'm talking about):
- 81.0PA KNEITZ Sylby Silbergrau 65726598 / add 5 meter roll to contract
- 411.N015 System cable with a plugin connecting the 19 "box to the printer
One thing i can match values is number before "." cause it places value in group, but there can be multiple entries in one group or there could be none.
So at the end i would need to get 3-5 the most likely similar values to the entered one.
|
|
|
|
|
Garbage in; garbage out.
You need to capture "product / upc" codes; the rest is just "comments".
Mind you, USPS does have a "dangerous goods" keyword list.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I am working with C# and I have a tab control with several tab pages (tab pages T0, T1, T2, etc). On each tab page there are group boxes ("etched borders"), each with a heading (heading H0, H1, H2, etc). In each group box there are labels (L0, L1, L2, etc). The tab controls, headings, and labels are specified randomly in a table:
T0 H0 L2
T1 H2 L1
T0 H1 L4
T0 H0 L0
T2 H4 L2
T2 H3 L6
I need to sort these like this:
T0 H0 L2
T0 H0 L0
T0 H1 L4
T1 H2 L1
T2 H4 L2
T2 H3 L6
Does anybody know what algorithm I should a look into?
|
|
|
|
|
What is the rule according which they have been ordered?
|
|
|
|
|
The first row in the table dictates what label should be in the first group box in the first tab page. Then, all other labels that belong in same the tab page and group box are added in the order they appear in the original table. When no more labels belong to the first group box in the first tab page, then second group box in the first tab page are added in the order they appear in the original table. Then the third group box is processed, then the fourth, etc until there are no more group boxes in the first tab. Then same algorithm applies same way to the second tab page, then the third tab page, then the fourth, etc.
|
|
|
|
|
That looks to be just a simple sort using the T field as the first key, and the H field as the second. Er, except the last two entries.
|
|
|
|
|
I'm not sure it's particularly efficient, but using LINQ, you can at least get the right answer.
struct Record
{
public int T { get; set; }
public int H { get; set; }
public int L { get; set; }
}
Record[] UnsortedRecords =
{
new Record { T = 0, H = 0, L = 2 },
new Record { T = 1, H = 2, L = 1 },
new Record { T = 0, H = 1, L = 4 },
new Record { T = 0, H = 0, L = 0 },
new Record { T = 2, H = 4, L = 2 },
new Record { T = 2, H = 3, L = 6 },
};
public static IEnumerable<Record> SortRecords(IEnumerable<Record> source)
{
return source
.GroupBy(r => r.T, (key, items) => items
.GroupBy(r => r.H)
.SelectMany(g => g)
)
.SelectMany(g => g);
}
IEnumerable<Record> SortedRecords = SortRecords(UnsortedRecords);
NB: The documentation for GroupBy states that the order of the input sequence is preserved by both the returned groups, and the items within each group:
The IGrouping<TKey,TElement> objects are yielded in an order based on the order of the elements in source that produced the first key of each IGrouping<TKey,TElement> . Elements in a grouping are yielded in the order they appear in source .
You might be tempted to use a composite key in the grouping, to reduce the nesting. But that won't work - T0H1 and T1H2 will be returned in the wrong order:
source.GroupBy(r => new { r.T, r.H }).SelectMany(g => g);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This seems to be exactly what I need. Does anybody know how I can implement this in Visual Studio 2005? Or, does anybody know how I can convert my traditional ArrayList into an IEnumerable<record>? The contents of my ArrayList are objects of a class containing about 20 different variables (out of which 3 are strings representing tab page, group box, and label).
|
|
|
|
|
You can use LINQBridge[^] to bring the LINQ methods into C# 2.0, although the syntax is nowhere near as clean:
public static IEnumerable<Record> SortRecords(IEnumerable<Record> source)
{
IEnumerable<IEnumerable<Record>> groupT = Enumerable.GroupBy(source,
delegate(Record r) { return r.T; },
delegate(int key, IEnumerable<Record> items)
{
IEnumerable<IGrouping<int, Record>> groupH = Enumerable.GroupBy(items, delegate(Record r) { return r.H; });
return Enumerable.SelectMany(groupH, delegate(IGrouping<int, Record> g) { return g; });
});
return Enumerable.SelectMany(groupT, delegate(IEnumerable<Record> g) { return g; });
}
You can either replace the ArrayList with a List<T>[^], or use the Cast[^] or OfType[^] methods to convert it to an IEnumerable<T> .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|