public void AddIndefiniteEmployee(string name, string surname, DateTime dateOfBirth, string IDnumber, employmentPosition_indefinitePeriod employeePosition, double norm, string jobQualification, string title)
        {
            foreach (Employee x in _listOfAllEmployees)
            {
                if (x.IDnumber == IDnumber)
                {
                    throw new ArgumentException("There is already person with the same ID number in the system");
                }
            }

            int employeeID = employee_ID_start;

            employee_ID_start += 1;

            employeeINDEFINITEContract input = new employeeINDEFINITEContract(name, surname, dateOfBirth, IDnumber, employeeID, employeePosition, norm, jobQualification, title);

            _listOfIndefiniteContractEmployees.Add(input);
            _listOfAllEmployees.Add(input);
            _expenditure += input.Salary;
            balanceRefresh();
            if (_balance < 0)
            {
                _flag = accountBalance.negative;
            }
            else
            {
                _flag = accountBalance.pozitive;
            }
        }
        string _name; // naziv fakulteta;

        public Faculty(string name)
        {
            _listOfBachelorStudents = new List <bachelorStudent>();
            _listOfMasterStudents   = new List <masterStudent>();
            _listOfAllStudents      = new List <Student>();

            _listOfAllEmployees = new List <Employee>();
            _listOfDefiniteContractEmployees   = new List <employeeDEFINITEContract>();
            _listOfIndefiniteContractEmployees = new List <employeeINDEFINITEContract>();

            _courses = new List <Course>();

            _testCourses = new List <ICourse>();

            _testAssociateCourses = new List <ICourse_Associate>();

            /* We are going to create an instance of stub object for testing
             * methods not implemented
             */

            _name = name;

            bachelor_index_start = 17000;
            master_index_start   = 100;
            employee_ID_start    = 1;

            _income      = 0;
            _expenditure = 0;
            _balance     = 0;
            _flag        = accountBalance.pozitive;
        }
        /* Based on different parameters sent
         * in the function different type of
         * employee will be added to corresponding list.
         */
        public void AddDefiniteEmployee(string name, string surname, DateTime dateOfBirth, string IDnumber, employmentPosition_OnContract employeePosition, DateTime startOfContract, DateTime endOfContract, int numberOfClassesWeekly)
        {
            foreach (Employee x in _listOfAllEmployees)
            {
                if (x.IDnumber == IDnumber)
                {
                    throw new ArgumentException("There is already person with the same ID number in the system");
                }
            }

            int employeeID = employee_ID_start;

            employee_ID_start += 1;

            employeeDEFINITEContract input = new employeeDEFINITEContract(name, surname, dateOfBirth, IDnumber, employeeID, employeePosition, startOfContract, endOfContract, numberOfClassesWeekly);

            _listOfDefiniteContractEmployees.Add(input);
            _listOfAllEmployees.Add(input);
            _expenditure += input.Salary;
            balanceRefresh();
            if (_balance < 0)
            {
                _flag = accountBalance.negative;
            }
            else
            {
                _flag = accountBalance.pozitive;
            }
        }
        /* We will not allow adding of object bachelorStudent or masterStudent
         * because container class Faculty handles the indexes
         * for both types of students
         */
        public void AddBachelorStudent(string name, string surname, DateTime dateOfBirth, string IDnumber, DateTime endOfPreviousEducation)
        {
            foreach (Student x in _listOfAllStudents)
            {
                if (x.IDnumber == IDnumber)
                {
                    throw new ArgumentException("There is already person with the same ID number in the system");
                }
            }

            // Oblik: "[0-9]{5}"
            string indexIDnumber = bachelor_index_start.ToString();

            bachelor_index_start++;

            bachelorStudent input = new bachelorStudent(name, surname, dateOfBirth, IDnumber, indexIDnumber, endOfPreviousEducation);

            _listOfBachelorStudents.Add(input);
            _listOfAllStudents.Add(input);
            _income += 9000;
            balanceRefresh();
            if (_balance < 0)
            {
                _flag = accountBalance.negative;
            }
            else
            {
                _flag = accountBalance.pozitive;
            }
        }
Beispiel #5
0
        public accountBalance TryDepositMoneyOnHub(string sTransactionId, uid User, decimal money, bool realMoney, ref Exception error, CashAcceptorType?type)
        {
            accountBalance iResult = SaveDepositOnHub(sTransactionId, User, money, realMoney, ref error, type);

            if (iResult != null)
            {
                Logger.InfoFormat("{0} successfully deposited", money);
            }
            else if (error != null)
            {
                var lostConnection = new Tuple <string, string, bool, int>("LostInternetConnection", "", false, 0);
                Mediator.SendMessage(lostConnection, "Error");
                Logger.ErrorFormat("{0} was not deposited. Errors:\r\n{1}", new Exception(), money, error.Message);

                PutDepositIntoTransactionQueue(sTransactionId, User, money, realMoney, "Cannot store Deposit:\r\n" + error.Message, type);
            }
            return(iResult);
        }
        public void AddMasterStudent(string name, string surname, DateTime dateOfBirth, string IDnumber, DateTime endOfPreviousEducation, string placeOfPreviousEd)
        {
            string        indexIDnumber;
            masterStudent input;
            bool          exists = false;

            foreach (Student x in _listOfAllStudents)
            {
                if (x.IDnumber == IDnumber && (x is masterStudent))
                {
                    throw new ArgumentException("There is already person with the same ID number in the system");
                }
            }

            foreach (bachelorStudent x in _listOfBachelorStudents)
            {
                if (x.IDnumber == IDnumber)
                {
                    // Oblik: "[0-9]{3}/[0-9]{5}"
                    indexIDnumber = master_index_start.ToString() + "/" + x.IndexIDNumber;
                    master_index_start++;

                    input = new masterStudent(name, surname, dateOfBirth, IDnumber, indexIDnumber, endOfPreviousEducation, placeOfPreviousEd);
                    _listOfMasterStudents.Add(input);
                    _listOfBachelorStudents.Remove(x);
                    _listOfAllStudents.Remove(x);
                    _listOfAllStudents.Add(input);
                    _income += 11000;
                    balanceRefresh();
                    if (_balance < 0)
                    {
                        _flag = accountBalance.negative;
                    }
                    else
                    {
                        _flag = accountBalance.pozitive;
                    }
                    exists = true;

                    break;
                }
            }

            if (exists == false)
            {
                // Oblik: "[0-9]{3}/[0-9]{5}"
                indexIDnumber = master_index_start.ToString() + "/" + bachelor_index_start;
                master_index_start++;
                bachelor_index_start++;

                input = new masterStudent(name, surname, dateOfBirth, IDnumber, indexIDnumber, endOfPreviousEducation, placeOfPreviousEd);
                _listOfMasterStudents.Add(input);
                _listOfAllStudents.Add(input);
                _income += 11000;
                balanceRefresh();
                if (_balance < 0)
                {
                    _flag = accountBalance.negative;
                }
                else
                {
                    _flag = accountBalance.pozitive;
                }
            }
        }
Beispiel #7
0
        public void TryToSaveTransactionObjectsOnHub()
        {
            lock (m_oLocker)
            {
                try
                {
                    List <TransactionQueueSr> lTransactionObjects = GetAllFromQueue();

                    if (lTransactionObjects != null && lTransactionObjects.Count > 0)
                    {
                        Logger.InfoFormat("Trying to save {0} Transaction Objects on HUB ...", lTransactionObjects.Count);

                        var lObjectsToDelete = new List <TransactionQueueSr>();


                        foreach (TransactionQueueSr tq in lTransactionObjects)
                        {
                            try
                            {
                                Logger.InfoFormat("Trying to save {0}", TraceTransactionQueue(tq));

                                eTransactionQueueType eType = ShortToType(tq.Type);
                                var uId = SerializeHelper.StringToSerializableObject <uid>(tq.UidState);

                                if (uId == null)
                                {
                                    Logger.ErrorFormat("uid is null, there is something wrong!!! tq.id = {0}", new Exception(), tq.ORMID);
                                }


                                string sErrors = string.Empty;

                                switch (eType)
                                {
                                case eTransactionQueueType.None:

                                    Logger.Error("Unknown Type. Skipping...", new Exception());
                                    break;

                                case eTransactionQueueType.Ticket:

                                    var ticket = SerializeHelper.StringToDataContractObject <TicketWS>(tq.Object1);
                                    var td     = SerializeHelper.StringToSerializableObject <TicketData>(tq.Tag1);
                                    uId.session_id = "";

                                    try
                                    {
                                        int iResult = SaveTicketOnHub(tq.TransactionId, uId, ticket, td.StationNumber, td.IsOffLineTicket, ref sErrors);

                                        if (iResult == Ticket.TICKET_SAVE_SUCCESSFUL)
                                        {
                                            PrinterHandler.CreateXmlAndSaveFile(ticket, false);
                                            Logger.InfoFormat("{0} successfully saved", ticket);
                                            lObjectsToDelete.Add(tq);
                                        }
                                        else if (iResult == Ticket.TICKET_ALREADY_SAVED)
                                        {
                                            PrinterHandler.CreateXmlAndSaveFile(ticket, false);
                                            Logger.InfoFormat("{0} already saved", ticket);
                                            lObjectsToDelete.Add(tq);
                                        }
                                        else if (iResult != 0)
                                        {
                                            Logger.InfoFormat("{0} have invalid data", ticket);
                                            lObjectsToDelete.Add(tq);
                                        }
                                        else
                                        {
                                            Logger.ErrorFormat("{0} was not saved:\r\n{1}\r\nResult {2}. Continue trying to save next time...", new Exception(), ticket, sErrors, iResult);
                                        }
                                    }
                                    catch (FaultException <HubServiceException> ex)
                                    {
                                        Logger.InfoFormat("{0} have invalid data", ticket);
                                        Logger.Error(ex.Message, ex);
                                        lObjectsToDelete.Add(tq);
                                    }


                                    break;

                                case eTransactionQueueType.Deposit:

                                    decimal          amount    = decimal.Parse(tq.Object1);
                                    bool             realMoney = bool.Parse(tq.Object3);
                                    CashAcceptorType?type      = null;
                                    CashAcceptorType typeTmp;
                                    Enum.TryParse(tq.Object2, out typeTmp);
                                    if (!String.IsNullOrEmpty(tq.Object2))
                                    {
                                        type = typeTmp;
                                    }
                                    uId.session_id = "";

                                    Exception error = null;
                                    try
                                    {
                                        accountBalance bResult = SaveDepositOnHub(tq.TransactionId, uId, amount, realMoney, ref error, type);

                                        if (bResult != null)
                                        {
                                            Logger.InfoFormat("Deposit {0} for {1} successfully saved", amount, uId);
                                            lObjectsToDelete.Add(tq);
                                        }
                                        else
                                        {
                                            if (error == null)
                                            {
                                                Logger.ErrorFormat("Deposit {0} for {1} was not saved. Errors:\r\n{2}\r\nContinue trying to save next time...", new Exception(), amount, uId, "empty responce");
                                                break;
                                            }
                                            Logger.ErrorFormat("Deposit {0} for {1} was not saved. Errors:\r\n{2}\r\nContinue trying to save next time...", new Exception(), amount, uId, error.Message);
                                        }
                                    }
                                    catch (FaultException <HubServiceException> ex)
                                    {
                                        Logger.ErrorFormat("Deposit {0} for {1} was not saved. Errors:\r\n{2}\r\nContinue trying to save next time...", new Exception(), amount, uId, error.Message);
                                        lObjectsToDelete.Add(tq);
                                    }

                                    break;

                                case eTransactionQueueType.DepositByTicket:

                                    string ticketNumber = tq.Object1;
                                    string creditNumber = tq.Object2;
                                    uId.session_id = "";
                                    try
                                    {
                                        var tnumber  = "";
                                        var tcode    = "";
                                        var crnumber = "";
                                        var crcode   = "";
                                        if (ticketNumber.Length > 4)
                                        {
                                            tnumber = ticketNumber.Substring(0, ticketNumber.Length - 4);
                                        }
                                        if (ticketNumber.Length > 4)
                                        {
                                            tcode = ticketNumber.Substring(ticketNumber.Length - 4);
                                        }
                                        if (creditNumber.Length > 4)
                                        {
                                            crnumber = creditNumber.Substring(0, creditNumber.Length - 4);
                                        }
                                        if (creditNumber.Length > 4)
                                        {
                                            crcode = creditNumber.Substring(creditNumber.Length - 4);
                                        }

                                        bool bResultDeposit = DepositByTicketOnHub(tq.TransactionId, uId, tnumber, tcode, crnumber, crcode, ref sErrors);

                                        if (bResultDeposit)
                                        {
                                            Logger.InfoFormat("DepositByTicket {0} for {1} successfully saved", ticketNumber, uId);
                                            lObjectsToDelete.Add(tq);
                                        }
                                        else
                                        {
                                            Logger.ErrorFormat("DepositByTicket {0} for {1} was not saved. TicketNumber {2}  Errors:\r\n{2}\r\nContinue trying to save next time...", new Exception(), ticketNumber, uId, sErrors);
                                        }
                                    }
                                    catch (FaultException <HubServiceException> ex)
                                    {
                                        Logger.ErrorFormat("DepositByTicket {0} for {1} was not saved. TicketNumber {2}  Errors:\r\n{2}\r\nContinue trying to save next time...", ex, ticketNumber, uId, sErrors);
                                        lObjectsToDelete.Add(tq);
                                    }
                                    break;

                                case eTransactionQueueType.DepositByCreditNote:

                                    string checksum   = tq.Object1;
                                    string noteNumber = tq.Object2;
                                    uId.session_id = "";

                                    try
                                    {
                                        bool bResultCredit = DepositByCreditNoteOnHub(tq.TransactionId, uId, noteNumber, checksum, ref sErrors);

                                        if (bResultCredit)
                                        {
                                            Logger.InfoFormat("DepositByCreditNote {0} for {1} successfully saved", checksum, uId);
                                            lObjectsToDelete.Add(tq);
                                        }
                                        else
                                        {
                                            Logger.ErrorFormat("DepositByCreditNote {0} for {1} was not saved. NoteNumber {2}  Errors:\r\n{2}\r\nContinue trying to save next time...", new Exception(), checksum, uId, sErrors, noteNumber);
                                        }
                                    }
                                    catch (FaultException <HubServiceException> ex)
                                    {
                                        Logger.ErrorFormat("DepositByCreditNote {0} for {1} was not saved. NoteNumber {2}  Errors:\r\n{2}\r\nContinue trying to save next time...", new Exception(), checksum, uId, sErrors, noteNumber);
                                        lObjectsToDelete.Add(tq);
                                    }
                                    break;

                                case eTransactionQueueType.Cash:
                                    bool moneyIn = bool.Parse(tq.Object3);
                                    uid  userUID = SerializeHelper.StringToSerializableObject <uid>(tq.UidState);

                                    try
                                    {
                                        DateTime startdate;
                                        DateTime enddate;
                                        var      bResultCash = RegisterMoney(userUID, moneyIn, ref sErrors, out startdate, out enddate);
                                        Logger.InfoFormat("RegisterMoney {0} successfully saved", moneyIn, uId);
                                        lObjectsToDelete.Add(tq);
                                    }
                                    catch (FaultException <HubServiceException> ex)
                                    {
                                        Logger.InfoFormat("{0}{1} have invalid data", moneyIn, uId);
                                        Logger.Error(ex.Message, ex);
                                        lObjectsToDelete.Add(tq);
                                    }
                                    break;

                                default:

                                    Debug.Assert(false);
                                    break;
                                }
                            }
                            catch (Exception excp)
                            {
                                Logger.InfoFormat("Cannot save on HUB {0}", TraceTransactionQueue(tq));
                            }
                        }

                        DeleteTransactionObjects(lObjectsToDelete);
                    }
                }
                catch (Exception excp)
                {
                    Logger.Error("General Error", excp);
                }
            }
        }