Exemple #1
0
 public static bool Create(Exhibition e)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Insert into [Exhibitions] (ExhibitionName,ManagerId,StartDate,EndDate,ExhibitionDescription)";
         sql += " values (@1,@2,@3,@4,@5)";
         SqlCommand cmd = new SqlCommand(sql, DBUtilities.objConnection);
         cmd.Parameters.AddWithValue("@1",e.ExhibitionName);
         cmd.Parameters.AddWithValue("@2", e.ManagerId);
         cmd.Parameters.AddWithValue("@3", e.StartDate);
         cmd.Parameters.AddWithValue("@4", e.EndDate);
         cmd.Parameters.AddWithValue("@5", e.ExhibitionDescription);
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
     finally
     {
         DBUtilities.Close_Connection();
     }
 }
Exemple #2
0
        protected void btnAccept_Click(object sender, EventArgs e)
        {
            if (Validate_Control())
            {
                Exhibition exhibition = new Exhibition();

                exhibition.Id = Id;
                exhibition.ExhibitionName = txtExhibitionName.Text;
                exhibition.ManagerId = int.Parse(ddlManagerName.SelectedValue);
                exhibition.StartDate = DateTime.Parse(txtStartDate.Text);
                exhibition.EndDate = DateTime.Parse(txtEndDate.Text);
                exhibition.ExhibitionDescription = txtExhibitionDescription.Text;

                if (ExhibitionDAO.Update(exhibition))
                {
                    Flash.dictFlash.Add("success", String.Format("Update Exhibition [<b>{0}</b>] successfully", exhibition.ExhibitionName));
                    Response.Redirect("Index.aspx");
                }
                else
                {
                    Flash.dictFlash.Add("danger", "Error update Exhibition. You should check again.");
                    Response.Redirect("Edit.aspx?ID="+Id);
                }
            }
        }
Exemple #3
0
 public static bool Destroy(Exhibition u)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Delete from [Exhibitions] where Id = @1";
         SqlCommand cmd = new SqlCommand(sql, DBUtilities.objConnection);
         cmd.Parameters.AddWithValue("@1", u.Id);
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
     finally
     {
         DBUtilities.Close_Connection();
     }
 }
Exemple #4
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (Validate_Add())
     {
         User u = (User)Session["current_user"];
         Exhibition ex = new Exhibition();
         ex.ManagerId = u.Id;
         ex.StartDate = DateTime.Parse(txtStartDate.Text);
         ex.EndDate = DateTime.Parse(txtEndDate.Text);
         ex.ExhibitionName = txtExName.Text;
         ex.ExhibitionDescription = txtDesc.Text;
         if (ExhibitionDAO.Create(ex))
         {
             Flash.dictFlash.Add("success", String.Format("Created exhibition [<b>{0}</b>] successfully", ex.ExhibitionName));
             Response.Redirect("List.aspx");
         }
         else
         {
             Flash.dictFlash.Add("danger", " Cannot create exhibition !!!");
             Response.Redirect("List.aspx");
         }
     }
 }
Exemple #5
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Validate_Control())
     {
         Exhibition ex = new Exhibition();
         ex.Id = Convert.ToInt32(hdID.Value);
         ex.ManagerId = Convert.ToInt32(hdManager.Value);
         ex.ExhibitionDescription = txtEdit.Text;
         ex.StartDate = DateTime.Parse(txtEditStart.Text);
         ex.EndDate = DateTime.Parse(txtEditEnd.Text);
         if (ExhibitionDAO.Update(ex))
             Flash.dictFlash.Add("success", "Update successfully");
         else
             Flash.dictFlash.Add("danger", "Update error");
         Response.Redirect("List.aspx");
     }
 }
Exemple #6
0
 public static Exhibition Find(int Id)
 {
     DBUtilities.objConnection = new SqlConnection(DBUtilities.connStr);
     DataTable dt = new DataTable();
     string sql = "Select * from [Exhibitions] where Id = @Id";
     SqlDataAdapter adap = new SqlDataAdapter(sql, DBUtilities.objConnection);
     adap.SelectCommand.Parameters.AddWithValue("@Id", Id);
     adap.Fill(dt);
     if (dt.Rows.Count > 0)
     {
         Exhibition e = new Exhibition();
         e.Id = Convert.ToInt32(dt.Rows[0]["Id"]);
         e.ManagerId = Convert.ToInt32(dt.Rows[0]["ManagerId"]);
         e.ExhibitionName = dt.Rows[0]["ExhibitionName"].ToString();
         e.StartDate = Convert.ToDateTime(dt.Rows[0]["StartDate"]);
         e.EndDate = Convert.ToDateTime(dt.Rows[0]["EndDate"]);
         e.ExhibitionDescription = dt.Rows[0]["ExhibitionDescription"].ToString();
         return e;
     }
     return null;
 }
Exemple #7
0
 public static bool Update(Exhibition e)
 {
     DBUtilities.Connection();
     try
     {
         string sql = "Update [Exhibitions] set ";
         Type myType = e.GetType();
         IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
         int i = 1;
         int j = 1;
         foreach (PropertyInfo prop in props)
         {
             object propValue = prop.GetValue(e, 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(e, 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), e.Id);
                 }
                 i++;
             }
             j++;
         }
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
     finally
     {
         DBUtilities.Close_Connection();
     }
 }