Esempio n. 1
0
        protected void btnAccept_Click(object sender, EventArgs e)
        {
            if (Validate_Control())
            {
                InstutiteOfFineArt.Models.Award a = new InstutiteOfFineArt.Models.Award();
                a.AwardName = txtAwardName.Text;
                a.CompetitionId = Convert.ToInt32(drlCompetitionId.SelectedValue);
                a.PaintingId = Convert.ToInt32(txtPatingID.Value);
                if (rdb1st.Checked)
                    a.AwardRank = "1st";
                else if (rdb2nd.Checked)
                    a.AwardRank = "2nd";
                else
                    a.AwardRank = "3rd";
                a.AwardDescription = txtAwardDesc.Text;
                if (AwardDAO.Create(a))
                {
                    Flash.dictFlash.Add("success", String.Format("Created Award [<b>{0}</b>] successfully", a.AwardName));
                    Response.Redirect("/awards");
                }
                else
                {
                    Flash.dictFlash.Add("danger", "[<b>Award name</b>] are already used");
                    Response.Redirect("New.aspx");
                }

            }
        }
Esempio n. 2
0
 public static bool Create(Award a)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Insert into Awards (AwardName,AwardRank,AwardDescription,PaintingId,CompetitionId)";
         sql += " values (@1,@2,@3,@4,@5)";
         SqlCommand cmd = new SqlCommand(sql, DBUtilities.objConnection);
         cmd.Parameters.AddWithValue("@1", a.AwardName);
         cmd.Parameters.AddWithValue("@2", a.AwardRank);
         cmd.Parameters.AddWithValue("@3", a.AwardDescription);
         cmd.Parameters.AddWithValue("@4", a.PaintingId);
         cmd.Parameters.AddWithValue("@5", a.CompetitionId);
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
     finally
     {
         DBUtilities.Close_Connection();
     }
 }
Esempio n. 3
0
 public static Award Find(int id)
 {
     DBUtilities.objConnection = new SqlConnection(DBUtilities.connStr);
     DataTable dt = new DataTable();
     string sql = "Select * from Awards where Id = @Id";
     SqlDataAdapter adap = new SqlDataAdapter(sql, DBUtilities.objConnection);
     adap.SelectCommand.Parameters.AddWithValue("@Id", id);
     adap.Fill(dt);
     if (dt.Rows.Count > 0) {
         Award a = new Award();
         a.Id = Convert.ToInt32(dt.Rows[0]["Id"]);
         a.AwardName = dt.Rows[0]["AwardName"].ToString();
         a.AwardRank = dt.Rows[0]["AwardRank"].ToString();
         a.AwardDescription = dt.Rows[0]["AwardDescription"].ToString();
         a.PaintingId = Convert.ToInt32(dt.Rows[0]["PaintingId"]);
         a.CompetitionId = Convert.ToInt32(dt.Rows[0]["CompetitionId"]);
         return a;
     }
     return null;
 }
Esempio n. 4
0
 public static bool Destroy(Award a)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Delete from Awards 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();
     }
 }
Esempio n. 5
0
 protected void btnAccept_Click(object sender, EventArgs e)
 {
     Award a = new Award();
     a.CompetitionId = Convert.ToInt32(hdID.Value);
     a.PaintingId = Convert.ToInt32(hdIDPaint.Value);
     a.AwardName = txtAdName.Text;
     if (rdb1st.Checked)
         a.AwardRank = "1st";
     else if (rdb2nd.Checked)
         a.AwardRank = "2nd";
     else
         a.AwardRank = "3rd";
     a.AwardDescription = txtAwardDesc.Text;
     if (Check_Paint_Award(a.CompetitionId, a.PaintingId, a.AwardRank))
     {
         if (AwardDAO.Create(a))
             Flash.dictFlash.Add("success", "Set award successfully");
         else
             Flash.dictFlash.Add("danger", "Set award error");
     }
 }
Esempio n. 6
0
 public static bool Update(Award a)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Update Awards 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();
     }
 }