Ejemplo n.º 1
0
        /// <summary>
        /// Delete Item
        /// </summary>
        private void DeleteItemLending()
        {
            databaseEntities db = new databaseEntities();
            int count           = olvLending.SelectedObjects.Count;

            if (count == 1)                  // If selected Item
            {                                // Find Object
                Lending borr = db.Lending.Find(((Lending)olvLending.SelectedObject).ID);

                if (Dialogs.ShowQuest(Lng.Get("DeleteItem", "Really delete item") + " \"" + global.GetLendingItemName(borr.CopyType.Trim(), borr.CopyID ?? Guid.Empty) + "\"?", Lng.Get("Delete")) == DialogResult.Yes)
                {
                    db.Lending.Remove(borr);                    // Delete Item
                    db.SaveChanges();                           // Save to DB
                    UpdateLendingOLV();                         // Update Lending OLV
                    UpdateAllItemsOLV();
                }
            }
            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 olvLending.SelectedObjects) // Find Object
                    {
                        Lending itm = db.Lending.Find(((Lending)item).ID);
                        db.Lending.Remove(itm);                 // Delete Item
                    }
                    db.SaveChanges();                           // Save to DB
                    UpdateLendingOLV();                         // Update Lending OLV
                    UpdateAllItemsOLV();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Button Ok
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            // ----- Find selected person in DB -----
            FindPerson();

            // ----- Check if record valid -----
            if (PersonGuid == Guid.Empty)
            {
                Dialogs.ShowWar(Lng.Get("NoSelPerson", "Not selected person!"), Lng.Get("Warning"));
                return;
            }

            if (selItemList.Count == 0)
            {
                Dialogs.ShowWar(Lng.Get("NoSelItem", "Not selected item!"), Lng.Get("Warning"));
                return;
            }

            databaseEntities db = new databaseEntities();

            Lending borr;

            // ----- Delete old data -----
            if (ID.Count > 0)
            {
                foreach (var itm in ID)
                {
                    borr = db.Lending.Find(itm);
                    db.Lending.Remove(borr);
                }
                db.SaveChanges();
            }

            // ----- Create new -----
            foreach (var itm in selItemList)
            {
                borr    = new Lending();
                borr.ID = Guid.NewGuid();
                FillLend(ref borr, itm);
                db.Lending.Add(borr);
            }

            // ----- Save to DB -----
            db.SaveChanges();

            // ----- Refresh Copy Status -----
            global.RefreshCopiesStatus(selItemList, (short)cbStatus.SelectedIndex);

            // ----- Refresh Available Items in Items Tables -----
            RefreshAvailableItems(selItemList);

            // ----- Close Barcode reader connection -----
            com.Close();

            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fing other Lendings to fill Item list
        /// </summary>
        /// <param name="ID">Main ID</param>
        /// <returns></returns>
        private List <Guid> FindOtherLendings(Guid ID)
        {
            databaseEntities db = new databaseEntities();

            List <Guid> list = new List <Guid>();

            Lending borr = db.Lending.Find(ID);

            if (borr != null)
            {
                list = db.Lending.Where(x => x.PersonID == borr.PersonID && x.Status == borr.Status && x.From == borr.From && x.To == borr.To).Select(x => x.ID).ToList();
            }

            return(list);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set Fast Tags
        /// </summary>
        /// <param name="tag">Tags Mask</param>
        private void SetTagItemLending(short tag)
        {
            if (olvLending.SelectedObjects != null)                 // If selected Item
            {
                databaseEntities db = new databaseEntities();

                foreach (var item in olvLending.SelectedObjects) // Find Object
                {
                    Lending itm = db.Lending.Find(((Lending)item).ID);
                    itm.FastTags |= tag;
                }
                db.SaveChanges();                           // Save to DB
                UpdateLendingOLV();                         // Update Contacts OLV
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// OLV color row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void olvItem_FormatRow(object sender, BrightIdeasSoftware.FormatRowEventArgs e)
        {
            Lending  itm = (Lending)e.Model;
            DateTime now = DateTime.Now;

            if (itm.Status == 2 || itm.Status == 3)
            {
                e.Item.ForeColor = Color.Gray;
            }
            else if ((itm.To ?? now) < now)
            {
                e.Item.ForeColor = Color.Red;
            }
            else
            {
                e.Item.ForeColor = Color.Black;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fill Lending Items
        /// </summary>
        /// <param name="lend"></param>
        /// <param name="item"></param>
        private void FillLend(ref Lending lend, Copies item)
        {
            // ----- Item -----
            lend.CopyType = item.ItemType.ToString();
            lend.CopyID   = item.ID;

            // ----- Other -----
            lend.PersonID = PersonGuid;
            lend.From     = dtFrom.Value;
            lend.To       = dtTo.Value;
            lend.Status   = (short)cbStatus.SelectedIndex;
            lend.Note     = txtNote.Text;

            // ----- 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;
            }
            lend.FastTags = fastTag;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Load Form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmEditLending_Load(object sender, EventArgs e)
        {
            databaseEntities db = new databaseEntities();

            // ----- Create connection to barcode reader -----
            com.ReceivedData += new ReceivedEventHandler(DataReceive);
            try
            {
                com.ConnectSP(Properties.Settings.Default.scanCOM);
            }
            catch { }

            // ----- Prepare Status Combo box -----
            cbStatus.Items.Clear();
            cbStatus.Items.Add(Lng.Get("Reserved"));
            cbStatus.Items.Add(Lng.Get("Borrowed"));
            cbStatus.Items.Add(Lng.Get("Returned"));
            cbStatus.Items.Add(Lng.Get("Canceled"));
            cbStatus.SelectedIndex = 1;

            // ----- Prepare autocomplete Context -----
            SetContactsContext();               // Contacts
            SetItemsContext();                  // Items

            // ----- Set Default values -----
            dtFrom.Value = DateTime.Now;
            dtTo.Value   = DateTime.Now.AddDays(Properties.Settings.Default.DefaultBorrInterval);

            // ----- If Edit items -----
            if (ID.Count > 0)
            {
                Lending lend = new Lending();

                // ----- Find all edited items -----
                foreach (var itm in ID)
                {
                    lend = db.Lending.Find(itm);

                    // ----- Fill Item list -----
                    Copies copy = db.Copies.Find(lend.CopyID);
                    selItemList.Add(copy);          // Selected list
                    //origItemList.Add(copy);         // Original list
                }

                // ----- Fill Person -----
                Contacts person = db.Contacts.Find(lend.PersonID);
                if (person != null)
                {
                    txtPerson.Text    = person.Name.Trim() + " " + person.Surname.Trim();
                    lblPersonNum.Text = Lng.Get("PersonNum", "Person number") + ": " + person.PersonCode.Trim();
                }

                // ----- Fill other values -----
                dtFrom.Value = lend.From ?? DateTime.Now;
                dtTo.Value   = lend.To ?? DateTime.Now;
                int stat = lend.Status ?? 1;
                if (stat < cbStatus.Items.Count)
                {
                    cbStatus.SelectedIndex = stat;
                }
                txtNote.Text = lend.Note;

                ItemGuid     = lend.CopyID ?? Guid.Empty;
                LastItemGuid = ItemGuid;
                PersonGuid   = lend.PersonID ?? Guid.Empty;

                // ----- Fill Fast tags -----
                FastFlags flag = (FastFlags)(lend.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 Items OLV -----
                UpdateOLV();
            }
            // ----- Lending to person -----
            else if (PersonGuid != Guid.Empty)
            {
                Guid temp = PersonGuid;
                // ----- Fill Person -----
                Contacts person = db.Contacts.Find(PersonGuid);
                if (person != null)
                {
                    txtPerson.Text    = person.Name.Trim() + " " + person.Surname.Trim();
                    lblPersonNum.Text = Lng.Get("PersonNum", "Person number") + ": " + person.PersonCode.Trim();
                }
                PersonGuid           = temp;
                txtPerson.Enabled    = false;
                btnAddPerson.Enabled = false;
                this.ActiveControl   = txtItem;
            }
        }