rijads

Untitled

Jan 30th, 2017
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.56 KB | None | 0 0
  1. SQL
  2. create database [3020_Integralni]
  3. use [3020_Integralni]
  4.  
  5. create table Brendovi (
  6.     BrendId int primary key IDENTITY(1,1),
  7.     ImeBrenda NVARCHAR(100) NOT NULL
  8. )
  9. create table Uredjaji (
  10.     UredjajId int primary key IDENTITY(1,1),
  11.     BrendId int foreign key references Brendovi(BrendId),
  12.     SerijskiBroj NVARCHAR(100) NOT NULL,
  13.     PodGarancijom bit
  14. )
  15.  
  16. create table Servisi (
  17.     ServisId int primary key IDENTITY(1,1),
  18.     UredjajId int foreign key references Uredjaji(UredjajId),
  19.     DatumPrijema Date NOT NULL,
  20.     OpisKvara NVARCHAR(250) NOT NULL,
  21.     ZavrsenServis bit
  22. )
  23.  
  24. insert into Brendovi
  25. values ('Apple')
  26.  
  27.  
  28. SET ANSI_NULLS ON
  29. GO
  30. SET QUOTED_IDENTIFIER ON
  31. GO
  32. CREATE PROCEDURE spAddNewService
  33.     @BrendId int,
  34.     @SerijskiBroj NVARCHAR(100),
  35.     @PodGarancijom bit,
  36.     @DatumPrijema date,
  37.     @OpisKvara NVARCHAR(250),
  38.     @ZavrsenServis bit
  39. AS
  40. BEGIN
  41.     INSERT INTO Uredjaji
  42.     VALUES(@BrendId, @SerijskiBroj,@PodGarancijom);
  43.     INSERT INTO Servisi
  44.     VALUES(@@IDENTITY, @DatumPrijema, @OpisKvara, @ZavrsenServis);
  45. END
  46. GO
  47.  
  48. SET ANSI_NULLS ON
  49. GO
  50. SET QUOTED_IDENTIFIER ON
  51. GO
  52. CREATE PROCEDURE spGetServices
  53. AS
  54. BEGIN
  55.     SELECT CONVERT(VARCHAR(10), S.DatumPrijema, 104) as DatumPrijema,                      U.SerijskiBroj, S.OpisKvara, S.ZavrsenServis
  56.     FROM Servisi as S join Uredjaji as U on
  57.     S.UredjajId=U.UredjajId join Brendovi as B on
  58.     U.BrendId = B.BrendId
  59. order by S.DatumPrijema DESC
  60. END
  61. GO
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. DAServisi.cs
  69.  
  70. using System;
  71. using System.Collections.Generic;
  72. using System.Linq;
  73. using System.Text;
  74. using System.Threading.Tasks;
  75.  
  76. namespace DAServisi
  77. {
  78.     public class DAServisi
  79.     {
  80.         public static List<spGetServices_Result> GetServices()
  81.         {
  82.             using (Entities s = new Entities())
  83.             {
  84.                 return s.spGetServices().ToList();
  85.             }
  86.         }
  87.         public static void InsertService(int? brendId, string serijskiBroj, bool? podGarancijom,      DateTime? datumPrijema, string opisKvara, bool? zavrsenServis)
  88.         {
  89.             using (Entities s = new Entities())
  90.             {
  91.                 s.spAddNewService(brendId, serijskiBroj, podGarancijom, datumPrijema, opisKvara, zavrsenServis);
  92.             }
  93.         }
  94.     }
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. Servisi.aspx
  113. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Servisi.aspx.cs" Inherits="WT_Integralni_ispit_3020NEWWW.Servisi" %>
  114.  
  115. <!DOCTYPE html>
  116.  
  117. <html xmlns="http://www.w3.org/1999/xhtml">
  118. <head runat="server">
  119.     <title></title>
  120.     <link href="style.css" rel="stylesheet" />
  121. </head>
  122. <body>
  123.     <form id="form1" runat="server">
  124.     <div>
  125.         <h1>Novi servis:</h1>
  126.         <asp:Label ID="Label1" runat="server" Text="Brend:"></asp:Label>
  127.         <asp:DropDownList ID="brendoviList" runat="server" DataSourceID="SqlDataSource1" DataTextField="ImeBrenda" DataValueField="BrendId"></asp:DropDownList>
  128.         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:3020_IntegralniConnectionString %>" SelectCommand="SELECT [BrendId], [ImeBrenda] FROM [Brendovi]"></asp:SqlDataSource>
  129.         <br />
  130.         <asp:Label ID="Label2" runat="server" Text="Serijski broj:"></asp:Label>
  131.         <asp:TextBox ID="serijskiBroj" runat="server"></asp:TextBox>
  132.         <br />
  133.         <asp:Label ID="Label3" runat="server" Text="Pod garancijom: "></asp:Label>
  134.         <asp:CheckBox ID="podGarancijom" runat="server" Checked="true" />
  135.         <h2>Uredjaj:</h2>
  136.         <asp:Label ID="Label4" runat="server" Text="Datum prijema: "></asp:Label>
  137.         <asp:Calendar ID="Calendar1" runat="server" ></asp:Calendar>
  138.         <br />
  139.         <asp:Label ID="Label5" runat="server" Text="Opis kvara:"></asp:Label>
  140.         <asp:TextBox ID="opisKvara" runat="server" TextMode="MultiLine"></asp:TextBox>
  141.         <br />
  142.         <asp:Button ID="Button1" runat="server" Text="Posalji" OnClick="Button1_Click" OnClientClick="return validate();" />
  143.         <h1>Servisi:</h1>
  144.         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
  145.             <Columns>
  146.                 <asp:BoundField DataField="DatumPrijema" HeaderText="DatumPrijema" SortExpression="DatumPrijema" />
  147.                 <asp:BoundField DataField="SerijskiBroj" HeaderText="SerijskiBroj" SortExpression="SerijskiBroj" />
  148.                 <asp:BoundField DataField="OpisKvara" HeaderText="OpisKvara" SortExpression="OpisKvara" />
  149.                 <asp:CheckBoxField DataField="ZavrsenServis" HeaderText="ZavrsenServis" SortExpression="ZavrsenServis" />
  150.             </Columns>
  151.         </asp:GridView>
  152.         <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:3020_IntegralniConnectionString %>" SelectCommand="spGetServices" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
  153.     </div>
  154.     </form>
  155.     <script src="validation.js"></script>
  156. </body>
  157. </html>
  158.  
  159. Servisi.aspx.cs
  160. using System;
  161. using System.Collections.Generic;
  162. using System.Linq;
  163. using System.Web;
  164. using System.Web.UI;
  165. using System.Web.UI.WebControls;
  166. using DAServisi;
  167.  
  168. namespace WT_Integralni_ispit_3020NEWWW
  169. {
  170.     public partial class Servisi : System.Web.UI.Page
  171.     {
  172.         protected void Page_Load(object sender, EventArgs e)
  173.         {
  174.             if (!IsPostBack)
  175.             {
  176.             }
  177.         }
  178.  
  179.         protected void Button1_Click(object sender, EventArgs e)
  180.         {
  181.             if (Calendar1.SelectedDate == DateTime.MinValue)
  182.                 Response.Write("Select date !");
  183.             else {
  184.                 DAServisi.DAServisi.InsertService(Convert.ToInt32(brendoviList.SelectedValue), serijskiBroj.Text, podGarancijom.Checked, Calendar1.SelectedDate, opisKvara.Text
  185.                     , false);
  186.                 GridView1.DataBind();
  187.             }
  188.         }
  189.     }
  190. }
  191. Style.css
  192. .error{
  193.     border:1px solid red;
  194. }
  195.  
  196. Validation.js
  197. function validate() {
  198.     var valid = true;
  199.     var brend = document.getElementById("brendoviList");
  200.     var serijskiBroj = document.getElementById("serijskiBroj");
  201.     var datumPrijema = document.getElementById("Calendar1");
  202.     var opisKvara = document.getElementById("opisKvara");
  203.     if (brend.selectedIndex == 0) {
  204.         brend.className = "error";
  205.         valid = false;
  206.     }
  207.     else
  208.         brend.className = "";
  209.  
  210.     if (serijskiBroj.value == "") {
  211.         serijskiBroj.className = "error";
  212.         valid = false;
  213.     }
  214.     else
  215.         serijskiBroj.className = "";
  216.  
  217.     if (opisKvara.value.length <20) {
  218.         opisKvara.className = "error";
  219.         valid = false;
  220.     }
  221.     else
  222.         opisKvara.className = "";
  223.  
  224.     return valid;
  225. }
Advertisement
Add Comment
Please, Sign In to add comment