File FrmInputDataBarang
File FrmInputDataBarang
cs
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using TokoJoniApp.DAL;
namespace TokoJoniApp.Forms
{
public partial class FrmInputDataBarang : Form
{
private bool isEditMode = false;
private string originalKodeBarang = "";
private DataTable dtKelompokBarang; // Menyimpan data kelompok barang
public FrmInputDataBarang()
{
InitializeComponent();
LoadKelompokBarang(); // Muat data kelompok barang
}
if (hasHargaKhusus && !
decimal.TryParse(harga_khusus_TxBox_inBarang.Text.Trim(), out hk))
{
MessageBox.Show("Harga khusus harus berupa angka!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
using (var conn = new Database().GetConnection())
{
conn.Open();
// Siapkan query
string query = "";
OleDbCommand cmd;
if (isEditMode)
{
// Update jika sudah ada
query = "UPDATE tbBarang SET nama_barang = ?,
KelompokBarang_ID = ?, harga_beli = ?, harga_jual = ?, harga_khusus = ? WHERE
kode_barang = ?";
}
else
{
// Insert barang baru
query = "INSERT INTO tbBarang (kode_barang, nama_barang,
KelompokBarang_ID, harga_beli, harga_jual, harga_khusus) VALUES
(?, ?, ?, ?, ?, ?)";
}
File FrmInputDataBarang.Designer.cs
using System;
using System.Windows.Forms;
namespace TokoJoniApp.Forms
{
partial class FrmInputDataBarang
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.simpan_btn_inBarang = new System.Windows.Forms.Button();
this.clear_btn_inBarang = new System.Windows.Forms.Button();
this.close_btn_inBarang = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.kode_barang_TxBox_inBarang = new System.Windows.Forms.TextBox();
this.nama_barang_TxBox_inBarang = new System.Windows.Forms.TextBox();
this.harga_beli_TxBox_inBarang = new System.Windows.Forms.TextBox();
this.harga_jual_TxBox_inBarang = new System.Windows.Forms.TextBox();
this.harga_khusus_TxBox_inBarang = new System.Windows.Forms.TextBox();
this.kelompok_ComBox_inBarang = new System.Windows.Forms.ComboBox();
this.user_ID_error_Label_inUser = new System.Windows.Forms.Label(); //
Tambahkan jika dibutuhkan untuk validasi
this.SuspendLayout();
//
// simpan_btn_inBarang
//
this.simpan_btn_inBarang.Location = new System.Drawing.Point(50, 230);
this.simpan_btn_inBarang.Name = "simpan_btn_inBarang";
this.simpan_btn_inBarang.Size = new System.Drawing.Size(100, 30);
this.simpan_btn_inBarang.TabIndex = 7;
this.simpan_btn_inBarang.Text = "Simpan";
this.simpan_btn_inBarang.UseVisualStyleBackColor = true;
this.simpan_btn_inBarang.Click += new
System.EventHandler(this.simpan_btn_inBarang_Click);
//
// clear_btn_inBarang
//
this.clear_btn_inBarang.Location = new System.Drawing.Point(160, 230);
this.clear_btn_inBarang.Name = "clear_btn_inBarang";
this.clear_btn_inBarang.Size = new System.Drawing.Size(100, 30);
this.clear_btn_inBarang.TabIndex = 8;
this.clear_btn_inBarang.Text = "Clear";
this.clear_btn_inBarang.UseVisualStyleBackColor = true;
this.clear_btn_inBarang.Click += new
System.EventHandler(this.clear_btn_inBarang_Click);
//
// close_btn_inBarang
//
this.close_btn_inBarang.Location = new System.Drawing.Point(270, 230);
this.close_btn_inBarang.Name = "close_btn_inBarang";
this.close_btn_inBarang.Size = new System.Drawing.Size(100, 30);
this.close_btn_inBarang.TabIndex = 9;
this.close_btn_inBarang.Text = "Tutup";
this.close_btn_inBarang.UseVisualStyleBackColor = true;
this.close_btn_inBarang.Click += new
System.EventHandler(this.close_btn_inBarang_Click);
//
// label1 (Kode Barang)
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(50, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(70, 20);
this.label1.Text = "Kode Barang";
//
// label2 (Nama Barang)
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(50, 60);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(70, 20);
this.label2.Text = "Nama Barang";
//
// label3 (Kelompok)
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(50, 90);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(70, 20);
this.label3.Text = "Kelompok";
//
// label4 (Harga Beli)
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(50, 120);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(70, 20);
this.label4.Text = "Harga Beli";
//
// label5 (Harga Jual)
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(50, 150);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(70, 20);
this.label5.Text = "Harga Jual";
//
// label6 (Harga Khusus)
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(50, 180);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(70, 20);
this.label6.Text = "Harga Khusus";
//
// kode_barang_TxBox_inBarang
//
this.kode_barang_TxBox_inBarang.Location = new
System.Drawing.Point(150, 27);
this.kode_barang_TxBox_inBarang.Name = "kode_barang_TxBox_inBarang";
this.kode_barang_TxBox_inBarang.Size = new System.Drawing.Size(150,
25);
this.kode_barang_TxBox_inBarang.TabIndex = 0;
//
// nama_barang_TxBox_inBarang
//
this.nama_barang_TxBox_inBarang.Location = new
System.Drawing.Point(150, 57);
this.nama_barang_TxBox_inBarang.Name = "nama_barang_TxBox_inBarang";
this.nama_barang_TxBox_inBarang.Size = new System.Drawing.Size(200,
25);
this.nama_barang_TxBox_inBarang.TabIndex = 1;
//
// harga_beli_TxBox_inBarang
//
this.harga_beli_TxBox_inBarang.Location = new System.Drawing.Point(150,
117);
this.harga_beli_TxBox_inBarang.Name = "harga_beli_TxBox_inBarang";
this.harga_beli_TxBox_inBarang.Size = new System.Drawing.Size(100, 25);
this.harga_beli_TxBox_inBarang.TabIndex = 3;
this.harga_beli_TxBox_inBarang.Leave += new
System.EventHandler(this.ValidateHargaBeliOnLeave);
//
// harga_jual_TxBox_inBarang
//
this.harga_jual_TxBox_inBarang.Location = new System.Drawing.Point(150,
147);
this.harga_jual_TxBox_inBarang.Name = "harga_jual_TxBox_inBarang";
this.harga_jual_TxBox_inBarang.Size = new System.Drawing.Size(100, 25);
this.harga_jual_TxBox_inBarang.TabIndex = 4;
this.harga_jual_TxBox_inBarang.Leave += new
System.EventHandler(this.ValidateHargaJualOnLeave);
//
// harga_khusus_TxBox_inBarang
//
this.harga_khusus_TxBox_inBarang.Location = new
System.Drawing.Point(150, 177);
this.harga_khusus_TxBox_inBarang.Name = "harga_khusus_TxBox_inBarang";
this.harga_khusus_TxBox_inBarang.Size = new System.Drawing.Size(100,
25);
this.harga_khusus_TxBox_inBarang.TabIndex = 5;
this.harga_khusus_TxBox_inBarang.Leave += new
System.EventHandler(this.ValidateHargaKhususOnLeave);
//
// kelompok_ComBox_inBarang
//
this.kelompok_ComBox_inBarang.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.kelompok_ComBox_inBarang.FormattingEnabled = true;
this.kelompok_ComBox_inBarang.Location = new System.Drawing.Point(150,
87);
this.kelompok_ComBox_inBarang.Name = "kelompok_ComBox_inBarang";
this.kelompok_ComBox_inBarang.Size = new System.Drawing.Size(150, 25);
this.kelompok_ComBox_inBarang.TabIndex = 2;
//
// user_ID_error_Label_inUser (untuk validasi error)
//
this.user_ID_error_Label_inUser.AutoSize = true;
this.user_ID_error_Label_inUser.ForeColor = System.Drawing.Color.Red;
this.user_ID_error_Label_inUser.Location = new
System.Drawing.Point(150, 50);
this.user_ID_error_Label_inUser.Name = "user_ID_error_Label_inUser";
this.user_ID_error_Label_inUser.Size = new System.Drawing.Size(0, 13);
this.user_ID_error_Label_inUser.TabIndex = 10;
//
// FrmInputDataBarang
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(400, 300);
this.Controls.Add(this.kelompok_ComBox_inBarang);
this.Controls.Add(this.harga_khusus_TxBox_inBarang);
this.Controls.Add(this.harga_jual_TxBox_inBarang);
this.Controls.Add(this.harga_beli_TxBox_inBarang);
this.Controls.Add(this.nama_barang_TxBox_inBarang);
this.Controls.Add(this.kode_barang_TxBox_inBarang);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.close_btn_inBarang);
this.Controls.Add(this.clear_btn_inBarang);
this.Controls.Add(this.simpan_btn_inBarang);
this.Name = "FrmInputDataBarang";
this.Text = "Input Data Barang";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion