Beispiel #1
0
        public DialogResult ShowDialog(DepositReturnTemplate returnTpl, User user)
        {
            this.returnTpl = returnTpl;
            this.user = user;

            string doPrint;
            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}", (returnTpl.Cart.AmountWithDeposit - returnTpl.Cart.Amount));

            dgvCartTable.Rows.Clear();
            foreach (ArticleCount ac in returnTpl.Cart.Container)
            {
                dgvCartTable.Rows.Add(
                    ac.Article.Deposit.Name,
                    ac.Count,
                    (ac.Article.PriceWithDeposit - ac.Article.Price),
                    (ac.Article.PriceWithDeposit - ac.Article.Price) * ac.Count
                );
            }

            // disable button if printer is busy
            btnPrintReceipt.Enabled = printDevice.PrintStatus == PrintStatus.Stopped;

            this.ShowDialog();
            return System.Windows.Forms.DialogResult.OK;
        }   
Beispiel #2
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            bool isInserted = false;

            try
            {
                //PurchaseTemplate tpl = new PurchaseTemplate(cart, userLoggedIn);
                //DatabaseHandler.NewPurchase(tpl);

                DepositReturnTemplate tpl = new DepositReturnTemplate(cart, userLoggedIn, primaryProfile);
                DatabaseHandler.NewDepositReturn(tpl);
                isInserted = true;

                // fire event to start printing
                OnSaleSuccessed(new SaleSuccessedEventArgs(cart));

                confirmationDialog.ShowDialog(tpl, userLoggedIn);
                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);
            }
        }
Beispiel #3
0
        public static void NewDepositReturn(DepositReturnTemplate tpl)
        {
            StringBuilder sqlCommand = new StringBuilder();
            sqlCommand.AppendLine("BEGIN TRANSACTION;");
            sqlCommand.AppendLine("BEGIN TRY");

            foreach (ArticleCount ac in tpl.Cart.Container)
            {
                sqlCommand.AppendLine("INSERT INTO DepositReturn (DepositID, UserID, ProfileID, [Count]) VALUES (" +
                    ac.Article.Deposit.DepositID + ", " +
                    tpl.User.UserID + ", " +
                    tpl.Profile.ProfileID + ", " +
                    ac.Count + ");");
            }

            sqlCommand.AppendLine("COMMIT;");
            sqlCommand.AppendLine("END TRY");
            sqlCommand.AppendLine("BEGIN CATCH");
            sqlCommand.AppendLine("DECLARE @err VARCHAR(1000);");
            sqlCommand.AppendLine("SET @err = ERROR_MESSAGE();");
            sqlCommand.AppendLine("RAISERROR(@err, 18, 255);");
            sqlCommand.AppendLine("ROLLBACK;");
            sqlCommand.AppendLine("END CATCH");

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(sqlCommand.ToString(), connection);
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
            }
            catch(Exception ex)
            {
                LogWriter.Write(ex, LOGFILE_NAME);
                string errmsg = "Fehler beim Erstellen der Nachricht.\n\n";
                errmsg += "DatabaseHandler.NewDepositReturn(tpl): " + ex.ToString();
                throw new Exception(errmsg);
            }
        }