public void AddRecord(PeopleInfo record) { if ( m_people.ContainsKey( record.Name)) { List<PeopleInfo> recordlist = m_people[record.Name]; foreach(PeopleInfo people in recordlist) { if (people == record) { return; } } recordlist.Add(record); } else { List<PeopleInfo> recordlist = new List<PeopleInfo>(); PeopleInfo p = new PeopleInfo(record); recordlist.Add(p); m_people.Add(record.Name, recordlist); } }
public PeopleInfo(PeopleInfo p) { m_name = p.Name; m_no = p.No; m_address = p.Address; m_age = p.Age; m_sex = p.Sex; }
public Record(Record record) { m_p = record.People; m_diagnose = record.Diagnose; m_allcost = record.AllCost; m_compensation = record.Compensation; m_date = record.Date; }
public Record(PeopleInfo p, string diagose, float allcost, float compensation, string date) { m_p = p; m_diagnose = diagose; m_allcost = allcost; m_compensation = compensation; m_date = date; }
public Record(string name, string no, float age, string address, string sex, string diagose, float allcost, float compensation, string date) { m_diagnose = diagose; m_allcost = allcost; m_compensation = compensation; m_date = date; m_p = new PeopleInfo(name,no,age,address,sex); }
private void InitDataStructure() { if (String.IsNullOrEmpty(m_filePath) || !File.Exists(m_filePath)) { // default path ./data/DB.cs m_filePath = ".\\data\\DB.csv"; } if (!File.Exists(m_filePath)) { // there is no smart buffer file return; } using (CsvReader csv = new CsvReader(new StreamReader(m_filePath, Encoding.GetEncoding("gb2312")), true)) { int fieldCount = csv.FieldCount; int lineNumber = 0; while (csv.ReadNextRecord()) { for (int i = 0; i < fieldCount; i++) { if (String.IsNullOrEmpty(csv[i].Trim())) { continue; } // Console.WriteLine("{0}: {1} {2} {3} {4} {5}", lineNumber, // csv[0],csv[1],csv[2],csv[3],csv[4]); } if (!String.IsNullOrEmpty(csv[0].Trim())) { string address = csv[0].Trim(); string no = csv[1].Trim(); string tname = csv[2].Trim(); string name = tname.Replace(" ", ""); float age = float.Parse(csv[3].Trim()); string sex = csv[4].Trim(); PeopleInfo people = new PeopleInfo(name, no, age, address, sex); AddRecord(people); } lineNumber++; } } }
public void SaveFile(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } FileStream fs = new FileStream(path, FileMode.Create); StreamWriter streamWriter = new StreamWriter(fs, Encoding.GetEncoding("gb2312")); string header = @"乡村名称,合疗证号,患者姓名,年龄,性别,"; streamWriter.WriteLine(header); foreach (KeyValuePair <string, List <PeopleInfo> > pair in m_people) { PeopleInfo p = pair.Value.First(); string record = p.Address + "," + p.No + "," + p.Name + "," + p.Age + "," + p.Sex + ","; streamWriter.WriteLine(record); } streamWriter.Flush(); fs.Close(); }
public void AddRecord(PeopleInfo record) { if (m_people.ContainsKey(record.Name)) { List <PeopleInfo> recordlist = m_people[record.Name]; foreach (PeopleInfo people in recordlist) { if (people == record) { return; } } recordlist.Add(record); } else { List <PeopleInfo> recordlist = new List <PeopleInfo>(); PeopleInfo p = new PeopleInfo(record); recordlist.Add(p); m_people.Add(record.Name, recordlist); } }
private void InitDataStructure() { if (String.IsNullOrEmpty(m_filePath) || !File.Exists(m_filePath)) { // default path ./data/DB.cs m_filePath = ".\\data\\DB.csv"; } if(!File.Exists(m_filePath)) { // there is no smart buffer file return; } using (CsvReader csv = new CsvReader(new StreamReader(m_filePath, Encoding.GetEncoding("gb2312")), true)) { int fieldCount = csv.FieldCount; int lineNumber = 0; while (csv.ReadNextRecord()) { for (int i = 0; i < fieldCount; i++) { if (String.IsNullOrEmpty(csv[i].Trim()) ) { continue; } // Console.WriteLine("{0}: {1} {2} {3} {4} {5}", lineNumber, // csv[0],csv[1],csv[2],csv[3],csv[4]); } if (! String.IsNullOrEmpty(csv[0].Trim())) { string address = csv[0].Trim(); string no = csv[1].Trim(); string tname = csv[2].Trim(); string name = tname.Replace(" ", ""); float age = float.Parse(csv[3].Trim()); string sex = csv[4].Trim(); PeopleInfo people = new PeopleInfo(name, no, age, address, sex); AddRecord(people); } lineNumber++; } } }