GWT date- not allow to select date before start date - gwt

I have two dates start date and end date from gwt . I want "not to allow user to select end date before start date in gwt". please help..

You have to check start date while selecting date of end date box, something like
final DateBox startDateBox=new DateBox();
final DateBox endDateBox=new DateBox();
startDateBox.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {
#Override
public void onValueChange(ValueChangeEvent<Date> event) {
if(endDateBox.getValue()==null)
{
endDateBox.setValue(null);
Window.alert("Please select start date before selecting end date");
}
}
});
I did not check here this code, it should work.

Related

hello i need to compare 2 dates like start date and end date and if i select a wednesday i need all wednesdays occuring between these dates

I have a scenario where user selects a start date and end date and user also selects a specific day I need to show that specific day with date that occurs between them.
I tried the Intl package difference method but did not work
You can use this method. Takes the start and end date and also the weekday. Note, can pass in 3 as an int or 'DateTime.wednesday' as the argument.
Note, idea based on mirkancal's answer in this thread
List<DateTime> getAllDatesOfAWeekday(
{required DateTime startDate,
required DateTime endDate,
required int weekday}) {
List<DateTime> allDates = [];
for (int i = 0; i <= endDate.difference(startDate).inDays; i++) {
if (startDate.add(Duration(days: i)).weekday == weekday) {
allDates.add(startDate.add(Duration(days: i)));
}
}
return allDates;
}

how to insert new some records to grid using action button in acumatica

I have 2 tables, Timesheet_Head and Timesheet_Detail.
Timesheet_Head fields :
TimesheetID
Month
Year
Timesheet_Detail fields:
TimesheetID
ActivityDate
ActivityDesc
i want to show some records generated by month and year fields, from first day until last day of the month when action button clicked, for example:
No. date Description
1. 2/1/2016
2. 2/2/2016
3. 2/3/2016
4. 2/4/2016
... ...
29. 2/29/2016
does anyone have any ideas? Thanks in advance.
As I understand you are trying to achieve something like that:
expected behavior
So the action 'Generate' will look something like that:
public PXAction<Filter> generate;
[PXUIField(DisplayName = "Generate", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Visible = true)]
[PXButton()]
public virtual IEnumerable Generate(PXAdapter adapter)
{
Filter filter= TranFilter.Current;
if(filter==null || filter.Year==null)
return adapter.Get();
FinYear year = PXSelect<FinYear, Where<FinYear.year, Equal<Required<FinYear.year>>>>.Select(this, filter.Year);
for (DateTime date = year.StartDate ?? DateTime.Now; date < year.EndDate; date = date.AddDays(1))
{
Detail row = new Detail();
row.Date = date;
Details.Insert(row);
}
return adapter.Get();
}
If you want to use a year actually but not a financial year I guess you should use .Net DateTime class to get first and last date of the period.

How to extract day, month, and year from date returned by QML Calender?

The Calendar clicked signal returns a date as follows:
2015-11-13T00:00:00
However, I would like to have a date formatted like this:
Fri Nov 13 2015
This is what I tried:
onSelectedDateChanged:
{
calender.visible = false;
selectedDate = selectedDate.toLocaleTimeString(Qt.LocalDate, Locale.ShortFormat);
textOfSelectedDate.text = Date.fromLocaleTimeString(Qt.LocalDate, selectedDate, Locale.ShortFormat)}
}
textOfSelectedDate is the id of the text box where this date will be displayed.
How can I extract day, month, and year in a desired format from Date returned by Calender?
QML's date type extends Javascript's Date. Thus you can do:
onSelectedDateChanged: {
const day = selectedDate.getDate();
const month = selectedDate.getMonth() + 1; //assuming you want 1..12, getMonth()'s return value is zero-based!
const year = selectedDate.getFullYear();
...
}
First of all, date is similar to JS date type. So you can use all its functions, like getDate() etc. See it here
Also, you can use Qt.formatDate() object to format the result. In your case it can be as follows:
onClicked: {
console.log(Qt.formatDate(date,"ddd MMM d yyyy"))
}

How to insert DATE type in PostgreSql using Java?

I have a column of date type (daterecord) in PostgreSql and jdatechooser component in java (dateChooser). I am trying to insert the selected date into my database with this initial code:
Date daterec = dateChooser.getDate();
String sql= "INSERT INTO date values (?)";
pst.prepareStatement(sql);
pst.setDate(1, daterec);
pst.execute();
..but I know my setDate code is wrong..please help what to do?
i can tell you how to insert a date record into a mysql table by using the Datechooser control..it is how i do it..so it may differ from your point of view
public void getdate() {
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
String s=df.format(jDateChooser1.getDate());
jLabel1.setText(""+s);
}
public void insert(){
try{
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/<database_name>","root","<db password>");
Statement stmt=con.createStatement();
String query="insert into test values('"+jLabel1.getText()+"')";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Insert successful");
}
catch(Exception e) {
JOptionPane.showMessageDialog(null,"Error in connectivity");
}
}

Disable of date in DatePicker doen't works

I am trying to disable all the date in the DatePicker GWT component, here is my sample of code :
datePicker.addShowRangeHandler(new ShowRangeHandler<Date>() {
public void onShowRange(ShowRangeEvent<Date> event) {
System.out.println("First date : " + event.getStart());
System.out.println("Last date : " + event.getEnd());
System.out.println("First date from date picker : " + datePicker.getFirstDate());
System.out.println("Last date from date picker : " + datePicker.getLastDate());
// Disable all the date shown by the Calendar
List<Date> dateList = new ArrayList<Date>();
Date currentDate = event.getStart();
while(!currentDate.after(datePicker.getLastDate())) {
Date updateDate = CalendarUtil.copyDate(currentDate);
dateList.add(updateDate);
CalendarUtil.addDaysToDate(currentDate, 1);
}
for(Date date : dateList) {
System.out.println("Date selected : " + date);
System.out.println("date visibility : " + datePicker.isDateVisible(date));
}
}
});
Date visibility is always false , it keep telling me that all the date are not visible, but it should be true since it' between the first date and last date, anybody know a way to disable date in calendar?, so if tried the method setTransientOnEnables() on the datePicker for any of the date I keep getting an exception as the date arenot visible.
I had tried also impleenting my own DefaultClendarView but it requires protected class which is not available by GWT.
I had similar problems. I was trying to disable dates in the future.
I eventually found out that start and end dates are final variables. When I tried to change the start date, I got undefined behavior (In some cases my browser freezed completely.). The solution was to copy the start date and manipulate the copy instead of the start date directly..
This is what I ended up with:
datePicker.addShowRangeHandler(new ShowRangeHandler<java.util.Date>()
{
#Override
public void onShowRange(ShowRangeEvent<Date> event)
{
Date start = event.getStart();
Date temp = CalendarUtil.copyDate(start);
Date end = event.getEnd();
Date today = new Date();
while(temp.before(end))
{
if(temp.after(today) && datePicker.isDateVisible(temp))
{
datePicker.setTransientEnabledOnDates(false,temp);
}
CalendarUtil.addDaysToDate(temp, 1);
}
}
});
This should work in GWT 2.4. Earlier versions are not tested.