Está en la página 1de 10

001 using System; 002 using System.Web.UI; 003 using System.Web.UI.WebControls; 004 using System.Web.UI.WebControls.WebParts; 005 using System.Collections.

Generic; 006 using System.Text; 007 using System.Runtime.CompilerServices; 008 using System.Security; 009 using System.Security.Permissions; 010 using Microsoft.SharePoint; 011 using Microsoft.SharePoint.WebControls; 012 using System.Data.SqlClient; 013 using System.Data.OleDb; 014 using System.Configuration; 015 using System.Data; 016 using System.Linq; 017 using System.Web; 018 using System.Web.Security; 019 using System.Web.UI.HtmlControls; 020 using System.Net.Mail; 021 using System.Collections; 022 using System.Collections.Specialized; 023 using System.Reflection; 024 using System.Security.Principal; 025 using System.Net; 026 using System.Net.Mime; 027 using System.Xml.Serialization; 028 using System.Drawing; 029 using System.Text.RegularExpressions; 030 using Microsoft.SharePoint.WebPartPages; 031 using System.Runtime.InteropServices; 032 using System.DirectoryServices; 033 using System.Security.Cryptography; 034 using wsswebparts = Microsoft.SharePoint.WebPartPages; 035 using aspnetwebparts = System.Web.UI.WebControls.WebParts; 036 using System.ComponentModel; 037 using System.Collections.ObjectModel; 038 [assembly: AllowPartiallyTrustedCallers] 039 040 namespace Extranet_Materias 041 { 042 043 044 045 public class Extranet_Materias : wsswebparts.WebPart, wsswebparts.ITransformableFilterValues { chla.DatosUsuario Dusuarios = new chla.DatosUsuario(); GridView Grilla = new GridView();

046 047 048

string _sErrDescription, mensaje, show,view; string[] choices = new string[5];

protected DataTable GetDataTableFromQuery(string camlQry, SPList theList); //{ SPQuery listQry = new SPQuery(); listQry.Query = 050 camlQry; 049 // SPListItemCollection listItems = theList.GetItems(listQry); return ListItems.GetDataTable(); } protected void 052 BuildDataSet() { 051 //// get SPList objects for the lists in questions ... left as an exercise for the dev -//= "the CAML necessary to retreive the ites from 054 list1"; 053 055 056 057 058 059 //DataTable table1 = GetDataTable(camlQry, list1); //table1.TableName = "Table1"; //DataTable table2 = GetDataTable(camlQry, list2); //table1.TableName = "Table2";

// now build the DataSet DataSet ds = new DataSet(); ds.Tables.Add(table1); 060 //ds.Tables.Add(table2); ds.Tables.Add(table3); //ds.Relations.Add("Table1_2", ds.Tables["Table1"].Columns["FieldA"], 062 //ds.Tables["Table2"].Columns["FieldA"]); 061 //ds.Relations.Add("Table2_3", ds.Tables["Table2"].Columns["FieldB"], 064 //ds.Tables["Table3"].Columns["FieldB"]); 063 //// now you can do something with these, like store them in the web part class //and bind them to repeaters in the web part's Render() method 066 } 065 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 protected override void OnInit(EventArgs e) { try { this.ChromeType = PartChromeType.None; base.OnInit(e); } catch (Exception ex) } public Extranet_Materias() { this.ChromeType = PartChromeType.BorderOnly; this.ExportMode = WebPartExportMode.All;

083 084 085 086 087 088 089 090 091 092 093 094 095 }

{ _sErrDescription = " } 11 " + ex.Message;

protected override void CreateChildControls() { try { base.CreateChildControls(); Controls.Add(Grilla);

Grilla.RowDataBound += new GridViewRowEventHandler(Grilla_RowDataBound); 096 if (!Page.IsPostBack) 097 098 099 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 Password); string DecryptedString = DecryptString(EncryptedString, "Academica"); string varurl = string Msg = row.Cells[1].Text; string Password = "Academica"; string EncryptedString = EncryptString(Msg, protected override void OnPreRender(EventArgs e) { Dusuarios = new chla.DatosUsuario(); try { int i; GridViewRow row; Grilla.HeaderRow.Visible = false; for (i = 0; i < Grilla.Rows.Count; i++) { row = Grilla.Rows[i]; if (row.RowType == DataControlRowType.DataRow) { string var; string url = Dusuarios.UrlTop; } CargaInfo(); } catch (Exception ex) { _sErrDescription += " } " + ex.Message;

HttpContext.Current.Request.QueryString["var"].Replace(" ", "+"); 126 var = " <a href='" + url + 127 "Paginas/Asignaturas.aspx?mat=" + EncryptedString + "&var=" + varurl + "'>" + row.Cells[2].Text + "</a> "; 128 row.Cells[2].Font.Name = "Tahoma"; 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 protected override void Render(HtmlTextWriter writer) { try { Grilla.RenderControl(writer); writer.Write("</BR></BR>"); } void Grilla_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[0].Visible = false; e.Row.Cells[1].Visible = false; } ex.Message; } } } } //catch (Exception ex) catch (NullReferenceException ex) { _sErrDescription += " OnPreRender "+ row.Cells[2].Font.Size = 8; row.Cells[2].Text = var;

//writer.Write(mensaje); if (Dusuarios.Usuario == "juanp.lozano" || 154 Dusuarios.Usuario == "sharepoint.admin") 155 156 157 158 159 160 161 162 163 164 165 { writer.Write(_sErrDescription); //writer.Write(show); } } catch (Exception error) { if (Dusuarios.Usuario == "juanp.lozano" || Dusuarios.Usuario == "sharepoint.admin") { writer.Write(_sErrDescription + error); //writer.Write(show);

166 167 168 169 170 171 172 173 } }

private void CargaInfo() { string ins = Dusuarios.IdInscripcion;

string var = HttpContext.Current.Request.QueryString["var"].Replace(" ", "+"); 174 try 175 176 177 178 179 180 string DecryptedString = DecryptString(var, "Academica"); 181 string sqlAA = " 182 SELECT dbo.MSAsignaturas.AsignaturaURL, dbo.MateriaCurso.IdMateriaCurso, "; 183 184 INNER JOIN "; sqlAA += " dbo.MSAsignaturas.AsignaturaEsp "; sqlAA += " FROM dbo.InscripcinMateriaCurso { string ins = Dusuarios.IdInscripcion; string var = HttpContext.current.Request.QueryString["var"].Replace(" ",)

sqlAA += " dbo.MateriaCurso ON 185 dbo.InscripcinMateriaCurso.IdMateriaCurso = dbo.MateriaCurso.IdMateriaCurso INNER JOIN "; sqlAA += " dbo.AsignaturaGrado ON 186 dbo.MateriaCurso.IdAsignaturaGrado = dbo.AsignaturaGrado.IdAsignaturaGrado INNER JOIN "; 187 sqlAA += " dbo.Asignaturas INNER JOIN "; sqlAA += " dbo.MSAsignaturas ON 188 dbo.Asignaturas.IdMSAsignatura = dbo.MSAsignaturas.IdMSAsignatura ON "; sqlAA += " dbo.AsignaturaGrado.IdAsignatura = dbo.Asignaturas.IdAsignatura INNER JOIN "; sqlAA += " dbo.MSMaterias ON 190 dbo.AsignaturaGrado.IdMSMateria = dbo.MSMaterias.IdMSMateria INNER JOIN "; 189 sqlAA += " dbo.Inscripcin ON 191 dbo.InscripcinMateriaCurso.IdInscripcin = dbo.Inscripcin.IdInscripcin INNER JOIN "; sqlAA += " dbo.Alumnos ON dbo.Inscripcin.IdAlumno 192 = dbo.Alumnos.IdAlumno INNER JOIN "; sqlAA += " dbo.Empleados ON dbo.MateriaCurso.IdProfesor = dbo.Empleados.IdEmpleado "; sqlAA += " WHERE (dbo.MateriaCurso.Ao = 194 dbo.YearActual()) AND (dbo.Inscripcin.IdInscripcin = " + DecryptedString + ") "; 193 195 sqlAA += " ORDER BY dbo.MSAsignaturas.AsignaturaEsp

"; 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 223 // Step 1. We hash the passphrase using MD5 // We use the MD5 hash generator as the result is a 128 224 bit byte array 225 226 MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider(); byte[] TDESKey = 228 HashProvider.ComputeHash(UTF8.GetBytes(Passphrase)); 227 229 230 231 232 // Step 2. Create a new TripleDESCryptoServiceProvider object TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider(); // which is a valid length for the TripleDES encoder we use below public static string EncryptString(string Message, string Passphrase) { byte[] Results; System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding(); } } catch (Exception error) { _sErrDescription += "<b>Error</b>"+ error; } Grilla.DataSource = DS_AA; Grilla.DataBind(); Grilla.Font.Name = "Tahoma"; Grilla.Font.Size = 8; Grilla.BorderColor = System.Drawing.Color.Black; Grilla.GridLines = GridLines.None; DS_AA.Dispose(); DataSet DS_AA = Dusuarios.DameAllDatos(sqlAA); mensaje = "" + sqlAA; show = "" + sqlAA;

233 234 235 236 237 238 239 240 241 242 243 244

// Step 3. Setup the encoder TDESAlgorithm.Key = TDESKey; TDESAlgorithm.Mode = CipherMode.ECB; TDESAlgorithm.Padding = PaddingMode.PKCS7; // Step 4. Convert the input string to a byte[] byte[] DataToEncrypt = UTF8.GetBytes(Message); // Step 5. Attempt to encrypt the string try { ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();

Results = 245 Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length); 246 } 247 248 249 finally {

// Clear the TripleDes and Hashprovider services of any sensitive information 250 TDESAlgorithm.Clear(); 251 252 253 HashProvider.Clear(); }

// Step 6. Return the encrypted string as a base64 encoded string 254 return Convert.ToBase64String(Results); 255 256 public static string DecryptString(string Message, string Passphrase) 258 { 257 259 byte[] Results; System.Text.UTF8Encoding UTF8 = new 260 System.Text.UTF8Encoding(); 261 // Step 1. We hash the passphrase using MD5 // We use the MD5 hash generator as the result is a 128 262 bit byte array 263 264 265 // which is a valid length for the TripleDES encoder we use below MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider(); }

byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase)); // Step 2. Create a new TripleDESCryptoServiceProvider 266 object TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider(); 268 // Step 3. Setup the decoder 267

269 270 271 272 273

TDESAlgorithm.Key = TDESKey; TDESAlgorithm.Mode = CipherMode.ECB; TDESAlgorithm.Padding = PaddingMode.PKCS7; // Step 4. Convert the input string to a byte[]

byte[] DataToDecrypt = Convert.FromBase64String(Message); 274 // Step 5. Attempt to decrypt the string 275 276 277 try {

ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor(); Results = 278 Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length); 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 [wsswebparts.WebPartStorage(wsswebparts.Storage.None)] public virtual bool AllowEmptyValue { } [wsswebparts.WebPartStorage(wsswebparts.Storage.None)] public virtual bool AllowAllValue { get { return true; } } [wsswebparts.WebPartStorage(wsswebparts.Storage.Shared)] public virtual bool AllowMultipleValues { get { return true; } } } finally { // Clear the TripleDes and Hashprovider services of any sensitive information TDESAlgorithm.Clear(); HashProvider.Clear(); } // Step 6. Return the decrypted string in UTF8 format return UTF8.GetString(Results);

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 } }

get { return false; }

[wsswebparts.WebPartStorage(wsswebparts.Storage.None)] public virtual string ParameterName { get { return "Escuela"; }

[wsswebparts.WebPartStorage(wsswebparts.Storage.None)] public virtual ReadOnlyCollection<string> ParameterValues { get { string[] values = this.Dato_(); return values == null ? null : new ReadOnlyCollection<string>(values); } } public string[] Dato_() { try {

string var = HttpContext.Current.Request.QueryString["var"].Replace(" ", "+"); 344 //var = "VrXb3ktS42k="; 345 346 347 348 FROM ")"; 349 string sql_filtro = "SELECT CdigoMSCurso dbo.Inscripcin WHERE (IdInscripcin = " + DecryptedString + string DecryptedString = DecryptString(var, "Academica");

DataSet Datos_alum = Dusuarios.DameAllDatos(sql_filtro); string oCurso = 350 Datos_alum.Tables[0].Rows[0]["CdigoMSCurso"].ToString();

351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 } "Primaria"; 2));

Datos_alum.Dispose(); string escuela; try { int curso = int.Parse((oCurso).Substring(0, if ((curso >= 6) && (curso < 9)) escuela = "Escuela media"; else if (curso >= 9) escuela = "Bachillerato"; else if ((curso >= 1) && (curso <= 5)) escuela = else escuela = "Preescolar"; } catch { escuela = "Preescolar"; }

choices[0] = escuela; } catch (Exception error) { _sErrDescription += "Dato_ " + error.Message; } return choices;

[aspnetwebparts.ConnectionProvider("Filtro Lista", "ITransformableFilterValues", 378 AllowsMultipleConnections = true)] 379 380 381 382 383 384 385 } } public wsswebparts.ITransformableFilterValues SetConnectionInterface() { return this; }

También podría gustarte