예제 #1
0
        public ActionResult QueryDocument(TotalPODModel model, int?PageIndex)
        {
            var response = new TotalService().GetTotalPODReport(new GetTotalPODRequest()
            {
                PageIndex       = PageIndex ?? 0,
                PageSize        = UtilConstants.PAGESIZE,
                SearchCondition = model.SearchCondition,
                StateID         = model.SearchCondition.StateID
            });

            model.TotalPODCollection = response.Result.TotalPODCollection;
            model.PageIndex          = response.Result.PageIndex;
            model.PageCount          = response.Result.PageCount;
            model.RowCount           = response.Result.RowCount;
            return(View(model));
        }
예제 #2
0
 public ActionResult MessageHistoryQuery(MessageHistoryQueryModel model, int?PageIndex)
 {
     if (model.IsExprot)
     {
         return(this.GetMessageHistoryInfoReport(model));
     }
     else
     {
         GetMessageHistoryQueryRequest request = new GetMessageHistoryQueryRequest()
         {
             SqlWhere = GetSqlWhere(model), PageSize = UtilConstants.PAGESIZE, PageIndex = PageIndex ?? 0
         };
         Response <GetMessageHistoryQueryRequest> Response = new TotalService().GetMessageHistoryInfo(request);
         model.MessageHistoryTable = Response.Result.MessageHistoryTable;
         model.PageIndex           = Response.Result.PageIndex;
         model.PageSize            = Response.Result.PageSize;
         model.PageCount           = Response.Result.PageCount;
     }
     return(View(model));
 }
예제 #3
0
        public ActionResult GetMessageHistoryInfoReport(MessageHistoryQueryModel view)
        {
            string SQL        = this.GetSqlWhere(view);
            string ReportName = "Total短信信息" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
            GetMessageHistoryQueryRequest request = new GetMessageHistoryQueryRequest()
            {
                SqlWhere = GetSqlWhere(view)
            };
            Response <GetMessageHistoryQueryRequest> Response = new TotalService().GetMessageHistoryInfoReport(request);

            DataTable   Exprottable  = Response.Result.MessageHistoryTable;
            ExcelHelper excelHelper  = new ExcelHelper();
            string      targetPath   = Path.Combine(Runbow.TWS.Common.Constants.UPLOAD_FOLDER_PATH, base.UserInfo.ProjectID.ToString(), "Temp");
            string      fileFullPath = Path.Combine(targetPath, ReportName);

            excelHelper.CreateExcelByDataTable(fileFullPath, Exprottable);
            excelHelper.Dispose();

            string     mimeType = "application/msexcel";
            FileStream fs       = MyFile.Open(fileFullPath, FileMode.Open);

            return(File(fs, mimeType, Url.Encode(ReportName)));
        }
예제 #4
0
        public IActionResult Index(SearchBadge vm)
        {
            DateTime yesterday     = DateTime.Today.AddDays(-1);
            var      yesturdayDate = yesterday.ToString(@"ddMMMMyyyy");
            string   yesterdayFile = yesturdayDate + "ClockIn.csv";
            string   yesterdayCsv  = Path.Combine(Environment.CurrentDirectory, @"TimeSheets", yesterdayFile);

            System.Diagnostics.Debug.WriteLine("\nNOsdgfTERDAY##################################### " + yesterdayCsv);
            if (System.IO.File.Exists(yesterdayCsv))
            {
                TotalService ts = new TotalService();
                ts.Total();

                System.Diagnostics.Debug.WriteLine("\nYESsdgfTERDAY##################################### ");
            }
            DateTime today            = DateTime.Today;
            var      date             = today.ToString(@"ddMMMMyyyy");
            string   file             = date + "ClockIn.csv";
            var      _employeeService = new EmployeeService();
            string   fullPath         = Path.Combine(Environment.CurrentDirectory, @"TimeSheets", file);
            var      badgePath        = Path.Combine(Environment.CurrentDirectory, @"Badges.csv");
            var      readPath         = Path.Combine(Environment.CurrentDirectory, @"Castlebar Employee List.csv");

            string clockIn = Path.Combine(Environment.CurrentDirectory, @"ClockIn.csv");

            ViewBag.readPath = readPath;
            ViewBag.clockIn  = clockIn;
            var employeeList = _employeeService.ReadCSVFile(readPath);

            //bool newFile;

            try
            {
                //System.Diagnostics.Debug.WriteLine("badge path.................... " + badgePath);
                string[] records, records2, records3, records4;
                int      list  = 0;
                var      total = employeeList.Count;
                if (System.IO.File.Exists(fullPath))
                {
                    using (var reader = new StreamReader(badgePath, Encoding.Default))
                    {
                        records  = reader.ReadLine().Split(",");
                        records2 = reader.ReadLine().Split(",");
                        records3 = reader.ReadLine().Split(",");
                        records4 = reader.ReadLine().Split(",");
                    }
                    while (list < total)
                    {
                        //System.Diagnostics.Debug.WriteLine("\n\t\tindex\t\t" + list);
                        empName.Add(records[list]);
                        badges.Add(records2[list]);
                        lastClock.Add(records3[list]);
                        inOutStatus.Add(records4[list]);
                        list++;
                    }
                }

                EmployeeService employeeService = new EmployeeService();
                //Here We are calling function to read CSV file
                var resultData = employeeService.ReadCSVFile(readPath);

                if (!System.IO.File.Exists(fullPath))
                {
                    var count    = 0;
                    var empCount = employeeList.Count();

                    List <string> badgeName   = new List <string>();
                    List <string> badgeNumber = new List <string>();
                    List <string> badgeTime   = new List <string>();
                    List <string> badgeInOut  = new List <string>();

                    // Creating Employee Clockin CSV file
                    while (count < empCount)
                    {
                        // Adding column names with employee names
                        badgeName.Add(employeeList.Select(c => c.EmployeeFirstName).ToList().ElementAt(count) + " " + employeeList.Select(c => c.EmployeeLastName).ToList().ElementAt(count));

                        //System.Diagnostics.Debug.WriteLine("\n\t\tname\n" + badgeName[count] + "\n");
                        count++;
                    }
                    count = 0;
                    while (count < empCount)
                    {
                        // Adding column names with employee ID's
                        badgeNumber.Add(employeeList.Select(c => c.Badge).ToList().ElementAt(count));
                        badgeTime.Add("");
                        badgeInOut.Add("");
                        //System.Diagnostics.Debug.WriteLine("\n\t\tnum\n" + badgeNumber[count] + " " + badgeTime[count] + " " + badgeInOut[count] + "\n");
                        count++;
                    }
                    records  = badgeName.ToArray();
                    records2 = badgeNumber.ToArray();
                    records3 = badgeTime.ToArray();
                    records4 = badgeInOut.ToArray();

                    list  = 0;
                    total = employeeList.Count;
                    while (list < total)
                    {
                        empName.Add(records[list]);
                        badges.Add(records2[list]);
                        lastClock.Add(records3[list]);
                        inOutStatus.Add(records4[list]);
                        list++;
                    }

                    //Here We are calling function to read CSV file
                    //newFile = true;
                    int j = 0;
                    while (j < lastClock.Count)
                    {
                        // Adding column names with employee ID's
                        lastClock[j]   = "";
                        inOutStatus[j] = "";
                        j++;
                    }

                    using (StreamWriter sw = new StreamWriter(fullPath, false, new UTF8Encoding(true)))
                        using (CsvWriter cw = new CsvWriter(sw, CultureInfo.InvariantCulture))
                        {
                            int i = 0;
                            empCount = employeeList.Count();

                            // Creating Employee Clockin CSV file
                            while (i < empCount)
                            {
                                // Adding column names with employee names
                                cw.WriteField(employeeList.Select(c => c.EmployeeFirstName).ToList().ElementAt(i) + " " + employeeList.Select(c => c.EmployeeLastName).ToList().ElementAt(i));

                                i++;
                            }
                            cw.NextRecord();
                            i = 0;
                            while (i < empCount)
                            {
                                // Adding column names with employee ID's
                                cw.WriteField(employeeList.Select(c => c.EmployeeId).ToList().ElementAt(i));
                                i++;
                            }
                        }
                }
                else
                {
                    //newFile = false;
                }

                var scannedEmployeeInd = -1;
                // Outputting Employee Details when Scanned
                // and Time of Clock In/Out
                var    empBadge = vm.Badge;
                string inOut    = "In";
                if (empBadge != null && empBadge.Length > 4)
                {
                    Employee scannedEmployee = resultData.Find(x => x.Badge.Contains(empBadge));
                    if (scannedEmployee == null)
                    {
                        ViewBag.time = "This user does not exist yet";
                    }
                    else
                    {
                        var scannedEmpName = scannedEmployee.EmployeeFirstName + " " + scannedEmployee.EmployeeLastName;

                        Employee employee = new Employee();
                        employee.EmployeeId        = scannedEmployee.EmployeeId;
                        employee.EmployeeLastName  = scannedEmployee.EmployeeLastName;
                        employee.EmployeeFirstName = scannedEmployee.EmployeeFirstName;
                        employee.Status            = scannedEmployee.Status;
                        employee.Badge             = scannedEmployee.Badge;

                        ViewBag.scanEmpName = scannedEmployee.EmployeeFirstName + " " + scannedEmployee.EmployeeLastName;
                        ViewBag.time        = DateTime.Now;
                        var empTime = ViewBag.time;


                        string[] values = null;
                        try
                        {
                            using (var reader = new StreamReader(fullPath))
                            {
                                var linee = reader.ReadLine();
                                values = linee.Split(',');
                            }
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine(e.Message);
                        }

                        //var name = values.ToArray();
                        var scannedEmployeeIndex = Array.IndexOf(values, scannedEmpName);
                        scannedEmployeeInd = scannedEmployeeIndex;

                        var count    = 0;
                        var empCount = employeeList.Count();
                        // Creating Employee Clockin CSV file
                        while (count < empCount)
                        {
                            // Adding column names with employee names
                            badges.Add(employeeList.Select(c => c.EmployeeFirstName).ToList().ElementAt(count) + " " + employeeList.Select(c => c.EmployeeLastName).ToList().ElementAt(count));

                            count++;
                        }
                        //cw.NextRecord();
                        count = 0;
                        while (count < empCount)
                        {
                            // Adding column names with employee ID's
                            empName.Add(employeeList.Select(c => c.Badge).ToList().ElementAt(count));
                            count++;
                        }

                        if (lastClock[scannedEmployeeIndex] == "")
                        {
                            lastClock[scannedEmployeeIndex] = empTime.ToString("HH:mm:ss");
                        }
                        else
                        {
                            var currTime = DateTime.Now;
                            currTime = currTime.AddMinutes(-5);

                            var parsedDate = DateTime.Parse(lastClock[scannedEmployeeIndex]);

                            var currentTime = currTime.ToString("HH:mm:ss");
                            var g           = DateTime.Compare(parsedDate, currTime);
                            System.Diagnostics.Debug.WriteLine(currTime);
                            if (g > 0)
                            {
                                wait         = true;
                                ViewBag.time = "PLEASE WAIT 5 MINS. You are \nClocked " + inOutStatus[scannedEmployeeIndex];
                            }
                            else
                            {
                                wait = false;
                                lastClock[scannedEmployeeIndex] = empTime.ToString("HH:mm:ss");
                            }
                        }

                        //reading in from clock in file to add a clock in
                        StreamReader sr       = new StreamReader(fullPath);
                        var          lines    = new List <string[]>();
                        int          Row      = 0;
                        int          colCount = 0;
                        while (!sr.EndOfStream)
                        {
                            string[] Line = sr.ReadLine().Split(',');
                            lines.Add(Line);
                            colCount = Line.Length;
                            Row++;
                        }
                        sr.Close();

                        var  row   = 0;
                        bool added = false;
                        while (row < lines.Count && wait == false)
                        {
                            if (lines[row][scannedEmployeeIndex].Equals(""))
                            {
                                DateTime now      = empTime;
                                string   asString = now.ToString("HH:mm:ss");
                                if (row % 2 == 0)
                                {
                                    inOut = "In";
                                }
                                else
                                {
                                    inOut = "Out";
                                }
                                //asString = String.Concat(inOut, asString);
                                asString     = inOut + " " + asString;
                                ViewBag.time = ViewBag.time + " \nClocked " + inOut;
                                lines[row][scannedEmployeeIndex] = asString;
                                row   = lines.Count;
                                added = true;
                            }
                            row++;

                            // if checked all row and data has not been added
                            if (row == lines.Count && added == false)
                            {
                                //System.Diagnostics.Debug.WriteLine("not added");
                                string[] Line = new string[colCount];
                                lines.Add(Line);

                                DateTime now      = empTime;
                                string   asString = now.ToString("HH:mm:ss");
                                if (row % 2 == 0)
                                {
                                    inOut = "In";
                                }
                                else
                                {
                                    inOut = "Out";
                                }
                                asString     = inOut + " " + asString;
                                ViewBag.time = ViewBag.time + " \nClocked " + inOut;
                                lines[row][scannedEmployeeIndex] = asString;
                                row++;
                            }
                        }

                        //Writing out to file with updated clock ins
                        using (StreamWriter sw = new StreamWriter(fullPath, false, new UTF8Encoding(true)))
                            using (CsvWriter cw = new CsvWriter(sw, CultureInfo.InvariantCulture))
                            {
                                //cw.NextRecord();
                                int i        = 0;
                                int j        = 0;
                                int rowCount = lines.Count();

                                // Creating Employee Clockin CSV file
                                while (i < rowCount)
                                {
                                    j = 0;
                                    while (j < colCount)
                                    {
                                        // Adding column names with employee ID's
                                        cw.WriteField(lines[i][j]);
                                        j++;
                                    }
                                    // Adding column names with employee names
                                    cw.NextRecord();

                                    i++;
                                }
                            }
                    }
                }
                else if (empBadge != null)
                {
                    ViewBag.time = "This user does not exist yet";
                    StartCounter();
                }
                if (wait == false)
                {
                    using (StreamWriter sw = new StreamWriter(badgePath, false, new UTF8Encoding(true)))
                        using (CsvWriter cw = new CsvWriter(sw, CultureInfo.InvariantCulture))
                        {
                            //cw.WriteField(DateTime.Now.DayOfWeek.ToString() + " " + date);
                            //cw.NextRecord();
                            int i        = 0;
                            int empCount = employeeList.Count();

                            // Creating Employee Clockin CSV file
                            while (i < empCount)
                            {
                                // Adding column names with employee names
                                cw.WriteField(employeeList.Select(c => c.EmployeeFirstName).ToList().ElementAt(i) + " " + employeeList.Select(c => c.EmployeeLastName).ToList().ElementAt(i));

                                i++;
                            }
                            cw.NextRecord();
                            i = 0;
                            while (i < empCount)
                            {
                                // Adding column names with employee ID's
                                cw.WriteField(employeeList.Select(c => c.Badge).ToList().ElementAt(i));
                                i++;
                            }
                            cw.NextRecord();
                            i = 0;
                            while (i < empCount)
                            {
                                // Adding column names with employee ID's
                                cw.WriteField(lastClock[i]);
                                i++;
                            }
                            cw.NextRecord();
                            i = 0;
                            while (i < empCount)
                            {
                                // Adding column names with employee ID's
                                if (scannedEmployeeInd == i)
                                {
                                    cw.WriteField(inOut);
                                }
                                else
                                {
                                    cw.WriteField(inOutStatus[i]);
                                }
                                i++;
                            }
                        }
                }
                if (clear == true)
                {
                    ViewBag.time = "";
                    clear        = false;
                }
                ModelState.Clear();
                return(View());
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                ViewBag.time  = "";
                ViewBag.error = "Clock in failed. Please try again";
                ModelState.Clear();
                return(View());
            }
        }