WoTag
Download: wotag.exe (Pseudoexe, 28KB) |
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Kalender
{
/// <summary>
/// Zusammenfassung für Form1.
/// </summary>public class Form1 : System.Windows.Forms.Form
{private System.Windows.Forms.Button btn_Ende;
private System.Windows.Forms.Label lbl_Jahr;
private System.Windows.Forms.TextBox txt_Jahr;
private System.Windows.Forms.Label lbl_Tag;
private System.Windows.Forms.TextBox txt_Tag;
private System.Windows.Forms.Label lbl_Monat;
private System.Windows.Forms.TextBox txt_Monat;
private System.Windows.Forms.Button btn_Rechne;/// <summary>
/// Erforderliche Designervariable.private int t;
private int m;
private int j;
int WoTag;
private System.Windows.Forms.TextBox txt_WoTag;
private System.Windows.Forms.Label lbl_WoTag;
private System.Windows.Forms.Label lbl_julinr;
private System.Windows.Forms.TextBox txt_julinr;/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{//
// Erforderlich für die Windows Form-Designerunterstützung
//InitializeComponent();
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>protected override void Dispose( bool disposing )
{if( disposing )
{if (components != null)
{components.Dispose();
}
}
base.Dispose( disposing );}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>private void InitializeComponent()
{this.btn_Ende = new System.Windows.Forms.Button();
this.lbl_Jahr = new System.Windows.Forms.Label();
this.txt_Jahr = new System.Windows.Forms.TextBox();
this.lbl_Tag = new System.Windows.Forms.Label();
this.txt_Tag = new System.Windows.Forms.TextBox();
this.lbl_Monat = new System.Windows.Forms.Label();
this.txt_Monat = new System.Windows.Forms.TextBox();
this.btn_Rechne = new System.Windows.Forms.Button();
this.txt_WoTag = new System.Windows.Forms.TextBox();
this.lbl_WoTag = new System.Windows.Forms.Label();
this.lbl_julinr = new System.Windows.Forms.Label();
this.txt_julinr = new System.Windows.Forms.TextBox();
this.SuspendLayout();//
// btn_Ende
//this.btn_Ende.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_Ende.Location = new System.Drawing.Point(144, 208);
this.btn_Ende.Name = "btn_Ende";
this.btn_Ende.Size = new System.Drawing.Size(104, 24);
this.btn_Ende.TabIndex = 5;
this.btn_Ende.Text = "Be&enden";
this.btn_Ende.Click += new System.EventHandler(this.btn_Ende_Click);//
// lbl_Jahr
//this.lbl_Jahr.Location = new System.Drawing.Point(168, 24);
this.lbl_Jahr.Name = "lbl_Jahr";
this.lbl_Jahr.Size = new System.Drawing.Size(32, 20);
this.lbl_Jahr.TabIndex = 3;
this.lbl_Jahr.Text = "Jahr:";
this.lbl_Jahr.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;//
// txt_Jahr
//this.txt_Jahr.Location = new System.Drawing.Point(200, 24);
this.txt_Jahr.Name = "txt_Jahr";
this.txt_Jahr.Size = new System.Drawing.Size(40, 20);
this.txt_Jahr.TabIndex = 3;
this.txt_Jahr.Text = "";
this.txt_Jahr.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txt_Jahr.Click += new System.EventHandler(this.txt_Jahr_Click);//
// lbl_Tag
//this.lbl_Tag.Location = new System.Drawing.Point(8, 28);
this.lbl_Tag.Name = "lbl_Tag";
this.lbl_Tag.Size = new System.Drawing.Size(32, 16);
this.lbl_Tag.TabIndex = 5;
this.lbl_Tag.Text = "Tag:";
this.lbl_Tag.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;//
// txt_Tag
//this.txt_Tag.Location = new System.Drawing.Point(40, 24);
this.txt_Tag.Name = "txt_Tag";
this.txt_Tag.Size = new System.Drawing.Size(24, 20);
this.txt_Tag.TabIndex = 1;
this.txt_Tag.Text = "";
this.txt_Tag.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txt_Tag.Click += new System.EventHandler(this.txt_Tag_Click);//
// lbl_Monat
//this.lbl_Monat.Location = new System.Drawing.Point(80, 24);
this.lbl_Monat.Name = "lbl_Monat";
this.lbl_Monat.Size = new System.Drawing.Size(40, 20);
this.lbl_Monat.TabIndex = 7;
this.lbl_Monat.Text = "Monat:";
this.lbl_Monat.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;//
// txt_Monat
//this.txt_Monat.Location = new System.Drawing.Point(120, 24);
this.txt_Monat.Name = "txt_Monat";
this.txt_Monat.Size = new System.Drawing.Size(24, 20);
this.txt_Monat.TabIndex = 2;
this.txt_Monat.Text = "";
this.txt_Monat.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txt_Monat.Click += new System.EventHandler(this.txt_Monat_Click);//
// btn_Rechne
//this.btn_Rechne.Location = new System.Drawing.Point(144, 176);
this.btn_Rechne.Name = "btn_Rechne";
this.btn_Rechne.Size = new System.Drawing.Size(104, 24);
this.btn_Rechne.TabIndex = 4;
this.btn_Rechne.Text = "&Berechne";
this.btn_Rechne.Click += new System.EventHandler(this.btn_Rechne_Click);//
// txt_WoTag
//this.txt_WoTag.Location = new System.Drawing.Point(144, 120);
this.txt_WoTag.Name = "txt_WoTag";
this.txt_WoTag.ReadOnly = true;
this.txt_WoTag.Size = new System.Drawing.Size(96, 20);
this.txt_WoTag.TabIndex = 12;
this.txt_WoTag.TabStop = false;
this.txt_WoTag.Text = "";
this.txt_WoTag.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;//
// lbl_WoTag
//this.lbl_WoTag.Location = new System.Drawing.Point(72, 120);
this.lbl_WoTag.Name = "lbl_WoTag";
this.lbl_WoTag.Size = new System.Drawing.Size(72, 20);
this.lbl_WoTag.TabIndex = 13;
this.lbl_WoTag.Text = "Wochentag:";
this.lbl_WoTag.TextAlign = System.Drawing.ContentAlignment.MiddleRight;//
// lbl_julinr
//this.lbl_julinr.Location = new System.Drawing.Point(0, 88);
this.lbl_julinr.Name = "lbl_julinr";
this.lbl_julinr.Size = new System.Drawing.Size(144, 16);
this.lbl_julinr.TabIndex = 14;
this.lbl_julinr.Text = "Julianische Tagesnummer:";
this.lbl_julinr.TextAlign = System.Drawing.ContentAlignment.MiddleRight;//
// txt_julinr
//this.txt_julinr.Location = new System.Drawing.Point(144, 88);
this.txt_julinr.Name = "txt_julinr";
this.txt_julinr.ReadOnly = true;
this.txt_julinr.Size = new System.Drawing.Size(96, 20);
this.txt_julinr.TabIndex = 15;
this.txt_julinr.TabStop = false;
this.txt_julinr.Text = "";
this.txt_julinr.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;//
// Form1
//this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.btn_Ende;
this.ClientSize = new System.Drawing.Size(264, 246);
this.Controls.Add(this.txt_julinr);
this.Controls.Add(this.txt_WoTag);
this.Controls.Add(this.txt_Monat);
this.Controls.Add(this.txt_Tag);
this.Controls.Add(this.txt_Jahr);
this.Controls.Add(this.lbl_julinr);
this.Controls.Add(this.lbl_WoTag);
this.Controls.Add(this.btn_Rechne);
this.Controls.Add(this.lbl_Monat);
this.Controls.Add(this.lbl_Tag);
this.Controls.Add(this.lbl_Jahr);
this.Controls.Add(this.btn_Ende);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Wochentag";
this.ResumeLayout(false);}
#endregion/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>[STAThread]
static void Main()
{Application.Run(new Form1());
}
private void btn_Ende_Click(object sender, System.EventArgs e)
{this.Close();
}
private void btn_Rechne_Click(object sender, System.EventArgs e)
{//Ausnahmebehandlungen
try
{t=Convert.ToInt16(txt_Tag.Text);
}
catch(System.Exception ee)
{MessageBox.Show("Tageseingabe: "+ee.Message);
}
try
{m=Convert.ToInt16(txt_Monat.Text);
}
catch(Exception ee) //Exception liegt im Namespace System
{MessageBox.Show("Monatseingabe: "+ee.Message);
}
try
{j=Convert.ToInt16(txt_Jahr.Text);
}
catch(Exception ee)
{MessageBox.Show("Jahresseingabe: "+ee.Message);
MessageBox.Show("Die Jahreszahl wird auf 1 gesetzt !");
j=1;
txt_Jahr.Text="1";}
finally
{//Wird immer ausgeführt
}
WoTag=Convert.ToInt16(julinr(t,m,j)%7);
txt_WoTag.Text=TagText(WoTag);
txt_julinr.Text=Convert.ToString(julinr(t,m,j));}
private ulong julinr(int t,int m, int j)
{int h;
int k;
ulong a;
ulong b;
ulong c;
ulong n;
if(m>2)
{m-=3;
}
else
{m+=9;
j--;}
h=j/100;
k=j%100;
a=(146097*Convert.ToUInt64(h))/4;
b=(1461*Convert.ToUInt64(k))/4;
c=(153*Convert.ToUInt64(m)+2)/5;
n=a+b+c+Convert.ToUInt64(t)+1721119;
return n;}
private string TagText(int zhlTag)
{switch(zhlTag)
{case 0:
return "MONTAG";
break;case 1:
return "DIENSTAG";
break;case 2:
return "MITTWOCH";
break;case 3:
return "DONNERSTAG";
break;case 4:
return "FREITAG";
break;case 5:
return "SAMSTAG";
break;ccase 6:
return "SONNTAG";
break;default:
return "LEER";
}
}
private void txt_Tag_Click(object sender, System.EventArgs e)
{txt_Tag.Text="";
}
private void txt_Monat_Click(object sender, System.EventArgs e)
{txt_Monat.Text="";
}
private void txt_Jahr_Click(object sender, System.EventArgs e)
{txt_Jahr.Text="";
}
}
}