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

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

re #139

RevLine 
[477]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;
[486]32        if (!IsPostBack) { SetFocus(NIPTextBox); }
[477]33    }
34
35    protected void ZalogujButton_Click(object sender, EventArgs e)
36    {
[513]37        if (!Page.IsValid) return;
[486]38        string nip = NIPTextBox.Text.Replace(" ", string.Empty).Replace("-", string.Empty);
39        string nrZlec = NrZlecTextBox.Text.Replace(" ", string.Empty);
[513]40
[477]41        bool czyZalogowany = Zaloguj(nip, nrZlec);
42        if (czyZalogowany)
43        {
[486]44            FormsAuthentication.RedirectFromLoginPage(nip, false);
[477]45        }
46        else
47        {
48            errorMsg.Text = GetLocalResourceObject("errorMsg").ToString();
49        }
50    }
51
52    bool Zaloguj(string nip, string nrFaktury)
53    {
[513]54        if (nrFaktury.Split('/').Length != 3) return false;
55
[486]56        string fakturaNr = nrFaktury.Split('/')[0];
57        string fakturaRoz = nrFaktury.Split('/')[1];
58        string fakturaRok = nrFaktury.Split('/')[2];
59
[477]60        string connString = ConfigurationManager.ConnectionStrings["BazaReklamConn"].ConnectionString;
[486]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))
[477]64        {
65            SqlCommand cmd = new SqlCommand(cmdText, conn);
66            cmd.Parameters.Add("@nip", SqlDbType.NVarChar, 50).Value = nip;
[486]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;
[477]70            conn.Open();
[486]71
72            SqlDataReader reader = cmd.ExecuteReader();
73            if (reader == null)
[477]74            {
[486]75                conn.Close();
76                return false;
[477]77            }
[486]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();
[477]88            conn.Close();
89        }
[486]90        return znalezione;
[477]91    }
[486]92}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.