Esempio n. 1
0
 private void reserveBtn_Click(object sender, EventArgs e)
 {
     try
     {
         Model.Item item = controller.GetItem(int.Parse(itemIdTB.Text.Trim()));
         if (item == null)
         {
             updateMsg("The requested item does not exist.", true);
             return;
         }
         Model.Borrower borrower = controller.GetBorrower(int.Parse(borrowerIdTB.Text.Trim()));
         if (borrower == null)
         {
             updateMsg(string.Format("A customer with the id {0}\r\ndoes not exist.", borrowerIdTB.Text), true);
             return;
         }
         Model.State itemState = item.State;
         if (itemState == Model.State.Available)
         {
             updateMsg("The requested item is currently available.", true);
         }
         else
         {
             controller.Reserve(borrower.Id, item.ItemId);
             updateMsg("Reserved successfully.", false);
         }
     }
     catch (FormatException ex)
     {
         Console.WriteLine(ex.StackTrace);
         updateMsg("Invalid input format.", true);
     }
 }
        private void addBtn_Click(object sender, EventArgs e)
        {
            Model.Borrower borrower = null;

            if (studentRB.Checked)
            {
                borrower = new Model.Student();
                borrower.MaxAllowedItems = 3;
            }
            else
            {
                borrower = new Model.Teacher();
                borrower.MaxAllowedItems = 5;
            }

            try
            {
                borrower.Id    = int.Parse(borrowerIdTB.Text);
                borrower.Name  = borrowerNameTB.Text;
                borrower.Email = borrowerEmailTB.Text;

                if (controller.AddBorrower(borrower))
                {
                    updateMsg((borrower is Model.Student ? "Student" : "Teacher") + " successfully added.", false);
                }
                else
                {
                    updateMsg("Borrower already exists.", true);
                }
            }
            catch (FormatException ex)
            {
                updateMsg("Invalid Format", true);
            }
        }
Esempio n. 3
0
        void DatagridSelect(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dgBorrower.Rows.Count > 0)
                {
                    oMBorrower             = new Model.Borrower();
                    oMBorrower.PERSON_ID   = dgBorrower.Rows[e.RowIndex].Cells[0].Value.ToString();
                    eVariable.sBorrowerID  = dgBorrower.Rows[e.RowIndex].Cells[0].Value.ToString();
                    oMBorrower.FIRST_NAME  = dgBorrower.Rows[e.RowIndex].Cells[1].Value.ToString();
                    oMBorrower.MIDDLE_NAME = dgBorrower.Rows[e.RowIndex].Cells[2].Value.ToString();
                    oMBorrower.LAST_NAME   = dgBorrower.Rows[e.RowIndex].Cells[3].Value.ToString();
                    oMBorrower.DOB         = dgBorrower.Rows[e.RowIndex].Cells[4].Value.ToString();
                    oMBorrower.AGE         = dgBorrower.Rows[e.RowIndex].Cells[5].Value.ToString();
                    oMBorrower.CONTACT_NO  = dgBorrower.Rows[e.RowIndex].Cells[6].Value.ToString();
                    oMBorrower.ADDRESS     = dgBorrower.Rows[e.RowIndex].Cells[7].Value.ToString();
                    oMBorrower.ADDED_DATE  = dgBorrower.Rows[e.RowIndex].Cells[8].Value.ToString();

                    eVariable.sBorrowerID = oMBorrower.PERSON_ID;
                    AutoFillBook();
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 4
0
        public void UpdateBorrower(Model.Borrower oData)
        {
            try
            {
                osb.ConnectionString = sConnectionString;
                ddq = new DatabaseQuery.DBQuery();
                ddq.ConnectionString = osb.ConnectionString;

                ddq.CommandText = "SP_UPDATE_BORROWER";
                ddq.AddParamer("@BORROWER_ID", SqlDbType.VarChar, oData.PERSON_ID);
                ddq.AddParamer("@FIRST_NAME", SqlDbType.VarChar, oData.FIRST_NAME);
                ddq.AddParamer("@MIDDLE_NAME", SqlDbType.VarChar, oData.MIDDLE_NAME);
                ddq.AddParamer("@LAST_NAME", SqlDbType.VarChar, oData.LAST_NAME);
                ddq.AddParamer("@DOB", SqlDbType.VarChar, oData.DOB);
                ddq.AddParamer("@AGE", SqlDbType.VarChar, oData.AGE);
                ddq.AddParamer("@CONTACT_NO", SqlDbType.VarChar, oData.CONTACT_NO);
                ddq.AddParamer("@ADDRESS", SqlDbType.VarChar, oData.ADDRESS);
                ddq.AddParamer("@MODIFIED_DATE", SqlDbType.VarChar, oData.MODIFIED_DATE);
                ddq.AddParamer("@MODIFIED_BY", SqlDbType.VarChar, oData.MODIFIED_BY);
                ddq.AddParamer("@STATUS", SqlDbType.VarChar, oData.STATUS);
                ddq.AddParamer("@PROFILE_PIC", SqlDbType.VarChar, oData.PROFILE_PIC);

                ddq.ExecuteNonQuery(CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public void ReturnItem(int borrowerId, int itemId)
        {
            Model.Borrower borrower = dataRepository.GetBorrower(borrowerId);
            Model.Item     item     = dataRepository.GetItem(itemId);

            borrower.BorrowedItems.Remove(item.ItemId);
            item.BorrowerId = 0;
            if (item.WaitingList.Count > 0)
            {
                Model.Borrower first = dataRepository.GetBorrower(item.WaitingList.First());
                item.WaitingList.Remove(first.Id);
                item.State = Model.State.Reserved;
                string subject = "Item Available";
                string body    = string.Format("Dear {0},\r\n\r\nThe item {1} was returned and it has been reserved for you.\r\nYou have {2} hours to borrow the item.", first.Name, item.Name, item.ReservationTimeout / 60);
                new Thread(() => messageSender.SendEmail(first.Email, subject, body)).Start();
            }
            else
            {
                item.State = Model.State.Available;
            }
            item.ReservationTimeout = GetTimeout(0);
            item.NotReturnedTimeout = GetTimeout(1);
            item.OverdueTimeout     = GetTimeout(2);
            dataRepository.SetItem(item);
            dataRepository.SetBorrower(borrower);
        }
Esempio n. 6
0
        private void btnBrowseBorrower_Click(object sender, EventArgs e)
        {
            BrowseData.frmSearch oFrm = new BrowseData.frmSearch();
            oFrm.oFilterFindOption = ePublicVariable.eVariable.FIND_OPTION.BORROWER;
            oFrm.StartPosition     = FormStartPosition.CenterScreen;
            oFrm.ShowDialog();

            oBorrower            = new DataAccess.Borrower();
            oMBorrower           = new Model.Borrower();
            oMBorrower.PERSON_ID = oFrm.oMBorrower.PERSON_ID;
            if (!oBorrower.HasUnsettledBook(oMBorrower))
            {
                txtBorrowerID.Text = oFrm.oMBorrower.PERSON_ID;
                txtFname.Text      = oFrm.oMBorrower.FIRST_NAME;
                txtMname.Text      = oFrm.oMBorrower.MIDDLE_NAME;
                txtLname.Text      = oFrm.oMBorrower.LAST_NAME;
                txtBirthDate.Text  = oFrm.oMBorrower.DOB;
                txtAge.Text        = oFrm.oMBorrower.AGE;
                txtContactNo.Text  = oFrm.oMBorrower.CONTACT_NO;
                txtAddress.Text    = oFrm.oMBorrower.ADDRESS;
            }
            else
            {
                oFrmMsgBox = new frmMessageBox(eVariable.TransactionMessage.BORROWER_HAS_CURRENTLY_HAVE_ACTIVE_TRANSACTION.ToString().Replace("_", " "));
                oFrmMsgBox.m_MessageType = frmMessageBox.MESSAGE_TYPE.INFO;
                oFrmMsgBox.ShowDialog();
            }
        }
Esempio n. 7
0
        public void Reserve(int borrowerId, int itemId)
        {
            Model.Borrower borrower = dataRepository.GetBorrower(borrowerId);
            Model.Item     item     = dataRepository.GetItem(itemId);

            item.WaitingList.Add(borrower.Id);
            dataRepository.SetItem(item);
            dataRepository.SetBorrower(borrower);
        }
 public bool AddBorrower(Model.Borrower borrower)
 {
     if (!borrowers.Contains(borrower))
     {
         borrowers.Add(borrower);
         WriteData();
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Model.Borrower borrower = comboBox1.SelectedItem as Model.Borrower;
            idL.Text    = borrower.Id.ToString();
            nameL.Text  = borrower.Name;
            typeL.Text  = borrower is Model.Student ? "Student" : "Teacher";
            emailL.Text = borrower.Email;
            stateL.Text = borrower.MaxAllowedItems.ToString();

            dataGridView1.DataSource = borrower.BorrowedItems.Select(x => new { ItemId = x }).ToList();
        }
Esempio n. 10
0
 public frmBorrowerEntry(frmBorrowerList oFrmList, Model.Borrower oData)
 {
     InitializeComponent();
     eVariable.m_ActionType = eVariable.ACTION_TYPE.EDIT;
     oMBorrower             = oData;
     oFrmBorrowerLst        = oFrmList;
     eVariable.DisableKeyPress(txtBorrowerID);
     eVariable.DisableKeyPress(txtAge);
     eVariable.DisableTextEnterKey(pnlMain);
     eVariable.ValidNumber(txtContactNo);
 }
Esempio n. 11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            oMBorrower      = new Model.Borrower();
            oBorrower       = new DataAccess.Borrower();
            oCommonFunction = new CommonFunction.CommonFunction();
            oImageFunction  = new CommonFunction.CommonFunction();

            if (eVariable.IsFieldEmpty(pnlMain))
            {
                oFrmMsgBox = new frmMessageBox(eVariable.TransactionMessage.ALL_FIELDS_ARE_REQUIRED.ToString().Replace("_", " "));
                oFrmMsgBox.ShowDialog();
                return;
            }

            oMBorrower.PERSON_ID   = txtBorrowerID.Text;
            oMBorrower.FIRST_NAME  = txtFname.Text;
            oMBorrower.MIDDLE_NAME = txtMname.Text;
            oMBorrower.LAST_NAME   = txtLname.Text;
            oMBorrower.DOB         = dtDOB.Value.ToString("yyyy-MM-dd");
            oMBorrower.AGE         = txtAge.Text;
            oMBorrower.CONTACT_NO  = txtContactNo.Text;
            oMBorrower.ADDRESS     = txtAddress.Text;

            if (pImage.Image != null)
            {
                oMBorrower.PROFILE_PIC = oCommonFunction.CompressString(oImageFunction.ImageToBaseString(pImage.Image, ImageFormat.Png));
            }


            if (eVariable.m_ActionType == eVariable.ACTION_TYPE.EDIT)
            {
                oMBorrower.MODIFIED_BY   = eVariable.sUsername;
                oMBorrower.MODIFIED_DATE = DateTime.Now.ToString("yyyy-MM-dd");
                oBorrower.UpdateBorrower(oMBorrower);
            }
            else
            {
                oMBorrower.ADDED_BY   = eVariable.sUsername;
                oMBorrower.ADDED_DATE = DateTime.Now.ToString("yyyy-MM-dd");
                oBorrower.InsertBorrower(oMBorrower);
            }

            oFrmMsgBox = new frmMessageBox(eVariable.TransactionMessage.RECORD_HAS_BEEN_SUCESSFULLY_SAVED.ToString().Replace("_", " "));
            oFrmMsgBox.m_MessageType = frmMessageBox.MESSAGE_TYPE.INFO;
            oFrmMsgBox.ShowDialog();
            oFrmBorrowerLst.LoadBorrower();
            eVariable.ClearText(pnlMain);
            ResetFields();
            Close();
        }
Esempio n. 12
0
 private void DataGridviewSelectedData(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         oMBorrower = new Model.Borrower();
         if (dgDetails.Rows.Count > 0)
         {
             oMBorrower.PERSON_ID   = dgDetails.Rows[e.RowIndex].Cells[0].Value.ToString();
             oMBorrower.FIRST_NAME  = dgDetails.Rows[e.RowIndex].Cells[1].Value.ToString();
             oMBorrower.MIDDLE_NAME = dgDetails.Rows[e.RowIndex].Cells[2].Value.ToString();
             oMBorrower.LAST_NAME   = dgDetails.Rows[e.RowIndex].Cells[3].Value.ToString();
         }
     }
 }
Esempio n. 13
0
        public frmBorrowBook(Model.Borrower oData, ePublicVariable.eVariable.FIND_BOOK oType)
        {
            InitializeComponent();

            GetDataRecordFunctionPointer  += new GetDataRecordFunction(GetRecord);
            iGridControl.GetDataRecordList = GetDataRecordFunctionPointer;


            eVariable.DisablePanelTextKeyPress(pnlMain);

            oTranType             = oType;
            oMBorrower            = oData;
            eVariable.sBorrowerID = oMBorrower.PERSON_ID;
            AutoFillBorrower();
        }
Esempio n. 14
0
        public void Borrow(int borrowerId, int itemId)
        {
            Model.Borrower borrower = dataRepository.GetBorrower(borrowerId);
            Model.Item     item     = dataRepository.GetItem(itemId);

            borrower.BorrowedItems.Add(item.ItemId);
            item.State      = Model.State.Unavailable;
            item.BorrowerId = borrower.Id;
            item.WaitingList.Remove(borrower.Id);
            item.ReservationTimeout = GetTimeout(0);
            item.NotReturnedTimeout = GetTimeout(1);
            item.OverdueTimeout     = GetTimeout(2);
            dataRepository.SetItem(item);
            dataRepository.SetBorrower(borrower);
        }
Esempio n. 15
0
        public Boolean IsRecordExists(Model.Borrower oData)
        {
            try
            {
                osb.ConnectionString = sConnectionString;
                ddq = new DatabaseQuery.DBQuery();
                ddq.ConnectionString = osb.ConnectionString;

                ddq.CommandText = "SELECT * FROM TBL_BORROWER WHERE BORROWER_ID = '" + oData.PERSON_ID + "'";
                ds = ddq.GetDataset(CommandType.Text);

                return(ds.Tables[0].Rows.Count > 0 ? true : false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 16
0
        public frmProcessReturnBook(Model.Borrower oData)
        {
            InitializeComponent();

            GetDataRecordFunctionPointer  += new GetDataRecordFunction(GetRecord);
            iGridControl.GetDataRecordList = GetDataRecordFunctionPointer;

            oMBorrower = oData;

            eVariable.sBorrowerID = oMBorrower.PERSON_ID;
            eVariable.FirstName   = oMBorrower.FIRST_NAME;
            eVariable.MiddleName  = oMBorrower.MIDDLE_NAME;
            eVariable.LastName    = oMBorrower.LAST_NAME;

            eVariable.DisableKeyPress(pnlMain);

            AutoFillBook();
        }
Esempio n. 17
0
        public Boolean HasUnsettledBook(Model.Borrower oData)
        {
            try
            {
                osb.ConnectionString = sConnectionString;
                ddq = new DatabaseQuery.DBQuery();
                ddq.ConnectionString = osb.ConnectionString;

                ddq.CommandText = " SELECT BORROWER_ID FROM TBL_BORROWER WHERE BORROWER_ID = '" + oData.PERSON_ID + "' " +
                                  " AND (BORROWER_ID IN (SELECT BORROWER_ID FROM TBL_BORROWEDBOOKS WHERE [STATUS] = 'BORROWED') " +
                                  " OR BORROWER_ID IN (SELECT BORROWER_ID FROM TBL_BORROWERREQUEST WHERE [STATUS] = 'REQUEST')) ";

                ds = ddq.GetDataset(CommandType.Text);

                return(ds.Tables[0].Rows.Count > 0 ? true : false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 18
0
 void DatagridSelect(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (dgDetails.Rows.Count > 0)
         {
             oMBorrower             = new Model.Borrower();
             oMBorrower.PERSON_ID   = dgDetails.Rows[e.RowIndex].Cells[0].Value.ToString();
             oMBorrower.FIRST_NAME  = dgDetails.Rows[e.RowIndex].Cells[1].Value.ToString();
             oMBorrower.MIDDLE_NAME = dgDetails.Rows[e.RowIndex].Cells[2].Value.ToString();
             oMBorrower.LAST_NAME   = dgDetails.Rows[e.RowIndex].Cells[3].Value.ToString();
             oMBorrower.DOB         = dgDetails.Rows[e.RowIndex].Cells[4].Value.ToString();
             oMBorrower.AGE         = dgDetails.Rows[e.RowIndex].Cells[5].Value.ToString();
             oMBorrower.CONTACT_NO  = dgDetails.Rows[e.RowIndex].Cells[6].Value.ToString();
             oMBorrower.ADDRESS     = dgDetails.Rows[e.RowIndex].Cells[7].Value.ToString();
             oMBorrower.STATUS      = dgDetails.Rows[e.RowIndex].Cells[8].Value.ToString();
             oMBorrower.PROFILE_PIC = dgDetails.Rows[e.RowIndex].Cells[9].Value.ToString();
         }
     }
     catch (Exception ex)
     {
     }
 }
Esempio n. 19
0
        public List <Model.Borrower> GetCSVData(string sPath)
        {
            try
            {
                List <string>         queries     = new List <string>(File.ReadAllLines(sPath));
                List <Model.Borrower> lstBorrower = new List <Model.Borrower>();

                foreach (string query in queries)
                {
                    string[] queryArr = query.Split(',');

                    if (!queryArr[0].Contains("_"))
                    {
                        oMBorrower             = new Model.Borrower();
                        oMBorrower.PERSON_ID   = queryArr[0];
                        oMBorrower.FIRST_NAME  = queryArr[1];
                        oMBorrower.MIDDLE_NAME = queryArr[2];
                        oMBorrower.LAST_NAME   = queryArr[3];
                        oMBorrower.DOB         = Convert.ToDateTime(queryArr[4]).ToString();
                        oMBorrower.AGE         = queryArr[5];
                        oMBorrower.CONTACT_NO  = queryArr[6];
                        oMBorrower.ADDRESS     = queryArr[7];
                        oMBorrower.ADDED_DATE  = queryArr[8];
                        oMBorrower.ADDED_BY    = queryArr[9];

                        lstBorrower.Add(oMBorrower);
                    }
                }

                return(lstBorrower);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 20
0
 public frmDisplayBorrowedBook(Model.Borrower oData, eVariable.FIND_BOOK oType)
 {
     InitializeComponent();
     oMBorrower = oData;
     TranType   = oType;
 }
Esempio n. 21
0
 public bool AddBorrower(Model.Borrower borrower)
 {
     return(dataRepository.AddBorrower(borrower));
 }