protected void btnAddBookItem_Click(object sender, EventArgs e)
    {
        try
        {
            using (SqlConnection con = new SqlConnection(SQLConnectionString.getConnectionString()))
            {
                string query = "SELECT * FROM Book WHERE Title=@Title";

                SqlCommand command1 = new SqlCommand(query, con);

                command1.Parameters.AddWithValue("@Title", detailsViewBooks.Rows[0].Cells[1].Text.ToString().Trim());


                con.Open();

                SqlDataReader dataReader = command1.ExecuteReader(CommandBehavior.CloseConnection);

                while (dataReader.Read())
                {
                    bookItem.BookTitle = detailsViewBooks.Rows[0].Cells[1].Text.ToString();
                    bookItem.Quantity  = Int32.Parse(txtQuantity.Text.ToString().Trim());
                    appendToListBox();
                }

                con.Close();
            }
        }
        catch (Exception excptn)
        {
            Response.Write(excptn);
            Debug.Write(excptn.Message);
        }
    }
    /// <summary>
    /// User Account Class
    /// </summary>
    protected void ddlBookCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable bookTitle = new DataTable();

        using (SqlConnection con = new SqlConnection(SQLConnectionString.getConnectionString()))
        {
            try
            {
                string query = "SELECT Title FROM Book WHERE CategoryID='" + ((ddlBookCategory.SelectedIndex) + 1) + "' ";

                SqlDataAdapter bookDataAdapter = new SqlDataAdapter(query, con);

                bookDataAdapter.Fill(bookTitle);

                ddlBookName.DataSource     = bookTitle;
                ddlBookName.DataTextField  = "Title";
                ddlBookName.DataValueField = "Title";
                ddlBookName.DataBind();
            }
            catch (SqlException sqlErr)
            {
                Debug.Write(sqlErr.StackTrace);
                Debug.Write(sqlErr.Message);
            }
        }
    }
    protected void ddlBookName_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable bookInformation = new DataTable();

        using (SqlConnection con = new SqlConnection(SQLConnectionString.getConnectionString()))
        {
            try
            {
                string query = "SELECT Title,Quantity FROM Book WHERE Title=@Title";

                SqlDataAdapter bookDataAdapter = new SqlDataAdapter(query, con);
                bookDataAdapter.SelectCommand.Parameters.AddWithValue("@Title", ddlBookName.SelectedItem.Text.ToString());
                bookDataAdapter.Fill(bookInformation);

                detailsViewBooks.DataSource = bookInformation;
                detailsViewBooks.DataBind();
                toggleImagePanel(true);
            }
            catch (SqlException sqlErr)
            {
                Response.Write(sqlErr);
                Debug.Write(sqlErr.Message);
            }
            catch (Exception excpt)
            {
                Response.Write(excpt.StackTrace);
            }
        }
    }
        // konstruktor
        public RegistracijaKorisnika(string PutanjaParametara)
        {
            pPutanjaParametara = PutanjaParametara;
            SQLConnectionString objStringKonekcije = new SQLConnectionString();

            pStringKonekcije = objStringKonekcije.DajMiKonekcioniString();
        }
Example #5
0
    private void loadBooksFromDatabase()
    {
        DataTable book = new DataTable();

        using (conn = new SqlConnection(SQLConnectionString.getConnectionString()))
        {
            try
            {
                SqlDataAdapter bookDataAdapter = new SqlDataAdapter("spGetAllBooks", conn);

                bookDataAdapter.Fill(book);

                ddlBooksList.DataSource     = book;
                ddlBooksList.DataTextField  = "Title";
                ddlBooksList.DataValueField = "Title";
                ddlBooksList.DataBind();
            }
            catch (SqlException sqlErr)
            {
                Debug.Write(sqlErr.Message);
                Debug.Write(sqlErr.StackTrace);
            }
            catch (Exception excpt)
            {
                Debug.Write(excpt.Message);
                Debug.Write(excpt.StackTrace);
            }
            finally
            {
                conn.Close();
            }
        }

        ddlBooksList.Items.Insert(0, new ListItem("Select Item", "NA"));
    }
Example #6
0
    public void Delete(string title)
    {
        DataTable bookInformation = new DataTable();

        try
        {
            conn               = new SqlConnection(SQLConnectionString.getConnectionString());
            command            = new SqlCommand();
            command.Connection = conn;
            string storedProc = "spDeleteBook";
            command.CommandText = storedProc;
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@Title", title);

            conn.Open();
            command.ExecuteNonQuery();
        }
        catch (SqlException sqlErr)
        {
            Debug.Write(sqlErr.Message);
            Debug.Write(sqlErr.StackTrace);
        }
        catch (Exception excpt)
        {
            Debug.Write(excpt.Message);
            Debug.Write(excpt.StackTrace);
        }
        finally
        {
            conn.Close();
        }
    }
Example #7
0
        public BaseContext CreateDbContext(LoginModel model)
        {
            String      primaryConnectionString;
            BaseContext primaryDBContext;

            switch (model.PrimaryServerType)
            {
            case DatabaseConstants.SQL_SERVER:
                primaryConnectionString = SQLConnectionString.Replace("{server}", model.PrimaryServerName).Replace("{database}", model.PrimaryDatabaseName).Replace("{user id}", model.PrimaryUserName).Replace("{password}", model.PrimaryPassword);
                primaryDBContext        = new SQLContext(primaryConnectionString);
                break;

            case DatabaseConstants.MY_SQL:
                primaryConnectionString = MySQLConnectionString.Replace("{server}", model.PrimaryServerName).Replace("{database}", model.PrimaryDatabaseName).Replace("{user id}", model.PrimaryUserName).Replace("{password}", model.PrimaryPassword);
                primaryDBContext        = new MySQLContext(primaryConnectionString);
                break;

            default:
                throw new ArgumentOutOfRangeException("PrimaryServerName", null, "Could not establish connection to Primary Database Server");
                // primaryConnectionString = SQLConnectionString.Replace("{server}", model.PrimaryServerName).Replace("{database}", model.PrimaryDatabaseName).Replace("{user id}", model.PrimaryUserName).Replace("{password}", model.PrimaryPassword);
                // primaryDBContext = new SQLContext(primaryConnectionString);
                // break;
            }
            return(primaryDBContext);
        }
    /// <summary>
    /// Loads the book categories from database
    /// </summary>
    private void loadCategoriesFromDatabase()
    {
        DataTable category = new DataTable();

        using (conn = new SqlConnection(SQLConnectionString.getConnectionString()))
        {
            try
            {
                SqlDataAdapter categoryDataAdapter = new SqlDataAdapter("spSelectCategories", conn);

                categoryDataAdapter.Fill(category);

                ddlBookCategory.DataSource     = category;
                ddlBookCategory.DataTextField  = "CategoryName";
                ddlBookCategory.DataValueField = "CategoryName";
                ddlBookCategory.DataBind();
            }
            catch (SqlException sqlErr)
            {
                Debug.Write(sqlErr.Message);
                Debug.Write(sqlErr.StackTrace);
            }
            catch (Exception excpt)
            {
                Debug.Write(excpt.Message);
                Debug.Write(excpt.StackTrace);
            }
            finally
            {
                conn.Close();
            }
        }

        ddlBookCategory.Items.Insert(0, new ListItem("Select Item", "NA"));
    }
        //test



        public static string AdvertisementImages_InsertUpdate(int ID, string MembershipCardCode, string EnterpriseAccNo,
                                                              string MembershipCardFee, string MembershipCardType, string ExpiredDate, string MembershipCardBackgroundImg,
                                                              string CreatedBy, string StartDate, string MembershipCardName, string MembershipCardFeePaymentCycle, string StrExpiredDate,
                                                              string isValidLifeTime, string MembershipCardBackgroundImgName)
        {
            SqlConnection _SQLConnection = SQLConnectionString.BuildConnection();
            string        _value         = "true";

            using (SqlConnection _DBConnection = _SQLConnection)
            {
                SqlCommand _SQLCommand = new SqlCommand();
                _SQLCommand.CommandType    = System.Data.CommandType.StoredProcedure;
                _SQLCommand.CommandTimeout = 0;
                using (_SQLCommand)
                {
                    try
                    {
                        _SQLCommand.Connection  = _DBConnection;
                        _SQLCommand.CommandText = "AdvertisementImages_InsertUpdate";
                        _SQLCommand.Parameters.AddWithValue("@ID", ID);
                        _SQLCommand.Parameters.AddWithValue("@MembershipCardCode", MembershipCardCode);
                        _SQLCommand.Parameters.AddWithValue("@EnterpriseAccNo", EnterpriseAccNo);
                        _SQLCommand.Parameters.AddWithValue("@MembershipCardFee", MembershipCardFee);
                        _SQLCommand.Parameters.AddWithValue("@MembershipCardType", MembershipCardType);
                        _SQLCommand.Parameters.AddWithValue("@ExpiredDate", ExpiredDate);
                        _SQLCommand.Parameters.AddWithValue("@MembershipCardBackgroundImg", "http://42.1.63.57/AyohaImgCard/MembershipCardBackgroundImg/" + EnterpriseAccNo + "/" + MembershipCardBackgroundImgName);
                        _SQLCommand.Parameters.AddWithValue("@CreatedBy", CreatedBy);
                        _SQLCommand.Parameters.AddWithValue("@StartDate", StartDate);
                        _SQLCommand.Parameters.AddWithValue("@MembershipCardName", MembershipCardName);
                        _SQLCommand.Parameters.AddWithValue("@MembershipCardFeePaymentCycle", MembershipCardFeePaymentCycle);
                        _SQLCommand.Parameters.AddWithValue("@StrExpiredDate", StrExpiredDate);
                        _SQLCommand.Parameters.AddWithValue("@isValidLifeTime", isValidLifeTime);

                        _DBConnection.Open();
                        _SQLCommand.ExecuteNonQuery();
                    }

                    catch (Exception ex)
                    {
                        _value = "false," + ex.ToString();;
                        // _value = ex.ToString();
                    }

                    finally
                    {
                        _DBConnection.Close();

                        if (MembershipCardBackgroundImg != "ExistingImage")
                        {
                            MembershipCardBackground_CreateImg(MembershipCardBackgroundImg, EnterpriseAccNo, MembershipCardBackgroundImgName);
                        }
                    }
                }
            }



            return(_value);
        }
Example #10
0
    public static IEnumerable GetProductsByCategory(string CategoryName, SqlConnection con)
    {
        con = new SqlConnection(SQLConnectionString.getConnectionString());
        string     storedProcedureName = "spGetBookDetails";
        SqlCommand cmd = new SqlCommand(storedProcedureName, con);

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@SelectedBook", SqlDbType.NVarChar).Value = CategoryName;
        con.Open();
        SqlDataReader dataReader = cmd.ExecuteReader();

        return(dataReader);
    }
 public override bool Execute()
 {
     try
     {
         Log.LogMessageFromText(String.Format("PnPSqlAppConfigGeneratorTask: Reading information for configuration {0} to generate app.config in {1}", Configuration, AppConfigFolder), MessageImportance.Normal);
         PnPAppConfigManager appConfigManager = new PnPAppConfigManager(SQLConnectionString.Replace("&quot;", "\""), Configuration);
         appConfigManager.GenerateAppConfig(AppConfigFolder);
         return(true);
     }
     catch (Exception ex)
     {
         Log.LogErrorFromException(ex);
         return(false);
     }
 }
 public override bool Execute()
 {
     try
     {
         //Log.LogMessageFromText(String.Format("PnPAppConfigReaderTask: Reading information for configuration {0}", Configuration), MessageImportance.Normal);
         PnPAppConfigManager appConfigManager = new PnPAppConfigManager(SQLConnectionString.Replace("&quot;", "\""), Configuration);
         PnPBuildConfiguration = appConfigManager.GetConfigurationElement("PnPBuild");
         PnPBranch             = appConfigManager.GetConfigurationElement("PnPBranch");
         return(true);
     }
     catch (Exception ex)
     {
         Log.LogErrorFromException(ex);
         return(false);
     }
 }
    protected void ddlBookName_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable bookInformation = new DataTable();

        try
        {
            using (conn = new SqlConnection(SQLConnectionString.getConnectionString()))
            {
                command            = new SqlCommand();
                command.Connection = conn;
                string storedProc = "spSelectItemsQuantity";
                command.CommandText = storedProc;
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Title", ddlBookName.SelectedItem.Text.ToString());

                SqlDataAdapter bookDataAdapter = new SqlDataAdapter(command);

                bookDataAdapter.Fill(bookInformation);

                detailsViewBooks.DataSource = bookInformation;
                detailsViewBooks.DataBind();

                toggleImagePanel(true);
                updateBookImagePanel();
            }
        }
        catch (SqlException sqlErr)
        {
            Debug.Write(sqlErr.Message);
            Debug.Write(sqlErr.StackTrace);
        }
        catch (Exception excpt)
        {
            Debug.Write(excpt.Message);
            Debug.Write(excpt.StackTrace);
        }
        finally
        {
            command.Connection.Close();
            conn.Close();
        }
    }
    protected void btnAddBookItem_Click(object sender, EventArgs e)
    {
        try
        {
            using (conn = new SqlConnection(SQLConnectionString.getConnectionString()))
            {
                string storedProc = "spGetAllInformationForSingleBook";
                command             = new SqlCommand();
                command.Connection  = conn;
                command.CommandText = storedProc;
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Title", detailsViewBooks.Rows[0].Cells[1].Text.ToString().Trim());

                conn.Open();

                SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);

                while (dataReader.Read())
                {
                    bookItem.BookTitle = detailsViewBooks.Rows[0].Cells[1].Text.ToString();
                    bookItem.Quantity  = Int32.Parse(txtQuantity.Text.ToString().Trim());
                    bookItem.UnitPrice = Convert.ToDecimal(dataReader["UnitPrice"]);
                    appendToListBox();
                }
            }
        }
        catch (SqlException sqlErr)
        {
            Debug.Write(sqlErr.Message);
            Debug.Write(sqlErr.StackTrace);
        }
        catch (Exception excpt)
        {
            Debug.Write(excpt.Message);
            Debug.Write(excpt.StackTrace);
        }
        finally
        {
            conn.Close();
        }
    }
    /// <summary>
    /// User Account Class
    /// </summary>
    protected void ddlBookCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable bookTitle = new DataTable();

        try
        {
            using (conn = new SqlConnection(SQLConnectionString.getConnectionString()))
            {
                command             = new SqlCommand();
                command.Connection  = conn;
                command.CommandText = "spGetBooksBySelectedCategory";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@SelectedCategory", ((ddlBookCategory.SelectedIndex) + 1));

                SqlDataAdapter bookDataAdapter = new SqlDataAdapter(command);
                bookDataAdapter.Fill(bookTitle);

                ddlBookName.DataSource     = bookTitle;
                ddlBookName.DataTextField  = "Title";
                ddlBookName.DataValueField = "Title";
                ddlBookName.DataBind();
            }
        }
        catch (SqlException sqlErr)
        {
            Debug.Write(sqlErr.Message);
            Debug.Write(sqlErr.StackTrace);
        }
        catch (Exception excpt)
        {
            Debug.Write(excpt.Message);
            Debug.Write(excpt.StackTrace);
        }
        finally
        {
            command.Connection.Close();
            conn.Close();
        }
        ddlBookName.Items.Insert(0, new ListItem("Select Item", "NA"));
    }
Example #16
0
    public void Update(string bkTitle, string author, string shDes, string lngDes, string imgFile, int category, string isbn, string status, string rating,
                       decimal unitPrice, decimal preorderPrice,
                       int discount, string printLength, int quantity)
    {
        try
        {
            conn = new SqlConnection(SQLConnectionString.getConnectionString());

            string     storedProcedureName = "spUpdateBookInformation";
            SqlCommand cmd = new SqlCommand(storedProcedureName, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            //cmd.Parameters.AddWithValue("@Id", 2);
            cmd.Parameters.AddWithValue("@Title", bkTitle);
            cmd.Parameters.AddWithValue("@Author", author);
            cmd.Parameters.AddWithValue("@CategoryID", category);
            cmd.Parameters.AddWithValue("@ISBN", isbn);
            cmd.Parameters.AddWithValue("@BookStatus", status);
            cmd.Parameters.AddWithValue("@Rating", rating);
            cmd.Parameters.AddWithValue("@UnitPrice", unitPrice);
            cmd.Parameters.AddWithValue("@PreOrderPrice", preorderPrice);
            cmd.Parameters.AddWithValue("@Discount", discount);
            cmd.Parameters.AddWithValue("@PrintLength", printLength);
            cmd.Parameters.AddWithValue("@Quantity", quantity);
            cmd.Parameters.AddWithValue("@ShortDescription", shDes);
            cmd.Parameters.AddWithValue("@LongDescription", lngDes);
            cmd.Parameters.AddWithValue("@ImageFile", imgFile);

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        catch (Exception excpt)
        {
            Debug.Write(excpt.Message);
            Console.Write(excpt.Message);
        }
    }
Example #17
0
        public BaseContext CreateReplicaDbContext(LoginModel model)
        {
            String      replicaConnectionString;
            BaseContext replicaDBContext;

            switch (model.ReplicaServerType)
            {
            case DatabaseConstants.SQL_SERVER:
                replicaConnectionString = SQLConnectionString.Replace("{server}", model.ReplicaServerName).Replace("{database}", model.ReplicaDatabaseName).Replace("{user id}", model.ReplicaUserName).Replace("{password}", model.ReplicaPassword);
                replicaDBContext        = new SQLContext(replicaConnectionString);
                break;

            case DatabaseConstants.MY_SQL:
                replicaConnectionString = MySQLConnectionString.Replace("{server}", model.ReplicaServerName).Replace("{database}", model.ReplicaDatabaseName).Replace("{user id}", model.ReplicaUserName).Replace("{password}", model.ReplicaPassword);
                replicaDBContext        = new MySQLContext(replicaConnectionString);
                break;

            default:
                replicaConnectionString = SQLConnectionString.Replace("{server}", model.ReplicaServerName).Replace("{database}", model.ReplicaDatabaseName).Replace("{user id}", model.ReplicaUserName).Replace("{password}", model.ReplicaPassword);
                replicaDBContext        = new SQLContext(replicaConnectionString);
                break;
            }
            return(replicaDBContext);
        }
Example #18
0
        public BaseContext CreateDbContext(LoginModel model)
        {
            String      primaryConnectionString;
            BaseContext primaryDBContext;

            switch (model.PrimaryServerType)
            {
            case DatabaseConstants.SQL_SERVER:
                primaryConnectionString = SQLConnectionString.Replace("{server}", model.PrimaryServerName).Replace("{database}", model.PrimaryDatabaseName).Replace("{user id}", model.PrimaryUserName).Replace("{password}", model.PrimaryPassword);
                primaryDBContext        = new SQLContext(primaryConnectionString);
                break;

            case DatabaseConstants.MY_SQL:
                primaryConnectionString = MySQLConnectionString.Replace("{server}", model.PrimaryServerName).Replace("{database}", model.PrimaryDatabaseName).Replace("{user id}", model.PrimaryUserName).Replace("{password}", model.PrimaryPassword);
                primaryDBContext        = new MySQLContext(primaryConnectionString);
                break;

            default:
                primaryConnectionString = SQLConnectionString.Replace("{server}", model.PrimaryServerName).Replace("{database}", model.PrimaryDatabaseName).Replace("{user id}", model.PrimaryUserName).Replace("{password}", model.PrimaryPassword);
                primaryDBContext        = new SQLContext(primaryConnectionString);
                break;
            }
            return(primaryDBContext);
        }
Example #19
0
    private void placeOrder()
    {
        string username        = txtUserName.Text;
        string shippingAddress = txtUserAddress.Text;
        string shippingCity    = txtCity.Text;
        string shippingState   = txtState.Text;
        string zipCode         = txtZipCode.Text;
        string country         = ddlCountries.SelectedItem.ToString();
        string contactNumber   = txtContactNumber.Text.ToString();
        string purchaseType;
        int    cardID     = 0;
        int    pymentType = 0;

        string paymentMethod = rdbPaymentMethod.SelectedItem.ToString();

        if (rdbPaymentMethod.SelectedIndex.Equals(0))
        {
            order.CashPurchase       = true;
            order.CreditCardPurchase = false;
            order.DebitCardPurchase  = false;
            purchaseType             = "Yes";
            cardID     = 0;
            pymentType = 3;
        }
        else if (rdbPaymentMethod.SelectedIndex.Equals(1))
        {
            order.CreditCardPurchase = true;
            order.DebitCardPurchase  = false;
            order.CashPurchase       = false;
            order.CardNumber         = txtCardNumber.Text.ToString().Trim();
            purchaseType             = "Yes";
            cardID     = Convert.ToInt32(txtCardNumber.Text);
            pymentType = 1;
        }
        else if (rdbPaymentMethod.SelectedIndex.Equals(2))
        {
            order.DebitCardPurchase  = true;
            order.CreditCardPurchase = false;
            order.CashPurchase       = false;
            order.CardNumber         = txtCardNumber.Text.ToString().Trim();
            cardID     = Convert.ToInt32(txtCardNumber.Text);
            pymentType = 2;
        }

        bool   subscribeToNewsLetter = false;
        string userSubscibed         = "no";

        if (chkbxSignUp.Checked)
        {
            subscribeToNewsLetter = true;
        }
        else
        {
            subscribeToNewsLetter = false;
        }

        if (subscribeToNewsLetter == true)
        {
            userSubscibed.Equals("yes");
        }



        DateTime orderDate = DateTime.Now;

        Account acc = new Account();

        acc.UserName = Session["UserName"].ToString();

        conn = new SqlConnection(SQLConnectionString.getConnectionString());

        command             = new SqlCommand("spCompleteOrder", conn);
        command.CommandType = CommandType.StoredProcedure;


        //Response.Write(Book.NumberOfBooks());

        command.Parameters.Add("@OrderDate", SqlDbType.DateTime).Value      = orderDate;
        command.Parameters.Add("@PaymentDate", SqlDbType.DateTime).Value    = DateTime.Now;
        command.Parameters.Add("@ShipperID", SqlDbType.Int).Value           = 1;
        command.Parameters.Add("@ShipmentDate", SqlDbType.Date).Value       = DateTime.Now;
        command.Parameters.Add("@SalesTax", SqlDbType.Int).Value            = 30;
        command.Parameters.Add("@SalesTaxStatus", SqlDbType.NVarChar).Value = "Taxed";
        command.Parameters.Add("@UserID", SqlDbType.Int).Value                  = userAccountSessionTracker.UserID;
        command.Parameters.Add("@OrderStatus", SqlDbType.NVarChar).Value        = "ordered";
        command.Parameters.Add("@NumberOfBooks", SqlDbType.Int).Value           = 2;
        command.Parameters.Add("@CreditCardPurchase", SqlDbType.NVarChar).Value = "Yes";
        command.Parameters.Add("@DebitCardPurchase", SqlDbType.NVarChar).Value  = "Yes";
        command.Parameters.Add("@CashPurchase", SqlDbType.NVarChar).Value       = "Yes";
        command.Parameters.Add("@CardID", SqlDbType.Int).Value                  = cardID;
        command.Parameters.Add("@UserName", SqlDbType.VarChar).Value            = username;
        command.Parameters.Add("@TotalPrice", SqlDbType.Decimal).Value          = order.TotalAmount;
        command.Parameters.Add("@PaymentID", SqlDbType.Int).Value               = pymentType;
        try
        {
            conn.Open();
            command.ExecuteNonQuery();
        }
        catch (SqlException sqlErr)
        {
            Debug.Write(sqlErr);
            Response.Write(sqlErr);
            Debug.Write(sqlErr.Message);
        }
        catch (Exception excpt)
        {
            Debug.Write(excpt.StackTrace);
            Response.Write(excpt);
            Debug.Write(excpt.Message);
        }
        finally
        {
            conn.Close();
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        Account userAccount = new Account();

        String connectionString = SQLConnectionString.getConnectionString();

        conn = new SqlConnection(connectionString);

        PasswordHash hashPassWord = new PasswordHash();

        //string query = "SELECT * FROM UserAccount WHERE UserName='******' AND PasswordHash='" + hashPassWord.passwordHasher(txtPasswordBox.Text.ToString()) + "' ";

        command             = new SqlCommand("spLogin", conn);
        command.CommandType = CommandType.StoredProcedure;


        command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUserNameBox.Text;
        command.Parameters.Add("@Password", SqlDbType.VarChar).Value = hashPassWord.passwordHasher(txtPasswordBox.Text.ToString());
        //command = new SqlCommand(query, conn);

        conn.Open();

        SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);



        if (dataReader.Read())
        {
            string username = dataReader.GetString(1);
            string password = dataReader.GetString(5);

            userAccount.UserID      = dataReader.GetInt32(0);
            userAccount.UserName    = username;
            userAccount.FirstName   = dataReader.GetString(2);
            userAccount.LastName    = dataReader.GetString(3);
            userAccount.Password    = password;
            userAccount.AccessLevel = dataReader.GetString(26);



            if (userAccount.UserName.Equals(txtUserNameBox.Text) && userAccount.Password.Equals(hashPassWord.passwordHasher(txtPasswordBox.Text.ToString())) /*userAccount1==1*/)
            {
                if (rememberme.Checked == true)
                {
                    Response.Cookies["UserName"].Value   = txtUserNameBox.Text;
                    Response.Cookies["Password"].Value   = txtPasswordBox.Text;
                    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(15);
                    Response.Cookies["Password"].Expires = DateTime.Now.AddDays(15);
                }
                else
                {
                    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                }

                HttpContext.Current.Session["User"]            = userAccount;
                HttpContext.Current.Session["AccountUserName"] = txtUserNameBox.Text;
                HttpContext.Current.Session["FirstTimeUser"]   = false;
                HttpContext.Current.Session.Timeout            = 60;

                if (userAccount.AccessLevel == "admin")
                {
                    Response.Redirect("AdminManageAccount.aspx");
                }


                Response.Redirect("PurchasePage.aspx");
            }
            else
            {
            }
        }
    }
Example #21
0
 public DatabaseProcedures()
 {
     conn = new SqlConnection(SQLConnectionString.getConnectionString());
 }