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

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

                if (Dialogs.ShowQuest(Lng.Get("DeleteItem", "Really delete item") + " \"" + borr.Item + "\"?", Lng.Get("Delete")) == DialogResult.Yes)
                {
                    db.Borrowing.Remove(borr);                  // Delete Item
                    db.SaveChanges();                           // Save to DB
                    UpdateBorrowingOLV();                       // Update Borrowing 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 olvBorrowing.SelectedObjects) // Find Object
                    {
                        Borrowing itm = db.Borrowing.Find(((Borrowing)item).ID);
                        db.Borrowing.Remove(itm);               // Delete Item
                    }
                    db.SaveChanges();                           // Save to DB
                    UpdateBorrowingOLV();                       // Update Borrowing OLV
                }
            }
        }
Exemplo n.º 2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            FindPerson();
            FindItem();

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

            if (ItemGuid == Guid.Empty)
            {
                Dialogs.ShowWar(Lng.Get("NoSelItem", "Not selected item!"), Lng.Get("Warning"));
                return;
            }

            if (Conv.ToIntDef(cbItemNum.Text, 0) == 0)
            {
                Dialogs.ShowWar(Lng.Get("NoSelItemNum", "Not selected item number!"), Lng.Get("Warning"));
                return;
            }

            databaseEntities db = new databaseEntities();

            Borrowing borr;

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

            FillBorr(ref borr);

            if (ID == Guid.Empty)
            {
                db.Borrowing.Add(borr);
            }
            db.SaveChanges();

            RefreshAvailableItems();


            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 3
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();

            Borrowing borr;

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

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

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

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

            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Find other Borrowings to fill Item list
        /// </summary>
        /// <param name="ID">Main ID</param>
        /// <returns>Borrowings list</returns>
        private List <Guid> FindOtherBorrowings(Guid ID)
        {
            databaseEntities db = new databaseEntities();

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

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

            if (borr != null)
            {
                list = db.Borrowing.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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set Fast Tags
        /// </summary>
        /// <param name="tag">Tags Mask</param>
        private void SetTagItemBorrowing(short tag)
        {
            if (olvBorrowing.SelectedObjects != null)                 // If selected Item
            {
                databaseEntities db = new databaseEntities();

                foreach (var item in olvBorrowing.SelectedObjects) // Find Object
                {
                    Borrowing itm = db.Borrowing.Find(((Borrowing)item).ID);
                    itm.FastTags |= tag;
                }
                db.SaveChanges();                           // Save to DB
                UpdateBorrowingOLV();                       // Update Contacts OLV
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Color Row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void olvBorrowing_FormatRow(object sender, FormatRowEventArgs e)
        {
            Borrowing itm = (Borrowing)e.Model;
            DateTime  now = DateTime.Now;

            if (itm.Status == 2 || itm.Status == 3)     // Returned, Canceled
            {
                e.Item.ForeColor = Color.Gray;
            }
            else if ((itm.To ?? now) < now)
            {
                e.Item.ForeColor = Color.Red;
            }
            else
            {
                e.Item.ForeColor = Color.Black;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fill Borrowing Items
        /// </summary>
        /// <param name="borr">Borrowing DB item</param>
        /// <param name="item">New Item</param>
        private void FillBorr(ref Borrowing borr, IInfo item)
        {
            // ----- Item -----
            borr.Item       = item.Name;
            borr.ItemInvNum = item.InventoryNumber;
            borr.Note       = item.Note;

            // ----- Other -----
            borr.PersonID = PersonGuid;
            borr.From     = dtFrom.Value;
            borr.To       = dtTo.Value;
            borr.Status   = (short)cbStatus.SelectedIndex;

            // ----- 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;
            }
            borr.FastTags = fastTag;
        }
Exemplo n.º 8
0
        private void FillBorr(ref Borrowing borr)
        {
            if (cbItemType.SelectedIndex == 0)
            {
                borr.ItemType = "item";
            }
            else if (cbItemType.SelectedIndex == 1)
            {
                borr.ItemType = "book";
            }

            borr.ItemID     = ItemGuid;
            borr.ItemNum    = Conv.ToShortNull(cbItemNum.Text);
            borr.ItemInvNum = ItemInvNum;
            borr.PersonID   = PersonGuid;

            borr.From     = dtFrom.Value;
            borr.To       = dtFrom.Value;
            borr.Returned = chbReturned.Checked;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Load Form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmEditBorrowing_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 Contacts autocomplete Context -----
            SetContactsContext();

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

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

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

                    // ----- Fill Item list -----
                    IInfo info = new IInfo();
                    info.Name = borr.Item.Trim();
                    if (borr.ItemInvNum != null)
                    {
                        info.InventoryNumber = borr.ItemInvNum.Trim();
                    }
                    if (borr.Note != null)
                    {
                        info.Note = borr.Note.Trim();
                    }

                    selItemList.Add(info);                      // Selected list
                    origItemList.Add(info);                     // Original list
                }


                // ----- Fill Person -----
                Contacts person = db.Contacts.Find(borr.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           = borr.From ?? DateTime.Now;
                dtTo.Value             = borr.To ?? DateTime.Now;
                cbStatus.SelectedIndex = borr.Status ?? 1;

                // ----- Fill Fast tags -----
                FastFlags flag = (FastFlags)(borr.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;
                }

                PersonGuid = borr.PersonID ?? Guid.Empty;

                // ----- 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;
            }
        }
Exemplo n.º 10
0
        private void frmEditBorrowing_Load(object sender, EventArgs e)
        {
            cbItemType.Items.Clear();
            cbItemType.Items.Add(Lng.Get("Item"));
            cbItemType.Items.Add(Lng.Get("Book"));
            cbItemType.SelectedIndex = 0;

            SetContactsContext();
            SetItemsContext();

            dtFrom.Value = DateTime.Now;
            dtTo.Value   = DateTime.Now.AddDays(Properties.Settings.Default.DefaultBorrInterval);

            if (ID != Guid.Empty)
            {
                Borrowing borr = db.Borrowing.Find(ID);

                switch (borr.ItemType.Trim())
                {
                case "item":
                    cbItemType.SelectedIndex = 0;
                    break;

                case "book":
                    cbItemType.SelectedIndex = 1;
                    break;
                }



                if (cbItemType.SelectedIndex == 0)
                {
                    Items itm = db.Items.Find(borr.ItemID);
                    if (itm != null)
                    {
                        txtItem.Text = itm.Name.Trim();
                    }
                }
                else if (cbItemType.SelectedIndex == 1)
                {
                    Books book = db.Books.Find(borr.ItemID);

                    if (book != null)
                    {
                        txtItem.Text = book.Name.Trim();
                    }
                }

                // ----- Fill Inventory number
                ItemGuid = borr.ItemID ?? Guid.Empty;
                FillInventoryNumber();
                cbItemNum.Text = (borr.ItemNum ?? 1).ToString();

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


                dtFrom.Value        = borr.From ?? DateTime.Now;
                dtTo.Value          = borr.To ?? DateTime.Now;
                chbReturned.Checked = borr.Returned ?? false;

                ItemGuid     = borr.ItemID ?? Guid.Empty;
                LastItemGuid = ItemGuid;
                PersonGuid   = borr.PersonID ?? Guid.Empty;
            }
        }