private void ImportFromExcelClick(object sender, EventArgs eventArgs) { if (selectedAccount == null) { return; } OpenFileDialog of = new OpenFileDialog { CheckFileExists = true, Filter = "Excel 2007-2010|*.xlsx|Excel 97-2003|*.xls" }; if (of.ShowDialog(this) != DialogResult.OK) { return; } ExcelParsedFile sheet = ExcelParsedFile.Load(of.FileName, 0); while (sheet.MoveNext()) { DateTime date; DateTime.TryParse(sheet.GetString(0), out date); AccountTransaction t = new AccountTransaction { Date = date, Amount = sheet.GetDouble(1), Comment = sheet.GetString(2) }; NameValueCollection values = new NameValueCollection(); values.Add("AccountID", selectedAccount.ID); values.Add("ID", 0); values.Add("Amount", t.Amount); values.Add("Comment", t.Comment); values.Add("Date", t.Date.Ticks); AccountTransaction tt = ctx.ServiceCaller.PostData <AccountTransaction>(string.Format("{0}/AccountService/SaveTransaction", ctx.ServiceBaseURL), values); selectedAccount.Transactions.Add(tt); } LoadAccount(selectedAccount); }
private void ImportFromExcel(object sender, EventArgs eventArgs) { if (changed) { DialogResult dr = MessageBox.Show(this, string.Format("Vill du spara dina ändringar?{0}Det kommer att gå förlorade annars!", Environment.NewLine), "Spara ändringar", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Cancel) { return; } if (dr == DialogResult.Yes) { Save(); } } changed = false; OpenFileDialog of = new OpenFileDialog { AutoUpgradeEnabled = true, Filter = "Excel 2007-2010|*.xlsx|Excel 97-2003|*.xls", CheckFileExists = true, Multiselect = false }; if (of.ShowDialog(this) != DialogResult.OK) { return; } ExcelParsedFile file = ExcelParsedFile.Load(of.FileName, 0); while (file.MoveNext()) { Bill b = new Bill { TotalUsedKWh = file.GetDouble(0), TotalPriceElectricity = file.GetDouble(1), TotalPriceGroundFee = file.GetDouble(2), OCR = file.GetString(3), GuestLastReadingTicks = file.GetDateTime(4).Ticks, GuestLastReadingKWh = file.GetDouble(5), GuestCurrentReadingTicks = file.GetDateTime(6).Ticks, GuestCurrentReadingKWh = file.GetDouble(7), GuestPartInGroundFee = file.GetInt(8) }; SaveBill(b); Bills.Add(b); } LoadBills(); }