Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. carga();
  4. }
  5. private void carga()
  6. {
  7. datlogin dat = new datlogin();
  8. bool prueba = dat.veri;
  9. if(prueba == false)
  10. {
  11. Response.Redirect("login.aspx");
  12. }
  13. else { LBL_Nombre.Text = dat.nom; LBL_apellido.Text = dat.apel; }
  14.  
  15. }
  16. protected void cerrar(object sender, EventArgs e)
  17. {
  18. datlogin dat = new datlogin();
  19. bool sesion = dat.veri;
  20. if(sesion==true)
  21. {
  22. dat.veri = false;
  23. dat.id = ""; dat.nom = ""; dat.apel = "";
  24. Response.Redirect("login.aspx");
  25. }
  26. }
  27.  
  28. protected void Page_Load(object sender, EventArgs e)
  29. {
  30.  
  31. }
  32. protected void btnIngresar_Click(object sender, EventArgs e)
  33. {
  34. comprobacion();
  35. }
  36.  
  37. private void comprobacion()
  38. {
  39. string usua = TXT_Usuario.Text;
  40. string clav = TXT_clave.Text;
  41. datlogin dat = new datlogin();
  42. dat.usu = usua;
  43. dat.pas = clav;
  44. logindat log = new logindat();
  45. if (dat.veri == true) { alert.Visible = false; Response.Redirect("Default.aspx"); }
  46. else { alert.Visible = true; }
  47. }
  48.  
  49. private static string Usuario = string.Empty;
  50. private static string Password = string.Empty;
  51. private static bool verifica = false;
  52. private static string Nombre = string.Empty;
  53. private static string Apellido = string.Empty;
  54. private static string ID = string.Empty;
  55.  
  56.  
  57. public string usu
  58. {get { return Usuario; } set { Usuario = value; }}
  59.  
  60. public string pas
  61. {get { return Password; } set { Password = value; }}
  62.  
  63. public bool veri
  64. {get { return verifica; } set { verifica = value; }}
  65.  
  66. public string nom
  67. {get { return Nombre; }set { Nombre = value; }}
  68.  
  69. public string apel
  70. {get { return Apellido; } set { Apellido = value; }}
  71.  
  72. public string id
  73. {get { return ID; } set { ID = value; }}
  74.  
  75. public logindat()
  76. {
  77. verificacion();
  78. }
  79. string usua;
  80. string clave;
  81. private void verificacion()
  82. {
  83. datlogin dat = new datlogin();
  84. usua = dat.usu;
  85. clave = dat.pas;
  86.  
  87. Datos his = new Datos();
  88. DataTable tabla = new DataTable();
  89. string id = "";
  90. string nombre = "";
  91. string apellidos = "";
  92. try
  93. {
  94. tabla = his.iniciar("datosusu");
  95. id = tabla.Rows[0]["id_usuario"].ToString();
  96. nombre = tabla.Rows[0]["nombre"].ToString();
  97. apellidos = tabla.Rows[0]["apellidos"].ToString();
  98. }
  99. catch { }
  100. string id2 = "0";
  101. string nom = "No existe";
  102. string ape = "No existe";
  103.  
  104.  
  105.  
  106. if (id != id2 && nombre!=nom && apellidos!=ape && id != "" && nombre != "" && apellidos != "")
  107. {
  108. dat.veri = true;
  109. dat.id = id;
  110. dat.nom = nombre;
  111. dat.apel = apellidos;
  112. }
  113. else { dat.veri = false; dat.id = ""; dat.nom = ""; dat.apel = ""; }
  114.  
  115. }
  116.  
  117. SqlConnection conn;
  118.  
  119. public Datos()
  120. {
  121. SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();
  122. sb["Data Source"] = "10.0.0.77";
  123. sb["Initial Catalog"] = "BDprueba";
  124. sb["Persist Security Info"] = "True";
  125. sb["User ID"] = "sa";
  126. sb["Password"] = "123456";
  127. conn = new SqlConnection(sb.ConnectionString);
  128. }
  129. public DataTable iniciar(string tabla)
  130. {
  131. datlogin log = new datlogin();
  132. string usua = log.usu;
  133. string clav = log.pas;
  134. DataTable dt = new DataTable();
  135. string sql = "";
  136. switch (tabla)
  137. {
  138. case "datosusu":
  139. sql = "execute verificacion '"+usua+"','"+clav+"'";
  140. break;
  141. default:
  142. dt.Columns.Add("id_usuario");
  143. dt.Columns.Add("nombrer");
  144. dt.Columns.Add("apellidos");
  145. dt.Rows.Add("0", "No existe","No existe");
  146. break;
  147. }
  148. if (sql != "")
  149. {
  150. try
  151. {
  152. DataSet ds = new DataSet();//conjunto de tablas virtuales
  153. SqlDataAdapter da = new SqlDataAdapter(sql, conn);
  154. da.Fill(ds);
  155. if (ds.Tables.Count > 0)
  156. dt = ds.Tables[0];
  157. }
  158. catch
  159. {
  160. dt.Columns.Add("id_usuario");
  161. dt.Columns.Add("nombrer");
  162. dt.Columns.Add("apellidos");
  163. dt.Rows.Add("0", "No existe", "No existe");
  164. }
  165. }
  166. return dt;
  167. }
  168.  
  169. ALTER PROCEDURE [dbo].[verificacion]
  170. @usuario nvarchar(50),
  171. @clave nvarchar(50)
  172. AS
  173. BEGIN
  174. SET NOCOUNT ON;
  175. if @clave=(select clave from tbl_usuarios where usuario=@usuario)
  176. begin
  177. select tbl_usuarios.id_usuario,tbl_empleados.nombre,tbl_empleados.apellidos from tbl_usuarios LEFT JOIN tbl_empleados on tbl_usuarios.empleado=tbl_empleados.id_empleado where usuario=@usuario and clave=@clave
  178. end
  179. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement