Advertisement
themkss

Untitled

May 2nd, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8.  
  9. namespace LB4_V2
  10. {
  11.     public partial class WebForm1 : System.Web.UI.Page
  12.     {
  13.         protected void Page_Load(object sender, EventArgs e)
  14.         {
  15.             Label1.Visible = false;
  16.             Label2.Visible = false;
  17.             Label3.Visible = false;
  18.             Label4.Visible = false;
  19.             Label5.Visible = false;
  20.             Label6.Visible = false;
  21.         }
  22.  
  23.         protected void Button1_Click(object sender, EventArgs e)
  24.         {
  25.             string CFd = Server.MapPath("App_Data");
  26.  
  27.             string CFr1 = Server.MapPath("Rezultatai/Rezultatai.txt");
  28.             string CFr2 = Server.MapPath("Rezultatai/RetiLeidiniai.csv");
  29.             string CFr3 = Server.MapPath("Rezultatai/Nenauji.csv");
  30.             string CFr4 = Server.MapPath("Rezultatai/Technologija.csv");
  31.  
  32.             if (!Directory.Exists(CFd))
  33.             {
  34.                 throw new Exception(string.Format("Nėra tokio nurodyto aplankalo - {0}", CFd));
  35.             }
  36.  
  37.             try
  38.             {
  39.                 if (File.Exists(CFr1))
  40.                 {
  41.                     File.Delete(CFr1);
  42.                 }
  43.  
  44.                 if (File.Exists(CFr2))
  45.                 {
  46.                     File.Delete(CFr2);
  47.                 }
  48.  
  49.                 if (File.Exists(CFr3))
  50.                 {
  51.                     File.Delete(CFr3);
  52.                 }
  53.  
  54.                 if (File.Exists(CFr4))
  55.                 {
  56.                     File.Delete(CFr4);
  57.                 }
  58.  
  59.                 List<LibraryRegister> list = InOut.ReadData(CFd);
  60.                 InOut.PrintStartData(CFr1, "Pradiniai duomenys", list);
  61.                 PrintStartDataToTable(list);
  62.                 Label1.Visible = true;
  63.  
  64.                 // 1
  65.                 List<LibraryRegister> publications1 = TaskUtils.FindHighestEdition(list);
  66.                 if (publications1.Count > 0)
  67.                 {
  68.                     InOut.PrintData(CFr1, "Didžiausiu tiražu išleisti knyga, žurnalas ir laikraštis", publications1);
  69.                     Label2.Visible = true;
  70.                     PrintI(publications1);
  71.                 }
  72.                 else
  73.                 {
  74.                     StreamWriter sw = new StreamWriter(CFr1, true);
  75.  
  76.                     sw.WriteLine("Didžiausiu tiražu išleistos knygos ar žurnalo nėra.");
  77.                     sw.WriteLine();
  78.  
  79.                     sw.Close();
  80.  
  81.                     Label2.Visible = true;
  82.                     Label2.Text = "Rezultatų nėra";
  83.                 }
  84.  
  85.                 //2
  86.                 LibraryRegister publications2 = TaskUtils.OnlyOneLibrary(list);
  87.  
  88.                 if (publications2.Count() > 0)
  89.                 {
  90.                     Label3.Visible = true;
  91.                     InOut.PrintToCSV(CFr2, "Visi leidiniai, kuriuos galime rasti tik viename filiale", publications2);
  92.                     PrintToTable(Table3, publications2);
  93.  
  94.                 }
  95.                 else
  96.                 {
  97.                     Label3.Visible = true;
  98.                     Label3.Text = "Rezultatų nėra";
  99.                 }
  100.  
  101.                 //3
  102.                 LibraryRegister publications3 = TaskUtils.NotNew(list);
  103.  
  104.                 if (publications3.Count() > 0)
  105.                 {
  106.                     publications3.Sort();
  107.                     InOut.PrintToCSV(CFr3, "Nenauji leidiniai", publications3);
  108.                     Label4.Visible = true;
  109.                     PrintToTable(Table4, publications3);
  110.  
  111.                 }
  112.                 else
  113.                 {
  114.                     Label4.Visible = true;
  115.                     Label4.Text = "Rezultatų nėra";
  116.                 }
  117.  
  118.                 //4
  119.                 LibraryRegister publications4 = TaskUtils.FindByPublisher(list, "Technologija");
  120.  
  121.                 if (publications4.Count() == 0)
  122.                 {
  123.                     StreamWriter sw = new StreamWriter(CFr4);
  124.  
  125.                     sw.WriteLine("Nėra šios leidyklos leidinių");
  126.  
  127.                     sw.Close();
  128.  
  129.                     Label5.Visible = true;
  130.                     Label5.Text = "Rezultatų nėra";
  131.                 }
  132.                 else
  133.                 {
  134.                     Label5.Visible = true;
  135.                     InOut.PrintToCSV(CFr4, ("Leidiniai leidyklos - Technologija"), publications4);
  136.                     PrintToTable(Table5, publications4);
  137.                 }
  138.             }
  139.             catch(Exception ex)
  140.             {
  141.                 Label6.Visible = true;
  142.                 Label6.Text = ex.Message;
  143.  
  144.                 StreamWriter sw = new StreamWriter(CFr1);
  145.  
  146.                 sw.WriteLine(ex.Message);
  147.                 sw.WriteLine();
  148.  
  149.                 sw.Close();
  150.             }
  151.         }
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement