en c#
en un formulario de Windows tengo cinco timepicker only time format. Los cuatro valores están escritos en 4 cuadros de texto. Necesito en un quinto textbox
o timepicker
, para ver la suma de horas de pprecedenti 4.
este código es incorrecto:
TimeSpan result = this.dateTimePicker22.Value + this.dateTimePicker23.Value + this.dateTimePicker24.Value + this.dateTimePicker25.Value + this.dateTimePicker26.Value);
this.textBox21.Text = result.ToString();
Calculo las horas de trabajo así que:
private void Calcolaweek1()
{
textBox23.MaxLength = 5;
DeleteChars();
if (textBox23.Text.Length == 2)
textBox23.Text += ":";
textBox23.SelectionStart = textBox23.Text.Length;
DateTime time = new DateTime();
this.textBox23.Text = time.ToString("HH:mm");
if ((textBox1.Text.Length > 0) && (textBox2.Text.Length > 0) && (textBox3.Text.Length > 0) && (textBox4.Text.Length > 0))
{
textBox23.MaxLength = 5;
TimeSpan result = this.dateTimePicker4.Value - this.dateTimePicker1.Value - (this.dateTimePicker3.Value - this.dateTimePicker2.Value);
this.textBox23.Text = result.ToString();
}
else if ((string.IsNullOrEmpty(textBox2.Text)) || (string.IsNullOrEmpty(textBox3.Text)))
{
TimeSpan result1 = this.dateTimePicker4.Value - this.dateTimePicker1.Value;
this.textBox23.Text = result1.ToString();
}
}
Debo resumir todas las horas de trabajo del día
Respuestas
0 para la respuesta № 1private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
int hours = picker1.Value.Hour % 12 +
picker2.Value.Hour % 12 +
picker3.Value.Hour % 12 +
picker4.Value.Hour % 12 +
picker5.Value.Hour % 12;
int minutes = picker1.Value.Minute % 60 +
picker2.Value.Minute % 60 +
picker3.Value.Minute % 60 +
picker4.Value.Minute % 60 +
picker5.Value.Minute % 60;
TimeSpan fromMinutes = TimeSpan.FromMinutes(minutes);
var ts = hours + fromMinutes.Hours + ":" + fromMinutes.Minutes;
}
catch (Exception)
{
throw;
}
}