Example #1
0
        public void WriteFixedIDs(string FolderPath, string FileName)
        {
            string fileName             = Path.Combine(FolderPath, FileName);
            var    file2UnknownID_Datas = File2Datas.Where((data) => ErrorIDs.Contains(data.ID));

            file2UnknownID_Datas.ToList().Sort((a, b) => a.ID.CompareTo(b.ID));

            //fixed
            foreach (var item in file2UnknownID_Datas)
            {
                var data = File1Datas.FirstOrDefault((_data) => _data.Name == item.Name);
                if (data != null)
                {
                    item.ID  = data.ID;
                    item.Dep = data.Dep;
                }
            }

            file2UnknownID_Datas.ToList().Sort((a, b) => a.Dep.CompareTo(b.Dep));

            using (var file = new StreamWriter(File.OpenWrite(fileName), Encoding.UTF8))
            {
                file.WriteLine(File2Fields);
                foreach (var item in file2UnknownID_Datas)
                {
                    var data = File1Datas.FirstOrDefault((_data) => _data.Name == item.Name);
                    if (data != null)
                    {
                        file.WriteLine(item.ToString());
                    }
                }
            }
        }
Example #2
0
 public void FixedOkIDsDep()
 {
     OKFile2Datas.Clear();
     OKFile2Datas.AddRange(File2Datas.Where((data) => OkIDs.Contains(data.ID)));
     foreach (var data in OKFile2Datas)
     {
         data.Dep  = File1Datas.First((item) => item.ID == data.ID).Dep;
         data.Name = File1Datas.First((item) => item.ID == data.ID).Name;
     }
 }
Example #3
0
        public void CheckIDsIsAllFound()
        {
            //問卷Data
            var WrittenIDs = File2Datas.Select((data) => data.ID);

            //已填的ID 與 人事Data id 比對
            OkIDs.Clear();
            OkIDs.AddRange(File1Datas.Where((data) => WrittenIDs.Contains(data.ID)).Select((data) => data.ID));

            //已填的ID但未從人事資料中找到
            ErrorIDs.Clear();
            ErrorIDs.AddRange(WrittenIDs.Except(OkIDs));

            //尚未填寫的IDs
            NotWriteIDs.Clear();
            NotWriteIDs.AddRange(File1Datas.Where((data) => !OkIDs.Contains(data.ID)).Select(data => data.ID));
        }
Example #4
0
        public void WriteUnKnownIDs_SortByID(string FolderPath, string FileName)
        {
            string fileName             = Path.Combine(FolderPath, FileName);
            var    file2UnknownID_Datas = File2Datas.Where((data) => ErrorIDs.Contains(data.ID));

            file2UnknownID_Datas.ToList().Sort((a, b) => a.ID.CompareTo(b.ID));
            using (var file = new StreamWriter(File.OpenWrite(fileName), Encoding.UTF8))
            {
                file.WriteLine(File2Fields);
                foreach (var item in file2UnknownID_Datas)
                {
                    if (int.TryParse(item.ID, out int _id))
                    {
                        file.WriteLine(item.ToString());
                    }
                }
            }
        }
Example #5
0
        public void CollectFile2Datas()
        {
            var    reader    = new StreamReader(File.OpenRead(Selected2FileName));
            string fieldLine = reader.ReadLine();

            File2Fields = fieldLine;
            var Fields = fieldLine.Split(new char[] { ',' }).Select((item) => item.Trim()).ToList();

            //Mapping
            File2Mapping.Clear();
            File2Mapping.Add(File2SortID, Fields.IndexOf(File2SortID));
            File2Mapping.Add(File2SortDep, Fields.IndexOf(File2SortDep));
            File2Mapping.Add(File2SortName, Fields.IndexOf(File2SortName));

            File2Datas.Clear();
            while (!reader.EndOfStream)
            {
                var line        = reader.ReadLine();
                var values      = line.Split(',').Select((item) => item.Trim()).ToList();
                var othersValue = values.Where(
                    (item) =>
                    File2Mapping[File2SortID] != values.IndexOf(item) &&
                    File2Mapping[File2SortDep] != values.IndexOf(item) &&
                    File2Mapping[File2SortName] != values.IndexOf(item));
                File2Data f2d = new File2Data
                                (
                    id: values[File2Mapping[File2SortID]],
                    name: values[File2Mapping[File2SortName]],
                    dep: values[File2Mapping[File2SortDep]],
                    others: string.Join(",", othersValue)
                                );
                File2Datas.Add(f2d);
            }

            reader.Close();
            reader.Dispose();
        }