Update vor Umbau Service
This commit is contained in:
156
API_NetFramework/SelectTable.aspx.cs
Normal file
156
API_NetFramework/SelectTable.aspx.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Web.Services;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
using System.Web.UI;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using System.Configuration;
|
||||
using Model;
|
||||
|
||||
namespace WebApp
|
||||
{
|
||||
public partial class SelectTable : System.Web.UI.Page
|
||||
{
|
||||
private string ConnectionString = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
|
||||
|
||||
private TableConfig CurrentTable =>
|
||||
TableConfigProvider.LoadConfig().Tables.FirstOrDefault(t => t.Key == ddlTables.SelectedValue);
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
BindTables();
|
||||
}
|
||||
|
||||
private void BindTables()
|
||||
{
|
||||
var config = TableConfigProvider.LoadConfig();
|
||||
ddlTables.DataSource = config.Tables;
|
||||
ddlTables.DataTextField = "DisplayName";
|
||||
ddlTables.DataValueField = "Key";
|
||||
ddlTables.DataBind();
|
||||
ddlTables.Items.Insert(0, "-- bitte wählen --");
|
||||
}
|
||||
|
||||
protected void ddlTables_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
gvData.PageIndex = 0;
|
||||
LoadTableData();
|
||||
}
|
||||
|
||||
protected void gvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
|
||||
{
|
||||
gvData.PageIndex = e.NewPageIndex;
|
||||
LoadTableData();
|
||||
}
|
||||
|
||||
private void LoadTableData()
|
||||
{
|
||||
if (ddlTables.SelectedIndex <= 0 || CurrentTable == null) return;
|
||||
var cfg = CurrentTable;
|
||||
|
||||
using (var con = new SqlConnection(ConnectionString))
|
||||
using (var cmd = new SqlCommand(cfg.SqlList, con))
|
||||
{
|
||||
var dt = new DataTable();
|
||||
con.Open();
|
||||
dt.Load(cmd.ExecuteReader());
|
||||
gvData.DataSource = dt;
|
||||
gvData.DataBind();
|
||||
}
|
||||
}
|
||||
|
||||
protected void gvData_RowCreated(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.Header)
|
||||
e.Row.Cells.Add(new TableHeaderCell { Text = "Details" });
|
||||
}
|
||||
|
||||
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType != DataControlRowType.DataRow) return;
|
||||
var cfg = CurrentTable;
|
||||
if (cfg == null) return;
|
||||
|
||||
var id = DataBinder.Eval(e.Row.DataItem, cfg.IdField)?.ToString();
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
|
||||
string tableKeyJs = HttpUtility.JavaScriptStringEncode(cfg.Key);
|
||||
string idJs = HttpUtility.JavaScriptStringEncode(id);
|
||||
|
||||
var cell = new TableCell();
|
||||
var lnk = new LinkButton
|
||||
{
|
||||
Text = "Öffnen",
|
||||
CssClass = "open"
|
||||
};
|
||||
lnk.OnClientClick = $"loadJson('{tableKeyJs}','{idJs}'); return false;";
|
||||
cell.Controls.Add(lnk);
|
||||
e.Row.Cells.Add(cell);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
//public static object GetJson(string table, string id)
|
||||
//{
|
||||
// var config = TableConfigProvider.LoadConfig();
|
||||
// var cfg = config.Tables.FirstOrDefault(t => t.Key == table);
|
||||
// if (cfg == null) return new { error = "Tabelle nicht gefunden" };
|
||||
|
||||
// using (var con = new SqlConnection(StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm")))
|
||||
// using (var cmd = new SqlCommand(cfg.SqlById, con))
|
||||
// {
|
||||
// cmd.Parameters.AddWithValue("@id", id);
|
||||
// con.Open();
|
||||
// var json = cmd.ExecuteScalar()?.ToString();
|
||||
// if (string.IsNullOrEmpty(json))
|
||||
// return new { error = "Datensatz nicht gefunden" };
|
||||
// return JsonConvert.DeserializeObject(json);
|
||||
// }
|
||||
//}
|
||||
|
||||
public static object GetJson(string table, string id)
|
||||
{
|
||||
var config = TableConfigProvider.LoadConfig();
|
||||
var cfg = config.Tables.FirstOrDefault(t => t.Key == table);
|
||||
if (cfg == null) return"Tabelle nicht gefunden" ;
|
||||
|
||||
using (var con = new SqlConnection(StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm")))
|
||||
using (var cmd = new SqlCommand(cfg.SqlById, con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
con.Open();
|
||||
string json = cmd.ExecuteScalar()?.ToString();
|
||||
if (string.IsNullOrEmpty(json)) return "Datensatz nicht gefunden" ;
|
||||
|
||||
try
|
||||
{
|
||||
if (json.TrimStart().StartsWith("\""))
|
||||
{
|
||||
json = JsonConvert.DeserializeObject<string>(json);
|
||||
}
|
||||
|
||||
Versandpaket vp = new Versandpaket();
|
||||
vp = JsonConvert.DeserializeObject<Versandpaket>(json);
|
||||
vp.finaldoc = "ABCD...";
|
||||
foreach (Versanddokument vd in vp.Dokument)
|
||||
{
|
||||
vd.dokument = "ABC...";
|
||||
}
|
||||
//vp.Dokument.Clear();
|
||||
json = JsonConvert.SerializeObject(vp, Formatting.Indented);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
// JSON in Objekt parsen, damit PageMethods es korrekt als JS-Objekt liefert
|
||||
return (json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user