You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB

using EDOKA_2024.Kalssen;
using Syncfusion.WinForms.DataGrid;
using Syncfusion.XlsIO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EDOKA_Database;
namespace EDOKA_2024.Helper
{
public static class TableHelper
{
public static void SetColumnsOrder(this DataTable dtbl, params String[] columnNames)
{
List<string> listColNames = columnNames.ToList();
//Remove invalid column names.
foreach (string colName in columnNames)
{
if (!dtbl.Columns.Contains(colName))
{
listColNames.Remove(colName);
}
}
foreach (string colName in listColNames)
{
dtbl.Columns[colName].SetOrdinal(listColNames.IndexOf(colName));
}
}
public static void FormatTable(ref DataTable tbl, string tablename, ref SfDataGrid grid)
{
EDOKA_DB db = new EDOKA_DB(AppParams.connectionstring);
db.Get_Tabledata("Select * from spalten where aktiv=1 and tabelle='" + tablename + "'", false, true);
foreach (System.Data.DataRow dr in db.dsdaten.Tables[0].Rows)
{
foreach (DataColumn dc in tbl.Columns)
{
if (dr["tabellenspalte"].ToString() == dc.ColumnName)
{
dc.SetOrdinal(Convert.ToInt32(dr["reihenfolge"].ToString()));
break;
}
}
tbl.AcceptChanges();
}
grid.DataSource = tbl;
foreach (System.Data.DataRow dr in db.dsdaten.Tables[0].Rows)
{
foreach (GridColumn col in grid.Columns)
{
if (col.HeaderText.ToString() == dr["tabellenspalte"].ToString())
{
col.HeaderText = dr["spalte"].ToString();
if (Convert.ToInt32(dr["Breite"].ToString()) > 0 )
{
col.Width = Convert.ToInt32(dr["Breite"].ToString());
}
if (Convert.ToBoolean(dr["Readonly"]) == true)
{
col.AllowEditing = false;
}
}
}
}
}
}
}