-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilitaires.cs
More file actions
222 lines (212 loc) · 8.16 KB
/
Copy pathUtilitaires.cs
File metadata and controls
222 lines (212 loc) · 8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using AliasPPM_Localisation.Properties;
using System;
using static AliasPPM_Localisation.ListeDeValeurs;
namespace AliasPPM_Localisation
{
public static class Utilitaires
{
#region Messages
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture = System.Globalization.CultureInfo.CurrentCulture;
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
private static global::System.Resources.ResourceManager ResourceManager
{
get
{
if (object.ReferenceEquals(resourceMan, null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AliasPPM_Localisation.Properties.Msg", typeof(Msg).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
public static string GetMessageErreur(string MsgCode)
{
if (string.IsNullOrEmpty(MsgCode)) return MsgCode;// return string.Format("{0} {1}", "null ", MsgCode);
if (MsgCode.Length > 4)
{
string msgCode = MsgCode.Substring(0, 4);
return GetMessageErreur(msgCode, MsgCode.Replace(msgCode, ""));
}
else
{
return string.Format("{0}", GetMessage(MsgCode));
}
}
public static string GetMessageErreur(string MsgCode, string MsgTxt)
{
string msg = GetMessage(MsgCode);
if (msg.Replace("xxxx", "") == msg)
{
return string.Format("{0}", msg + " | " + MsgTxt);
}
else
{
return string.Format("{0}", msg.Replace("xxxx", MsgTxt));
}
}
private static string GetMessage(string MsgCode)
{
string message = ResourceManager.GetString(MsgCode, resourceCulture);
if (string.IsNullOrEmpty(message))
{
return TexteAppli.TheMsg + " '" + MsgCode + "' " + TexteAppli.IsUnknown;
}
else
{
return message;
}
}
#endregion
#region #Conversion
public static Boolean IsNumeric(this string s)
{
float output;
return float.TryParse(s, out output);
}
public static UdeD ToUdeD(string u)
{
switch (u)
{
//case "mi"://Minute
//case "min":
// return UdeD.min;
//case "h"://Heure
// return UdeD.h;
//case "j"://Jour
case "d":
return UdeD.j;
case "s"://Semaine
case "w":
return UdeD.sem;
case "m"://Mois
case "mo":
return UdeD.mo;
case "tr"://Trimestre
return UdeD.trimestre;
case "se"://Semestre
return UdeD.semestre;
case "a"://Année
case "y":
return UdeD.a;
default:
return UdeD.j;
}
}
/// <summary>
/// Retourne l'unité de durée à partir de l'abréviation
/// </summary>
/// <param name="sts"></param>
/// <returns></returns>
public static UdeD SiUdeD(string sts)
{
switch (sts.ToLower())
{
case "min"://Minute
return UdeD.min;
case "h"://Heure
return UdeD.h;
case "d"://Jour
return UdeD.d;
case "j"://Jour
return UdeD.j;
case "w"://Semaine
return UdeD.w;
case "mo"://Mois
return UdeD.mo;
case "trimestre"://Trimestre
return UdeD.trimestre;
case "semestre"://Semestre
return UdeD.semestre;
case "a"://Année
return UdeD.a;
default:
return UdeD.sec;//Seconde
}
}
//public static TypeRessource ToTypeRessource(string t)
//{
// foreach (TypeRessource ty in Enum.GetValues(typeof(TypeRessource)))
// {
// if (ty.ToString() == t) return ty;
// }
// return TypeRessource.Alias_Main_DOeuvre;//Valeur par défaut
//}
//public static bool IsStrategieApprobation(string t)
//{
// foreach (StrategieApprobation s in Enum.GetValues(typeof(StrategieApprobation)))
// {
// if (s.ToString() == t) return true;
// }
// return false;
//}
//public static RoleUtilisateur ToRole(string role)
//{
// foreach (RoleUtilisateur ro in Enum.GetValues(typeof(RoleUtilisateur)))
// {
// if (ro.ToString() == role) return ro;
// }
// return RoleUtilisateur.Visiteur;
//}
#endregion #Conversion
#region Date
#endregion
#region Validation
public static string GetUserName()
{
return Environment.UserName;//System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
public static bool InvalidCharacter(string InvalidCharacter)
{
if (string.IsNullOrEmpty(InvalidCharacter)) return false;
if (InvalidCharacter.Contains("#") ||
InvalidCharacter.Contains("&") ||
InvalidCharacter.Contains("*")
)
{
return true;
}
return false;
}
public static string NomDivValide(string nom, int randomAlpha)
{
if (string.IsNullOrEmpty(nom)) return nom;
nom = SansAccent(randomAlpha.ToString() + nom);
for (int i = 1; i < 47; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 58; i < 63; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 64; i < 65; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 91; i < 96; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 123; i < 191; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
if (nom.Length > 20) nom = nom.Substring(0, 20);
return nom;
}
public static string ReplaceInvalidCharacter(string nom)
{
if (string.IsNullOrEmpty(nom)) return nom;
nom = SansAccent(nom);
nom = nom.Replace(" ", "");
for (int i = 1; i < 47; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 58; i < 63; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 64; i < 65; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 91; i < 96; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
for (int i = 123; i < 191; i++) { nom = nom.Replace(Convert.ToChar(i).ToString(), ""); }
return nom;
}
public static string SansAccent(string accentedStr)
{
if (string.IsNullOrEmpty(accentedStr)) return accentedStr;
string normalized = accentedStr.Normalize(System.Text.NormalizationForm.FormD);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (char c in normalized)
{
if (System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.NonSpacingMark)
{
sb.Append(c);
}
}
return sb.ToString().Normalize(System.Text.NormalizationForm.FormC);
}
#endregion
}
}