Feld Kategorie ergänzt

This commit is contained in:
meinholdc 2026-03-03 23:29:39 +01:00
parent 75c9eb2be8
commit 7a9dfb9c2c
2 changed files with 95 additions and 24 deletions

View File

@ -48,6 +48,8 @@
sePreisProWochenende = new DevExpress.XtraEditors.SpinEdit();
sePreisProWoche = new DevExpress.XtraEditors.SpinEdit();
meBezeichnung = new DevExpress.XtraEditors.MemoEdit();
labelControl10 = new DevExpress.XtraEditors.LabelControl();
lueKategorie = new DevExpress.XtraEditors.LookUpEdit();
tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)seKaution.Properties).BeginInit();
((System.ComponentModel.ISupportInitialize)txtName.Properties).BeginInit();
@ -58,19 +60,20 @@
((System.ComponentModel.ISupportInitialize)sePreisProWochenende.Properties).BeginInit();
((System.ComponentModel.ISupportInitialize)sePreisProWoche.Properties).BeginInit();
((System.ComponentModel.ISupportInitialize)meBezeichnung.Properties).BeginInit();
((System.ComponentModel.ISupportInitialize)lueKategorie.Properties).BeginInit();
SuspendLayout();
//
// tableLayoutPanel1
//
tableLayoutPanel1.ColumnCount = 8;
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3614454F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3614454F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3614454F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3614454F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.375F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9.875F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.0642567F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.0642567F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.37969F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3796825F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3796825F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10.3796825F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.4038219F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9.892382F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.0925312F));
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.0925312F));
tableLayoutPanel1.Controls.Add(seKaution, 5, 3);
tableLayoutPanel1.Controls.Add(labelControl1, 0, 0);
tableLayoutPanel1.Controls.Add(labelControl6, 4, 0);
@ -79,22 +82,27 @@
tableLayoutPanel1.Controls.Add(labelControl9, 4, 3);
tableLayoutPanel1.Controls.Add(labelControl4, 0, 2);
tableLayoutPanel1.Controls.Add(labelControl5, 0, 3);
tableLayoutPanel1.Controls.Add(labelControl2, 0, 4);
tableLayoutPanel1.Controls.Add(labelControl2, 0, 7);
tableLayoutPanel1.Controls.Add(txtName, 1, 0);
tableLayoutPanel1.Controls.Add(txtModell, 1, 2);
tableLayoutPanel1.Controls.Add(txtSeriennummer, 1, 3);
tableLayoutPanel1.Controls.Add(lueHersteller, 1, 1);
tableLayoutPanel1.Controls.Add(btnWerkzeugHinzufügen, 2, 8);
tableLayoutPanel1.Controls.Add(btnWerkzeugHinzufügen, 2, 11);
tableLayoutPanel1.Controls.Add(labelControl3, 0, 1);
tableLayoutPanel1.Controls.Add(sePreisProTag, 5, 0);
tableLayoutPanel1.Controls.Add(sePreisProWochenende, 5, 1);
tableLayoutPanel1.Controls.Add(sePreisProWoche, 5, 2);
tableLayoutPanel1.Controls.Add(meBezeichnung, 1, 4);
tableLayoutPanel1.Controls.Add(meBezeichnung, 1, 7);
tableLayoutPanel1.Controls.Add(labelControl10, 0, 4);
tableLayoutPanel1.Controls.Add(lueKategorie, 1, 4);
tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(6);
tableLayoutPanel1.Name = "tableLayoutPanel1";
tableLayoutPanel1.RowCount = 10;
tableLayoutPanel1.RowCount = 13;
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 64F));
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 64F));
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 64F));
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 64F));
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 64F));
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 64F));
@ -195,7 +203,7 @@
// labelControl2
//
labelControl2.Anchor = System.Windows.Forms.AnchorStyles.Left;
labelControl2.Location = new System.Drawing.Point(6, 275);
labelControl2.Location = new System.Drawing.Point(6, 467);
labelControl2.Margin = new System.Windows.Forms.Padding(6);
labelControl2.Name = "labelControl2";
labelControl2.Size = new System.Drawing.Size(126, 25);
@ -247,7 +255,7 @@
//
tableLayoutPanel1.SetColumnSpan(btnWerkzeugHinzufügen, 2);
btnWerkzeugHinzufügen.Dock = System.Windows.Forms.DockStyle.Fill;
btnWerkzeugHinzufügen.Location = new System.Drawing.Point(314, 518);
btnWerkzeugHinzufügen.Location = new System.Drawing.Point(314, 710);
btnWerkzeugHinzufügen.Margin = new System.Windows.Forms.Padding(6);
btnWerkzeugHinzufügen.Name = "btnWerkzeugHinzufügen";
btnWerkzeugHinzufügen.Size = new System.Drawing.Size(296, 52);
@ -311,12 +319,32 @@
//
tableLayoutPanel1.SetColumnSpan(meBezeichnung, 6);
meBezeichnung.Dock = System.Windows.Forms.DockStyle.Fill;
meBezeichnung.Location = new System.Drawing.Point(157, 259);
meBezeichnung.Location = new System.Drawing.Point(157, 451);
meBezeichnung.Name = "meBezeichnung";
tableLayoutPanel1.SetRowSpan(meBezeichnung, 4);
meBezeichnung.Size = new System.Drawing.Size(1085, 250);
meBezeichnung.TabIndex = 27;
//
// labelControl10
//
labelControl10.Anchor = System.Windows.Forms.AnchorStyles.Left;
labelControl10.Location = new System.Drawing.Point(6, 275);
labelControl10.Margin = new System.Windows.Forms.Padding(6);
labelControl10.Name = "labelControl10";
labelControl10.Size = new System.Drawing.Size(95, 25);
labelControl10.TabIndex = 28;
labelControl10.Text = "Kategorie:";
//
// lueKategorie
//
tableLayoutPanel1.SetColumnSpan(lueKategorie, 3);
lueKategorie.Dock = System.Windows.Forms.DockStyle.Fill;
lueKategorie.Location = new System.Drawing.Point(157, 259);
lueKategorie.Name = "lueKategorie";
lueKategorie.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo) });
lueKategorie.Size = new System.Drawing.Size(456, 40);
lueKategorie.TabIndex = 29;
//
// FrmWerkzeugeHinzufügen
//
AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
@ -340,6 +368,7 @@
((System.ComponentModel.ISupportInitialize)sePreisProWochenende.Properties).EndInit();
((System.ComponentModel.ISupportInitialize)sePreisProWoche.Properties).EndInit();
((System.ComponentModel.ISupportInitialize)meBezeichnung.Properties).EndInit();
((System.ComponentModel.ISupportInitialize)lueKategorie.Properties).EndInit();
ResumeLayout(false);
}
@ -365,5 +394,7 @@
private DevExpress.XtraEditors.SpinEdit sePreisProWochenende;
private DevExpress.XtraEditors.SpinEdit sePreisProWoche;
private DevExpress.XtraEditors.MemoEdit meBezeichnung;
private DevExpress.XtraEditors.LabelControl labelControl10;
private DevExpress.XtraEditors.LookUpEdit lueKategorie;
}
}

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Werkzeugverleih.Formen.Stammdaten;
using Werkzeugverleih.Klassen;
namespace Werkzeugverleih.Formen.Werkzeuge
@ -18,6 +19,8 @@ namespace Werkzeugverleih.Formen.Werkzeuge
{
InitializeComponent();
lueHerstellerFüllen();
lueKategorieFüllen();
}
private void FrmWerkzeugeHinzufügen_Shown(object sender, EventArgs e)
@ -57,33 +60,70 @@ namespace Werkzeugverleih.Formen.Werkzeuge
lueHersteller.EditValue = null;
}
private void lueKategorieFüllen()
{
List<Hauptkategorie> kategorie = new List<Hauptkategorie>();
using (var con = new MySqlConnection(DBTools.ConnectionString()))
{
con.Open();
const string sql = @"SELECT id, name FROM tool_categories ORDER BY name;";
using (var cmd = new MySqlCommand(sql, con))
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
kategorie.Add(new Hauptkategorie
{
Id = reader.GetInt32("id"),
Name = reader.GetString("name")
});
}
}
}
lueKategorie.Properties.DataSource = kategorie;
lueKategorie.Properties.DisplayMember = nameof(Hauptkategorie.Name);
lueKategorie.Properties.ValueMember = nameof(Hauptkategorie.Id);
lueKategorie.Properties.NullText = "(keine Kategorie)";
lueKategorie.EditValue = null;
}
private void btnWerkzeugHinzufügen_Click(object sender, EventArgs e)
{
string name = txtName.Text;
int manufacturer_id = Convert.ToInt32(lueHersteller.EditValue);
int category_id = Convert.ToInt32(lueKategorie.EditValue);
string model = txtModell.Text;
string description = meBezeichnung.Text;
// Hol den 'decimal'-Wert aus den SpinEdits, multipliziere mit 100 und konvertiere zu int.
// Dies ist der sichere und richtige Weg!
int daily_price_cents = Convert.ToInt32(sePreisProTag.Value * 100);
int weekend_price_cents = Convert.ToInt32(sePreisProWochenende.Value * 100);
int weekly_price_cents = Convert.ToInt32(sePreisProWoche.Value * 100);
int deposit_cents = Convert.ToInt32(seKaution.Value * 100);
//category_id`, `location_id`,`description`, ``, `serial_number`, `status`, `purchase_date`, `purchase_price_cents`, `replacement_value_cents`, `daily_price_cents`, `weekend_price_cents`, `weekly_price_cents`, `deposit_cents`, `is_active`, `created_at`, `updated_at`, `qr_code`, `manufacturer_id`
try
{
using (MySqlConnection con = new MySqlConnection(DBTools.ConnectionString()))
{
con.Open();
string sql = @"INSERT INTO tools (name, manufacturer_id, model, daily_price_cents, weekend_price_cents, weekly_price_cents, deposit_cents)
VALUES (@name, @manufacturer_id, @model, @daily_price_cents, @weekend_price_cents, @weekly_price_cents, @deposit_cents)";
string sql = @"INSERT INTO tools (name, category_id, manufacturer_id, model, daily_price_cents, weekend_price_cents, weekly_price_cents, deposit_cents)
VALUES (@name, @category_id, @manufacturer_id, @model, @daily_price_cents, @weekend_price_cents, @weekly_price_cents, @deposit_cents)";
using (MySqlCommand cmd = new MySqlCommand(sql, con))
{
// Die Parameter werden jetzt mit den korrekten Integer-Werten (in Cent) befüllt.
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("category_id", category_id);
cmd.Parameters.AddWithValue("@manufacturer_id", manufacturer_id);
cmd.Parameters.AddWithValue("@model", model);
cmd.Parameters.AddWithValue("@daily_price_cents", daily_price_cents);