193 lines
8.7 KiB
C#
193 lines
8.7 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Web;
|
|||
|
|
using System.Web.Routing;
|
|||
|
|
using System.Web.UI;
|
|||
|
|
|
|||
|
|
namespace safety
|
|||
|
|
{
|
|||
|
|
public static class General
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static void setTitle(MasterPage Master, object s)
|
|||
|
|
{
|
|||
|
|
if (s is string)
|
|||
|
|
{
|
|||
|
|
string PageTitle = s as string;
|
|||
|
|
if (s != null)
|
|||
|
|
{
|
|||
|
|
var pt = Master.FindControl("PageTitle") as System.Web.UI.WebControls.Literal;
|
|||
|
|
if (pt != null && PageTitle.Length > 0) pt.Text = PageTitle;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
static string UrlWithoutLang(Page p, string url, bool addParLang = true)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
var x = url.Split('?');
|
|||
|
|
if (x.Length > 0)
|
|||
|
|
{
|
|||
|
|
string newUrl = x[0];
|
|||
|
|
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
foreach (string d in p.Request.QueryString.AllKeys) if (!string.IsNullOrWhiteSpace(d) && !d.Equals("lang", StringComparison.InvariantCultureIgnoreCase)) sb.AppendFormat("{0}{1}={2}", sb.Length == 0 ? "?" : "&", d, p.Request.Params[d].ToString());
|
|||
|
|
if (addParLang) sb.AppendFormat("{0}{1}", sb.Length == 0 ? "?" : "&", "lang=");
|
|||
|
|
return string.Concat(newUrl, sb.ToString());
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static string UrlWithoutLang(Page p, bool addParLang=true)
|
|||
|
|
{
|
|||
|
|
string url = p.Request.Url.LocalPath;
|
|||
|
|
return UrlWithoutLang(p, url, addParLang);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void setLang(MasterPage Master, Page p , System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, string>> para, string PageTitle="", string otherurl="" )
|
|||
|
|
{
|
|||
|
|
System.Web.UI.HtmlControls.HtmlAnchor hn = Master.FindControl("liNL") as System.Web.UI.HtmlControls.HtmlAnchor;
|
|||
|
|
System.Web.UI.HtmlControls.HtmlAnchor hf = Master.FindControl("liFR") as System.Web.UI.HtmlControls.HtmlAnchor;
|
|||
|
|
System.Web.UI.HtmlControls.HtmlAnchor he = Master.FindControl("liEN") as System.Web.UI.HtmlControls.HtmlAnchor;
|
|||
|
|
|
|||
|
|
string href = UrlWithoutLang(p,true);
|
|||
|
|
if (!string.IsNullOrWhiteSpace(otherurl))
|
|||
|
|
href = UrlWithoutLang(p, otherurl, true);
|
|||
|
|
|
|||
|
|
if (hn != null) {hn.HRef = href + "nl"; hn.Visible = true;}
|
|||
|
|
if (hf != null) {hf.HRef = href + "fr";hf.Visible = true;}
|
|||
|
|
if (he != null) { he.HRef = href + "en"; he.Visible = true; }
|
|||
|
|
|
|||
|
|
if (PageTitle.Length>0) setTitle(Master, PageTitle);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string GetString(Page p, string nm, string def="W")
|
|||
|
|
{
|
|||
|
|
int i;
|
|||
|
|
String rv = def;
|
|||
|
|
if (p.Request.Params[nm] != null)
|
|||
|
|
{
|
|||
|
|
rv = p.Request.Params[nm];
|
|||
|
|
}
|
|||
|
|
else if (p.RouteData.Values.ContainsKey(nm))
|
|||
|
|
{
|
|||
|
|
rv = p.RouteData.Values[nm].ToString();
|
|||
|
|
}
|
|||
|
|
else if (p.RouteData.DataTokens != null && p.RouteData.DataTokens.Count > 0 && p.RouteData.DataTokens.ContainsKey(nm))
|
|||
|
|
{
|
|||
|
|
rv = p.RouteData.DataTokens[nm].ToString();
|
|||
|
|
}
|
|||
|
|
return rv;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public static int? GetDocIDParam(Page p, string nm)
|
|||
|
|
{
|
|||
|
|
int i;
|
|||
|
|
int ? rv = null;
|
|||
|
|
if (p.Request.Params["id"] != null )
|
|||
|
|
{
|
|||
|
|
if (int.TryParse(p.Request.Params["id"].ToString(), out i)) rv = i;
|
|||
|
|
}
|
|||
|
|
else if (p.RouteData.Values.ContainsKey("docaID") )
|
|||
|
|
{
|
|||
|
|
if (int.TryParse(p.RouteData.Values["docaID"].ToString(), out i)) rv = i;
|
|||
|
|
}
|
|||
|
|
else if (p.RouteData.DataTokens != null && p.RouteData.DataTokens.Count > 0 && p.RouteData.DataTokens.ContainsKey("docaID") )
|
|||
|
|
{
|
|||
|
|
if (int.TryParse(p.RouteData.DataTokens["docaID"].ToString(), out i)) rv = i;
|
|||
|
|
}
|
|||
|
|
return rv;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string Getinterface(Page p)
|
|||
|
|
{
|
|||
|
|
string rv = string.Empty;
|
|||
|
|
if (p.RouteData!= null && p.RouteData.Values.ContainsKey("interface"))
|
|||
|
|
{
|
|||
|
|
rv = p.RouteData.Values["interface"].ToString();
|
|||
|
|
if (p.Session["interface"] == null || p.Session["interface"].ToString() != rv) p.Session["interface"] = rv;
|
|||
|
|
}
|
|||
|
|
return rv;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//http://contrast-finder.tanaguru.com/result.html?foreground=%23228888&background=%23DFF0D8&isBackgroundTested=false&ratio=4.5&algo=HSV
|
|||
|
|
public static Color bgRed = Color.FromArgb(220, 92, 80), fgRed = Color.FromArgb(30, 30, 30);
|
|||
|
|
public static Color bgGreen = Color.FromArgb(180, 204, 74), fgGreen = Color.Black;
|
|||
|
|
public static Color bgOrange = Color.FromArgb(178, 140, 69), fgOrange = Color.FromArgb(69, 117, 178);
|
|||
|
|
public static Color bgBlue = Color.FromArgb(92, 92, 178), fgBlue = Color.FromArgb(255, 255, 255);
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static void ColorCell(int vcolor, ref Color bc, ref Color fc)
|
|||
|
|
{
|
|||
|
|
switch (vcolor)
|
|||
|
|
{
|
|||
|
|
case 4: bc = bgBlue; fc = fgBlue; break;
|
|||
|
|
case 3: bc = bgRed; fc = fgRed; break;
|
|||
|
|
case 2: bc = bgOrange; fc = fgOrange; break;
|
|||
|
|
case 1: bc = bgGreen; fc = fgGreen; break;
|
|||
|
|
default: bc = Color.White; fc = Color.Black; break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
static public void SetSessionIfDifferent(Page p, string name, bool? value, bool deleteIfMissing = false)
|
|||
|
|
{
|
|||
|
|
if (value.HasValue)
|
|||
|
|
{
|
|||
|
|
if ( p.Session[name] == null || (bool)p.Session[name] != value.Value) p.Session[name] = value.Value;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
if (deleteIfMissing && p.Session[name] != null) p.Session.Remove(name);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
static public void SetSessionIfDifferent(Page p, string name, int? value, bool deleteIfMissing=false)
|
|||
|
|
{
|
|||
|
|
if (value.HasValue)
|
|||
|
|
{
|
|||
|
|
if (p.Session[name] == null || (int)p.Session[name] != value.Value) p.Session[name] = value.Value;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
if (deleteIfMissing && p.Session[name] != null) p.Session.Remove(name);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
static public void SetSessionIfDifferent(Page p, string name, string value)
|
|||
|
|
{
|
|||
|
|
if ( !String.IsNullOrWhiteSpace(value) && (p.Session[name] == null || p.Session[name].ToString() != value)) p.Session[name] = value;
|
|||
|
|
}
|
|||
|
|
static public void PageBasicSettings(Page p, ref int? AanvragerID, ref bool? isIV, ref bool? isNV, ref bool? isIDPBW, ref string lang, ref string aanvragerFullname, ref int? mentorID, ref string mentorFullname, ref int? unit, ref string building, ref string ifa, ref string soort)
|
|||
|
|
{
|
|||
|
|
using (dsIDPBWTableAdapters.QueriesTableAdapter qta = new dsIDPBWTableAdapters.QueriesTableAdapter())
|
|||
|
|
qta.getUser2(ref AanvragerID, ref isIV, ref isNV, ref isIDPBW, ref lang, ref aanvragerFullname, ref mentorID, ref mentorFullname, ref unit, ref building);
|
|||
|
|
SetSessionIfDifferent(p, "Aanvrager", AanvragerID);
|
|||
|
|
SetSessionIfDifferent(p, "isIDPBW", isIDPBW);
|
|||
|
|
if (p.Request.Params["lang"] != null) lang = p.Request.Params["lang"].ToString();
|
|||
|
|
SetSessionIfDifferent(p, "lang", lang);
|
|||
|
|
ifa = Getinterface(p); SetSessionIfDifferent(p, "interface", ifa);
|
|||
|
|
soort = GetString(p, "soort", string.Empty);
|
|||
|
|
SetSessionIfDifferent(p, "soort", soort);
|
|||
|
|
p.UICulture = lang;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static public void PageBasicSettings3(Page p, ref int? AanvragerID, ref bool? isIV, ref bool? isNV, ref bool? isIDPBW, ref string lang, ref string aanvragerFullname, ref int? mentorID, ref string mentorFullname, ref int? unit, ref string building, ref bool? isMedic, ref string ifa, ref string soort, ref string prefLang)
|
|||
|
|
{
|
|||
|
|
using (dsIDPBWTableAdapters.QueriesTableAdapter qta = new dsIDPBWTableAdapters.QueriesTableAdapter())
|
|||
|
|
qta.getUser3(ref AanvragerID, ref isIV, ref isNV, ref isIDPBW, ref lang, ref aanvragerFullname, ref mentorID, ref mentorFullname, ref unit, ref building, ref isMedic, ref prefLang);
|
|||
|
|
SetSessionIfDifferent(p, "Aanvrager", AanvragerID);
|
|||
|
|
SetSessionIfDifferent(p, "isIDPBW", isIDPBW);
|
|||
|
|
lang = prefLang;
|
|||
|
|
SetSessionIfDifferent(p, "lang", lang);
|
|||
|
|
ifa = Getinterface(p); SetSessionIfDifferent(p, "interface", ifa);
|
|||
|
|
soort = GetString(p, "soort", string.Empty);
|
|||
|
|
SetSessionIfDifferent(p, "soort", soort);
|
|||
|
|
p.UICulture = lang;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|