Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/bduong/toms-list

  • Loading branch information...
commit 774aa81abbc3957befe9ce7cf1903943ded18a97 2 parents 0426a04 + 7947d52
@Martikos Martikos authored
View
30 App_Code/DataServices/GarageDataService.cs
@@ -33,12 +33,13 @@ public static Garage addGarageSale(Garage gs)
{
SqlConnection conn = DBConnector.getSqlConnection();
conn.Open();
- SqlCommand cmd = new SqlCommand("INSERT INTO GarageSale (UserID, DateBegin, DateEnd, Address, Description) VALUES (@UserId, @DateBegin, @DateEnd, @Address, @Description); SELECT SCOPE_IDENTITY()", conn);
+ SqlCommand cmd = new SqlCommand("INSERT INTO GarageSale (UserID, DateBegin, DateEnd, Address, Description, Image) VALUES (@UserId, @DateBegin, @DateEnd, @Address, @Description, @Image); SELECT SCOPE_IDENTITY()", conn);
cmd.Parameters.AddWithValue("@UserId", gs.userID);
cmd.Parameters.AddWithValue("@DateBegin", gs.DateBegin);
cmd.Parameters.AddWithValue("@DateEnd", gs.DateEnd);
cmd.Parameters.AddWithValue("@Address", gs.Address);
- cmd.Parameters.AddWithValue("@Description", gs.Description);
+ cmd.Parameters.AddWithValue("@Description", gs.Description);
+ cmd.Parameters.AddWithValue("@Image", gs.imageId);
int uid = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
gs.GarageID = uid;
@@ -48,12 +49,31 @@ public static Garage addGarageSale(Garage gs)
public static Boolean deleteGarageSale(String id)
{
- return false; //placeholder
+ SqlConnection conn = DBConnector.getSqlConnection();
+ conn.Open();
+ SqlCommand cmd = new SqlCommand("DELETE FROM GarageSale WHERE GarageID = @gid", conn);
+ cmd.Parameters.AddWithValue("@gid", id);
+
+ int rowsAffected = cmd.ExecuteNonQuery();
+ conn.Close();
+ return (rowsAffected > 0);
}
- public static Boolean updateGarageSale(String id)
+ public static Boolean updateGarageSale(String id, Garage newGarage)
{
- return false; //placeholder
+ SqlConnection conn = DBConnector.getSqlConnection();
+ conn.Open();
+ SqlCommand cmd = new SqlCommand("UPDATE GarageSale SET UserID = @userID, DateBegin = @DateBegin, DateEnd = @DateEnd, Address = @Address, Description = @Description", conn);
+ cmd.Parameters.AddWithValue("@userID", newGarage.userID);
+ cmd.Parameters.AddWithValue("@DateBegin", newGarage.DateBegin);
+ cmd.Parameters.AddWithValue("@DateEnd", newGarage.DateEnd);
+ cmd.Parameters.AddWithValue("@Address", newGarage.Address);
+ cmd.Parameters.AddWithValue("@Description", newGarage.Description);
+
+ int rowsAffected = cmd.ExecuteNonQuery();
+ conn.Close();
+
+ return (rowsAffected > 0);
}
public static class ColumnNames
View
19 App_Code/Entities/Garage.cs
@@ -13,14 +13,18 @@ public class Garage
public DateTime DateBegin { get; set; }
public DateTime DateEnd { get; set; }
public string Address { get; set; }
- public string Description { get; set; }
+ public string Description { get; set; }
+ public int imageId { get; set; }
+
+ public Garage(int id, Guid userID, DateTime DateBegin, DateTime DateEnd, string Address, string Description):
+ this(userID, DateBegin, DateEnd, Address, Description)
+ {
+ this.GarageID = id;
+ }
- public Garage(Guid userID, DateTime DateBegin, DateTime DateEnd, string Address, string Description)
+ public Garage(Guid userID, DateTime DateBegin, DateTime DateEnd, string Address, string Description)
+ : this(userID, DateBegin, DateEnd, Address)
{
- this.userID = userID;
- this.DateBegin = DateBegin;
- this.DateEnd = DateEnd;
- this.Address = Address;
this.Description = Description;
}
@@ -29,6 +33,7 @@ public Garage(Guid userID, DateTime DateBegin, DateTime DateEnd, string Address,
this.userID = userID;
this.DateBegin = DateBegin;
this.DateEnd = DateEnd;
- this.Address = Address;
+ this.Address = Address;
+ imageId = 0;
}
}
View
BIN  App_Data/Database.mdf
Binary file not shown
View
BIN  App_Data/Database_Log.ldf
Binary file not shown
View
32 Views/Private/GarageSale.aspx
@@ -1,24 +1,44 @@
<%@ Page Language="C#" MasterPageFile="~/Views/Layout.master" CodeFile="GarageSale.aspx.cs" Inherits="Views_Private_GarageSale" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
+ <script type="text/javascript">
+ function changeImagePreview(uploadControl) {
+ if (uploadControl.files && uploadControl.files[0]) {
+ var fileReader = new FileReader();
+ fileReader.onload = function (x) {
+ document.getElementById('image_preview').setAttribute('src', x.target.result);
+ };
+ fileReader.readAsDataURL(uploadControl.files[0]);
+ } else {
+ document.getElementById('image_preview').setAttribute('src', "../../public/img/grey_wash_wall.png");
+ }
+ }
+ </script>
<div id="form_item">
Create a new Garage Sale <br />
<table align="center">
<tr>
<td>
<fieldset>
- <label for="Date" class="form_label">Date of Sale</label><asp:TextBox ID="textbox_date" runat="server" name="Date" class="form_field"></asp:TextBox><br /><br />
- <label for="BeginTime" class="form_label">Begin Time</label><asp:TextBox ID="textbox_begin" runat="server" name="BeginTime" class="form_field"></asp:TextBox><br /><br />
- <label for="EndTime" class="form_label">End Time</label><asp:TextBox ID="textbox_end" runat="server" name="EndTime" class="form_field"></asp:TextBox><br /><br />
- <label for="Location" class="form_label">Location</label><asp:TextBox ID="textbox_location" runat="server" name="Location" class="form_field"></asp:TextBox><br /><br />
+ <label for="Date" class="form_label">Date of Sale</label><br />
+ <%--<asp:TextBox ID="textbox_date" runat="server" name="Date" class="form_field"></asp:TextBox>--%>
+ <asp:Calendar width="100%" ID="date_cal" runat="server"></asp:Calendar>
+
+ <br />
+ <label for="BeginTime" class="form_label">Begin Time</label><br /><asp:DropDownList ID="begin_time_list" width="100%" runat="server"></asp:DropDownList>
+ <br /><br />
+ <label for="EndTime" class="form_label">End Time</label><asp:DropDownList ID="end_time_list" width="100%" runat="server"></asp:DropDownList><br /><br />
+ <label for="Location" class="form_label">Address</label><textarea ID="textbox_location" runat="server" name="Location" class="form_field"></textarea>
+ <br /><br />
<label for="Description" class="form_label">Description</label><textarea id="textbox_description" runat="server" name="Description" class="form_field"></textarea><br /><br />
+ <label for="Image" class="form_label">Image (Optional)</label><asp:FileUpload ID="imageUpload" runat="server" onchange="changeImagePreview(this)"/><br /><br />
<asp:Label ID="creategarage_output" runat="server" Text=""></asp:Label><br />
- <label for="Tags" class="form_label"></label><asp:Button ID="button_post" runat="server" Text="List New Garage Sale" class="form_button" OnClick="Button1_Click"/>
+ <asp:Button ID="button_post" runat="server" Text="List New Garage Sale" class="form_button" OnClick="Button1_Click"/>
</fieldset>
</td>
<td style="background-color: #eee; width: 200px; height: 100px" >
- Image here
+ <img id="image_preview" src="../../public/img/grey_wash_wall.png" width="200"/>
</td>
</tr>
</table>
View
148 Views/Private/GarageSale.aspx.cs
@@ -4,46 +4,78 @@
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
-using System.Web.Security;
+using System.Web.Security;
+using System.IO;
+using System.Drawing;
public partial class Views_Private_GarageSale : System.Web.UI.Page
{
+
protected void Page_Load(object sender, EventArgs e)
- {
-
+ {
+ int[] hours = {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+ if (!IsPostBack)
+ {
+ foreach (int i in hours) {
+ for (int j = 0; j < 4; j++)
+ {
+ begin_time_list.Items.Add(i + ":" + (j*15).ToString().PadLeft(2,'0') + " AM");
+ end_time_list.Items.Add(i + ":" + (j * 15).ToString().PadLeft(2, '0') + " AM");
+ }
+ }
+ foreach (int i in hours)
+ {
+ for (int j = 0; j < 4; j++)
+ {
+ begin_time_list.Items.Add(i + ":" + (j * 15).ToString().PadLeft(2, '0') + " PM");
+ end_time_list.Items.Add(i + ":" + (j * 15).ToString().PadLeft(2, '0') + " PM");
+ }
+ }
+ date_cal.SelectedDate = DateTime.Now;
+ begin_time_list.SelectedIndex = 0;
+ end_time_list.SelectedIndex = 0;
+
+ }
}
protected void Button1_Click(object sender, EventArgs e)
{
- if (textbox_begin.Text != ""
- && textbox_date.Text != ""
- && textbox_end.Text != ""
- && textbox_location.Text != "")
+ if (begin_time_list.SelectedIndex > 0
+ && date_cal.SelectedDate != null
+ && end_time_list.SelectedIndex > 0
+ && textbox_location.Value != ""
+ && textbox_description.Value != "")
{
try
- {
-
- string[] dateday = textbox_date.Text.Split('/');
- string[] datetime_begin = textbox_begin.Text.Split(':');
- string[] datetime_end = textbox_end.Text.Split(':');
-
- DateTime begintime = new DateTime(Convert.ToInt32(dateday[0]), Convert.ToInt32(dateday[1]), Convert.ToInt32(dateday[2]), Convert.ToInt32(datetime_begin[0]), Convert.ToInt32(datetime_begin[1]), 0);
- DateTime endtime = new DateTime(Convert.ToInt32(dateday[0]), Convert.ToInt32(dateday[1]), Convert.ToInt32(dateday[2]), Convert.ToInt32(datetime_end[0]), Convert.ToInt32(datetime_end[1]), 0);
-
+ {
+ string address = textbox_location.Value.ToString();
+ string description = textbox_description.Value.ToString();
+
+
+ DateTime begintime = date_cal.SelectedDate.Date + DateTime.Parse(begin_time_list.SelectedValue).TimeOfDay;
+ DateTime endtime = date_cal.SelectedDate.Date + DateTime.Parse(end_time_list.SelectedValue).TimeOfDay;
+
+ if (date_cal.SelectedDate.CompareTo(DateTime.Now) < 0) throw new InvalidDataException("You cannot create a garage sale in the past");
+ if (endtime.CompareTo(begintime) <= 0) throw new InvalidDataException("End Time is before start time");
MembershipUser user = Membership.GetUser();
- Guid userId = (Guid)user.ProviderUserKey;
-
- Garage mygarage = new Garage(userId, begintime, endtime, textbox_location.Text, textbox_description.Value);
-
- Garage newgarage = GarageDataService.addGarageSale(mygarage);
-
-
- textbox_begin.Text = "";
- textbox_date.Text = "";
- textbox_end.Text = "";
- textbox_location.Text = "";
- textbox_description.Value = "";
-
- creategarage_output.Text = "Garage Sale successfully created!";
+ Guid userId = (Guid)user.ProviderUserKey;
+
+ Garage garageSale = new Garage(userId, begintime, endtime, address, description);
+
+ if (imageUpload.HasFile)
+ {
+ int imageId = saveImageFile();
+ garageSale.imageId = imageId;
+ }
+
+ garageSale = GarageDataService.addGarageSale(garageSale);
+
+ textbox_description.Value = "";
+ textbox_location.Value = "";
+ begin_time_list.SelectedIndex = 0;
+ end_time_list.SelectedIndex = 0;
+ date_cal.SelectedDate = DateTime.Now;
+
+ creategarage_output.Text = "Garage Sale created successfully!";
creategarage_output.Style.Add("color", "#00ff00");
}
catch (Exception ex)
@@ -53,5 +85,61 @@ protected void Button1_Click(object sender, EventArgs e)
}
+ else
+ {
+ /* Please fill all fields */
+ creategarage_output.Text = "Please fill all of the fields.";
+ creategarage_output.Style.Add("color", "#ff0000");
+
+ }
+ }
+ private int saveImageFile()
+ {
+ string ext = Path.GetExtension(imageUpload.PostedFile.FileName).ToLower();
+ string contentType = "";
+ switch (ext)
+ {
+ case ".jpg":
+ case ".jpeg":
+ contentType = "image/jpg";
+ break;
+ case ".png":
+ contentType = "image/png";
+ break;
+ case ".gif":
+ contentType = "image/gif";
+ break;
+ case ".bmp":
+ contentType = "image/bmp";
+ break;
+ }
+
+ Stream stream = imageUpload.PostedFile.InputStream;
+ BinaryReader binReader = new BinaryReader(stream);
+ byte[] data = binReader.ReadBytes(Convert.ToInt32(stream.Length));
+ System.Drawing.Image temp = System.Drawing.Image.FromStream(stream);
+ int width = (int)temp.Width;
+ int height = (int)temp.Height;
+ temp.Dispose();
+
+ int thumbWidth = 100;
+ int thumbHeight = thumbWidth * (int)((double)width / (double)height);
+
+ System.Drawing.Image thumb = System.Drawing.Image.FromStream(stream);
+ Bitmap tempThumb = new Bitmap(thumb, thumbWidth, thumbHeight);
+ Graphics g = Graphics.FromImage(tempThumb);
+ g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
+ g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
+ g.DrawImage(thumb, 0, 0, tempThumb.Width, tempThumb.Height);
+ MemoryStream memStream = new MemoryStream();
+ tempThumb.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg);
+ byte[] thumbData = memStream.ToArray();
+
+ thumb.Dispose();
+ tempThumb.Dispose();
+ g.Dispose();
+ Image fullImage = new Image(data, contentType, height, width);
+ Image thumbImage = new Image(thumbData, "image/jpg", thumbHeight, thumbWidth);
+ return ImageDataService.addImage(fullImage, thumbImage);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.