/// <summary> /// Updates the runnung balance. (Form element this.txtSaldo) /// </summary> /// <param name="paymentDataSetList">The new captured paymentDataSetList</param> private void UpdateRunnungBalance(ComparablePaymentDataSetList paymentDataSetList) { // for the right formating CultureInfo cultureInfo = CultureInfo.InvariantCulture; string amount; TextBox balanceTextBox; #region set amount & balanceTextBox if (boxTyp.Text == "Kreditkartenkonto") { amount = paymentDataSetList.GetValueByName("Kredit_Betrag"); balanceTextBox = GetWorkingTextBox("Kredit_Saldo"); } else if (boxTyp.Text == "Sparkonto") { amount = paymentDataSetList.GetValueByName("Spar_Betrag"); amount = amount.Replace(" EUR", ""); balanceTextBox = GetWorkingTextBox("Spar_Saldo"); } else { throw new Exception("unbekannter Konto-Typ"); } #endregion if (amount.Equals("")) { MessageBox.Show("Kein Betrag gefunden!\n" + "Wurde der korrekte Kontotyp ausgewählt?", "Warnung", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } amount = ToolBox.GermanAmountToEnglishAmount(amount); // calculates running balance try { decimal balance = Decimal.Parse(balanceTextBox.Text, cultureInfo); balance += Decimal.Parse(amount, cultureInfo); balanceTextBox.Text = balance.ToString("N2", cultureInfo); } catch (FormatException) { MessageBox.Show("Der eingegebene Saldo hat ein ungültiges Format!\n" + "Korrekte Werte sind z.B. '1002.50' und '-4.99'! (ohne Anführungszeichen)", "Warnung", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// Initializes a new instance /// </summary> public PaymentDataSetHolder() { _dataSets = new ComparablePaymentDataSetList(); }
/// <summary> /// Resets the vars if you change the account /// </summary> private void ResetVars() { _currentPaymentDataSetList = null; _lastPaymentDataSetList = null; txtTextOutput.Text = ""; List<TextBox> allWorkingTextBoxes = GetAllWorkingTextBoxes("all"); foreach (TextBox textBox in allWorkingTextBoxes) { textBox.Text = textBox.Name.Contains("Saldo") ? "0.00" : ""; } }
/// <summary> /// Captures the current StarMoneyWindow and fills the form with data from the capture /// </summary> private void DoCaptureAndFillForm() { _capture = new User32Capture( txtFenstername.Text, "SVWORK", boxAnker.Text, boxTyp.Text); try { ComparablePaymentDataSetList paymentDataSetList = _capture.DoCapture(); // ok, we are still in business _lastPaymentDataSetList = _currentPaymentDataSetList; _currentPaymentDataSetList = paymentDataSetList; // fills all TextBoxes with the captured data foreach (PaymentDataSet paymentDataSet in paymentDataSetList) { TextBox workingTextBox = GetWorkingTextBox(paymentDataSet.Name); workingTextBox.Text = paymentDataSet.Value; } // the amount would be mixed up if you click multiple times on "Auslesen" (capture) if (_lastPaymentDataSetList == null || !_currentPaymentDataSetList.Equals(_lastPaymentDataSetList)) { UpdateRunnungBalance(paymentDataSetList); } // displays a warning else { MessageBox.Show("Die neuen und die alten Daten sind identisch.\n" + "Der fortlaufende Saldo wurde nicht angepasst!", "Hinweis", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (WindowNotFoundException) { MessageBox.Show("Öffnen Sie zuerst die Umsatzdetails in StarMoney.\n" + "Wechseln Sie dann zurück zu StarMoneySpy.\n\n" + "Das StarMoney-Fenster muss während der gesamten Sitzung geöffnet bleiben!", "Warnung", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// builds the SQL command for a list that represents a savings account dataset /// </summary> /// <param name="paymentDataSetList">The payment data set list.</param> /// <param name="balance">The balance.</param> /// <returns></returns> public static string MakeTextCommand_Spar(ComparablePaymentDataSetList paymentDataSetList, string balance, bool makeCSV) { string primanota = paymentDataSetList.GetValueByName("Spar_Primanota"); string bookingdate = GermanDateToSQLDate(paymentDataSetList.GetValueByName("Spar_Buchungstag")); string valuedate = GermanDateToSQLDate(paymentDataSetList.GetValueByName("Spar_Wertstellungstag")); string tmpKey = paymentDataSetList.GetValueByName("Spar_Schlüssel"); string name = paymentDataSetList.GetValueByName("Spar_Absender"); string reasonForTransfer = paymentDataSetList.GetValueByName("Spar_Verwendungszweck").Replace("\r\n", "\\n"); string amount = GermanAmountToEnglishAmount(paymentDataSetList.GetValueByName("Spar_Betrag")); // needs to be a neutral culture string balance = balance.Replace(",", ""); amount = amount.Replace(" EUR", ""); Match match = Regex.Match(tmpKey, @"\(([0-9]+)\)$"); string txtKey = ""; if (match.Groups.Count > 1) { txtKey = match.Groups[1].ToString(); } string postingtext = Regex.Replace(tmpKey, @"\s{0,1}\([0-9]+\)$", ""); if (postingtext.Equals("")) { postingtext = "NULL"; } else { postingtext = "'" + postingtext + "'"; } string tmp = ""; if (makeCSV) { tmp += QuoteCSVItem(primanota) + ";"; tmp += QuoteCSVItem(bookingdate) + ";"; tmp += QuoteCSVItem(valuedate) + ";"; tmp += QuoteCSVItem(txtKey) + ";"; tmp += QuoteCSVItem(postingtext) + ";"; tmp += QuoteCSVItem(name) + ";"; tmp += QuoteCSVItem(reasonForTransfer) + ";"; tmp += QuoteCSVItem(EnglishAmountToGermanAmount(amount)) + ";"; tmp += QuoteCSVItem(EnglishAmountToGermanAmount(balance)) + "\r\n"; } else { tmp += "INSERT INTO payments SET "; tmp += "payments_accounts_id = 6, "; tmp += "primanota = '" + primanota + "', "; tmp += "bookingdate = '" + bookingdate + "', "; tmp += "valuedate = '" + valuedate + "', "; tmp += "txt_key = '" + txtKey + "', "; tmp += "postingtext = " + postingtext + ", "; tmp += "name = '" + name + "', "; tmp += "reason_for_transfer = '" + reasonForTransfer + "', "; tmp += "amount = '" + amount + "', "; tmp += "balance = '" + balance + "'"; tmp += ";\r\n"; } return tmp; }
/// <summary> /// builds the SQL command for a list that represents a credit card dataset /// </summary> /// <param name="paymentDataSetList">The payment data set list.</param> /// <param name="balance">The balance.</param> /// <returns></returns> public static string MakeTextCommand_Kredit(ComparablePaymentDataSetList paymentDataSetList, string balance, bool makeCSV) { string number = paymentDataSetList.GetValueByName("Kredit_Buchungsreferenz"); string bookingdate = GermanDateToSQLDate(paymentDataSetList.GetValueByName("Kredit_Buchungsdatum")); string valuedate = GermanDateToSQLDate(paymentDataSetList.GetValueByName("Kredit_Belegdatum")); string reasonForTransfer = paymentDataSetList.GetValueByName("Kredit_Transaktion").Replace("\r\n", "\\n"); string amount = GermanAmountToEnglishAmount(paymentDataSetList.GetValueByName("Kredit_Betrag")); // needs to be a neutral culture string balance = balance.Replace(",", ""); if (!paymentDataSetList.GetValueByName("Kredit_Auslandseinsatzentgeld").Equals("")) { reasonForTransfer += "\\n" + paymentDataSetList.GetValueByName("Kredit_Auslandseinsatzentgeld"); } // looks nicer if (reasonForTransfer.Equals("Einzug des Rechnungsbetra\\nges")) { reasonForTransfer = "Einzug des Rechnungsbetrages"; } string tmp = ""; // MS Excel compatible if (makeCSV) { tmp += QuoteCSVItem(number) + ";"; tmp += QuoteCSVItem(bookingdate) + ";"; tmp += QuoteCSVItem(valuedate) + ";"; tmp += QuoteCSVItem(reasonForTransfer) + ";"; tmp += QuoteCSVItem(EnglishAmountToGermanAmount(amount)) + ";"; tmp += QuoteCSVItem(EnglishAmountToGermanAmount(balance)) + "\r\n"; } else { tmp += "INSERT INTO payments SET "; tmp += "payments_accounts_id = 7, "; tmp += "number = '" + number + "', "; tmp += "bookingdate = '" + bookingdate + "', "; tmp += "valuedate = '" + valuedate + "', "; tmp += "reason_for_transfer = '" + reasonForTransfer + "', "; tmp += "amount = '" + amount + "', "; tmp += "balance = '" + balance + "'"; tmp += ";\r\n"; } return tmp; }
/// <summary> /// Makes an INSERT INTO SQL command or with the help of the form vars /// </summary> /// <returns>sql command</returns> public static string MakeTextCommand(ComparablePaymentDataSetList paymentDataSetList, string balance, string boxType, bool makeCSV) { if (boxType == "Kreditkartenkonto") { return MakeTextCommand_Kredit(paymentDataSetList, balance, makeCSV); } if (boxType == "Sparkonto") { return MakeTextCommand_Spar(paymentDataSetList, balance, makeCSV); } throw new Exception("unbekannter Konto-Typ"); }