I have a spin edit from Devexpress and what I would like to do with it is set its value to only display a year month value, with the format or YYYYMM. I have code to do that but I was wondering if it is possible to do this with the properties of the spin edit. The problem I encounter is that when it gets to 201212 and you increment it should go to 201301, but of cause it just goes to 201213. The same happens in revers from 201301 to 201299. I'll give the sample code just so that you can see how it is meant to work but again I want to know if this can be done using just the properties of the spinEdit.
private void spDate_EditValueChanged(object sender, EventArgs e)
{
spDate.Properties.EditValueChangedFiringMode = DevExpress.XtraEditors.Controls.EditValueChangedFiringMode.Default;
int year = Convert.ToInt32(Math.Floor(spDate.Value / 100));
int month = Convert.ToInt32(spDate.Value - (year * 100));
if (month > 12) { month = 1; year += 1; }
if (month < 1) { month = 12; year -= 1; }
spDate.Value = (year * 100) + (month);
}
obviously that first line is manually set with the properties otherwise its a little buggy but I added it in there so you can see what property to set beforehand.
Many thanks
I Think that you have to use editors masks. What you are trying to display is obviously a date. Try to have a look here.
Related
I am trying to implement a method for a Date selection in vue-chartjs. Here is the function that i have used in the methods life cycle hook:
DateSelect(event) {
const period = event.target.value
let minValue = new Date(Math.max(...this.date) * 1000)
const axisXMin = new Date(Math.min(...this.date) * 1000)
switch (period) {
case '1m':
minValue.setMonth(minValue.getMonth() - 1)
break
case '3m':
minValue.setMonth(minValue.getMonth() - 3)
break
case 'ytd':
minValue.setFullYear(minValue.getFullYear() - minValue.getMonth()) //Here I want to implement the YTD Logic.
break
default:
minValue = axisXMin
}
const data = this.data.filter(el => {
return el.x >= minValue
})
this.GraphOutput(data) // this is vue-chartjs function.
}
Here the logic '1m' and '3m' works absolutely fine, as they display the previous 1month's and 3month's chart to the user when the respective button is clicked.
I want to know how to implement the YTD (Year to Date) Logic in the function that i have used above. Please do help me.
As far I understand you may need a full year of data in the graph. So that you need to set the minimum value as below:
case 'ytd':
minValue.setYear(minValue.getFullYear() - 1);
break
I am currently developing an Outlook Addin for AppointmentItem. In case the AppointmentItem is a member of a recurring meeting "chain" I want to retrieve/find the AppointmentItem which is the previous meeting. How can I do that?
I figured out the following part-solution:
Outlook.AppointmentItem item = (Outlook.AppointmentItem)inspector.CurrentItem;
if (item.IsRecurring) {
Outlook.RecurrencePattern pattern = item.GetRecurrencePattern();
Outlook.OlRecurrenceType occurenceType = pattern.RecurrenceType;
int dayFactor = 0;
switch (occurenceType) {
case Outlook.OlRecurrenceType.olRecursDaily:
dayFactor = 1;
break;
case Outlook.OlRecurrenceType.olRecursWeekly:
default:
dayFactor = 7;
break;
// TODO handly all other cases of RecurrenceType
}
Outlook.AppointmentItem lastItem = pattern.GetOccurrence(item.StartInStartTimeZone.AddDays(-1*pattern.Interval*dayFactor));
But this handles only very few "easy" cases.
Especially when it comes to calculate e.g. every first tuesday per month it gets too tricky for me. Any input? This code sample might be usefull, too: http://www.outlookcode.com/codedetail.aspx?id=1414
In fact I found an answer which is a little bit inefficient but very powerfull as you don't have to care about any recurring rules outlook may have. First any recurring rule does not change the time of the occurence meaning that recurring appointments take place at the very same point in time during the day. Second
GetOcurrences(DateTime)
throws an exception if there is no AppointmentItem at the given DateTime.
And finally the RecurrencePattern gives you the
PatternStartDate
So all what you need to do is check each and every day backwards, beginning at the given AppointmentItem and ending at PatternStartDate.
This is my implementation which of course can be written better, but it works well:
if (myAppointment.IsRecurring)
{
Outlook.RecurrencePattern pattern = myAppointment.GetRecurrencePattern();
bool doContinue = true;
Outlook.AppointmentItem lastAppointmentItem = null ;
int currentDay = -1;
while (doContinue) {
try
{
DateTime currentDate = myAppointment.StartInStartTimeZone.AddDays(currentDay);
if (currentDate < pattern.PatternStartDate)
{
doContinue = false;
lastAppointmentItem = null;
}
else
{
lastAppointmentItem = pattern.GetOccurrence(currentDate);
if (lastAppointmentItem != null)
{
doContinue = false;
}
else
{
currentDay -= 1;
}
}
}
catch (Exception ex)
{
currentDay -= 1;
}
}
....
The same approach can be used to create an Array of all Orccurences. It'll take some time to calculate all and I don't know how to handle open ended series. But that was not the question for this stackoverflow item.
Not easily. You'd need to expand the series explicitly in your code taking into account the recurrence pattern and the exceptions or you can try all suspect dates until GetOccurrence succeeds.
If using Redemption (I am its author) is an option, its version of RDORecurrencePattern.GetOccurrence method allow to pass an integer index (besides the date a-la OOM) as a parameter, so you can build an array of occurrences.
newRow("OrderReference") = line.Substring(line.IndexOf("*1003") + 5, line.IndexOf("*", line.IndexOf("*1003") + 5) - line.IndexOf("*1003") - 5)
There you have it. Very long and ugly. I was thinking about this:
Dim indexPlus = line.IndexOf("*1003") + 5
Dim indexMinus = line.IndexOf("*1003") - 5
newRow("OrderReference") = line.Substring(indexPlus, line.IndexOf("*", indexPlus) - indexMinus)
But that introduces new and meaningless vars. Unsatisfying.
Maybe RegEx is the savior here?
Unfortunately I mustn't change the input data :-(
The input data consist of the BWA-format (popular with books). Here you can see the part in question:
All codes in this example set are required. Only corresponding values change.
I don't even think your second code works. It seems more like this.
Dim index = line.IndexOf("*1003") + 5
newRow("OrderReference") = line.Substring(index, line.IndexOf("*", indexPlus) - index)
10 - 5 - 2 isn't the same as 10 - (5 - 2) but instead it's the same as 10 - (5 + 2).
Next time, check out the codereview stack exchange.
Given that your data is always constant, and what you're looking for always begins with "*1003", you don't need to use Regex (Even though you could). Just use what you're already using but with some corrections.
using System;
public class Program
{
public static void Main()
{
string input = "L10113540 VD44444 VD2002100234949 000116161 04201261\r\n";
input += " KN00010000000129000LPEUR003000001*1003A.Muller-Schulz*1017Bastei\r\n";
input += "Lubbe.61204 Laund.Meine Schuld*1019KL*102990300*1030NO*1032EUR*1131KT";
int start = input.IndexOf("*1003");
int end = input.IndexOf("*", start + 1);
string result = input.Substring(start + 5, end - start - 5);
Console.WriteLine(result);
// Your code
start = input.IndexOf("*1003") + 5;
end = input.IndexOf("*1003") - 5;
result = input.Substring(start, input.IndexOf("*", start) - end);
Console.WriteLine(result);
}
}
Result
A.Muller-Schulz
A.Muller-Schulz*1017Baste
You can see that what you posted in your question, doesn't give the results you want. All you're really looking for is just the next asterisk after the first "*1003". You can see the difference between your code and what I've given.
.NET Fiddle Example
basically I am setting up a age verification script for a alcohol company and each country of course has a specific age to consume or buy alcohol.
I have set up the basics just now but I am running in to a problem. Right now I want to be able to gather there DOB using the input fields. Convert this to a date and them somehow compare it to the legal drinking age of the country in question.
Unfortunately testing the DOB is proving difficult and I know it is a problem with the event handler I am using as it won't output my required result to the console.
If anyone could help that would be fantastic.
Here is a link to my fiddle.
var countries = {
"Albania": 18,
"Algeria": 18,
"Argentina": 21,
"Armeria": 18,
"Australia": 18,
"Austria": 18
};
var individualCountry;
var day;
var month;
var year;
$("#verify").submit(function() {
day = $("#day").val();
month = $("#month").val();
year = $("#year").val();
var fullDate = day + month + year;
console.log(fullDate);
individualCountry = $("#countries").val();
var ageLimit = countries[individualCountry];
if (personsAge >= ageLimit) {
}
})
https://jsfiddle.net/h989qrLs/
try this code
function_calculateAge(birthday) { // birthday is a date
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
for more details open this link by André Snede Hansen
How to set a condition to say if a data in a table is less than 5 days ago and then display a users information.
Below I can say less than date now.
#foreach (var item in Model)
{
if(item.RegisteredAt < DateTime.Now )
{
}
}
You can get the difference between two dates as a TimeSpan and use TotalDays property.
(DateTime.Now - item.RegisteredAt).TotalDays < 5
You can pass in a negative number to the AddDays function.
if(item.RegisteredAt < DateTime.Now.AddDays(-5)) {
If you wanted to ignore the time portion then you should compare them off the Date property.
if(item.RegisteredAt.Date < DateTime.Today.AddDays(-5)) {
if(item.RegisteredAt.Substract(DateTime.Now).Days.ToString().AsInt() < 5)
{
#* your expected code *#
}