Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----LOGIN----
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="formlogin.aspx.cs" Inherits="WebApplication1.formlogin" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Login</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h1>WEBSITE</h1>
- <asp:Label ID="Label3" runat="server"></asp:Label><br />
- <asp:Label ID="Label1" text="Username" runat="server"></asp:Label><br />
- <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox><br/>
- <asp:Label ID="Label2" text="password" runat="server"></asp:Label><br />
- <asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
- <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnklik"/>
- </div>
- <br/><asp:Label ID="Label4" runat="server"></asp:Label><br />
- </form>
- </body>
- </html>
- --------------------------------------------------------------------------------------------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- namespace WebApplication1
- {
- public partial class formlogin : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Label3.Text="My Website";
- }
- protected void btnklik(object sender, EventArgs e)
- {
- //if (txtUsername.Text == "master" && txtPassword.Text == "123")
- //{
- // //Response.Write("<script>alert('Login successfully')</script");
- // Response.Redirect("Home.aspx");
- //}
- //else
- //{
- // Response.Write("<script>alert('Login gagal')</script");
- // //Label4.Text = "Salah User dan Password";
- // txtUsername.Text = "";
- // txtPassword.Text = "";
- //}
- SqlConnection con = new SqlConnection(@"Data Source=THEBROTHER-PC;Initial Catalog=BelajarLogin;Integrated Security=True;Pooling=False");
- SqlCommand cmd = new SqlCommand("select * from tbuser where username=@username and password=@password", con);
- cmd.Parameters.AddWithValue("@username", txtUsername.Text);
- cmd.Parameters.AddWithValue("@password", txtPassword.Text);
- SqlDataAdapter sda = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- con.Open();
- Int32 i = cmd.ExecuteNonQuery();
- con.Close();
- if (dt.Rows.Count > 0)
- {
- Session["id"] = txtUsername.Text;
- Response.Redirect("HOME.aspx");
- Session.RemoveAll();
- }
- else
- {
- Response.Write("<script>alert('Login gagal')</script");
- }
- //SqlConnection koneksi = new SqlConnection(ConfigurationManager.ConnectionStrings["KoneksiDatabese"].ConnectionString);
- //SqlCommand cmd = new SqlCommand("CheckUser", koneksi);
- //cmd.CommandType = CommandType.StoredProcedure;
- //SqlParameter user = new SqlParameter("username", txtUsername.Text);
- //SqlParameter pass = new SqlParameter("password", txtPassword.Text);
- //cmd.Parameters.Add("user");
- //cmd.Parameters.Add("pass");
- //koneksi.Open();
- //SqlDataReader dr = cmd.ExecuteReader();
- //if (dr.HasRows)
- //{
- // Response.Redirect("home.aspx");
- //}
- //else
- //{
- // Page.ClientScript.RegisterStartupScript(this.GetType(), "Correct", "alert('Username atau Password Salah')", true);
- //}
- }
- }
- }
- --------------------------------------home--------------------------
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="WebApplication1.home" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>HOME</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <p>Welcome to Main menu</p>
- <p> Selamat Datang
- <asp:Label ID="Label1" runat="server"></asp:Label> <br/> <br/>
- </p>
- <br/>
- <a href="home.aspx">Home</a>
- <a href="home.aspx">About</a>
- <a href="home.aspx">Help</a>
- <br/> <br/>
- <asp:Button ID="btnBack" runat="server" Text="Logout" OnClick="btnlogout"/>
- </div>
- </form>
- </body>
- </html>
- --------------------------------------home.aspx.cs--------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace WebApplication1
- {
- public partial class home : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Label1.Text = Session["id"].ToString();
- }
- protected void btnlogout(object sender, EventArgs e)
- {
- Session.Abandon();
- Session.Clear();
- Response.Redirect("formlogin.aspx");
- }
- }
- }
- -------------------------------------kalkulasi.aspx--------------------------
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="kalkulasi.aspx.cs" Inherits="WebApplication1.kalkulasi" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h1>KALKULASI</h1>
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <br />
- <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
- <br />
- <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
- <br/>
- <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
- <br />
- </div>
- <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
- <p>
- <asp:Button ID="Button1" runat="server" Text="Total" OnClick="btnsum" Width="95px" />
- <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Urutkan" />
- <asp:Button ID="Button3" runat="server" Text="Rata2" OnClic="btnrata" OnClick="Button3_Click"/>
- <asp:Button ID="Button2" runat="server" Text="Reset" OnClick="btnreset" Width="82px" />
- </p>
- <p>
- <asp:Label ID="Label3" runat="server" Text="Total "></asp:Label>
- <asp:Label ID="Label1" runat="server"></asp:Label>
- </p>
- <asp:Label ID="Label4" runat="server" Text="Rata "></asp:Label>
- <asp:Label ID="Label2" runat="server"></asp:Label>
- <p>
- <asp:ListBox ID="ListBox1" runat="server" Height="128px" style="margin-top: 0px" Width="101px"></asp:ListBox>
- </p>
- </form>
- </body>
- </html>
- --------------------------------------kalkulasi.aspx.cs-------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace WebApplication1
- {
- public partial class kalkulasi : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnsum(object sender, EventArgs e)
- {
- int angka1 = Int32.Parse(TextBox1.Text);
- int angka2 = Int32.Parse(TextBox2.Text);
- int angka3 = Int32.Parse(TextBox3.Text);
- int angka4 = Int32.Parse(TextBox4.Text);
- int angka5 = Int32.Parse(TextBox5.Text);
- int sum = angka1 + angka2 + angka3 + angka4 + angka5;
- Label1.Text = sum.ToString();
- }
- protected void btnreset(object sender, EventArgs e)
- {
- TextBox1.Text = "";
- TextBox2.Text = "";
- TextBox3.Text = "";
- TextBox4.Text = "";
- TextBox5.Text = "";
- Label1.Text = "";
- Label2.Text = "";
- ListBox1.Items.Clear();
- }
- protected void Button3_Click(object sender, EventArgs e)
- {
- double angka1 = Double.Parse(TextBox1.Text);
- double angka2 = Double.Parse(TextBox2.Text);
- double angka3 = Double.Parse(TextBox3.Text);
- double angka4 = Double.Parse(TextBox4.Text);
- double angka5 = Double.Parse(TextBox5.Text);
- double angka = 5;
- double rata = (angka1 + angka2 + angka3 + angka4 + angka5)/angka;
- Label2.Text = rata.ToString();
- }
- protected void Button4_Click(object sender, EventArgs e)
- {
- int[] a = new int[5];
- a[0] = Convert.ToInt16(TextBox1.Text);
- a[1] = Convert.ToInt16(TextBox2.Text);
- a[2] = Convert.ToInt16(TextBox3.Text);
- a[3] = Convert.ToInt16(TextBox4.Text);
- a[4] = Convert.ToInt16(TextBox5.Text);
- int x;
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- if (a[i] < a[j])
- {
- x = a[i];
- a[i] = a[j];
- a[j] = x;
- }
- }
- }
- for (int i = 0; i < 5; i++)
- {
- ListBox1.Items.Add(Convert.ToString(a[i]));
- //Label2.Text = (Convert.ToString(a[i]));
- }
- }
- }
- }
- --------------------------------------simpan.aspx-------------------------
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Simpan.aspx.cs" Inherits="WebApplication1.Simpan" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <%--<script type="text/javascript">
- function Validasi() {
- var angka = "0123456789";
- var x = 0;
- var kuis = document.getElementById('TextBox1').value;
- var tugas = document.getElementById('TextBox2').value;
- var uts = document.getElementById('TextBox3').value;
- var uas = document.getElementById('TextBox4').value;
- //var email = document.getElementById('TextBox2').value;
- //if (email == "" || kodepos == "" || notelepon == "")
- //{ alert("Ada form yang belum terisi"); }
- //if ((email.indexOf('@', 0) == -1) || (email.indexOf('.', 0) == -1))
- //{ alert("Email Kurang Tepat"); }
- //if (kodepos.length != 5)
- //{ alert("kode pos harus 5 karakter"); return false; }
- //if (notelepon.length != 12)
- //{ alert("no telepon harus 12 karakter"); return false; }
- for (var i = 0; i < kuis || tugas || uts || uas.length; i++)
- {
- digita = "" + kuis.substring(i, i + 1);
- digitb = "" + tugas.substring(i, i + 1);
- digitc = "" + uts.substring(i, i + 1);
- digitd = "" + uas.substring(i, i + 1);
- if (angka.indexOf(digita) == "-1")
- {
- window.alert("Silahkan masukkan angka"); return false;
- }
- if (angka.indexOf(digitb) == "-1")
- {
- window.alert("Silahkan masukkan angka"); return false;
- }
- if (angka.indexOf(digitc) == "-1")
- {
- window.alert("Silahkan masukkan angka"); return false;
- }
- if (angka.indexOf(digitd) == "-1")
- {
- window.alert("Silahkan masukkan angka"); return false;
- }
- }
- return true;
- }
- </script>--%>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h1>SIMPAN DATA</h1>
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <br />
- <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
- <br />
- <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
- <br/>
- <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
- <br />
- </div>
- <asp:TextBox ID="TextBox5" runat="server" ReadOnly="True"></asp:TextBox>
- <asp:Label ID="Label1" runat="server"></asp:Label>
- <p>
- <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Hitung" Width="87px" />
- <asp:Button ID="Button2" runat="server" Text="Reset" OnClick="btnreset" Width="99px" />
- </p>
- <p>
- <asp:Button ID="Button1" runat="server" Text="Simpan" OnClick="btnsimpan" Width="185px" />
- </p>
- <p>
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
- <Columns>
- <asp:BoundField DataField="kuis" HeaderText="kuis" SortExpression="kuis" />
- <asp:BoundField DataField="tugas" HeaderText="tugas" SortExpression="tugas" />
- <asp:BoundField DataField="uts" HeaderText="uts" SortExpression="uts" />
- <asp:BoundField DataField="uas" HeaderText="uas" SortExpression="uas" />
- <asp:BoundField DataField="akhir" HeaderText="akhir" SortExpression="akhir" />
- <asp:BoundField DataField="huruf" HeaderText="huruf" SortExpression="huruf" />
- </Columns>
- </asp:GridView>
- </p>
- <p>
- </p>
- <p>
- </p>
- </form>
- </body>
- </html>
- --------------------------------------simpan.aspx.cs-------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- namespace WebApplication1
- {
- public partial class Simpan : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- tampilgridview();
- }
- protected void tampilgridview()
- {
- SqlConnection con = new SqlConnection(@"Data Source=THEBROTHER-PC;Initial Catalog=BelajarLogin;Integrated Security=True;Pooling=False");
- con.Open();
- DataTable table = new DataTable();
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = con;
- cmd.CommandText = "SELECT * FROM tbnilai";
- SqlDataAdapter adapter = new SqlDataAdapter(cmd);
- adapter.Fill(table);
- GridView1.DataSource = table;
- GridView1.DataBind();
- }
- private void clear()
- {
- TextBox1.Text = "";
- TextBox2.Text = "";
- TextBox3.Text = "";
- TextBox4.Text = "";
- TextBox5.Text = "";
- Label1.Text = "";
- }
- protected void btnsimpan(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(@"Data Source=THEBROTHER-PC;Initial Catalog=BelajarLogin;Integrated Security=True;Pooling=False");
- con.Open();
- SqlCommand cmd = new SqlCommand();
- cmd.Connection=con;
- cmd.CommandText = "insert into tbnilai values (@kuis,@tugas,@uts,@uas,@akhir,@huruf)";
- cmd.Parameters.AddWithValue("@kuis", TextBox1.Text);
- cmd.Parameters.AddWithValue("@tugas", TextBox2.Text);
- cmd.Parameters.AddWithValue("@uts", TextBox3.Text);
- cmd.Parameters.AddWithValue("@uas", TextBox4.Text);
- cmd.Parameters.AddWithValue("@akhir", TextBox5.Text);
- cmd.Parameters.AddWithValue("@huruf",Label1.Text);
- cmd.ExecuteNonQuery();
- con.Close();
- Response.Write("<script>alert('Data Berhasil Disimpan')</script");
- clear();
- tampilgridview();
- }
- protected void btnreset(object sender, EventArgs e)
- {
- clear();
- }
- protected void Button3_Click(object sender, EventArgs e)
- {
- if (TextBox1.Text == "" && TextBox2.Text == "" && TextBox3.Text == "" && TextBox4.Text == "")
- {
- Response.Write("<script>alert('Mohon diisi data')</script");
- }
- else
- {
- double angka1 = Double.Parse(TextBox1.Text);
- double angka2 = Double.Parse(TextBox2.Text);
- double angka3 = Double.Parse(TextBox3.Text);
- double angka4 = Double.Parse(TextBox4.Text);
- double nilaiakhir = (angka1 * 0.1) + (angka2 * 0.2) + (angka3 * 0.3) + (angka4 * 0.4);
- TextBox5.Text = nilaiakhir.ToString();
- double angka5 = Double.Parse(TextBox5.Text);
- if (angka5 >= 80)
- {
- Label1.Text = "A";
- }
- else if (angka5 >= 68 && angka5 < 80)
- {
- Label1.Text = "B";
- }
- else if (angka5 >= 55 && angka5 < 68)
- {
- Label1.Text = "C";
- }
- else if (angka5 >= 40 && angka5 < 55)
- {
- Label1.Text = "D";
- }
- else
- {
- Label1.Text = "E";
- }
- }
- }
- protected void Button4_Click(object sender, EventArgs e)
- {
- double angka5 = Double.Parse(TextBox5.Text);
- if (angka5 >= 80)
- {
- Label1.Text = "A";
- }
- else if (angka5 >= 68 && angka5 < 80)
- {
- Label1.Text = "B";
- }
- else if (angka5 >= 55 && angka5 < 68)
- {
- Label1.Text = "C";
- }
- else if (angka5 >= 40 && angka5 < 55)
- {
- Label1.Text = "D";
- }
- else
- {
- Label1.Text = "E";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement