Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace KioskLibrary
- {
- public class coStatistiques
- {
- private static readonly string _statsFile = "/KioskStats";
- private static readonly string _filePath =
- Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
- /// <summary>
- /// Ifs the file exist.
- /// </summary>
- /// <param name="weekNum">The week number.</param>
- /// <returns></returns>
- /// =====================================================================================
- /// Modification : Initial : 17/04/2018 | N.WILCKE (SESA474351)
- /// =====================================================================================
- public static bool IfFileExist(int weekNum)
- {
- try
- {
- if (File.Exists(_filePath + _statsFile + "." + weekNum + "." + DateTime.Now.Year + ".txt")) return true;
- return false;
- }
- catch
- {
- return false;
- }
- }
- /// <summary>
- /// Whats kind of project is it.
- /// </summary>
- /// <param name="number">The number.</param>
- /// <returns></returns>
- /// =====================================================================================
- /// Modification : Initial : 17/04/2018 | N.WILCKE (SESA474351)
- /// =====================================================================================
- public static string WhatIsIt(string number)
- {
- try
- {
- switch (number.Substring(0, 1))
- {
- case "4":
- return "ODT";
- case "7":
- return "CRT";
- case "9":
- return "CRT";
- case "8":
- return "MPT";
- }
- return "NA";
- }
- catch
- {
- return "ERROR";
- }
- }
- /// <summary>
- /// Writes the stats.
- /// </summary>
- /// <param name="number">The number.</param>
- /// <param name="writtenNumber">The written number. (numero de projet ou d'OF)</param>
- /// <param name="IsProject">if set to <c>true</c> [is project].</param>
- /// <param name="user">The user.</param>
- /// =====================================================================================
- /// Modification : Initial : 17/04/2018 | N.WILCKE (SESA474351)
- /// =====================================================================================
- public static void WriteStats(string number, string writtenNumber, bool IsProject, string user)
- {
- try
- {
- // CRT ODT or MPT
- var projectType = WhatIsIt(number);
- var isProjectText = "";
- var weekNum = DateTime.Now.DayOfYear / 7;
- if (IsProject)
- isProjectText = "Projet";
- else
- isProjectText = "OF";
- if (IfFileExist(weekNum))
- File.AppendAllText(_filePath + _statsFile + "." + weekNum + "." + DateTime.Now.Year + ".txt",
- isProjectText + ";" + projectType + ";" + writtenNumber + ";" + weekNum + ";" +
- DateTime.Now.ToLongDateString() + ";" + DateTime.Now.ToLongTimeString() + Environment.NewLine);
- else
- using (var sw =
- File.CreateText(_filePath + _statsFile + "." + weekNum + "." + DateTime.Now.Year + ".txt"))
- {
- sw.WriteLine(isProjectText + ";" + projectType + ";" + writtenNumber + ";" + weekNum + ";" +
- DateTime.Now.ToLongDateString() + ";" + DateTime.Now.ToLongTimeString());
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// Reads the stats.
- /// </summary>
- /// <param name="weekNum">The week number.</param>
- /// <param name="date">The date.</param>
- /// <returns></returns>
- /// =====================================================================================
- /// Modification : Initial : 17/04/2018 | N.WILCKE (SESA474351)
- /// =====================================================================================
- public static List<string> ReadStats(string weekNum, int date)
- {
- var stats = new List<string>();
- var weekString = weekNum.Split(',');
- var test = _filePath + "\\" + weekNum;
- if (File.Exists(test))
- {
- var file = File.ReadAllLines(test);
- for (var j = 0; j < file.Length; j += 1)
- {
- var line = file[j];
- stats.Add(line);
- }
- return stats;
- }
- return stats;
- }
- public static List<List<string>> ReadAllStats()
- {
- List<List<string>> allWeeks = new List<List<string>>();
- return allWeeks;
- }
- /// <summary>
- /// Gets existing weeks.
- /// </summary>
- /// <returns></returns>
- /// =====================================================================================
- /// Modification : Initial : 17/04/2018 | N.WILCKE (SESA474351)
- /// =====================================================================================
- public static Dictionary<int, int> GetWeeks()
- {
- try
- {
- var semaines = new Dictionary<int, int>();
- var firstWeek = 15; // First week of stats
- var firstYear = 2018; // First Year of stats
- var weekNum = DateTime.Now.DayOfYear / 7; // Current week number
- while (firstYear < firstYear + 1)
- {
- while (firstWeek <= weekNum)
- {
- if (File.Exists(_filePath + _statsFile + "." + firstWeek + "." + firstYear + ".txt"))
- semaines.Add(firstWeek, firstYear);
- firstWeek++;
- if (firstWeek == 52)
- {
- firstYear++;
- firstWeek = 1;
- }
- }
- }
- return semaines;
- }
- catch
- {
- var semaines = new Dictionary<int, int>();
- return semaines;
- }
- }
- public static List<Tuple<int, int, int>> GetAllWeeks()
- {
- try
- {
- var semaines = new List<Tuple<int, int, int>>();
- var firstWeek = 15; // First week of stats
- var firstYear = 2018; // First Year of stats
- var weekNum = DateTime.Now.DayOfYear / 7; // Current week number
- while (firstWeek <= weekNum && firstYear < firstYear + 1)
- {
- if (File.Exists(_filePath + _statsFile + "." + firstWeek + "." + firstYear + ".txt"))
- {
- int lines = 0;
- using (TextReader reader = File.OpenText(_filePath + _statsFile + "." + firstWeek + "." + firstYear + ".txt"))
- {
- while (reader.ReadLine() != null) { lines++; }
- }
- semaines.Add(new Tuple<int, int, int>(firstWeek, firstYear, lines));
- }
- firstWeek++;
- if (firstWeek == 52)
- {
- firstYear++;
- firstWeek = 1;
- }
- }
- return semaines;
- }
- catch
- {
- var semaines = new List<Tuple<int, int, int>>();
- return semaines;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement