root/Baza Reklam 2 - Faktury/Classes/Global.cs @ 708

Wersja 65, 2.6 KB (wprowadzona przez dorota, 17 years temu)
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Data.SqlClient;
6using System.Text;
7using System.Globalization;
8
9namespace Baza_Reklam
10{
11    /// <summary>
12    /// Klasa pobiera numry wydan na ten tydzien.
13    /// </summary>
14    class Global
15    {       
16
17        private static Global global;
18
19        private Global() {
20            pobierzAktualneNrWydan();
21        }
22
23        public static Global getGlobal()
24        {
25            if (global == null){
26                global = new Global();
27            }
28            return global;
29        }
30
31        //aktualny nr AMT
32        private int nrAMT;
33        //nr GS z tego tygodnia
34        private int nrGS1;
35        private int nrGS2;
36
37        public int NrAMT
38        {
39            get { return nrAMT; }
40        }
41           
42        public int NrGS1
43        {
44            get { return nrGS1; }
45        }
46       
47        public int NrGS2
48        {
49            get { return nrGS2; }
50        }
51
52        private void pobierzAktualneNrWydan()
53        {
54
55            DateTime dzisiaj = DateTime.Today;
56            CultureInfo myCI = new CultureInfo("pl-PL");
57            Calendar myCal = myCI.Calendar;
58
59            int nrTygodnia = myCal.GetWeekOfYear(dzisiaj, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
60            int pom = nrTygodnia;
61            while (nrTygodnia == pom)
62            {
63                dzisiaj = dzisiaj.Subtract(new TimeSpan(1, 0, 0, 0));
64                pom = myCal.GetWeekOfYear(dzisiaj, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
65            }
66
67            DateTime poczatek = dzisiaj.AddDays(1);
68            DateTime koniec = dzisiaj.AddDays(7);
69
70            SqlCommand cm = new SqlCommand();
71            cm.CommandText = "select nrw from dbo.NR where @poczatek <= DATA_W AND DATA_W <= @koniec AND tyt='AMT' order by nrw";
72            cm.Parameters.AddWithValue("@poczatek", poczatek);
73            cm.Parameters.AddWithValue("@koniec", koniec);
74
75            cm.Connection = new SqlConnection(ConnString.getConnString().Value);
76
77            cm.Connection.Open();
78
79            this.nrAMT = Convert.ToInt32(cm.ExecuteScalar());
80
81            cm.Connection.Close();
82
83            cm.CommandText = "select nrw from dbo.NR where @poczatek <= DATA_W AND DATA_W <= @koniec AND tyt='GS' order by nrw";
84
85            cm.Connection.Open();
86
87            this.nrGS1 = Convert.ToInt32(cm.ExecuteScalar());
88
89            cm.Connection.Close();
90
91            this.nrGS2 = this.nrGS1 + 1;
92
93        }
94    }
95}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.