Pass DatePicker.Value of one form to another form? - c#

i have a login form that accepts an admin and ordinary users.
when an admin logs-in, his form has two DateTimePickers.
the first DateTimePicker allows the admin to choose a date that will serve as a minimum date = MinDate.
the second DateTimePicker allows the admin to choose a date that will serve as a maximum date = MaxDate.
click ok and both MinDate and MaxDate should be saved even when the application exited.
now, if an ordinary user logs-in his form has one DateTimePicker which allows him to choose a date. however, that DateTimePicker has a limited range defined by the MinDate and MaxDate from the admin form.
i have seen tutorials do this but they only use text/strings which are easy to manipulate.
please help... sorry if there's no "try" code here, i just cant do it.

You should save the values the Admin provides in a database.
When the non-admin user visits the form, you will use the values in the database to set the minimum and maximum dates.
Then when the OK or Save button is pressed you validate the values against the values stored in the database.

Related

Scheduler Calendar datetime Picker time intervals

I need scheduler pop up datetime picker with one hour intervals. I tried this thing after changing outer Html of the popped input screen it will display data in correct way but their are issues in reading the selected data. It read wrong dates after i change the Popup. Please refer the attached images for more info. And want to define time range 8.00 am to 6.00 pmenter image description here
From the provided information it's not clear how exactly you are setting the corresponding option of the DateTimePicker, however the described scenario works as expected on my side - please check the example below:
http://dojo.telerik.com/inonu

How to programatically dismiss the calendar of a DateTimePicker

I am working on a Windows Form that uses a good amount of DateTimePicker controls.
As per spec, the controllers need to show 'no date' initially till user manually selects a date.
As per the DateTimePicker functionality, we cant assign 'nothing' as a value.
So what we do is set a default minimum date, and then change the custom format of the control to "", to give the illusion of an empty field.
A quirk we have found is that when the user clicks on the DateTimePicker and selects a new date for the first time, his initial click does not dismiss the calendar. So instead the calendar persists, and the user has to manually click outside the control to dismiss the calendar.
To make the user experience slightly worse, while in this state the calendar is immune to any further date selection. So the date selection is stuck with the initially selected date, and the user needs to click out.
Once a date has been selected by the control, selecting a new date dismisses the calendar as expected.
My best guess would be that it would have something to do with the custom format that is there originally, which causes a hiccup with the control when a new properly formatted date is selected.
I am trying to find a way to 'force' the calendar to dismiss if open on value change, but I am not finding the way to do this.
I have even tried to set focus elsewhere on value change, but no luck either.
Has anybody else experienced this behavior and/or know of a way around it?
Thanks!
Some of the code-----------
//if dateTime property has not been saved, then call ClearDateTime on the controller, else display the saved value.
public static void ClearDateTime(DateTimePicker dtp)
{
dtp.Value = DateTime.Today.AddDays(-1);
//set the format
dtp.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
// set custom format to empty
dtp.CustomFormat = " " ;
}
// When value is changed/date is selected
private void DateTimePicker_ValueChanged(object sender, EventArgs e)
{
MainFormUtilities.ShowDateTime(this.DateTimePicker);
this.LockFormDown();
}
public static void ShowDateTime(DateTimePicker dtp)
{
dtp.Format = System.Windows.Forms.DateTimePickerFormat.Long;
}
Essentially you need to manually raise the CloseUp event, please refer to the solutions here, How can I programmatically close the dropdown calendar of a datetimepicker or update the dropdown calendar to reflect the .Value property?.
I had a similar situation where a client insisted on having the field show no date (appear blank). I gave up on trying to hack the standard .NET DateTimePicker and used the DevExpress DateEdit control which does allow a blank value.
The solution I have pursued that was most practical for my project was the suggestion by Reniuz, to use a checkbox to control the values and behaviour of the DateTimePicker.
If a user wants to add a date, he selects the checkbox which enables the Picker and defaults to todays date.
If he wants to clear the date (ie not submit a date after all) he unchecks the checkbox which clears the picker with a empty format and we save nothing to the database.
If I had the points I would upvote all the other suggestions. They were helpful, but this solution seemed to be the practical path for us. Thanks to all again!

MVC auto complete inputs according to recent user entries

I have a site that manages a database.
Lets say the users enter information about people (height, weight, name etc...)
A lot of people are entered each day and the height range is quite small so if a user entered a person with a certain height I want it to auto complete next time he enters a person.
(like most login forms where you click a textbox and it shows your recent entered login info and when you start typing it auto completes you).
I am using MVC 4 and the person entry is not within a form. When a user clicks save it uses ajax to save.
I know it works with forms but how can I do it on certain textboxes which arent in a form.
The jQuery autocomplete solution doesn't require fields to be in a form.
If you look at the source code of the sample, the previous data is stored as a JavaScript array. You could store previous entries for each user in a database and then use this data to build an JSON array that can be passed via a view-model to the view and then use jQuery.parseJSON() to render it straight into place in the JavaScript.

best way to handle time validation for textbox

Hello my WinForm application has a textbox that will be used for a time value. I know how to load like the current time into the textbox, but say when a user enters a value, what is the best way to validate or format the number so I can attempt to Convert it to a TimeDate value?
Example:
User enters something like 800 should be able to be converted to 8:00am or 2354 should be 11:54pm. Also if they enter an invalid time, like 9cdf83 or something, I need to check that this value is convertable to a time. If not, throw a warning. Is there a way to display a system clock to choose the time from like the dateTimePicker?
For things like date and time which u want user to enter best is to use DateTimePicker bcoz n number of users will have n number of ideas to fill it. u can't go on checking each and every option.
Instead DateTimePicker will make user to enter through it only.
you can place the textbox and a label beside it specifying the format like 8:00 AM and for validating it you can use custom validation and use a suitable regular expression as required for the validator and attach it to textbox.
But For conversion I thing you will have to code and check its validity.

Avoid pressing . (period) key to move to next field in DateTime picker control

In datetime picker control the user has to press .(period) to move to different fields (like day, month year)
I want to override this behaviour by allowing the user to enter date without entering .(period)
Is there any to achieve this programmatically in C# winforms?
Thanks in advance.
Not very beautiful code but you could of course send the . automatically.
Just handle the ValueChanged event (which will only be called when the user has entered a "whole" value for date part he's currently editing) and in the event handler you add the code SendKeys.Send(".");.

Categories

Resources