Inheritance: IChangeable
Esempio n. 1
0
 /*
 * Returns the amount of itemtypes that are existent in the given room.
 * The itemtype that you require is given in the parameter.
 */
 public int AmountInRoom(ItemType type, Room r)
 {
     List<Item> matches = ItemHandler.GetInstance().GetItemsBy(delegate (Item i) {
         return i.RoomID == r.GetID();
     });
     int rtn = 0;
     foreach (Item i in matches)
         if (i.Type.ID == type.ID) rtn++;
     return rtn;
 }
Esempio n. 2
0
 /*
 With this constructor you can make the dialog for deleteing new items to a room.
 The handlers used in this class will be set here.
 */
 public DeleteItemDialog(string name, Action parentCallback, Room targetRoom, ItemType itemType)
     : base(name, parentCallback)
 {
     this._callback = parentCallback;
     this._itemTypeHandler = ItemTypeHandler.GetInstance();
     this._itemHandler = ItemHandler.GetInstance();
     this._documentHandler = DocumentHandler.GetInstance();
     this._targetRoom = targetRoom;
     this._itemType = itemType;
 }
Esempio n. 3
0
 public EditItemDialog(string name, Action callback, ItemType itemType)
     : base(name, callback)
 {
     this._callback = callback;
     this._itemType = itemType;
 }
Esempio n. 4
0
 private void ObjectComboBx_SelectedIndexChanged(object sender, EventArgs e)
 {
     this._currentComboBoxItem = (ComboboxItem) this._newObjectTypeComboBox.SelectedItem;
     this._currentItemType = (ItemType) _currentComboBoxItem.Value;
 }
Esempio n. 5
0
 /* Deletes a given itemtype, both in cache and in database*/
 public void DeleteType(ItemType type)
 {
     if (type != null && this._items.Contains(type)) this._items.Remove(type);
 }
Esempio n. 6
0
 /*
 * Creates new ItemType and saves it into database
 */
 public void CreateType(ItemType type)
 {
     if (this._items.Contains(type) || type == null) return;
     this._items.Add(type);
 }
Esempio n. 7
0
 /* Loads all itemtypes into cache (Cache list) */
 public void LoadItemTypes()
 {
     this._items.Clear();
     DataTable table = this._handler.SelectSQL("SELECT * FROM ItemType");
     if (table != null) {
         foreach (DataRow row in table.Rows) {
             uint itemID = DatabaseUtil.parseInt(row, "ID");
             string name = row.Field<string>("Description");
             string brand = row.Field<string>("Brand");
             string color = row.Field<string>("Color");
             uint price = DatabaseUtil.parseInt(row, "Price");
             uint width = DatabaseUtil.parseInt(row, "Width");
             uint length = DatabaseUtil.parseInt(row, "Length");
             ItemType type = new ItemType(itemID, name, brand, color, width, length, price);
             if(!String.IsNullOrEmpty(row["Photo"].ToString())) loadImage(type);
             type.IsLoaded = true;
             this._items.Add(type);
         }
     }
 }
Esempio n. 8
0
 /*
 * Saves picture from path into the database
 * Will be attached to the given itemtype.
 * The result will be a byte array in BLOB form
 *
 * Author: Maarten + Eelco
 */
 public void SavePicture(ItemType type, String path)
 {
     byte[] result = BlobUtil.ConvertToBlob(path);
     String query = "UPDATE ItemType SET Photo = @Byte WHERE ID = "+type.ID;
     MySqlCommand cmd = new MySqlCommand(query, DatabaseHandler.GetInstance().getConnection());
     cmd.Parameters.AddWithValue("@Byte", result);
     cmd.ExecuteNonQuery();
     loadImage(type);
 }
Esempio n. 9
0
 /*
 * Builds image file from BLOB code in database.
 * Using the byte array saved in array a image file will be saved at our
 * resources directory.
 *
 * Author: Maarten + Eelco
 */
 public void loadImage(ItemType type)
 {
     MySqlDataReader reader = DatabaseHandler.GetInstance().getReader("SELECT Description, Photo FROM ItemType WHERE ID = " + type.ID);
     try {
         string Description;
         FileStream fs;
         BinaryWriter bw;
         int bufferSize = 4096;
         byte[] ImageData = new byte[bufferSize];
         long nBytesReturned, startIndex = 0;
         if (!Directory.Exists("Resources")) {
             Directory.CreateDirectory("Resources");
         }
         while (reader.Read()) {
             Description = reader.GetString("Description");
             fs = new FileStream("Resources/" + Description.ToString().ToLower() + ".png", FileMode.OpenOrCreate, FileAccess.Write);
             bw = new BinaryWriter(fs);
             startIndex = 0;
             nBytesReturned = reader.GetBytes(1, startIndex, ImageData, 0, bufferSize);
             while (nBytesReturned == bufferSize) {
                 bw.Write(ImageData);
                 bw.Flush();
                 startIndex += bufferSize;
                 nBytesReturned = reader.GetBytes(1, startIndex, ImageData, 0, bufferSize);
             }
             bw.Write(ImageData, 0, (int)nBytesReturned - 1);
             bw.Close();
             fs.Close();
         }
     } catch (Exception e) {
     }
     reader.Close();
 }
Esempio n. 10
0
 public Bitmap GetPicture(ItemType item)
 {
     if (item == null) { item = new ItemType(""); }
     if (!this._picture.ContainsKey(item.ID)) {
         String path = item.ToString();
         char sep = System.IO.Path.DirectorySeparatorChar;
         string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
         string imgPath = exePath + sep + "Resources" + sep;
         try {
             Bitmap map = new Bitmap(imgPath + path.ToLower() + ".png");
             this._picture.Add(item.ID, map);
         }
         catch (Exception e) {
             return null;
         }
     }
     return this._picture[item.ID];
 }
Esempio n. 11
0
 private void AddItemAccept_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(this._typeBorderedTextBox.Text) || !string.IsNullOrEmpty(this._priceBorderedTextBox.Text) || !string.IsNullOrEmpty(this._brandBorderedTextBox.Text)
         || !string.IsNullOrEmpty(this._colorBorderedTextBox.Text) || !string.IsNullOrEmpty(this._lengthBorderedTextBox.Text) ||
         !string.IsNullOrEmpty(this._widthBorderedTextBox.Text)) {
         uint price;
         uint length;
         uint width;
         if (!UInt32.TryParse(this._priceBorderedTextBox.Text, out price) || !UInt32.TryParse(this._lengthBorderedTextBox.Text, out length)
             || !UInt32.TryParse(this._widthBorderedTextBox.Text, out width)) {
             MessageBoxUtil.ShowError("Foutmelding", "U Dient geldige getallen in te vullen.");
             return;
         }
         ItemType itemType = new ItemType(this._typeBorderedTextBox.Text, this._brandBorderedTextBox.Text, this._colorBorderedTextBox.Text, width, length, price);
         if (ItemTypeHandler.GetInstance().GetByName(itemType.Description) != null) {
             MessageBoxUtil.ShowError("Foutmelding", "Er is al een item met deze naam.");
             return;
         }
         this._itemTypeHandler.CreateType(itemType);
         if (!string.IsNullOrEmpty(this._filepathBorderedTextBox.Text)) ItemTypeHandler.GetInstance().SavePicture(itemType, this._filepathBorderedTextBox.Text);
         if (this._callBack != null) this._callBack();
         MessageBox.Show("Object succesvol toegevoegd!");
         if (AbstractDialog.Current != null) {
             AbstractDialog.Current.Hide();
         }
     }
     else {
         MessageBoxUtil.ShowError("Foutmelding", "U dient alle velden in te vullen.");
     }
 }
Esempio n. 12
0
 /**
 * Returns an icon image that also has a button function attached to it.
 * param name="imageName" represents the name of the image (raw name)
 * param name="methodTarget" represents the name of the event handler method for the click event
 * param name="typeTarget" represents the itemtype the image is attached to
 * the location represents the location of the picturebox
     */
 private PictureBox GetImageIconBox(String imageName, MouseEventHandler methodTarget, ItemType typeTarget, Point location)
 {
     char sep = System.IO.Path.DirectorySeparatorChar;
     string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     string imagePath = exePath + sep + "Resources" + sep;
     PictureBox box = new PictureBox();
     box.Image = Bitmap.FromFile(imagePath + imageName + ".png");
     box.Size = new Size(24, 24);
     box.Location = location;
     box.MouseClick += methodTarget;
     box.MouseEnter += new EventHandler(iconMouseEnter);
     box.MouseLeave += new EventHandler(iconMouseLeave);
     box.Tag = typeTarget;
     return box;
 }
Esempio n. 13
0
 public MoveItemDialog(String title, Action callback, Room targetRoom, ItemType targetItem)
     : base(title, callback)
 {
     this._targetRoom = targetRoom;
     this._targetItem = targetItem;
 }