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.
96 lines
3.1 KiB
96 lines
3.1 KiB
using OnDoc.Klassen;
|
|
using Syncfusion.WinForms.DataGrid;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Database;
|
|
using System.Drawing;
|
|
|
|
namespace OnDoc.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)
|
|
{
|
|
|
|
DB db = new 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
public static string GetCellCValue(ref SfDataGrid grid,string columname)
|
|
{
|
|
try {
|
|
var selectedItem = grid.CurrentItem as DataRowView;
|
|
var dataRow = (selectedItem as DataRowView).Row;
|
|
var cellValue = dataRow[columname].ToString();
|
|
return cellValue;
|
|
}
|
|
catch { return ""; }
|
|
}
|
|
public static DataTable resort(DataTable dt, string colName, string direction)
|
|
{
|
|
dt.DefaultView.Sort = colName + " " + direction;
|
|
dt = dt.DefaultView.ToTable();
|
|
return dt;
|
|
}
|
|
}
|
|
}
|