Category Archives: Recent articles

Create marquee news in front page and the news is read from the database with expired data,also included management page to insert news

My boss just saw other company website has a marquee new on the front page, so she asked me if I could make one and arrow her to insert news and the news will dispear at the expired data.

For achieve that task, first I create a table in my database table, here is my table:

breadNewTable

then I write a store proceedure, a little tip for fresh guy, alway use store preceedure to insert data for security reasons.

breadNewStoreProceedure

Now, We could start the front end job. I create a user control:marquee.ascx(so you could put it in anyway you like), to display the new, here is my html code:

frontUCmarquee

here is the backcod, I used ado.net to open the database and qurery what I need, and bind it to my BulledtedList:

databasereadertomarquee

See the code this if(!IsPostBack) is not neccessary, but I use web froms so it wil inherit maintain state so I don’t need retrieve database everytime postback.

here I am also happy to share the css file for style this unorder list to display inline:

MarqueeCssStyle

A tip for fresh guy, put this in the page your use control will stand it.

Now, you just need drag the usercontrol to any page you want it with this css style in top of the header it. You coud see it.

Then We could start create a page to arrow my boss to insert the bread news, I used boostrap format so it save my time to write css. here is the front page look like:

addNews

here is the html code:

htmlCodeAddnews

The form use jQury Validate, the jquery-ui.js, is for my boss click then will pop up the jQuery calender to arrow her to put the expired date. So simple isn’t, I am love JQure very much, save a lot of time. It remind me when I first time write javascript over 10 years ago, for every simply function I need write a lot codes.

Finally I just need write a event could be fired by this button.

storeIntodatabase

Ok, That’s all. Have fun!

Advertisements

Using c# code to force bootstrap modal stay open after page postback

Recently I write a small function into my asp.net application.To enable the driver to input the time the submit the pick up client and drop off the client time.
My boss like the pick up time and drop off time should been populate by just click.so I write a code on the back of page to retrive the time every time the driver click the button.
But the dropoff button driver me to nuts,Because When the dropoff button click I pop out the bootstrap modal.But the problems came out this button need make page postback to retrive the current time and after postback my modal need stay open.
It take me a while to fix out this.
Here is my solution.
first, I need write javascript like this is for to open the modal: #dropoffModal is my hidden modal.

 function openModal() {
$('#dropoffModal').modal({ show: true });
}
 

Second I have the the button is like this(See the button click will fire a event named:”Button_DropOff_Click” behind it):

 button_click_event_fire_javascript

Finally, just write your event on the page behind file:


protected void Button_DropOff_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
}

here just a solution. by the way, You could use ScriptManager.RegisterStartupScript() this command call another function in your frond page javascript.

create a php page with in paypal button and link–this just continue with previous page

<?php
echo “<h1>Welcome to Bazaar online shop</h1>”;
include(“inc_db.php”);//connect to database newsletter
if($DBConnect)
{
$table = “products”;
$query = “select * from $table”;
$result = @mysql_query($query,$DBConnect);
echo “<table width = ‘80%’ border = ‘1’>”;
echo “<tr><th>Name</th><th>Cost</th><th>Image</th><th>Description</th><th>Add to Cart</th><th>Go Pay</th></tr>”;
while($row = mysql_fetch_assoc($result))
{
echo “<tr><td>$row[Name]</td><td>$row[Cost]</td>”;
echo “<td><img src =’images/”.$row[‘Image’].”‘/></td><td>$row[Description]</td><td>”;
echo “<form action=’https://www.paypal.com/cgi-bin/webscr&#8217; method =’post’>”;
echo “<input type=’hidden’ name=’cmd’ value=’_cart’>”;
echo “<input type=’hidden’ name=’business’ value=’youremail@host.com’>”;
echo “<input type=’hidden’ name=’item_name’ value='”.$row[‘Name’].”‘>”;
echo “<input type=’hidden’ name=’amount’ value='”.$row[‘Cost’].”‘>”;
echo “<input type=’hidden’ name=’currency_code’ value=’AUD’>”;
echo “<input type=’hidden’ name=’add’ value=’add’>”;

echo “<input type=’hidden’ name=’bn’ value=’PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest’>”;
echo “<input type=’image’ src = ‘https://www.paypalobjects.com/en_AU/i/btn/btn_cart_LG.gif&#8217; border=’0′ name=’submit’ alt=’PayPal – The safer,easier way to pay online.’>”;
echo “<img alt=” border=’0′ src=’https://www.paypalobjects.com/en_AU/i/src/pixel.gif&#8217; width=’1′ height=’1′>”;
echo “</form></td>”;
echo “<td><form action=’https://www.paypal.com/cgi-bin/webscr&#8217; method =’post’>”;
echo “<input type=’hidden’ name=’cmd’ value=’_xclick’>”;
echo “<input type=’hidden’ name=’business’ value=’youremail@host.com’>”;
echo “<input type=’hidden’ name=’item_name’ value='”.$row[‘Name’].”‘>”;
echo “<input type=’hidden’ name=’amount’ value='”.$row[‘Cost’].”‘>”;
echo “<input type=’hidden’ name=’currency_code’ value=’AUD’>”;
echo “<input type=’hidden’ name=’bn’ value=’PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest’>”;
echo “<input type=’image’ src = ‘https://www.paypalobjects.com/en_AU/i/btn/btn_buynowCC_LG.gif&#8217; border=’0′ name=’submit’ alt=’PayPal – The safer,easier way to pay online.’>”;
echo “<img alt=” border=’0′ src=’https://www.paypalobjects.com/en_Au/i/src/pixel.gif&#8217; width=’1′ height=’1′>”;
echo “</form></td></tr>”;

}
echo “</table>”;
mysql_free_result($result);
mysql_close($DBConnect);

}
?>

a paypal shopping cart with php here is the source code for you catalog–continue

first, create your catalog and product database, here is the source code:

— phpMyAdmin SQL Dump
— version 2.10.3
http://www.phpmyadmin.net

— Host: localhost
— Generation Time: May 24, 2013 at 02:43 PM
— Server version: 5.0.51
— PHP Version: 5.2.6

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


— Database: `bazaar`

CREATE DATABASE `bazaar` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `bazaar`;

— ——————————————————–


— Table structure for table `categories`

CREATE TABLE `categories` (
`CatID` int(11) NOT NULL auto_increment,
`Name` varchar(50) NOT NULL,
PRIMARY KEY  (`CatID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;


— Dumping data for table `categories`

INSERT INTO `categories` VALUES (1, ‘Bazaar Ceramics Catalogue’);

— ——————————————————–


— Table structure for table `products`

CREATE TABLE `products` (
`ProdID` int(11) NOT NULL auto_increment,
`CartID` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Cost` decimal(8,2) NOT NULL,
`Image` varchar(50) NOT NULL default ‘NoImage.jpg’,
`Description` varchar(250) default NULL,
PRIMARY KEY  (`ProdID`),
KEY `CartID` (`CartID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;


— Dumping data for table `products`

INSERT INTO `products` VALUES (1, 1, ‘Copper Red Dish 001’, 450.00, ‘bcpot002_smaller.jpg’, ‘Shallow Copper Red dish form showing distinctive qualities of this traditional reduction fired glaze.  Fired to 1300 degrees’);
INSERT INTO `products` VALUES (2, 1, ‘Copper Red Bottle 001’, 550.00, ‘bcpot003_smaller.jpg’, ‘Copper Red bottle form.  Reduction fired to 1300 degrees’);
INSERT INTO `products` VALUES (3, 1, ‘Chun bowl 001’, 350.00, ‘bcpot006_smaller.jpg’, ‘Blue Chun bowl with tea stain rim over terracotta.  Fired to 1300 degrees’);
INSERT INTO `products` VALUES (4, 1, ‘Moonscape bowl 001’, 320.00, ‘bcpot009_smaller.jpg’, ‘High Calcium bowl with white glaze over blue slip.  Fired to 1280 degrees’);
INSERT INTO `products` VALUES (5, 1, ‘Crystalline bowl 001’, 250.00, ‘bcpot013_smaller.jpg’, ‘Blue Green Crystalline glaze.  Narrow-foot bowl with clear glaze outside.  Fired to 1300 degrees’);
INSERT INTO `products` VALUES (6, 1, ‘Carved vase form 001’, 450.00, ‘bcpot014_smaller.jpg’, ‘Carved Iron stoneware vase form.  Oxidation lustre on rim.  Fired to 1280 degrees’);
INSERT INTO `products` VALUES (7, 1, ‘Carved vase form 002’, 450.00, ‘bcpot016_smaller.jpg’, ‘Carved dry matt calcium vase form.  Fired to 1280 degrees’);
INSERT INTO `products` VALUES (8, 1, ‘Carved Bottle form 001’, 600.00, ‘bcpot018_smaller.jpg’, ‘Carved dry matt calcium bottle form.  Lustre rim.  Fired to 1280 degrees’);
INSERT INTO `products` VALUES (9, 1, ‘Dry earth vase form 001’, 500.00, ‘bcpot012_smaller.jpg’, ‘Vase form.  White slip over earthenware clay. Fired to 1000 degrees’);
INSERT INTO `products` VALUES (10, 1, ‘Carnivale cup and saucer 001’, 150.00, ‘bcpot008_smaller.jpg’, ‘ Cup and Saucer with Carnivale design.  Coloured slips under clear glaze.  Earthenware’);

Unsetting Variables and Destroying the Session

When you are finished with a session variable, you can unset it.You can do this directly
by unsetting the appropriate element of the $_SESSION array, as in this example:
unset($_SESSION[‘myvar’]);
Note that the use of session_unregister() and session_unset() is no longer
required and is not recommended.These functions were used prior to the introduction
of $_SESSION.
You should not try to unset the whole $_SESSION array because doing so will effectively
disable sessions.To unset all the session variables at once, use
$_SESSION = array();
When you are finished with a session, you should first unset all the variables and
then call  session_destroy();
to clean up the session ID.

Create a php page that will process the order using an array and display the results on another page.

your html form must look like blown:
———————————————————————————————————————————

<form action=”hardware_order.php” method=”post”>
<fieldset>
<legend>Order Form</legend>
<p><label for=”user”> Name</label> <input type=”text” name=”name” id=”user” /></p>
<p><strong>Select Some Products:</strong> <br>
<select name=”products[]” multiple>
<option value=”Sonic Screwdriver”>Sonic Screwdriver</option>
<option value=”Hammer”>Hammer</option>
<option value=”Drill”>Drill</option>
<option value=”Spanner”>Spanner</option>
</select>
<p><input type=”submit” name=”submit” value=”send”></p>
</fieldset>
</form>

————————————————————————————————————————
there are two ways can proceed this: one is :
————————————————————————————————————————-
<?php
$name =trim($_POST[‘name’]);
if(empty($_POST[‘products’])||empty($name))
{
echo “nothing has been selected”;
}
else
{
echo “Thanks “.$name.” your select products is “;

foreach($_POST[‘products’] as $o)
{
echo $o.”<br/>”;
}
}
?>
————————————————————————————————————————–
another ways is teacher’s answers:
———————————————————————————————————————————<?php
$name =trim($_POST[‘name’]);
if (!empty($name))
{     echo “<p>Welcome <b>$name</b>!</p>”;
}
else
{
echo “<p>Enter a name</p>”;
}

if(!empty($_POST[‘products’]))
{
echo “<ul>”;
echo “<p>Your product choices are:<br/>”;
foreach ($_POST[‘products’] as $value)
{
echo “<li>$value</li>”;
}
echo “</ul>”;
}
else
{
echo “<p> Nothing selected</p>”;
}
?>