/// <inheritdoc /> protected override void Execute(Context context) { var firstDate = FirstDate.Get(context); var secondDate = SecondDate.Get(context); var minuend = firstDate; // уменьшаемое var subtrahend = secondDate; // вычитаемое if (firstDate < secondDate) { minuend = secondDate; subtrahend = firstDate; } var diff = minuend - subtrahend; DifferenceInWholeMilliseconds.Set(context, (int)Math.Floor(diff.TotalMilliseconds)); DifferenceInSeconds.Set(context, diff.TotalSeconds); DifferenceInWholeSeconds.Set(context, (int)Math.Floor(diff.TotalSeconds)); DifferenceInMinutes.Set(context, diff.TotalMinutes); DifferenceInWholeMinutes.Set(context, (int)Math.Floor(diff.TotalMinutes)); DifferenceInHours.Set(context, diff.TotalHours); DifferenceInWholeHours.Set(context, (int)Math.Floor(diff.TotalHours)); DifferenceInDays.Set(context, diff.TotalDays); DifferenceInWholeDays.Set(context, diff.Days); var wholeMonths = 0; var counter = subtrahend; while (minuend.CompareTo(counter) > 0) { wholeMonths++; counter = counter.AddMonths(1); } wholeMonths--; counter = counter.AddMonths(-1); var daysInMonth = (double)DateTime.DaysInMonth(counter.Year, counter.Month); var monthDiff = minuend - counter; var months = monthDiff.Days + (monthDiff.TotalMilliseconds / (daysInMonth * 24 * 60 * 60 * 1000)); DifferenceInMonths.Set(context, months); DifferenceInWholeMonths.Set(context, wholeMonths); var years = (double)wholeMonths / 12; DifferenceInYears.Set(context, years); DifferenceInWholeYears.Set(context, (int)Math.Floor(years)); }
public MainPresenter() { Customer = "Research & development"; SubmissionDate = DateTime.Today; FirstDate = GetFirstDayOfNextWeek(SubmissionDate); LastDate = FirstDate.AddDays(4); Choices = new ObservableCollection <EmployeeMenu>(); Menus = new ObservableCollection <WeeklyMenu>(); RandomizeChoices = new RelayCommand(RandomizeMenu); CreateExcel = new RelayCommand(OpenExcelDocument); CreateWord = new RelayCommand(OpenWordDocument); CreateCSV = new RelayCommand(OpenCSVDocument); var service = new MainServiceSoapClient(); service.GetEmployeesCompleted += (s, ea) => PrepareMenu(ea.Result); service.GetEmployeesAsync(); service.GetMenusCompleted += (s, ea) => ea.Result.ToList().ForEach(it => Menus.Add(it)); service.GetMenusAsync(); }
public DateTime GetDate(int position) { return(FirstDate.AddDays(position)); }
// Wywołanie ukrywania poszczególnych paneli public void HideFirst() { FirstTitle.Hide(); FirstDescription.Hide(); FirstDate.Hide(); }
private void Insertperiod(int round) { CultureInfo culture = new CultureInfo("EN-US"); DateTime FirstDate, LastDate = new DateTime(2000, 12, 30), EndDate; EndDate = Convert.ToDateTime(enddate.Value.ToString(), culture); FirstDate = Convert.ToDateTime(startdate.Value.ToString(), culture); int thailandnosaurus; round -= 1; SqlConnection con = new SqlConnection(constr); string queryStringID = "select IDENT_CURRENT('project') AS ID "; con.Open(); SqlCommand cmdID = new SqlCommand(queryStringID, con); SqlDataReader readerID = cmdID.ExecuteReader(); readerID.Read(); thailandnosaurus = Convert.ToInt16(readerID["ID"]); readerID.Close(); cmdID.ExecuteNonQuery(); con.Close(); while (LastDate <= EndDate) { int Stegosaurus = 0; ////check firstDate while (Stegosaurus == 0) { string queryString = @"select * from Holiday where Holydate = '" + FirstDate.ToString("yyyy-MM-dd", culture) + "' "; con.Open(); SqlCommand command = new SqlCommand(queryString, con); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { FirstDate = FirstDate.AddDays(+1); } else { Label1.Text = FirstDate.ToShortDateString(); Stegosaurus = 1; } con.Close(); } LastDate = FirstDate.AddDays(+round); //check lastDate while (Stegosaurus == 0) { string queryString = @"select * from Holiday where Holydate = '" + LastDate.ToString("yyyy-MM-dd", culture) + "' "; con.Open(); SqlCommand command = new SqlCommand(queryString, con); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { LastDate = LastDate.AddDays(+1); } else { Label2.Text = LastDate.ToShortDateString(); Stegosaurus = 1; } con.Close(); } string queryStringIS = "insert into Setperiod(Firstcommit,Lastcommit,ProjectID) values('" + FirstDate.ToString("yyyy-MM-dd") + "','" + LastDate.ToString("yyyy-MM-dd") + "','" + thailandnosaurus + "')"; con.Open(); SqlCommand cmdIS = new SqlCommand(queryStringIS, con); cmdIS.ExecuteNonQuery(); con.Close(); FirstDate = LastDate.AddDays(+1); } }