root/trunk/eCard/Expo/login.aspx.cs @ 513

Wersja 513, 3.2 KB (wprowadzona przez marek, 17 years temu)

re #139

Line 
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web.Security;
5using System.Data.SqlClient;
6using System.Threading;
7using System.Globalization;
8
9public partial class login : System.Web.UI.Page
10{
11    protected override void InitializeCulture()
12    {
13        if (Session["culture"] != null)
14        {
15            UICulture = Session["culture"].ToString();
16            Culture = Session["culture"].ToString();
17
18            Thread.CurrentThread.CurrentCulture =
19              CultureInfo.CreateSpecificCulture(Session["culture"].ToString());
20            Thread.CurrentThread.CurrentUICulture =
21              new CultureInfo(Session["culture"].ToString());
22        }
23        base.InitializeCulture();
24    }
25
26    protected void Page_Load(object sender, EventArgs e)
27    {
28        //throw new ApplicationException("TEST");
29
30
31        FakturaImageButton.ImageUrl = Resources.Common.Faktura;
32        if (!IsPostBack) { SetFocus(NIPTextBox); }
33    }
34
35    protected void ZalogujButton_Click(object sender, EventArgs e)
36    {
37        if (!Page.IsValid) return;
38        string nip = NIPTextBox.Text.Replace(" ", string.Empty).Replace("-", string.Empty);
39        string nrZlec = NrZlecTextBox.Text.Replace(" ", string.Empty);
40
41        bool czyZalogowany = Zaloguj(nip, nrZlec);
42        if (czyZalogowany)
43        {
44            FormsAuthentication.RedirectFromLoginPage(nip, false);
45        }
46        else
47        {
48            errorMsg.Text = GetLocalResourceObject("errorMsg").ToString();
49        }
50    }
51
52    bool Zaloguj(string nip, string nrFaktury)
53    {
54        if (nrFaktury.Split('/').Length != 3) return false;
55
56        string fakturaNr = nrFaktury.Split('/')[0];
57        string fakturaRoz = nrFaktury.Split('/')[1];
58        string fakturaRok = nrFaktury.Split('/')[2];
59
60        string connString = ConfigurationManager.ConnectionStrings["BazaReklamConn"].ConnectionString;
61        const string cmdText = "SELECT ID_Faktury FROM dbo.vDanePlatnosciEcard WHERE nip=@nip AND [Numer]=@numer AND [Numer_Roz]=@numerRoz AND [Numer_Rok]=@numerRok";
62        bool znalezione = false;
63        using (SqlConnection conn = new SqlConnection(connString))
64        {
65            SqlCommand cmd = new SqlCommand(cmdText, conn);
66            cmd.Parameters.Add("@nip", SqlDbType.NVarChar, 50).Value = nip;
67            cmd.Parameters.Add("@numer", SqlDbType.NVarChar, 10).Value = fakturaNr;
68            cmd.Parameters.Add("@numerRoz", SqlDbType.NVarChar, 10).Value = fakturaRoz;
69            cmd.Parameters.Add("@numerRok", SqlDbType.NVarChar, 10).Value = fakturaRok;
70            conn.Open();
71
72            SqlDataReader reader = cmd.ExecuteReader();
73            if (reader == null)
74            {
75                conn.Close();
76                return false;
77            }
78
79            if (reader.Read())
80            {
81                Session["Nip"] = nip;
82                Session["NrFaktury"] = nrFaktury;
83                Session["IdFaktury"] = reader.GetInt32(0);
84                znalezione = true;
85            }
86            reader.Close();
87            reader.Dispose();
88            conn.Close();
89        }
90        return znalezione;
91    }
92}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.