private void Clone(TimeSheetPerson cloneTarget)
 {
     Name       = cloneTarget.Name;
     Id         = cloneTarget.Id;
     RoleCode   = cloneTarget.RoleCode;
     Department = cloneTarget.Department;
     DeptCode   = cloneTarget.DeptCode;
 }
 public string GetCroppedExcelFile(string xlsFileName, TimeSheetPerson cropSinglePerson, string delim = "|", bool crop = true)
 {
     return(GetCroppedExcelFile(
                xlsFileName,
                DateTime.Now.ToString("MMM"),
                cropSinglePerson.Name,
                "Total",
                delim,
                crop));
 }
        private static TimeSheetPerson NameRowToPerson(Dictionary <string, string> Cells)
        {
            var person = new TimeSheetPerson();

            person.Name       = Cells[HomeRow];
            person.Id         = Cells["K"];
            person.Role       = Cells["Q"];
            person.RoleCode   = Cells["Z"];
            person.Department = Cells["AD"];
            person.DeptCode   = Cells["AM"];
            return(person);
        }
예제 #4
0
        static void Main(string[] args)
        {
            const string DELIMITER   = "|";
            var          xls         = @"C:\Users\morrisow\OneDrive\Documents\00 Work Docs\Copy-of-471.xlsx";
            var          helper      = new XLSXHelper();
            var          emptyPerson = new TimeSheetPerson();

            var output = helper.GetCroppedExcelFile(xls, emptyPerson, DELIMITER, crop: false);

            var people = SplitOnPerson(output, DELIMITER);

            Console.WriteLine("people: {0}", people.Count);
            foreach (var person in people)
            {
                var croppedChunk = helper.GetCroppedExcelFile(xls, person, DELIMITER, crop: true);
                person.FillValuesFromTimeSheetChunk(croppedChunk);
                Console.WriteLine(person.ToString());
            }
        }
        private static bool IsPersonRow(string[] columns, RowType stickyRowType, out TimeSheetPerson person)
        {
            var Cells = GetSingleColumnExcelDict(columns);

            person = new TimeSheetPerson();
            if (!Cells.Any())
            {
                return(false);
            }
            person = NameRowToPerson(Cells);
            int Id       = -1;
            int roleCode = -1;

            // There is one case that passes the test below - DATES row.
            double dateNotName = 0;

            if (double.TryParse(person.Name, out dateNotName) &&
                DateTime.FromOADate(dateNotName).Month == DateTime.Now.Month)
            {
                // This is a Date row, not a person row.
                return(false);
            }

            try
            {
                if (!String.IsNullOrWhiteSpace(person.Name) &&
                    Int32.Parse(person.Id) > 0 &&
                    !String.IsNullOrWhiteSpace(person.Role) &&
                    Int32.Parse(person.RoleCode) > 0 &&
                    !String.IsNullOrWhiteSpace(person.Department) &&
                    !String.IsNullOrWhiteSpace(person.DeptCode)
                    )
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                // It's ok
            }
            return(false);
        }
        public static List <TimeSheetPerson> SplitOnPerson(string output, string delim = "|")
        {
            var results = new List <TimeSheetPerson>();
            //Console.WriteLine(output);

            // First row we're getting is Person's Name
            var lines         = output.Split("\r\n");
            var stickyRowType = RowType.Name; // Init with Name first...

            foreach (var line in lines)
            {
                var columns = line.Split(delim);
                var person  = new TimeSheetPerson();
                if (IsPersonRow(columns, stickyRowType, out person))
                {
                    results.Add(person);
                }
            }
            return(results);
        }
 public TimeSheetPerson(TimeSheetPerson cloneTarget)
 {
     this.Clone(cloneTarget);
 }