I want the data coming from the database to be sorted as subheadings, first the Thickness will be given and the Genres belonging to that thickness will be displayed. When I click, it will open under it, and then I want the colors of the type we pressed to appear.
My code is as below.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
namespace Randuman
{
public partial class Iplık_Cozgu : Form
{
public Iplık_Cozgu()
{
InitializeComponent();
}
sqlbaglanti bgl = new sqlbaglanti();
private DataTable iplikTable;
private void InitializeTables()
{
iplikTable = new DataTable();
iplikTable.Columns.Add("Kalınlık", typeof(float));
iplikTable.Columns.Add("Cins", typeof(string));
iplikTable.Columns.Add("Renk", typeof(string));
iplikTable.Columns.Add("Birim", typeof(string));
iplikTable.Columns.Add("TARIH", typeof(string));
}
private void SetupGridControl()
{
gridControl1.DataSource = iplikTable;
GridView kalinlikView = gridControl1.MainView as GridView;
GridView cinsView = new GridView(gridControl1);
GridView renkView = new GridView(gridControl1);
gridControl1.LevelTree.Nodes.Add("Kalınlık", cinsView);
gridControl1.LevelTree.Nodes.Add("Cins", renkView);
cinsView.PopulateColumns(iplikTable);
renkView.PopulateColumns(iplikTable);
// Set Relations
gridControl1.LevelTree.Nodes["Kalınlık"].RelationName = "Kalınlık_Cins";
gridControl1.LevelTree.Nodes["Cins"].RelationName = "Cins_Renk";
}
private void LoadData()
{
// Load Iplik Data
SqlCommand cmd = new SqlCommand($"SELECT Kalınlık, Cins, Renk, Birim, TARIH FROM {config.IPLIK} ORDER BY Kalınlık, Cins, Renk", bgl.Connection());
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(iplikTable);
bgl.Connection().Close();
}
private void Clear()
{
CozguName.Text = string.Empty;
Tel.Text = string.Empty;
En.Text = string.Empty;
}
private void ClearIplıkAll()
{
kalın.Text = string.Empty;
birim.Text = string.Empty;
cins.Text = string.Empty;
renk.Text = string.Empty;
}
private void ClearSave()
{
renk.Text = string.Empty;
}
private void ListDbCombo()
{
SqlCommand cmd = new SqlCommand($"SELECT DISTINCT Renk from {config.IPLIK}", bgl.Connection());
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
renk.Properties.Items.Add(dr[0].ToString());
}
bgl.Connection().Close();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand($"insert into {config.COZGU} (Ad,Tel,En,TARIH) values(@p1,@p2,@p3,@p4)", bgl.Connection());
cmd.Parameters.AddWithValue("@p1", CozguName.Text.Trim());
cmd.Parameters.AddWithValue("@p2", Tel.Text);
cmd.Parameters.AddWithValue("@p3", En.Text);
cmd.Parameters.AddWithValue("@p4", DateTime.Now.ToString("dd.MM.yyyy - HH:mm"));
cmd.ExecuteNonQuery();
bgl.Connection().Close();
MessageBox.Show("Çözgü Başarıyla Veritabanına Kaydedildi.", "Kayıt Başarılı!", MessageBoxButtons.OK, MessageBoxIcon.Information);
Thread.Sleep(1);
Clear();
}
catch (SqlException ex)
{
MessageBox.Show("VeriTabanı Hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show("Program Hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void simpleButton2_Click(object sender, EventArgs e)
{
Clear();
}
private void simpleButton4_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand($"insert into {config.IPLIK} (Kalınlık,Birim,Cins,Renk,TARIH) values(@p1,@p2,@p3,@p4,@p5)", bgl.Connection());
cmd.Parameters.AddWithValue("@p1", kalın.Text.Trim());
cmd.Parameters.AddWithValue("@p2", birim.Text);
cmd.Parameters.AddWithValue("@p3", cins.Text);
cmd.Parameters.AddWithValue("@p4", renk.Text);
cmd.Parameters.AddWithValue("@p5", DateTime.Now.ToString("dd.MM.yyyy - HH:mm"));
cmd.ExecuteNonQuery();
bgl.Connection().Close();
MessageBox.Show("İplik " + cins.Text + " Başarıyla Veritabanına Kaydedildi.", "Kayıt Başarılı!", MessageBoxButtons.OK, MessageBoxIcon.Information);
Thread.Sleep(1);
ClearSave();
}
catch (FormatException ex)
{
MessageBox.Show("Kullanıcı Hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (SqlException ex)
{
MessageBox.Show("VeriTabanı Hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show("Program Hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Iplık_Cozgu_Load(object sender, EventArgs e)
{
InitializeTables();
LoadData();
SetupGridControl();
}
private void XtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
{
if (e.Page.Text == "Çözgü Kayıt")
{
}
else if (e.Page.Text == "İPLİK KAYIT")
{
LoadData();
ListDbCombo();
}
}
private void simpleButton3_Click(object sender, EventArgs e)
{
ClearIplıkAll();
}
}
}
1