public DialogResult ShowDialog(PurchaseTemplate purchase) { this.purchase = purchase; string doPrint; if (LoginForm.CashpointSettings["DoPrint"] == "False") btnPrintReceipt.Enabled = true; else btnPrintReceipt.Enabled = false; if (LoginForm.ConfigReader.TryGetValue("printer", out doPrint)) if (doPrint.ToLower() == "false") btnPrintReceipt.Enabled = true; else btnPrintReceipt.Enabled = false; txtSum.Text = string.Format("{0:0.00}", purchase.Articles.AmountWithDeposit); txtGiven.Text = "0"; CalculateBackMoney(); dgvCartTable.Rows.Clear(); foreach (ArticleCount ac in purchase.Articles.Container) { dgvCartTable.Rows.Add( ac.Article.Name, ac.Count, ac.Article.PriceWithDeposit, ac.Article.PriceWithDeposit * ac.Count ); } this.ShowDialog(); return System.Windows.Forms.DialogResult.OK; }
private void btnPrint_Click(object sender, EventArgs e) { bool isInserted = false; try { PurchaseTemplate tpl = new PurchaseTemplate(cart, userLoggedIn); DatabaseHandler.NewPurchase(tpl); isInserted = true; // fire event to start printing OnSaleSuccessed(new SaleSuccessedEventArgs(cart)); confirmationDialog.ShowDialog(tpl); cart.Clear(); if (RefreshNeeded) StartRefreshRoutine(); } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Programmfehler\n\n"; errmsg += isInserted ? "ACHTUNG: Der Einkauf wurde boniert. Werden keine Bons gedruckt wenden Sie sich an den Veranstalter." : "ACHTUNG: Der Einkauf wurde NICHT boniert."; errmsg += "\n\nFehlernachricht: " + ex.Message; MessageBox.Show(errmsg); } }
public static void NewPurchase(PurchaseTemplate ptpl) { SqlParameter success, error; try { SqlConnection connection; SqlCommand cmd; // create ArticleCart SQL object DataTable articles = new DataTable(); articles.Columns.Add("userId", typeof(int)); articles.Columns.Add("articleCount", typeof(int)); foreach (ArticleCount ac in ptpl.Articles.Container) articles.Rows.Add(ac.Article.ArticleID, ac.Count); // stored procedure settings connection = new SqlConnection(ConnectionString); cmd = new SqlCommand("usp_create_purchase", connection); cmd.CommandType = CommandType.StoredProcedure; // add parameters cmd.Parameters.AddWithValue("@userId", ptpl.User.UserID); SqlParameter recs = cmd.Parameters.AddWithValue("@articles", articles); recs.SqlDbType = SqlDbType.Structured; success = cmd.Parameters.Add("@success", SqlDbType.Bit); success.Size = 1; success.Direction = ParameterDirection.Output; error = cmd.Parameters.Add("@errormsg", SqlDbType.VarChar); error.Size = 5000; error.Direction = ParameterDirection.Output; // execute procedure connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); if (!(bool)success.Value) { throw new Exception(error.Value.ToString()); } } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Fehler beim Erstellen der Nachricht.\n\n"; errmsg += "DatabaseHandler.NewMessage(msgtempl): " + ex.ToString(); throw new Exception(errmsg); } }