|
And if there's any chance the military will use it, be it will be possible to NOT exclude weekends. (Smart troopies just put in for Mon-Fri and hope no one bothers them on the weekends.
|
|
|
|
|
I have designed a system where different groups have different days set up for weekends plus a different set of holidays per group and a staff can be a member of multiple groups and move between them (done in VB6).
Getting the bastards to accept a non midnight clock off was the most difficult job.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
You may proceed with my blessing.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I Have a employee work tracking system written in C# and back end is SQL DB .
In Leave tab user can apply single entry for given date when he wants to take a leave .Now i want to add functionality where user can insert multiple leaves like if he want to go on long Holiday for one/two week ,where he can give start date and end date for his leave plan and code will fill entries against only weekdays for given start and end date and will exclude weekends (Sat and Sun) .
Also need to look Office Holidays in between .
I Hope i have explained my Question enough everyone to understand .
Can anyone please share sample code for same. Dont need any slogans or blessings .
Thanks in Advance ,
Shwetali
|
|
|
|
|
shwetaliv wrote: Dont need any slogans or blessings . We do not provide those, any more than we provide code for people who cannot be bothered to do their own work.
|
|
|
|
|
shwetaliv wrote: Can anyone please share sample code for same.
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for all support .Working on my system further improvements.
|
|
|
|
|
You're welcome.
Good luck with your task.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Message Removed
modified 24-Sep-20 15:26pm.
|
|
|
|
|
Message Removed
modified 24-Sep-20 15:26pm.
|
|
|
|
|
|
|
Hi,
I am fairly new to C#.I am currently writing a windows form program with 50 labels created on the form. I would like to know if there is a better way to change the label's backcolor according to the input number by the user. I am currently using Switch to do it. It makes the coding long and hard to read.
Appreciated if someone can give me advice on this.
My labels are named from label01 ..... label50
Thanks,
John
|
|
|
|
|
You could add all the labels to a List<> object or an array.
That way you can refer to each one by index notation:
Labels[5].BackColor = Color.Green;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
One way is to add the number to the Label.Tag property - every Control has one, and it's a "free object" variable that is for the designer to use as he will.
You can then access each label very easily:
Label lab = Controls.OfType<Label>().FirstOrDefault(c => Convert.ToInt32(c.Tag) == 2);
lab.Text = "Hello";
You could just use the Label.Name property, but that's messier as the VS default names do not have zero padded numbers:
Label1
Label2
...
Label10
Label11
... So you'd need a substring and to rely on the names being in the right order on screen:
Label lab = Controls.OfType<Label>().FirstOrDefault(c => Convert.ToInt32(c.Name.Substring(5)) == 2);
lab.Text = "Hello";
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
modified 22-Sep-20 6:08am.
|
|
|
|
|
You've mentioned: labels, background color, an input number and a switch. If you explain how all this fits together, you'll probably get a better answer.
e.g. Are all labels colored the same based on some choice? Or does every label get their own number? etc.
Most projects fail due to inadequate specs.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
As an alternative to the excellent example posted by OriginalGriff, I'd like to demonstrate how easy it is to make a Component [^] that "bakes in" the functionality you describe; the Component is derived from Label:
... you might ask: why go to all this trouble ? I assert that mastery of using custom (inherited) WinForm Controls is a very valuable skill that can help with code encapsulation, and "separation of concerns" ...
0 as you may know: a Component is created using the Project/Add Component menu choice, and, like a UserControl, will appear in the Toolbar.
... this Component, AutoNumberedLabel ...
1 keeps a static Dictionary <int, AutoNumberedLabel> which is updated automatically each time you create an instance by drag-dropping from toolbar, or, in code.
2 provides a method that looks up the AutoNumberedLabel instance from an integer parameter..
3 provides a public read-only property that holds the AutoNumberedLabel's integer id.
4 provides a public method that sets the AutoNumberedLabel's BackColor
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class AutoNumberedLabel : Label
{
public AutoNumberedLabel()
{
InitializeComponent();
}
public AutoNumberedLabel(IContainer container)
{
container.Add(this);
InitializeComponent();
LabelId = lblId;
IntToLabel.Add(lblId++, this);
}
static Dictionary<int, AutoNumberedLabel> IntToLabel = new Dictionary<int, AutoNumberedLabel>();
static int lblId = 0;
public int LabelId { get; }
public static AutoNumberedLabel GetLabelByID(int id)
{
if (IntToLabel.ContainsKey(id))
{
return IntToLabel[id];
}
throw new KeyNotFoundException();
}
public static void SetLabelColorByID(int id, Color color)
{
if (IntToLabel.ContainsKey(id))
{
IntToLabel[id].BackColor = color;
return;
}
throw new KeyNotFoundException();
}
}
} Here's how you might use this, assuming you've assigned all your AutoNumberedLabels the same Click Eventhandler:
private void autoNumberedLabel_Click(object sender, EventArgs e)
{
AutoNumberedLabel lbl = (AutoNumberedLabel) sender;
int Id = lbl.LabelId;
AutoNumberedLabel lbl2 = AutoNumberedLabel.GetLabelByID(Id);
if(lbl2 != lbl) throw new ArgumentException();
AutoNumberedLabel.SetLabelColorByID(Id, Color.Gold);
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 22-Sep-20 23:59pm.
|
|
|
|
|
I always named the controls with the same number suffix therefore the label and the input control the same suffix eg cboState05 would be related to label05.
So then you have a function to extract the number from the control and concatenate the label name.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Thanks to all. I have solved the problem, you guys have been very helpful.
|
|
|
|
|
Thanks guys for the help. I have found the solution to it.
|
|
|
|
|
I'm sorry to bother you, I just have a question regarding how to validate a list of object when is inside other list... I do have a list of cities, each city has another list of zones, an example could be like this:
public class City
{
public int Id { get; set; }
public string CityName { get; set; }
public virtual List<Zone> Zones { get; set; } = new List<Zone>();
}
public class Zone
{
public int Id { get; set; }
public string ZoneName { get; set; }
public int CityId { get; set; }
public virtual City City { get; set; }
}
Now, as you can see, the City is the principal and the Zone is the dependent class. Now I decided to pass what I have into my database to a view with a form to make changes to these Cities and their Zones, so I created a view model like this:
public class SettingsModel
{
public City NewCity { get; set; }
public List<City> CurrentCities { get; set; }
}
The first property is to create a new City that is not in the db. The other list contains the Cities already in the database. So I started by creating a list of forms using a for loop (not foreach) that uses an index. At the end, it produces something like this:
<form method="post" action="/Administration/UpdateCity">
...
<input type="hidden" id="CurrentCities_0__Id" name="CurrentCities[0].Id" value="7">
<input type="text" id="CurrentCities_0__CityName" name="CurrentCities[0].CityName" value="Austin">
...
</form>
...
<form method="post" action="/Administration/UpdateCity">
...
<input type="hidden" id="CurrentCities_1__Id" name="CurrentCities[1].Id" value="4">
<input type="text" id="CurrentCities_1__CityName" name="CurrentCities[1].CityName" value="Dallas">
...
</form>
as far as I understand, in the receiving action method (POST), I should use the [Bind(Prefix="CurrentCities")] to remove the unnecessary class name of the field name and, should specify a list<city> (or IEnumerable or Array) to tell that the object received is an array. in other words:
public IActionResult UpdateCity([Bind(Prefix = "CurrentCities")]List<City> myCity)
{
...
}
My question is: When I try to add a form in the same way for the Zones property of City, I end with the form fields named as:
<input type="text" id="CurrentCities_0__Zones_0__ZoneName" name="CurrentCities[0].Zones[0].ZoneName" value="Austin Metro Area">
...
<input type="text" id="CurrentCities_1__Zones_0__ZoneName" name="CurrentCities[1].Zones[0].ZoneName" value="San Antonio Metro Area">
As you can see, now all the fields have an extra index indicator like this "CurrentCities[0].Zones[0]" and I was wondering, how can I get this object in the POST action method? how can I specify a Bind Prefix of this kind? and how could I specify that the item is a collection item of other collection item?? Please help and thank you for your patience!
|
|
|
|
|
You posted this also in the ASP.NET forum. Please do not crosspost.
|
|
|
|
|
There, you nailed it. In web interfaces, there is no (well-known) pattern that will allow you to (reasonably) add or update more than one record at a time.
It's:
- Add a city
- Add a zone
- Add another zone
- Add another city
- Add a zone
- Edit a city
- Edit a zone.
The classic Edit and Delete action per row. 1st gen client-server.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hello, I need your help.
I want to read a .docx file line by line and insert chapters and paragraphs of the chapter in database table.
I have tried using Microsoft.Office.Interop.Word to read the document, without success because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
Now I read on google that the suitable tool for this is OpenXML.
My file.docx is divided for chapters and paragraphs of the chapter
The structure of file.docx
Chapter 1 - Events
-alert or disservices
-significant activities
Chapter 2 – Safety
-near miss
-security checks
Chapter 3 – Training
-environment
-upkeep
I need insert on database table according with this schema
https://i.stack.imgur.com/41YQL.png[^]
How to do resolve this?
Thanks in advance for any help or suggestion
Chevy
DROP TABLE IF EXISTS `chapters`;
CREATE TABLE `chapters` (
`chapter` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`subheading` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`contents` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`sID` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`sID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
|
I don't know about "OpenXML", but if you save your docx in MS Word as a "Word XML document", you can actually "see" the xml and make sense of your document if you then open it in Xml Notepad, for example.
("OpenXml" seems to have it's own internal "non-xml" format. Bizarre).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|