static void Main(string[] args) { string strServer = "localhost"; string strDB = "LittleTree"; string strUser = "******"; string strPass = "******"; string strConn = string.Format("Server={0};Database={1};Uid={2};Pwd={3}", strServer, strDB, strUser, strPass); if (args.Contains("--init")) { Program pg = new Program(); pg.initdb(strConn); } if (args.Length == 0) { while (true) { Console.Write("\n" + "dnm: Denomination \n" + "ctg: Category \n" + "trn: Transaction \n" //+ "--init: Initialize database \n" + "csv: Import CSV \n" + "ext: Exit \n" + "\n"); Console.Write("Select option : "); string strOption = Console.ReadLine(); switch (strOption) { case "dnm": Denomination dnm = new Denomination(strConn); if (dnm.dialogue() == 0) { break; } else { return; } case "ctg": Category ctg = new Category(strConn); if (ctg.dialogue() == 0) { break; } else { return; } case "trn": Transaction trn = new Transaction(strConn); if (trn.dialogue() == 0) { break; } else { return; } case "--init": Program pg = new Program(); pg.initdb(strConn); break; case "csv": CSV csv = new CSV(strConn); if (csv.dialogue() == 0) { break; } else { return; } case "ext": return; default: Console.WriteLine(string.Format("Inputted '{0}' is not suporteed.", strOption)); break; } continue; } } }
private void add(string strMode) { string _TransDate; string _MainCategoryId; string _SubCategoryId; string _Amount; string _DenomiId; string _Memo; DateTime dt = DateTime.Today; string _Today = dt.ToShortDateString(); Console.Write(string.Format("Trans date? (Default : {0}) : ", _Today)); _TransDate = Console.ReadLine(); if (_TransDate == "") { _TransDate = _Today; } while (true) { Console.Write("Input MainCategoryId (Optional) : "); _MainCategoryId = Console.ReadLine(); switch (_MainCategoryId) { case "\t": Category ctg = new Category(_strConn); ctg.listMain(); continue; case "": //Noneを選択 _MainCategoryId = "1"; break; case "x": return; default: break; } break; } while (true) { Console.Write("Input SubCategoryId (Optional) : "); _SubCategoryId = Console.ReadLine(); switch (_SubCategoryId) { case "\t": Category ctg = new Category(_strConn); ctg.list(); continue; case "": //Noneを選択 _SubCategoryId = "1"; break; case "x": return; default: break; } break; } while (true) { Console.Write("Input Amount : "); _Amount = Console.ReadLine(); //Expenseの場合に符号を逆転 if (strMode =="e") { _Amount = "-" + _Amount; } try { Convert.ToDecimal(_Amount); } catch { Console.WriteLine("Inputed was not decimal number. \n"); continue; } break; } while (true) { Console.Write("Input DenomiId : "); _DenomiId = Console.ReadLine(); Denomination dnm = new Denomination(_strConn); switch (_DenomiId) { case "\t": dnm.list(); continue; case "x": return; case "": Console.WriteLine("Input valid DenomiId"); continue; default: break; } if (dnm.find(_DenomiId) == "") { Console.WriteLine(_DenomiId + " is not valid."); continue; } break; } Console.Write("Input Memo (Optional) : "); _Memo = Console.ReadLine(); string strCommand; strCommand = string.Format(@" insert into GeneralTrans( TransDate , MainCategoryId , SubCategoryId , Amount , DenomiId , Memo) values( '{0}' #TransDate , {1} #MainCategoryId , {2} #SubCategoryId , {3} #Amount , {4} #DenomiId , '{5}' #Memo ) ", _TransDate, _MainCategoryId, _SubCategoryId, _Amount, _DenomiId, _Memo); Sql sql = new Sql(_strConn); sql.exec(strCommand); }