コード例 #1
0
ファイル: New.aspx.cs プロジェクト: jin9691/IFA
        protected void btnAccept_Click(object sender, EventArgs e)
        {
            if (validateControl())
            {
                Painting p = new Painting();
                p.Comment = txtComment.Text;
                if (cbCompetition.SelectedValue != null && cbCompetition.SelectedValue != "")
                    p.CompetitionId = Convert.ToInt32(cbCompetition.SelectedValue);
                if (cbCustomer.SelectedValue != null && cbCustomer.SelectedValue != "")
                    p.CustomerId = Convert.ToInt32(cbCustomer.SelectedValue);
                if (cbExhibition.SelectedValue != null && cbExhibition.SelectedValue != "")
                    p.ExhibitionId = Convert.ToInt32(cbExhibition.SelectedValue);
                p.IsExhibited = rbdPaid.Checked;
                p.IsPaid = rbdPaid.Checked;

                if (rdbBad.Checked)
                    p.Mark = 1;
                else if (rdbNormal.Checked)
                    p.Mark = 2;
                else if (rdbGood.Checked)
                    p.Mark = 3;
                else if (rdbBest.Checked)
                    p.Mark = 4;
                p.PaintingDescription = txtDescription.Text;
                if (!string.IsNullOrWhiteSpace(txtPrice.Text))
                    p.Price = Convert.ToInt32(txtPrice.Text);

                p.UploadDate = DateTime.Now;
                p.LastModify = DateTime.Now;
                if (cbStudent.SelectedValue != null && cbStudent.SelectedValue != "")
                    p.StudentId = Convert.ToInt32(cbStudent.SelectedValue);
                p.PaintingURL = UploadImage(flImage);
                if (!Validate_Image_ONCE())
                {
                    Flash.dictFlash.Add("danger", "This student had painting in this competition !!!");
                    Response.Redirect("New.aspx");
                }
                else
                {
                    if (PaintingDAO.Create(p))
                    {
                    Flash.dictFlash.Add("success", String.Format("Created painting [<b>{0}</b>] successfully", flImage.FileName));
                    Response.Redirect("Index.aspx");
                    }
                    else
                    {
                        Flash.dictFlash.Add("danger", " Cannot create Painting !!!");
                        Response.Redirect("New.aspx");
                    }
                }
            }
        }
コード例 #2
0
ファイル: PaintingDAO.cs プロジェクト: jin9691/IFA
 public static bool Destroy(Painting a)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Delete from Paintings where Id = @1";
         SqlCommand cmd = new SqlCommand(sql, DBUtilities.objConnection);
         cmd.Parameters.AddWithValue("@1", a.Id);
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
     finally
     {
         DBUtilities.Close_Connection();
     }
 }
コード例 #3
0
ファイル: PaintingDAO.cs プロジェクト: jin9691/IFA
        public static bool Create(Painting a)
        {
            DBUtilities.Connection();
            try
            {
                string sql = "Insert into Paintings (PaintingDescription,PaintingURL,Mark,UploadDate,LastModify,CompetitionId,StudentId,ExhibitionId,CustomerId,Comment,IsExhibited,Price,IsPaid)";
                sql += " values (@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13)";
                SqlCommand cmd = new SqlCommand(sql, DBUtilities.objConnection);
                cmd.Parameters.AddWithValue("@1", a.PaintingDescription);
                cmd.Parameters.AddWithValue("@2", a.PaintingURL);
                cmd.Parameters.AddWithValue("@3", a.Mark);
                cmd.Parameters.AddWithValue("@4", a.UploadDate);
                cmd.Parameters.AddWithValue("@5", a.LastModify);
                cmd.Parameters.AddWithValue("@6", a.CompetitionId);
                cmd.Parameters.AddWithValue("@7", a.StudentId);
                cmd.Parameters.AddWithValue("@8", a.ExhibitionId);
                cmd.Parameters.AddWithValue("@9", a.CustomerId);
                if (a.Comment == null)
                    cmd.Parameters.AddWithValue("@10", "");
                else
                    cmd.Parameters.AddWithValue("@10", a.Comment);
                cmd.Parameters.AddWithValue("@11", a.IsExhibited);
                cmd.Parameters.AddWithValue("@12", a.Price);
                cmd.Parameters.AddWithValue("@13", a.IsPaid);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
            finally
            {
                DBUtilities.Close_Connection();
            }
        }
コード例 #4
0
ファイル: Show.aspx.cs プロジェクト: jin9691/IFA
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            int CompetitionID = Convert.ToInt32(hdID.Value);

            if (validateControl())
            {
                User u = (User)Session["current_user"];
                //Check Student unique Competition
                Dictionary<string, object> query = new Dictionary<string, object>();
                query.Add("CompetitionId", CompetitionID);
                query.Add("StudentId", Convert.ToInt32(u.Id));
                DataTable dt = PaintingDAO.Where(query);
                if (dt.Rows.Count == 0)
                {
                    //Upload painting
                    Painting p = new Painting();
                    p.PaintingDescription = txtDesc.Text;
                    p.PaintingURL = UploadImage(fileUploadField);
                    p.CompetitionId = CompetitionID;
                    p.UploadDate = DateTime.Now;
                    p.LastModify = DateTime.Now;
                    p.StudentId = Convert.ToInt32(u.Id);
                    if (PaintingDAO.Create(p))
                    {
                        Flash.dictFlash.Add("success", String.Format("Upload painting [<b>{0}</b>] successfully", fileUploadField.FileName));
                        Response.Redirect("Show.aspx?ID=" + hdID.Value);
                    }
                    else
                    {
                        Flash.dictFlash.Add("danger", " Cannot create Painting !!!");
                        Response.Redirect("Show.aspx?ID=" + hdID.Value);
                    }
                }
                else
                {
                    Flash.dictFlash.Add("warning", String.Format("You have sent picture with this competition"));
                }

            }
        }
コード例 #5
0
ファイル: PaintingDAO.cs プロジェクト: jin9691/IFA
 public static Painting Find(int id)
 {
     DBUtilities.objConnection = new SqlConnection(DBUtilities.connStr);
     DataTable dt = new DataTable();
     string sql = "Select * from Paintings where Id = @Id";
     SqlDataAdapter adap = new SqlDataAdapter(sql, DBUtilities.objConnection);
     adap.SelectCommand.Parameters.AddWithValue("@Id", id);
     adap.Fill(dt);
     if (dt.Rows.Count > 0)
     {
         Painting p = new Painting();
         p.Id = Convert.ToInt32(dt.Rows[0]["Id"]);
         p.PaintingDescription = dt.Rows[0]["PaintingDescription"].ToString();
         p.PaintingURL = dt.Rows[0]["PaintingURL"].ToString();
         p.Mark = Convert.ToInt32(dt.Rows[0]["Mark"]);
         p.UploadDate = Convert.ToDateTime(dt.Rows[0]["UploadDate"]);
         p.LastModify = Convert.ToDateTime(dt.Rows[0]["LastModify"]);
         p.CompetitionId = Convert.ToInt32(dt.Rows[0]["CompetitionId"]);
         p.StudentId = Convert.ToInt32(dt.Rows[0]["StudentId"]);
         p.ExhibitionId = Convert.ToInt32(dt.Rows[0]["ExhibitionId"]);
         p.CustomerId = Convert.ToInt32(dt.Rows[0]["CustomerId"]);
         p.Comment = dt.Rows[0]["Comment"].ToString();
         p.IsExhibited = Convert.ToBoolean(dt.Rows[0]["IsExhibited"]);
         p.Price = Convert.ToInt32(dt.Rows[0]["Price"]);
         p.IsPaid = p.IsExhibited = Convert.ToBoolean(dt.Rows[0]["IsPaid"]);
         return p;
     }
     return null;
 }
コード例 #6
0
ファイル: PaintingDAO.cs プロジェクト: jin9691/IFA
        public static bool Update(Painting a)
        {
            DBUtilities.Connection();
            try
            {
                string sql = "Update Paintings set ";
                Type myType = a.GetType();
                IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
                int i = 1;
                int j = 1;
                foreach (PropertyInfo prop in props)
                {
                    object propValue = prop.GetValue(a, null);
                    if (propValue != null && prop.Name != "Id")
                    {
                        if (j < props.Count)
                            sql += String.Format("{0} = @{1} ,", prop.Name, i);
                        else
                            sql += String.Format("{0} = @{1} where ID= @{2}", prop.Name, i, i + 1);
                        i++;
                    }
                    j++;
                }
                i = 1;
                j = 1;
                SqlCommand cmd = new SqlCommand(sql, DBUtilities.objConnection);
                foreach (PropertyInfo prop in props)
                {
                    object propValue = prop.GetValue(a, null);
                    if (propValue != null && prop.Name != "Id")
                    {
                        if (j < props.Count)
                            cmd.Parameters.AddWithValue(String.Format("@{0}", i), propValue);
                        else
                        {
                            cmd.Parameters.AddWithValue(String.Format("@{0}", i), propValue);
                            cmd.Parameters.AddWithValue(String.Format("@{0}", i + 1), a.Id);
                        }
                        i++;
                    }
                    j++;
                }
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                return true;
            }
            catch (Exception)
            {
                return false;

            }
            finally
            {
                DBUtilities.Close_Connection();
            }
        }