Advertisement
djprocool

login

May 13th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.67 KB | None | 0 0
  1. ----LOGIN----
  2. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="formlogin.aspx.cs" Inherits="WebApplication1.formlogin" %>
  3.  
  4. <!DOCTYPE html>
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head runat="server">
  8. <title>Login</title>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <div>
  13. <h1>WEBSITE</h1>
  14.  
  15.  
  16. <asp:Label ID="Label3" runat="server"></asp:Label><br />
  17. <asp:Label ID="Label1" text="Username" runat="server"></asp:Label><br />
  18. <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox><br/>
  19. <asp:Label ID="Label2" text="password" runat="server"></asp:Label><br />
  20. <asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
  21.  
  22. <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnklik"/>
  23.  
  24. </div>
  25. <br/><asp:Label ID="Label4" runat="server"></asp:Label><br />
  26.  
  27. </form>
  28. </body>
  29. </html>
  30.  
  31.  
  32. --------------------------------------------------------------------------------------------------------------------------------------
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.WebControls;
  39. using System.Data;
  40. using System.Data.SqlClient;
  41. using System.Configuration;
  42.  
  43. namespace WebApplication1
  44. {
  45. public partial class formlogin : System.Web.UI.Page
  46. {
  47. protected void Page_Load(object sender, EventArgs e)
  48. {
  49. Label3.Text="My Website";
  50. }
  51.  
  52. protected void btnklik(object sender, EventArgs e)
  53. {
  54. //if (txtUsername.Text == "master" && txtPassword.Text == "123")
  55. //{
  56. // //Response.Write("<script>alert('Login successfully')</script");
  57. // Response.Redirect("Home.aspx");
  58.  
  59. //}
  60. //else
  61. //{
  62. // Response.Write("<script>alert('Login gagal')</script");
  63. // //Label4.Text = "Salah User dan Password";
  64. // txtUsername.Text = "";
  65. // txtPassword.Text = "";
  66.  
  67. //}
  68.  
  69. SqlConnection con = new SqlConnection(@"Data Source=THEBROTHER-PC;Initial Catalog=BelajarLogin;Integrated Security=True;Pooling=False");
  70. SqlCommand cmd = new SqlCommand("select * from tbuser where username=@username and password=@password", con);
  71. cmd.Parameters.AddWithValue("@username", txtUsername.Text);
  72. cmd.Parameters.AddWithValue("@password", txtPassword.Text);
  73. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  74. DataTable dt = new DataTable();
  75. sda.Fill(dt);
  76. con.Open();
  77. Int32 i = cmd.ExecuteNonQuery();
  78. con.Close();
  79. if (dt.Rows.Count > 0)
  80. {
  81. Session["id"] = txtUsername.Text;
  82. Response.Redirect("HOME.aspx");
  83. Session.RemoveAll();
  84. }
  85. else
  86. {
  87. Response.Write("<script>alert('Login gagal')</script");
  88. }
  89.  
  90. //SqlConnection koneksi = new SqlConnection(ConfigurationManager.ConnectionStrings["KoneksiDatabese"].ConnectionString);
  91. //SqlCommand cmd = new SqlCommand("CheckUser", koneksi);
  92. //cmd.CommandType = CommandType.StoredProcedure;
  93. //SqlParameter user = new SqlParameter("username", txtUsername.Text);
  94. //SqlParameter pass = new SqlParameter("password", txtPassword.Text);
  95. //cmd.Parameters.Add("user");
  96. //cmd.Parameters.Add("pass");
  97. //koneksi.Open();
  98. //SqlDataReader dr = cmd.ExecuteReader();
  99. //if (dr.HasRows)
  100. //{
  101. // Response.Redirect("home.aspx");
  102. //}
  103. //else
  104. //{
  105. // Page.ClientScript.RegisterStartupScript(this.GetType(), "Correct", "alert('Username atau Password Salah')", true);
  106. //}
  107. }
  108. }
  109. }
  110.  
  111. --------------------------------------home--------------------------
  112. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="WebApplication1.home" %>
  113.  
  114. <!DOCTYPE html>
  115.  
  116. <html xmlns="http://www.w3.org/1999/xhtml">
  117. <head runat="server">
  118. <title>HOME</title>
  119. </head>
  120. <body>
  121. <form id="form1" runat="server">
  122. <div>
  123. <p>Welcome to Main menu</p>
  124. <p> Selamat Datang
  125. <asp:Label ID="Label1" runat="server"></asp:Label> <br/> <br/>
  126.  
  127. </p>
  128. <br/>
  129.  
  130. <a href="home.aspx">Home</a>
  131. <a href="home.aspx">About</a>
  132. <a href="home.aspx">Help</a>
  133.  
  134. <br/> <br/>
  135. <asp:Button ID="btnBack" runat="server" Text="Logout" OnClick="btnlogout"/>
  136. </div>
  137. </form>
  138. </body>
  139. </html>
  140. --------------------------------------home.aspx.cs--------------------------
  141. using System;
  142. using System.Collections.Generic;
  143. using System.Linq;
  144. using System.Web;
  145. using System.Web.UI;
  146. using System.Web.UI.WebControls;
  147.  
  148. namespace WebApplication1
  149. {
  150. public partial class home : System.Web.UI.Page
  151. {
  152. protected void Page_Load(object sender, EventArgs e)
  153. {
  154. Label1.Text = Session["id"].ToString();
  155. }
  156. protected void btnlogout(object sender, EventArgs e)
  157. {
  158. Session.Abandon();
  159. Session.Clear();
  160. Response.Redirect("formlogin.aspx");
  161. }
  162.  
  163. }
  164. }
  165.  
  166. -------------------------------------kalkulasi.aspx--------------------------
  167.  
  168. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="kalkulasi.aspx.cs" Inherits="WebApplication1.kalkulasi" %>
  169.  
  170. <!DOCTYPE html>
  171.  
  172. <html xmlns="http://www.w3.org/1999/xhtml">
  173. <head runat="server">
  174. <title></title>
  175. </head>
  176. <body>
  177. <form id="form1" runat="server">
  178. <div>
  179. <h1>KALKULASI</h1>
  180.  
  181.  
  182. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  183. <br />
  184. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  185. <br />
  186. <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  187. <br/>
  188. <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
  189. <br />
  190.  
  191. </div>
  192. <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
  193. <p>
  194. <asp:Button ID="Button1" runat="server" Text="Total" OnClick="btnsum" Width="95px" />
  195.  
  196. <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Urutkan" />
  197. <asp:Button ID="Button3" runat="server" Text="Rata2" OnClic="btnrata" OnClick="Button3_Click"/>
  198.  
  199. <asp:Button ID="Button2" runat="server" Text="Reset" OnClick="btnreset" Width="82px" />
  200. </p>
  201. <p>
  202. <asp:Label ID="Label3" runat="server" Text="Total "></asp:Label>
  203. <asp:Label ID="Label1" runat="server"></asp:Label>
  204. </p>
  205. <asp:Label ID="Label4" runat="server" Text="Rata "></asp:Label>
  206. <asp:Label ID="Label2" runat="server"></asp:Label>
  207. <p>
  208. <asp:ListBox ID="ListBox1" runat="server" Height="128px" style="margin-top: 0px" Width="101px"></asp:ListBox>
  209. </p>
  210. </form>
  211. </body>
  212. </html>
  213.  
  214.  
  215. --------------------------------------kalkulasi.aspx.cs-------------------------
  216. using System;
  217. using System.Collections.Generic;
  218. using System.Linq;
  219. using System.Web;
  220. using System.Web.UI;
  221. using System.Web.UI.WebControls;
  222.  
  223. namespace WebApplication1
  224. {
  225. public partial class kalkulasi : System.Web.UI.Page
  226. {
  227. protected void Page_Load(object sender, EventArgs e)
  228. {
  229.  
  230. }
  231. protected void btnsum(object sender, EventArgs e)
  232. {
  233. int angka1 = Int32.Parse(TextBox1.Text);
  234. int angka2 = Int32.Parse(TextBox2.Text);
  235. int angka3 = Int32.Parse(TextBox3.Text);
  236. int angka4 = Int32.Parse(TextBox4.Text);
  237. int angka5 = Int32.Parse(TextBox5.Text);
  238. int sum = angka1 + angka2 + angka3 + angka4 + angka5;
  239. Label1.Text = sum.ToString();
  240.  
  241. }
  242. protected void btnreset(object sender, EventArgs e)
  243. {
  244. TextBox1.Text = "";
  245. TextBox2.Text = "";
  246. TextBox3.Text = "";
  247. TextBox4.Text = "";
  248. TextBox5.Text = "";
  249. Label1.Text = "";
  250. Label2.Text = "";
  251. ListBox1.Items.Clear();
  252. }
  253.  
  254. protected void Button3_Click(object sender, EventArgs e)
  255. {
  256. double angka1 = Double.Parse(TextBox1.Text);
  257. double angka2 = Double.Parse(TextBox2.Text);
  258. double angka3 = Double.Parse(TextBox3.Text);
  259. double angka4 = Double.Parse(TextBox4.Text);
  260. double angka5 = Double.Parse(TextBox5.Text);
  261. double angka = 5;
  262. double rata = (angka1 + angka2 + angka3 + angka4 + angka5)/angka;
  263. Label2.Text = rata.ToString();
  264. }
  265.  
  266. protected void Button4_Click(object sender, EventArgs e)
  267. {
  268. int[] a = new int[5];
  269.  
  270. a[0] = Convert.ToInt16(TextBox1.Text);
  271. a[1] = Convert.ToInt16(TextBox2.Text);
  272. a[2] = Convert.ToInt16(TextBox3.Text);
  273. a[3] = Convert.ToInt16(TextBox4.Text);
  274. a[4] = Convert.ToInt16(TextBox5.Text);
  275. int x;
  276. for (int i = 0; i < 5; i++)
  277. {
  278. for (int j = 0; j < 5; j++)
  279. {
  280.  
  281. if (a[i] < a[j])
  282. {
  283. x = a[i];
  284. a[i] = a[j];
  285. a[j] = x;
  286. }
  287. }
  288. }
  289.  
  290. for (int i = 0; i < 5; i++)
  291. {
  292. ListBox1.Items.Add(Convert.ToString(a[i]));
  293. //Label2.Text = (Convert.ToString(a[i]));
  294. }
  295. }
  296. }
  297. }
  298.  
  299. --------------------------------------simpan.aspx-------------------------
  300.  
  301. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Simpan.aspx.cs" Inherits="WebApplication1.Simpan" %>
  302.  
  303. <!DOCTYPE html>
  304.  
  305. <html xmlns="http://www.w3.org/1999/xhtml">
  306. <head runat="server">
  307. <title></title>
  308. <%--<script type="text/javascript">
  309. function Validasi() {
  310. var angka = "0123456789";
  311. var x = 0;
  312. var kuis = document.getElementById('TextBox1').value;
  313. var tugas = document.getElementById('TextBox2').value;
  314. var uts = document.getElementById('TextBox3').value;
  315. var uas = document.getElementById('TextBox4').value;
  316.  
  317. //var email = document.getElementById('TextBox2').value;
  318. //if (email == "" || kodepos == "" || notelepon == "")
  319. //{ alert("Ada form yang belum terisi"); }
  320. //if ((email.indexOf('@', 0) == -1) || (email.indexOf('.', 0) == -1))
  321. //{ alert("Email Kurang Tepat"); }
  322. //if (kodepos.length != 5)
  323. //{ alert("kode pos harus 5 karakter"); return false; }
  324. //if (notelepon.length != 12)
  325. //{ alert("no telepon harus 12 karakter"); return false; }
  326. for (var i = 0; i < kuis || tugas || uts || uas.length; i++)
  327. {
  328. digita = "" + kuis.substring(i, i + 1);
  329. digitb = "" + tugas.substring(i, i + 1);
  330. digitc = "" + uts.substring(i, i + 1);
  331. digitd = "" + uas.substring(i, i + 1);
  332.  
  333. if (angka.indexOf(digita) == "-1")
  334. {
  335. window.alert("Silahkan masukkan angka"); return false;
  336. }
  337. if (angka.indexOf(digitb) == "-1")
  338. {
  339. window.alert("Silahkan masukkan angka"); return false;
  340. }
  341. if (angka.indexOf(digitc) == "-1")
  342. {
  343. window.alert("Silahkan masukkan angka"); return false;
  344. }
  345. if (angka.indexOf(digitd) == "-1")
  346. {
  347. window.alert("Silahkan masukkan angka"); return false;
  348. }
  349. }
  350. return true;
  351. }
  352.  
  353. </script>--%>
  354. </head>
  355. <body>
  356. <form id="form1" runat="server">
  357. <div>
  358. <h1>SIMPAN DATA</h1>
  359.  
  360.  
  361. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  362. <br />
  363. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  364. <br />
  365. <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  366. <br/>
  367. <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
  368. <br />
  369.  
  370. </div>
  371. <asp:TextBox ID="TextBox5" runat="server" ReadOnly="True"></asp:TextBox>
  372. <asp:Label ID="Label1" runat="server"></asp:Label>
  373.  
  374. <p>
  375. <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Hitung" Width="87px" />
  376.  
  377. <asp:Button ID="Button2" runat="server" Text="Reset" OnClick="btnreset" Width="99px" />
  378. </p>
  379. <p>
  380. <asp:Button ID="Button1" runat="server" Text="Simpan" OnClick="btnsimpan" Width="185px" />
  381.  
  382. </p>
  383. <p>
  384. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  385. <Columns>
  386. <asp:BoundField DataField="kuis" HeaderText="kuis" SortExpression="kuis" />
  387. <asp:BoundField DataField="tugas" HeaderText="tugas" SortExpression="tugas" />
  388. <asp:BoundField DataField="uts" HeaderText="uts" SortExpression="uts" />
  389. <asp:BoundField DataField="uas" HeaderText="uas" SortExpression="uas" />
  390. <asp:BoundField DataField="akhir" HeaderText="akhir" SortExpression="akhir" />
  391. <asp:BoundField DataField="huruf" HeaderText="huruf" SortExpression="huruf" />
  392. </Columns>
  393. </asp:GridView>
  394.  
  395. </p>
  396. <p>
  397. &nbsp;</p>
  398. <p>
  399. &nbsp;</p>
  400. </form>
  401. </body>
  402. </html>
  403.  
  404. --------------------------------------simpan.aspx.cs-------------------------
  405.  
  406. using System;
  407. using System.Collections.Generic;
  408. using System.Linq;
  409. using System.Web;
  410. using System.Web.UI;
  411. using System.Web.UI.WebControls;
  412. using System.Data;
  413. using System.Data.SqlClient;
  414. using System.Configuration;
  415.  
  416. namespace WebApplication1
  417. {
  418. public partial class Simpan : System.Web.UI.Page
  419. {
  420. protected void Page_Load(object sender, EventArgs e)
  421. {
  422. tampilgridview();
  423. }
  424.  
  425. protected void tampilgridview()
  426. {
  427. SqlConnection con = new SqlConnection(@"Data Source=THEBROTHER-PC;Initial Catalog=BelajarLogin;Integrated Security=True;Pooling=False");
  428. con.Open();
  429.  
  430. DataTable table = new DataTable();
  431. SqlCommand cmd = new SqlCommand();
  432.  
  433. cmd.Connection = con;
  434. cmd.CommandText = "SELECT * FROM tbnilai";
  435. SqlDataAdapter adapter = new SqlDataAdapter(cmd);
  436. adapter.Fill(table);
  437. GridView1.DataSource = table;
  438. GridView1.DataBind();
  439.  
  440. }
  441.  
  442. private void clear()
  443. {
  444. TextBox1.Text = "";
  445. TextBox2.Text = "";
  446. TextBox3.Text = "";
  447. TextBox4.Text = "";
  448. TextBox5.Text = "";
  449. Label1.Text = "";
  450. }
  451.  
  452.  
  453. protected void btnsimpan(object sender, EventArgs e)
  454. {
  455. SqlConnection con = new SqlConnection(@"Data Source=THEBROTHER-PC;Initial Catalog=BelajarLogin;Integrated Security=True;Pooling=False");
  456.  
  457. con.Open();
  458. SqlCommand cmd = new SqlCommand();
  459.  
  460. cmd.Connection=con;
  461. cmd.CommandText = "insert into tbnilai values (@kuis,@tugas,@uts,@uas,@akhir,@huruf)";
  462.  
  463. cmd.Parameters.AddWithValue("@kuis", TextBox1.Text);
  464. cmd.Parameters.AddWithValue("@tugas", TextBox2.Text);
  465. cmd.Parameters.AddWithValue("@uts", TextBox3.Text);
  466. cmd.Parameters.AddWithValue("@uas", TextBox4.Text);
  467. cmd.Parameters.AddWithValue("@akhir", TextBox5.Text);
  468. cmd.Parameters.AddWithValue("@huruf",Label1.Text);
  469. cmd.ExecuteNonQuery();
  470. con.Close();
  471. Response.Write("<script>alert('Data Berhasil Disimpan')</script");
  472. clear();
  473. tampilgridview();
  474. }
  475.  
  476. protected void btnreset(object sender, EventArgs e)
  477. {
  478. clear();
  479.  
  480. }
  481.  
  482. protected void Button3_Click(object sender, EventArgs e)
  483. {
  484. if (TextBox1.Text == "" && TextBox2.Text == "" && TextBox3.Text == "" && TextBox4.Text == "")
  485. {
  486. Response.Write("<script>alert('Mohon diisi data')</script");
  487. }
  488. else
  489. {
  490. double angka1 = Double.Parse(TextBox1.Text);
  491. double angka2 = Double.Parse(TextBox2.Text);
  492. double angka3 = Double.Parse(TextBox3.Text);
  493. double angka4 = Double.Parse(TextBox4.Text);
  494.  
  495.  
  496. double nilaiakhir = (angka1 * 0.1) + (angka2 * 0.2) + (angka3 * 0.3) + (angka4 * 0.4);
  497. TextBox5.Text = nilaiakhir.ToString();
  498.  
  499. double angka5 = Double.Parse(TextBox5.Text);
  500.  
  501. if (angka5 >= 80)
  502. {
  503. Label1.Text = "A";
  504. }
  505. else if (angka5 >= 68 && angka5 < 80)
  506. {
  507. Label1.Text = "B";
  508. }
  509. else if (angka5 >= 55 && angka5 < 68)
  510. {
  511. Label1.Text = "C";
  512. }
  513. else if (angka5 >= 40 && angka5 < 55)
  514. {
  515. Label1.Text = "D";
  516. }
  517. else
  518. {
  519. Label1.Text = "E";
  520. }
  521. }
  522. }
  523.  
  524.  
  525. protected void Button4_Click(object sender, EventArgs e)
  526. {
  527. double angka5 = Double.Parse(TextBox5.Text);
  528.  
  529. if (angka5 >= 80)
  530. {
  531. Label1.Text = "A";
  532. }
  533. else if (angka5 >= 68 && angka5 < 80)
  534. {
  535. Label1.Text = "B";
  536. }
  537. else if (angka5 >= 55 && angka5 < 68)
  538. {
  539. Label1.Text = "C";
  540. }
  541. else if (angka5 >= 40 && angka5 < 55)
  542. {
  543. Label1.Text = "D";
  544. }
  545. else
  546. {
  547. Label1.Text = "E";
  548. }
  549.  
  550. }
  551.  
  552.  
  553.  
  554.  
  555.  
  556. }
  557. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement