// Nhập các loại xe từ bàn phím public void Nhap() { Console.Write("Nhập số lượng loại xe: "); try { do { n = int.Parse(Console.ReadLine()); if (n < 0 || n > maxsize) { System.Console.WriteLine("N quá lớn hoặc quá nhỏ, 0 <= N <= {0}.\nNhập lại n:", maxsize); } } while (n < 0 || n > maxsize); } catch (Exception ex) { n = 0; ErrorLogs el = new ErrorLogs(ex.ToString()); el.write(); } for (int i = 0; i < n; i++) { Console.Write("Nhập tên loại xe thứ {0}: ", i + 1); string s; s = Console.ReadLine(); dsLoai[i] = s; } Console.WriteLine("Đã nhập {0} loại xe", n); }
//------------------------------------------------------------------------------------------------------------------------------ public void Nhap() { Console.Write("Nhập số lượng xe: "); try { do { n = int.Parse(Console.ReadLine()); if (n < 0 || n > maxsize) { System.Console.WriteLine("Số lượng xe (N) quá lớn hoặc quá nhỏ, 0 <= N <= {0}.\nNhập lại N:", maxsize); } } while (n < 0 || n > maxsize); } catch (Exception ex) { n = 0; ErrorLogs el = new ErrorLogs(ex.ToString()); el.write(); } for (int i = 0; i < n; i++) { Console.WriteLine("Nhập tên thông tin xe thứ {0}: ", i + 1); dsXE[i] = new Xe(); dsXE[i].Nhap(); } Console.WriteLine("Đã nhập {0} xe", n); }
/* * Trả về tên loại ứng với mã loại * * @param int c Mã loại * @return string */ public string getNameByID(int c) { string rt = ""; try { rt = dsLoai[c]; } catch (Exception ex) { rt = "[N/a]"; ErrorLogs el = new ErrorLogs(ex.ToString()); el.write(); } return(rt); }
public void Nhap_File() { try { StreamReader myfile = File.OpenText(Properties.Settings.Default.FILE_DANHSACHCHUYENDI); n = int.Parse(myfile.ReadLine()); Console.WriteLine("Số lượng chuyến đi: " + n); if (n < 0 || n > maxsize) { throw new System.AggregateException("Số lượng chuyến đi (N) quá lớn hoặc quá nhỏ, 0 <= N <= {0}."); } for (int i = 0; i < n; i++) { string[] separators = { "\t" }; string value = myfile.ReadLine(); string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries); // Ví dụ: 58-A6.7993 88.4, mỗi thuộc tính cách nhau bởi phím TAB dsCD[i] = new ChuyenDi(int.Parse(words[0]), float.Parse(words[1])); } myfile.Close(); } catch (FileNotFoundException) { Console.WriteLine("\n{0} không tồn tại", Properties.Settings.Default.FILE_DANHSACHCHUYENDI); } catch (IOException) { Console.WriteLine("\n{0} đã tồn tại", Properties.Settings.Default.FILE_DANHSACHCHUYENDI); } catch (Exception ex) { Console.WriteLine("Có lỗi không rõ đã xảy ra"); ErrorLogs el = new ErrorLogs(ex.ToString()); el.write(); } }
// Nhập hàng loạt các loại xe từ file đã lưu public void Nhap_File() { try { StreamReader myfile = File.OpenText(Properties.Settings.Default.FILE_DANHSACHLOAIXE); n = int.Parse(myfile.ReadLine()); Console.WriteLine("Số lượng loại xe: " + n); if (n < 1) { return; } for (int i = 0; i < n; i++) { string[] separators = { "\t" }; string value = myfile.ReadLine(); string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries); // Ví dụ: 0 Thuong, mỗi thuộc tính cách nhau bởi phím TAB dsLoai[int.Parse(words[0])] = words[1]; // Chú ý, việc nhập xuất file nên làm tự động, tránh can thiệp vào file dữ liệu dễ dẫn tới hỏng } myfile.Close(); } catch (FileNotFoundException) { Console.WriteLine("\n{0} không tồn tại", Properties.Settings.Default.FILE_DANHSACHLOAIXE); } catch (IOException) { Console.WriteLine("\n{0} đã tồn tại", Properties.Settings.Default.FILE_DANHSACHLOAIXE); } catch (Exception ex) { Console.WriteLine("Có lỗi không rõ đã xảy ra"); ErrorLogs el = new ErrorLogs(ex.ToString()); el.write(); } }