示例#1
0
        public SingleExhibitForm(int id,int category, object sender,EventArgs e)
        {
            InitializeComponent();

            this.id=id;
            this.category = category;
            dao = new ExhibitDAO();
            mainExhibit = dao.displayFromId(id);

            //Image.Fromfile returns an Image object
            singlePictureBox.BackgroundImage = Image.FromFile("..\\..\\Resources\\" + mainExhibit.image);
            singlePictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            singleLabelPlace.Text = mainExhibit.place;
            singleLabeltype.Text = mainExhibit.type;
            singleLabelDimensions.Text = mainExhibit.dimensions;
            singleLabelDescription.Text = mainExhibit.description;
            singleLabelTiming.Text = mainExhibit.timing;
            singleLabelArea.Text = mainExhibit.area;
            singleLabelDescription.MaximumSize = new Size(296, 0);
            singleLabelDescription.AutoSize = true;
            /*here we pass data that we are going to need for the history functionality of the application to the name of the sender object. So when we would get the sender in the
              historyObjectList, we will have these data available. For the same reason, each SingleExhibitForm object takes a different name.*/
            arrowLeftPicture.Name = "arrowPictureLeft-" + id + "-" + category;
            arrowRightPictured.Name = "arrowPictureRight-" + id + "-" + category;

            /*unique name*/
            this.Name = "form-" + id;

            arrowLeftPicture.BackgroundImage = Properties.Resources.arrow_alt_left;
            arrowRightPictured.BackgroundImage = Properties.Resources.arrow_alt_right;

            //don't add a history or a session object if the creation of the form was not a result of an event handler. In such case the event handler that created the form will add it
            if (sender != null && ((PictureBox)sender).Name.StartsWith("arrowPictureLeft"))
            {
                Globals.addHistoryObject(arrowLeftPicture, e);
                Globals.addObject(arrowLeftPicture, e);
            }else if(sender != null && ((PictureBox)sender).Name.StartsWith("arrowPictureRight"))
            {
                Globals.addHistoryObject(arrowRightPictured, e);
                Globals.addObject(arrowRightPictured, e);
            }
        }
示例#2
0
        public List<Exhibit> displayAll()
        {
            List<Exhibit> exhibitList = new List<Exhibit>();
            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["museum.Properties.Settings.museumConnectionString"].ConnectionString))
                {
                    connection.Open();
                    string strSQL = "SELECT * FROM  info";
                    SqlCommand command = new SqlCommand(strSQL, connection);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            /*for every row in the SqlDataReader we create an Exhibit object and then we fill in all its fields with the
                              required data. Then we add the object to the ArrayList which is finally returned from the display method*/
                            Exhibit exhibit = new Exhibit();

                            exhibit.id = (int)reader["id"];
                            exhibit.type = (string)reader["type"];
                            exhibit.place = (string)reader["place"];
                            exhibit.timing = (string)reader["timing"];
                            exhibit.dimensions = (string)reader["dimensions"];
                            exhibit.area = (string)reader["area"];
                            exhibit.description = (string)reader["description"];
                            exhibit.image = (string)reader["image"];
                            exhibit.category = (int)reader["category"];

                            exhibitList.Add(exhibit);
                        }
                    }
                }
            }
            catch (SqlException sql)
            {
                MessageBox.Show("The exhibits could not be retrieved" + sql);
            }
            return exhibitList;
        }
示例#3
0
 public Exhibit displayFromId(int id)
 {
     Exhibit exhibit = new Exhibit();
     try
     {
         using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["museum.Properties.Settings.museumConnectionString"].ConnectionString))
         {
             connection.Open();
             string sqlString = "SELECT * FROM info WHERE id = " + id;
             SqlCommand command = new SqlCommand(sqlString, connection);
             using (SqlDataReader reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     exhibit.id = (int)reader["id"];
                     exhibit.type = (string)reader["type"];
                     exhibit.place = (string)reader["place"];
                     exhibit.timing = (string)reader["timing"];
                     exhibit.dimensions = (string)reader["dimensions"];
                     exhibit.area = (string)reader["area"];
                     exhibit.description = (string)reader["description"];
                     exhibit.image = (string)reader["image"];
                     exhibit.category = (int)reader["category"];
                 }
             }
         }
     }
     catch (SqlException sql)
     {
         MessageBox.Show("The exhibit could not be retrieved!" + sql);
     }
     return exhibit;
 }