Esempio n. 1
0
        /// <summary>
        /// Method Name: LoadContainer
        /// The function is called to populate the container object with the data from the database file
        /// </summary>
        /// <param name="fileName">the Name of the database file</param>
        /// <returns>A boolean indicating whether the operation was successful</returns>
        public bool LoadContainer()
        {
            bool result = true;

            string[] fileContents; // create string to hold file contents
            string[] input;
            Int32    validCount = 0;
            Int32    lineCount  = 0;
            Int32    entryCount = 0;
            Employee e          = new Employee();
            bool     duplicate  = false;

            fileContents = dbFile.dBaseOpen_R(); // fill the string with file contents
            container.Clear();
            Console.Clear();
            foreach (string s in fileContents)
            {
                lineCount++;
                if (s != "")
                {
                    input = s.Split('|');
                    if (s[0] == 'F')
                    {
                        entryCount++;
                        FulltimeEmployee f = new FulltimeEmployee();
                        if (!f.SetLastName(input[1]) || !f.SetFirstName(input[2]) || !f.SetSIN(input[3]) || !f.SetDOB(input[4]) || !f.SetDateOfHire(input[5]) || !f.SetDateOfTermination(input[6]) || !f.SetSalary(input[7]))
                        {
                            log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == f.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(f);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'P')
                    {
                        entryCount++;
                        ParttimeEmployee p = new ParttimeEmployee();
                        if (!p.SetLastName(input[1]) || !p.SetFirstName(input[2]) || !p.SetSIN(input[3]) || !p.SetDOB(input[4]) || !p.SetDateOfHire(input[5]) || !p.SetDateOfTermination(input[6]) || !p.SetHourlyRate(input[7]))
                        {
                            log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == p.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(p);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'C')
                    {
                        entryCount++;
                        ContractEmployee c = new ContractEmployee();
                        if (!c.SetLastName(input[1]) || !c.SetFirstName(input[2]) || !c.SetSIN(input[3]) || !c.SetDOB(input[4]) || !c.SetContractStartDate(input[5]) || !c.SetContractEndDate(input[6]) || !c.SetFixedContractAmt(input[7]))
                        {
                            log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == c.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(c);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'S')
                    {
                        entryCount++;
                        SeasonalEmployee n = new SeasonalEmployee();
                        if (!n.SetLastName(input[1]) || !n.SetFirstName(input[2]) || !n.SetSIN(input[3]) || !n.SetDOB(input[4]) || !n.SetSeason(input[5]) || !n.SetPiecePay(input[6]))
                        {
                            log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == n.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(n);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("\n\n>>>>>>>>>>>>>>>> TOTAL LINES READ           : " + lineCount);
            Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL ENTRIES FOUND        : " + entryCount);
            Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL VALID ENTRIES LOADED : " + validCount);
            return(result);
        }
Esempio n. 2
0
        protected void btnModify_Click(object sender, EventArgs e)
        {
            bool             isAllValid      = true;
            ParttimeEmployee pt              = new ParttimeEmployee();
            FulltimeEmployee ft              = new FulltimeEmployee();
            SeasonalEmployee sl              = new SeasonalEmployee();
            ContractEmployee ct              = new ContractEmployee();
            List <string>    normalUpdates   = new List <string>();
            List <string>    specificUpdates = new List <string>();
            string           updateString    = "UPDATE tb_Emp SET";
            string           updateSpecific  = "UPDATE tb_";
            int    empID   = 0;
            string empType = Session["type"].ToString();

            if (empType == "FT")
            {
                updateSpecific += "Ft";
            }
            else if (empType == "PT")
            {
                updateSpecific += "Pt";
            }
            else if (empType == "SL")
            {
                updateSpecific += "Sl";
            }
            else if (empType == "CT")
            {
                updateSpecific += "Ct";
            }

            updateSpecific += "Emp SET ";

            string endUpdate = " OUTPUT INSERTED.empID WHERE socialInsNumber=" + Session["sin"] + " and firstName='" + Session["fname"] + "' and lastName='" + Session["lname"] + "' and companyName='" + Session["company"] + "';";

            //string updateSpecificString = "UPDATE " +

            //for fulltime
            if (ftfName.Text != "")
            {
                if (!ft.SetFirstName(ftfName.Text))
                {
                    ftfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("firstName='" + ftfName.Text + "'");
            }
            if (ftlName.Text != "")
            {
                if (!ft.SetLastName(ftlName.Text))
                {
                    ftlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("lastName='" + ftlName.Text + "'");
            }
            if (ftSin.Text != "")
            {
                if (!ft.SetSIN(ftSin.Text.Replace(" ", "")))
                {
                    ftSinError.Text += "<b>SIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber=" + ftSin.Text);
            }
            if (ftDOB.Text != "")
            {
                if (!ft.SetDOB(ftDOB.Text.Replace(" ", "")))
                {
                    ftDOBError.Text += "<b>Date Of Hire</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth'" + ftDOB.Text + "'");
            }
            if (ftDateHire.Text != "")
            {
                if (!ft.SetDateOfHire(ftDateHire.Text.Replace(" ", "")))
                {
                    ftDateHireError.Text += "<b>Date Of Birth</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfHire='" + ftDateHire.Text + "'");
            }
            if (ftDateTerm.Text != "")
            {
                if (!ft.SetDateOfTermination(ftDateTerm.Text.Replace(" ", "")) && ftDateTerm.Text != "")
                {
                    ftDateTermError.Text += "<b>Date Of Termination</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfTermination='" + ftDateTerm.Text + "'");
            }
            if (ftSalary.Text != "")
            {
                if (!ft.SetSalary(ftSalary.Text.Replace(" ", "")) && ftSalary.Text != "")
                {
                    ftSalaryError.Text += "<b>Salary</b> should be a number higher than 0";
                    isAllValid          = false;
                }
                specificUpdates.Add("salary=" + ftSalary.Text + "");
            }

            //for part time
            if (ptfName.Text != "")
            {
                if (!pt.SetFirstName(ptfName.Text))
                {
                    ptfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("firstName='" + ptfName.Text + "'");
            }
            if (ptlName.Text != "")
            {
                if (!pt.SetLastName(ptlName.Text) || ptlName.Text == "")
                {
                    ptlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("lastName='" + ptlName.Text + "'");
            }
            if (ptSin.Text != "")
            {
                if (!pt.SetSIN(ptSin.Text.Replace(" ", "")))
                {
                    ptSinError.Text += "<b>SIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber=" + ptSin.Text);
            }
            if (ptDOB.Text != "")
            {
                if (!pt.SetDOB(ptDOB.Text.Replace(" ", "")))
                {
                    ptDOBError.Text += "<b>Date Of Birth</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth='" + ptDOB.Text + "'");
            }
            if (ptDateHire.Text != "")
            {
                if (!pt.SetDateOfHire(ptDateHire.Text.Replace(" ", "")))
                {
                    ptDateHireError.Text += "<b>Date Of Hire</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfHire='" + ptDateHire.Text + "'");
            }
            if (ptDateTerm.Text != "")
            {
                if (!pt.SetDateOfTermination(ptDateTerm.Text.Replace(" ", "")) && ptDateTerm.Text != "")
                {
                    ptDateTermError.Text += "<b>Date Of Termination</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfTermination='" + ptDateTerm.Text + "'");
            }
            if (ptWage.Text != "")
            {
                if (!pt.SetHourlyRate(ptWage.Text.Replace(" ", "")) && ptWage.Text != "")
                {
                    ptWageError.Text += "<b>Salary</b> should be a number higher than 0";
                    isAllValid        = false;
                }
                specificUpdates.Add("hourlyRate=" + ptWage.Text);
            }

            //for seasonal
            if (slfName.Text != "")
            {
                if (!sl.SetFirstName(slfName.Text) || slfName.Text == "")
                {
                    slfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("firstName='" + slfName.Text + "'");
            }
            if (sllName.Text != "")
            {
                if (!sl.SetLastName(sllName.Text) || sllName.Text == "")
                {
                    sllNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("lastName='" + sllName.Text + "'");
            }
            if (slSin.Text != "")
            {
                if (!sl.SetSIN(slSin.Text.Replace(" ", "")))
                {
                    slSinError.Text += "<b>SIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber=" + ftfName.Text);
            }
            if (slDOB.Text != "")
            {
                if (!sl.SetDOB(slDOB.Text.Replace(" ", "")))
                {
                    slDOBError.Text += "<b>Date Of Birth</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth='" + slDOB.Text + "'");
            }
            if (slSeason.Text != "" && Session["type"].ToString() == "SL")
            {
                if (!sl.SetSeason(slSeason.Text.Replace(" ", "")) && slSeason.Text != "")
                {
                    slSeasonError.Text += "<b>Season</b> must be valid. It should not be possible to get this error. Look at you, you little hacker";
                    isAllValid          = false;
                }
                specificUpdates.Add("season='" + slSeason.Text + "'");
            }
            if (slPcPay.Text != "")
            {
                if (!sl.SetPiecePay(slPcPay.Text.Replace(" ", "")) && slPcPay.Text != "")
                {
                    slPcPayError.Text += "<b>Salary</b> should be a number higher than 0";
                    isAllValid         = false;
                }
                specificUpdates.Add("piecePay='" + slPcPay.Text + "'");
            }

            //for contract
            if (ctName.Text != "")
            {
                if (!ct.SetLastName(ctName.Text))
                {
                    ctNameError.Text += "<b>Company Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid        = false;
                }
                normalUpdates.Add("lastName='" + ctName.Text + "'");
            }
            if (ctBin.Text != "")
            {
                if (!ct.SetSIN(ctBin.Text.Replace(" ", "")))
                {
                    ctBinError.Text += "<b>BIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber='" + ctBin.Text + "'");
            }
            if (ctDOI.Text != "")
            {
                if (!ct.SetDOB(ctDOI.Text.Replace(" ", "")))
                {
                    ctDOIError.Text += "<b>Date Of Incorporation</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth='" + ctDOI.Text + "'");
            }
            if (ctStart.Text != "")
            {
                if (!ct.SetContractStartDate(ctStart.Text.Replace(" ", "")))
                {
                    ctStartError.Text += "<b>Contract Start Date</b> must be valid. It should not be possible to get this error. Look at you, you little hacker";
                    isAllValid         = false;
                }
                specificUpdates.Add("dateStart='" + ctStart.Text + "'");
            }
            if (ctEnd.Text != "")
            {
                if (!ct.SetContractEndDate(ctEnd.Text.Replace(" ", "")))
                {
                    ctEndError.Text += "<b>Contract End Date</b> should have valid date format";
                    isAllValid       = false;
                }
                specificUpdates.Add("dateStop='" + ctEnd.Text + "'");
            }
            if (ctAmt.Text != "")
            {
                if (!ct.SetFixedContractAmt(ctAmt.Text.Replace(" ", "")))
                {
                    ctAmtError.Text += "<b>Contract Amount</b> should be a number higher than 0";
                    isAllValid       = false;
                }
                specificUpdates.Add("fixedCtAmt='" + ctAmt.Text + "'");
            }
            if (isAllValid)
            {
                int emp = 0;
                int.TryParse(Session["empID"].ToString(), out emp);
                bool first = true;
                if (normalUpdates.Count < 1)
                {
                    normalUpdates.Add("lastName='" + Session["lname"] + "'");
                }
                foreach (string s in normalUpdates)
                {
                    if (first)
                    {
                        updateString += " " + s;
                        first         = false;
                    }
                    else
                    {
                        updateString += ", " + s;
                    }
                    string fieldValue = s.Substring(0, s.IndexOf('='));
                    string oldVal     = sup.GetPreviousValue(conString, emp, @s, "");
                    string newVal     = s;
                    newVal = newVal.Replace(fieldValue + @"='", "");
                    sup.CreateAudit(conString, userName, emp.ToString(), fieldValue, oldVal, newVal);
                }
                updateString += endUpdate;

                first = true;
                foreach (string s in specificUpdates)
                {
                    if (first)
                    {
                        updateSpecific += " " + s;
                        first           = false;
                    }
                    else
                    {
                        updateSpecific += ", " + s;
                    }
                    string oldVal = sup.GetPreviousValue(conString, emp, @s, empID.ToString());
                }


                try
                {
                    using (SqlConnection connect = new SqlConnection(conString))
                    {
                        connect.Open();
                        using (SqlCommand changeCmd = new SqlCommand())
                        {
                            changeCmd.Connection  = connect;
                            changeCmd.CommandType = CommandType.Text;
                            changeCmd.CommandText = updateString;
                            empID = (Int32)changeCmd.ExecuteScalar();
                            changeCmd.Dispose();
                        }
                        updateSpecific += " WHERE empID=" + empID;
                        using (SqlCommand changeCmd = new SqlCommand())
                        {
                            changeCmd.Connection  = connect;
                            changeCmd.CommandType = CommandType.Text;
                            changeCmd.CommandText = updateSpecific;
                            changeCmd.ExecuteNonQuery();
                            changeCmd.Dispose();
                        }
                    }
                }
                catch (Exception exce)
                {
                }
            }
        }
Esempio n. 3
0
        public void addFtEmp()
        {
            FulltimeEmployee ft         = new FulltimeEmployee();
            bool             isAllValid = true;

            ftfNameError.Text    = "";
            ftlNameError.Text    = "";
            ftSinError.Text      = "";
            ftDOBError.Text      = "";
            ftDateHireError.Text = "";
            ftDateTermError.Text = "";
            ftSalaryError.Text   = "";

            if (!ft.SetFirstName(ftfName.Text) && ftfName.Text != "")
            {
                ftfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                isAllValid         = false;
            }
            if (!ft.SetLastName(ftlName.Text) && ftlName.Text != "")
            {
                ftlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                isAllValid         = false;
            }
            if (!ft.SetSIN(ftSin.Text.Replace(" ", "")) && ftSin.Text != "")
            {
                ftSinError.Text += "<b>SIN</b> should be 9-digit number";
                isAllValid       = false;
            }
            if (!ft.SetDOB(ftDOB.Text.Replace(" ", "")) && ftDOB.Text != "")
            {
                ftDOBError.Text += "<b>Date Of Hire</b> should have valid date format";
                isAllValid       = false;
            }
            if (!ft.SetDateOfHire(ftDateHire.Text.Replace(" ", "")) && ftDateHire.Text != "")
            {
                ftDateHireError.Text += "<b>Date Of Birth</b> should have valid date format";
                isAllValid            = false;
            }
            if ((!ft.SetDateOfTermination(ftDateTerm.Text.Replace(" ", "")) && ftDateTerm.Text != "") || (ftReason.Text == "" && ftDateTerm.Text != ""))
            {
                ftDateTermError.Text += "<b>Date Of Termination</b> should have valid date format";
                isAllValid            = false;
            }
            if (!ft.SetSalary(ftSalary.Text.Replace(" ", "")) && ftSalary.Text != "")
            {
                ftSalaryError.Text += "<b>Salary</b> should be a number higher than 0";
                isAllValid          = false;
            }
            if (isAllValid)
            {
                string activity = "0";
                if (ftDateHire.Text != "" && ftSalary.Text != "" && ftDOB.Text != "" && ftSin.Text != "")
                {
                    activity = "1";
                    if (ftReason.Text != "")
                    {
                        activity = "2";
                    }
                }
                if (addEmpDB("FT", ftCompany.Text, ftfName.Text, ftlName.Text, ftSin.Text, ftDOB.Text, activity))
                {
                    addFtEmpDB(returnID, ftDateHire.Text, ftDateTerm.Text, ftSalary.Text);
                    sucessLbl.Text = ftfName.Text + " Has been succesfully added";
                }
            }
        }