Ejemplo n.º 1
0
        public void GetMyLeaves(int empId)
        {
            //List<LeavesModel> lstLeaves = new List<LeavesModel>();
            try
            {
                CsvParser objCsvParser = new CsvParser();

                DataTable dt = new DataTable();

                dt = objCsvParser.GetDataTableFromCSV(leavesCsvPath);

                if (dt != null && dt.Rows.Count > 0)
                {
                    List <string> lstColumnNames = new List <string>();
                    string[]      columnNames    = { };

                    foreach (DataColumn dc in dt.Columns)
                    {
                        lstColumnNames.Add(dc.ColumnName);
                    }

                    columnNames = lstColumnNames.ToArray();

                    dt.TableName = "My Leaves";

                    DataView dv = new DataView(dt);
                    dv.RowFilter = "CreatorId=" + empId;

                    Console.WriteLine("===================================================================");

                    PrintDataExtensions.Print(dv, columnNames);

                    Console.WriteLine("===================================================================");
                }

                //return lstLeaves;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void SearchLeaves(int empId, string searchOption)
        {
            try
            {
                CsvParser objCsvParser = new CsvParser();
                DataTable dt           = new DataTable();
                dt = objCsvParser.GetDataTableFromCSV(leavesCsvPath);

                DataView dv = new DataView(dt);

                List <string> lstColumnNames = new List <string>();
                string[]      columnNames    = { };
                foreach (DataColumn dc in dt.Columns)
                {
                    lstColumnNames.Add(dc.ColumnName);
                }
                columnNames = lstColumnNames.ToArray();

                if (searchOption == "1")
                {
                    Console.WriteLine("Enter Title");
                    string titleToSearch = Console.ReadLine();

                    dt.TableName = "Searched Leaves By Title = " + titleToSearch;

                    dv.RowFilter = "CreatorId = " + empId + "and Title like '%" + titleToSearch + "%'";

                    Console.WriteLine("===========================================================================================");
                    if (dv.Count > 0)
                    {
                        PrintDataExtensions.Print(dv, columnNames);
                        Console.WriteLine("* " + dv.Count + " record(s) found.");
                    }
                    else
                    {
                        Console.WriteLine("There are no matching records.");
                    }
                    Console.WriteLine("===========================================================================================");
                }
                else if (searchOption == "2")
                {
                    Console.WriteLine("Please select the status to search");
                    Console.WriteLine("1. Pending");
                    Console.WriteLine("2. Approved");
                    Console.WriteLine("3. Rejected");
                    string statusChoice = Console.ReadLine();
                    Console.WriteLine("-------------------------------------------------------------------------------------------");

                    switch (statusChoice)
                    {
                    case "1":
                        dt.TableName = "Pending Leaves.";
                        dv.RowFilter = "CreatorId = " + empId + "and Status = 'Pending'";
                        break;

                    case "2":
                        dt.TableName = "Approved Leaves.";
                        dv.RowFilter = "CreatorId = " + empId + "and Status = 'Approved'";
                        break;

                    case "3":
                        dt.TableName = "Rejected Leaves.";
                        dv.RowFilter = "CreatorId = " + empId + "and Status = 'Rejected'";
                        break;

                    default:
                        Console.WriteLine("Wrong Choice.");
                        break;
                    }

                    Console.WriteLine("===========================================================================================");
                    if (dv.Count > 0)
                    {
                        PrintDataExtensions.Print(dv, columnNames);
                        Console.WriteLine("* " + dv.Count + " record(s) found.");
                    }
                    else
                    {
                        Console.WriteLine("There are no matching records.");
                    }
                    Console.WriteLine("===========================================================================================");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public bool UpdateLeaves(int empId)
        {
            try
            {
                CsvParser objCsvParser = new CsvParser();

                DataTable dt = new DataTable();

                dt = objCsvParser.GetDataTableFromCSV(leavesCsvPath);

                if (dt != null && dt.Rows.Count > 0)
                {
                    List <string> lstColumnNames = new List <string>();
                    string[]      columnNames    = { };

                    foreach (DataColumn dc in dt.Columns)
                    {
                        lstColumnNames.Add(dc.ColumnName);
                    }

                    columnNames = lstColumnNames.ToArray();

                    dt.TableName = "Leaves Assigned to me";

                    DataRow[] drEmp = dt.Select("ManagerId = " + empId);

                    Console.WriteLine("===================================================================");

                    //DataView dv = new DataView(dt);
                    //dv.RowFilter = "ManagerId=" + empId;
                    //PrintDataExtensions.Print(dv, columnNames);

                    PrintDataExtensions.Print(drEmp, columnNames);

                    Console.WriteLine("Please choose one of the options below.");
                    Console.WriteLine("1. Update Specific Leave by entering Leave ID");
                    Console.WriteLine("2. Approve All");
                    Console.WriteLine("3. Reject All");

                    string updateLeaveOption = Console.ReadLine();

                    int oldTblRowCount = dt.Rows.Count;

                    switch (updateLeaveOption)
                    {
                    case "1":
                        Console.WriteLine("Enter Leave ID:");
                        string leaveID = Console.ReadLine();

                        bool isLeaveExist = false;

                        foreach (var dr in drEmp)
                        {
                            if (dr.Field <string>("ID") == leaveID)
                            {
                                isLeaveExist = true;
                                break;
                            }
                        }

                        if (!isLeaveExist)
                        {
                            Console.WriteLine("Leave with ID=" + leaveID + " not found.");
                            return(false);
                        }
                        else
                        {
                            Console.WriteLine("Choose option to change the status.");
                            Console.WriteLine("1. Approve");
                            Console.WriteLine("2. Reject");
                            Console.WriteLine("3. Pending");

                            string newStatusOption = Console.ReadLine();

                            if (string.IsNullOrEmpty(newStatusOption))
                            {
                                Console.WriteLine("Error while accepting option.");
                            }
                            else
                            {
                                if (newStatusOption == "1" || newStatusOption == "2" || newStatusOption == "3")
                                {
                                    string newStatus = newStatusOption == "1" ? "Approved" : newStatusOption == "2" ? "Rejected" : "Pending";

                                    foreach (DataRow dr in dt.Rows)
                                    {
                                        if (dr["ID"].ToString() == leaveID)
                                        {
                                            dr.BeginEdit();
                                            dr["Status"] = newStatus;
                                            dr.EndEdit();

                                            dt.AcceptChanges();
                                            break;
                                        }
                                    }

                                    if (oldTblRowCount == dt.Rows.Count)
                                    {
                                        bool isUpdated = objCsvParser.UpdateCsvFromDataTable(dt, leavesCsvPath);

                                        if (isUpdated)
                                        {
                                            return(true);
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("Something went wrong.");
                                        return(false);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Wrong choice.");
                                }
                            }
                        }

                        break;

                    case "2":

                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["ManagerId"].ToString() == empId.ToString())
                            {
                                dr.BeginEdit();
                                dr["Status"] = "Approved";
                                dr.EndEdit();

                                dt.AcceptChanges();
                            }
                        }

                        if (oldTblRowCount == dt.Rows.Count)
                        {
                            bool isUpdated = objCsvParser.UpdateCsvFromDataTable(dt, leavesCsvPath);

                            if (isUpdated)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Something went wrong.");
                            return(false);
                        }

                        break;

                    case "3":

                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["ManagerId"].ToString() == empId.ToString())
                            {
                                dr.BeginEdit();
                                dr["Status"] = "Rejected";
                                dr.EndEdit();

                                dt.AcceptChanges();
                            }
                        }

                        if (oldTblRowCount == dt.Rows.Count)
                        {
                            bool isUpdated = objCsvParser.UpdateCsvFromDataTable(dt, leavesCsvPath);

                            if (isUpdated)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Something went wrong.");
                            return(false);
                        }
                        break;

                    default:
                        Console.WriteLine("Wrong Choice.");
                        break;
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }