Ejemplo n.º 1
0
        /// <summary>
        /// Save edited items to DB
        /// </summary>
        private void SaveItem()
        {
            Boardgames itm;

            // ----- Save last Specimen values -----
            SaveCopy();

            // ----- Check Duplicate InvNum -----
            foreach (var item in CopiesList)
            {
                string DulpicateInvNUm = "";
                if (global.IsDuplicate(item.InventoryNumber, item.ID))
                {
                    if (Dialogs.ShowQuest(String.Format(Lng.Get("DuplicateInvNum", "The inventory number {0} is already in use. Do you really write to database?"), DulpicateInvNUm), Lng.Get("Warning")) != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

            // ----- ID -----
            if (ID != Guid.Empty)
            {
                itm = db.Boardgames.Find(ID);
            }
            else
            {
                itm    = new Boardgames();
                itm.ID = Guid.NewGuid();
            }

            // ----- Delete original Copies -----
            foreach (var item in OriginalCopies)
            {
                db.Copies.Remove(item);
            }
            db.SaveChanges();

            // ----- Add Copies to DB -----
            foreach (var item in CopiesList)
            {
                item.ItemID = itm.ID;
                db.Copies.Add(item);
            }
            db.SaveChanges();

            // ----- Fill Item values -----
            FillItem(ref itm);

            // ----- Update database -----
            if (ID == Guid.Empty)
            {
                db.Boardgames.Add(itm);
            }
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Color Row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void olvBoard_FormatRow(object sender, FormatRowEventArgs e)
        {
            Boardgames itm = (Boardgames)e.Model;

            if (itm.Available == 0)
            {
                e.Item.ForeColor = Color.Red;
            }
            else
            {
                e.Item.ForeColor = Color.Black;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Set Fast Tags
 /// </summary>
 /// <param name="tag">Tags Mask</param>
 private void SetTagItemBoard(short tag)
 {
     if (olvBoard.SelectedObjects != null)                 // If selected Item
     {
         databaseEntities db = new databaseEntities();
         foreach (var item in olvBoard.SelectedObjects) // Find Object
         {
             Boardgames itm = db.Boardgames.Find(((Boardgames)item).ID);
             itm.FastTags |= tag;
         }
         db.SaveChanges();                           // Save to DB
         UpdateBoardOLV();                           // Update Contacts OLV
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Set active (excluded)
        /// </summary>
        /// <param name="active"></param>
        private void SetActiveBoard(bool active)
        {
            if (olvBoard.SelectedObjects != null)                 // If selected Item
            {
                databaseEntities db = new databaseEntities();

                foreach (var item in olvBoard.SelectedObjects) // Find Object
                {
                    Boardgames itm = db.Boardgames.Find(((Boardgames)item).ID);
                    itm.Excluded = !active;
                }
                db.SaveChanges();                           // Save to DB
                UpdateBoardOLV();                           // Update Contacts OLV
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete Item
        /// </summary>
        private void DeleteItemBoard()
        {
            databaseEntities db = new databaseEntities();
            int count           = olvBoard.SelectedObjects.Count;

            if (count == 1)                     // If selected Item
            {                                   // Find Object
                Boardgames itm = db.Boardgames.Find(((Boardgames)olvBoard.SelectedObject).ID);

                if (Dialogs.ShowQuest(Lng.Get("DeleteItem", "Really delete item") + " \"" + itm.Name.Trim() + "\"?", Lng.Get("Delete")) == DialogResult.Yes)
                {
                    db.Boardgames.Remove(itm);                       // Delete Item

                    // ----- Remove copies -----
                    var copies = db.Copies.Where(x => (x.ItemType.Trim() == ItemTypes.boardgame.ToString()) && (x.ItemID == ((Boardgames)olvBoard.SelectedObject).ID)).ToList();
                    foreach (var copy in copies)
                    {
                        db.Copies.Remove(copy);                 // Remove copy
                    }

                    db.SaveChanges();                           // Save to DB
                    UpdateBoardOLV();                           // Update Items OLV
                    UpdateCopOLV();                             // Update Copies OLV
                }
            }
            else if (count > 1)                 // If selected Item
            {
                if (Dialogs.ShowQuest(Lng.Get("DeleteItems", "Really delete selected items") + " (" + count.ToString() + ")?", Lng.Get("Delete")) == DialogResult.Yes)
                {
                    foreach (var item in olvBoard.SelectedObjects) // Find Object
                    {
                        Boardgames itm = db.Boardgames.Find(((Boardgames)item).ID);
                        db.Boardgames.Remove(itm);                   // Delete Item

                        // ----- Remove copies -----
                        var copies = db.Copies.Where(x => (x.ItemType.Trim() == ItemTypes.boardgame.ToString()) && (x.ItemID == ((Boardgames)item).ID)).ToList();
                        foreach (var copy in copies)
                        {
                            db.Copies.Remove(copy);                 // Remove copy
                        }
                    }
                    db.SaveChanges();                           // Save to DB
                    UpdateBoardOLV();                           // Update Items OLV
                    UpdateCopOLV();                             // Update Copies OLV
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Refresh Available Items
        /// </summary>
        /// <param name="list"></param>
        private void RefreshAvailableItems()
        {
            databaseEntities db = new databaseEntities();

            foreach (var itm in lendList)
            {
                var copy = db.Copies.Find(itm.CopyID);

                if (copy != null)
                {
                    var borr = db.Copies.Where(p => (p.ItemID == copy.ItemID) && p.ItemType.Contains(copy.ItemType.ToString()) && ((p.Status ?? 1) == (short)LendStatus.Reserved || (p.Status ?? 1) == (short)LendStatus.Lended)).Select(c => c.ID).ToList();

                    if (global.GetItemType(copy.ItemType) == ItemTypes.item)
                    {
                        Items item = db.Items.Find(copy.ItemID);
                        if (item != null)
                        {
                            item.Available = (short)((item.Count ?? 1) - borr.Count);
                        }
                    }
                    else if (global.GetItemType(copy.ItemType) == ItemTypes.book)
                    {
                        Books book = db.Books.Find(copy.ItemID);
                        if (book != null)
                        {
                            book.Available = (short)((book.Count ?? 1) - borr.Count);
                        }
                    }
                    else if (global.GetItemType(copy.ItemType) == ItemTypes.boardgame)
                    {
                        Boardgames board = db.Boardgames.Find(copy.ItemID);
                        if (board != null)
                        {
                            board.Available = (short)((board.Count ?? 1) - borr.Count);
                        }
                    }
                }
            }
            db.SaveChanges();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Form Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmEditBoardGames_Load(object sender, EventArgs e)
        {
            // ----- Create barcode reader connection -----
            com.ReceivedData += new ReceivedEventHandler(DataReceive);
            try
            {
                com.ConnectSP(Properties.Settings.Default.scanCOM);
            }
            catch { }

            // ----- Get Autofill lists -----
            var categoryList = db.Boardgames.Select(x => x.Category.Trim()).ToList();
            var locationList = db.Copies.Select(x => x.Location.Trim()).ToList();

            // ----- Delete duplicates -----
            categoryList = global.DeleteDuplicates(categoryList);
            locationList = global.DeleteDuplicates(locationList);

            // ----- Prepare autocomplete -----
            txtCondition.AutoCompleteCustomSource.Add(Lng.Get("New"));
            txtCondition.AutoCompleteCustomSource.Add(Lng.Get("Preserved"));
            txtCondition.AutoCompleteCustomSource.Add(Lng.Get("Damaged"));
            txtCondition.AutoCompleteCustomSource.Add(Lng.Get("Destroyed"));
            txtCondition.AutoCompleteCustomSource.Add(Lng.Get("Unfunctional"));

            foreach (var item in categoryList)
            {
                txtCategory.AutoCompleteCustomSource.Add(item);
            }
            foreach (var item in locationList)
            {
                txtLocation.AutoCompleteCustomSource.Add(item);
            }

            // ----- Add Specimen -----
            cbCopy.Items.Clear();
            cbCopy.Items.Add("1");
            cbCopy.SelectedIndex = 0;

            Copies copy = global.CreateCopy(ID, ItemTypes.boardgame);

            CopiesList.Add(copy);

            // ----- If Edit -> fill form -----
            if (ID != Guid.Empty)
            {
                Boardgames itm = db.Boardgames.Find(ID);

                // ----- Fill Image -----
                imgCover.Image = Conv.ByteArrayToImage(itm.Cover);
                img1.Image     = Conv.ByteArrayToImage(itm.Img1);
                img2.Image     = Conv.ByteArrayToImage(itm.Img2);
                img3.Image     = Conv.ByteArrayToImage(itm.Img3);

                // ----- Fill main data -----
                txtName.Text      = itm.Name.Trim();                // Name
                txtURL.Text       = itm.URL.Trim();                 // URL
                txtCategory.Text  = itm.Category.Trim();            // Category
                txtLanguage.Text  = itm.Language.Trim();            // Language
                txtKeywords.Text  = itm.Keywords.Trim();            // Keywords
                txtGameWorld.Text = itm.GameWorld.Trim();           // Game World
                txtPublisher.Text = itm.Publisher.Trim();           // Publisher
                txtAuthor.Text    = itm.Author.Trim();              // Author
                txtYear.Text      = itm.Year.ToString();            // Year

                txtNote.Text = itm.Note.Trim();                     // Note

                numMinPlayers.Value = itm.MinPlayers ?? 0;          // Min Players
                numMaxPlayers.Value = itm.MaxPlayers ?? 0;          // Max Players
                numMinAge.Value     = itm.MinAge ?? 0;              // Min Age
                numGameTime.Value   = itm.GameTime ?? 0;            // Game Time

                txtFamily.Text       = itm.Family.Trim();           // Family
                chbExtension.Checked = itm.Extension ?? false;      // Extension
                numExtension.Value   = itm.ExtensionNumber ?? 0;    // Extension number

                txtRating.Text   = itm.Rating.ToString();           // Rating
                txtMyRating.Text = itm.MyRating.ToString();         // My rating


                // ----- Fill Specimen -----
                CopiesList     = db.Copies.Where(x => x.ItemID == ID).ToList();
                OriginalCopies = db.Copies.Where(x => x.ItemID == ID).ToList();

                cbCopy.Items.Clear();

                // ----- If found copies -----
                if (CopiesList != null && CopiesList.Count > 0)
                {
                    // ----- Fill textboxes -----
                    FillFromCopies(CopiesList[0]);

                    // ----- Prepare buttons -----
                    if (CopiesList.Count > 1)
                    {
                        btnDelCopy.Enabled = true;
                    }

                    // ----- Prepare combobox -----
                    for (int i = 0; i < CopiesList.Count; i++)              // Fill Copies combobox
                    {
                        cbCopy.Items.Add((i + 1).ToString());
                    }
                    cbCopy.SelectedIndex = 0;
                    lblCount.Text        = "/ " + CopiesList.Count.ToString();     // Counts
                }

                // ----- Fast tags -----
                FastFlags flag = (FastFlags)(itm.FastTags ?? 0);
                if (flag.HasFlag(FastFlags.FLAG1))
                {
                    btnTag1.BackColor = SelectColor;
                }
                if (flag.HasFlag(FastFlags.FLAG2))
                {
                    btnTag2.BackColor = SelectColor;
                }
                if (flag.HasFlag(FastFlags.FLAG3))
                {
                    btnTag3.BackColor = SelectColor;
                }
                if (flag.HasFlag(FastFlags.FLAG4))
                {
                    btnTag4.BackColor = SelectColor;
                }
                if (flag.HasFlag(FastFlags.FLAG5))
                {
                    btnTag5.BackColor = SelectColor;
                }
                if (flag.HasFlag(FastFlags.FLAG6))
                {
                    btnTag6.BackColor = SelectColor;
                }

                // ----- Update -----
                lblUpdated.Text = Lng.Get("LastUpdate", "Last update") + ": " + (itm.Updated ?? DateTime.Now).ToShortDateString();
            }
            else
            {
                // ----- Set Acquisition date -----
                dtAcqDate.Value     = DateTime.Now;
                numMinPlayers.Value = 2;          // Min Players
                numMaxPlayers.Value = 4;          // Max Players

                // ----- New Inv Number -----
                if (TempMaxInvNum < Properties.Settings.Default.BoardStart)
                {
                    TempMaxInvNum = Properties.Settings.Default.BoardStart;
                }
                else
                {
                    TempMaxInvNum++;
                }
                txtInvNum.Text = Properties.Settings.Default.BoardPrefix + (TempMaxInvNum).ToString("D" + Properties.Settings.Default.BoardMinCharLen.ToString()) + Properties.Settings.Default.BoardSuffix;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Fill Item values
        /// </summary>
        /// <param name="itm"></param>
        private void FillItem(ref Boardgames itm)
        {
            // ----- Fill Image -----
            byte[] bytes = Conv.ImageToByteArray(imgCover.Image);
            if (bytes != null)
            {
                itm.Cover = bytes;
            }
            bytes = Conv.ImageToByteArray(img1.Image);
            if (bytes != null)
            {
                itm.Img1 = bytes;
            }
            bytes = Conv.ImageToByteArray(img2.Image);
            if (bytes != null)
            {
                itm.Img2 = bytes;
            }
            bytes = Conv.ImageToByteArray(img3.Image);
            if (bytes != null)
            {
                itm.Img3 = bytes;
            }


            // ----- Fill main data -----
            itm.Name     = txtName.Text;                       // Name
            itm.URL      = txtURL.Text;                        // URL
            itm.Category = txtCategory.Text;                   // Category

            itm.Language  = txtLanguage.Text;                  // Language
            itm.Keywords  = txtKeywords.Text;                  // Keywords
            itm.GameWorld = txtGameWorld.Text;                 // Game World
            itm.Publisher = txtPublisher.Text;                 // Publisher
            itm.Author    = txtAuthor.Text;                    // Author
            itm.Year      = Conv.ToShortNull(txtYear.Text);    // Year

            itm.Note = txtNote.Text;                           // Note

            itm.MinPlayers = (short)numMinPlayers.Value;       // Min Players
            itm.MaxPlayers = (short)numMaxPlayers.Value;       // Max Players
            itm.MinAge     = (short)numMinAge.Value;           // Min Age
            itm.GameTime   = (short)numGameTime.Value;         // Game Time

            itm.Family          = txtFamily.Text;              // Family
            itm.Extension       = chbExtension.Checked;        // Extension
            itm.ExtensionNumber = (short)numExtension.Value;   // Extension number

            itm.Rating   = Conv.ToShortNull(txtRating.Text);   // Rating
            itm.MyRating = Conv.ToShortNull(txtMyRating.Text); // My rating

            itm.Description  = "";
            itm.Rules        = "";
            itm.MaterialPath = "";

            // ----- Status -----
            itm.Count     = global.GetCopiesCount(CopiesList);      // Get counts
            itm.Available = global.GetAvailableCopies(CopiesList);  // Get available items

            // ----- Fast tags -----
            short fastTag = 0;

            if (btnTag1.BackColor == SelectColor)
            {
                fastTag |= 0x01;
            }
            if (btnTag2.BackColor == SelectColor)
            {
                fastTag |= 0x02;
            }
            if (btnTag3.BackColor == SelectColor)
            {
                fastTag |= 0x04;
            }
            if (btnTag4.BackColor == SelectColor)
            {
                fastTag |= 0x08;
            }
            if (btnTag5.BackColor == SelectColor)
            {
                fastTag |= 0x10;
            }
            if (btnTag6.BackColor == SelectColor)
            {
                fastTag |= 0x20;
            }
            itm.FastTags = fastTag;

            // ----- Last Update -----
            itm.Updated = DateTime.Now;
        }