// cardInfo : [카드ID(8)][버스번호(7)][승차/하차 코드(1)][최근 승차시각(14)] // sample : CARD_001BUS_001N20171019143610 public void InspectCard(string startTime, string id, string busID, string cardInfo) { string strValidateCode; // cardInfo parsing //string cardID = cardInfo.Substring(0, 8); string cardBusID = cardInfo.Substring(8, 7); string code = cardInfo.Substring(15, 1); string rideTime = cardInfo.Substring(16); // Get Inspect Time string strInspectTime = DateTime.Now.ToString("yyyyMMddHHmmss"); // Validation // 1. Bus ID Match if (busID.Equals(cardBusID)) { // 2. Check Aboard Code if (code.Equals("N")) { // 3. Time Difference if (CardUtility.HourDiff(strInspectTime, rideTime) < 3) { strValidateCode = "R1"; } else { strValidateCode = "R4"; } } else { strValidateCode = "R3"; } } else { strValidateCode = "R2"; } // Create Folder string destFolder = "..\\..\\..\\" + id; System.IO.Directory.CreateDirectory(destFolder); // File Writing string strFilename = destFolder + "\\" + id + "_" + startTime + ".TXT"; string strWrite = id + "#" + busID + "#" + cardInfo + "#" + strValidateCode + "#" + strInspectTime + "\n"; FileStream fs = new System.IO.FileStream(strFilename, FileMode.Append); fs.Write(Encoding.UTF8.GetBytes(strWrite), 0, strWrite.Length); fs.Close(); }
public static void validate(string inputStr) { string card_id = inputStr.Substring(0, 8); string bus_id = inputStr.Substring(8, 7); string code = inputStr.Substring(15, 1); string time = inputStr.Substring(16, 14); string insptTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string inspecting; if (Bus_id.Equals(bus_id)) { // 2. Check Aboard Code if (code.Equals("N")) { // 3. Time Difference if (CardUtility.HourDiff(insptTime, time) < 3) { inspecting = "R1"; } else { inspecting = "R4"; } } else { inspecting = "R3"; } } else { inspecting = "R2"; } string result = Inspector + "#" + bus_id + "#" + inputStr + "#" + inspecting + "#" + insptTime + "\n"; if (!File.Exists(PathString)) { // Create a file to write to. File.WriteAllText(PathString, result); } else { File.AppendAllText(PathString, result); } }