public static void Save_BankAccount(BankAccountSetting setting) { if (!Directory.Exists($"{MyWorkPath}\\stf")) { Directory.CreateDirectory($"{MyWorkPath}\\stf"); } string SettingPath = $"{MyWorkPath}\\stf\\BankAccount.json"; string output = JsonConvert.SerializeObject(setting, Formatting.Indented, new JsonSerializerSettings()); File.WriteAllText(SettingPath, output); }
/// <summary> /// 系統設定畫面 /// </summary> /// <param name="bankAccount"></param> public SystemSettingUserControl(BankAccountSetting bankAccount) { InitializeComponent(); BankNametextEdit.Text = bankAccount.BankName; BankCodetextEdit.Text = bankAccount.BankCode.ToString(); BankAccounttextEdit.Text = bankAccount.BankAccount; AccountTitletextEdit.Text = bankAccount.AccountTitle; ContactPersontextEdit.Text = bankAccount.ContactPerson; ContactNumbertextEdit.Text = bankAccount.ContactNumber; PaymentDeadilinetextEdit.Text = bankAccount.PaymentDeadiline.ToString(); ElectricityCosttextEdit.Text = bankAccount.ElectricityCost.ToString(); SystemPasswordtextEdit.Text = bankAccount.SystemPassword; }
/// <summary> /// 銀行與系統密碼資訊 /// </summary> /// <returns></returns> public static BankAccountSetting BankAccountLoad() { BankAccountSetting setting = null; if (!Directory.Exists($"{MyWorkPath}\\stf")) { Directory.CreateDirectory($"{MyWorkPath}\\stf"); } string SettingPath = $"{MyWorkPath}\\stf\\BankAccount.json"; try { if (File.Exists(SettingPath)) { string json = File.ReadAllText(SettingPath, Encoding.UTF8); setting = JsonConvert.DeserializeObject <BankAccountSetting>(json); } else { BankAccountSetting Setting = new BankAccountSetting() { BankName = "XX銀行", BankCode = 123, BankAccount = "123456789", AccountTitle = "XX公司", ContactPerson = "X先生/女士", ContactNumber = "09-12345678", PaymentDeadiline = 5, ElectricityCost = 6, SystemPassword = "******" }; setting = Setting; string output = JsonConvert.SerializeObject(setting, Formatting.Indented, new JsonSerializerSettings()); File.WriteAllText(SettingPath, output); } } catch (Exception ex) { Log.Error(ex, " 銀行與系統密碼資訊設定載入錯誤"); } return(setting); }