支付后返回主账户

时间:2019-02-13 15:27:20

标签: c# sql-server forms printing

我拥有由c#和sql server创建的POS系统到快餐店。 付款过程后,单击确定以显示“购买成功,付款”窗口,再次返回到ProductsReceiptPreview表单, 付款后,我要转到主表单。 这是我的代码.......


       private void lblPayments_Click(object sender, EventArgs e)
    {

            if (pnlPayments.Height != lbl.Height)
            {
                pnlPayments.Height = lbl.Height;
                btnDone.Text = "DONE";
                lbl.Text = "RECEIPT";
                btnDone.Image = Resources.done;
                Data.Show();
            }
            else
            {
                pnlPayments.Height = 394;
                btnDone.Text = "RECEIPT";
                lbl.Text = "AMOUNT";
                btnDone.Image = Resources.receipt;
                Data.Hide();
            }


    }

    private void Touch_Click(object sender, EventArgs e)
    {
        var btn = (Button)sender;
        txtCashReceived.Text += btn.Text;
    }

    private void btnClear_Click(object sender, EventArgs e)
    {
     if(txtCashReceived.Text.Length >0)   txtCashReceived.Text = 
     txtCashReceived.Text.Remove(txtCashReceived.Text.Length - 1);
    }


    double totalBill = 0;
    private void btnPay_Click(object sender, EventArgs e)
    {

        if (txtCashReceived.Text.Length > 0 && totalBill <= 
    Convert.ToInt32(txtCashReceived.Text) && Data.RowCount > 0)
        {
            int i = 0;
            foreach (var rep in ListReports)
            {
                i++;
                var report = new ModelReports();
                report.Productname = rep.Productname;
                report.TotalSales = rep.TotalSales;
                report.TotalTransactions = rep.TotalTransactions;
                report.Save();


            }

            var rpd = new ProductsReceiptPreview(dataReceiptBindingSource, 
            txtTotal.Text, txtCashReceived.Text, txtChange.Text);
            rpd.ShowDialog();
            if (i == ListReports.Count)
            {
                MessageBox.Show("Order Successfully Paid");
            }
            pnlProducts.Controls.Clear();
            pnlCategoryPanel.Visible = false;
            dataReceiptBindingSource.Clear();
            LoadTables();
            btnDone.PerformClick();
        }
        else
        {
            MessageBox.Show("Please pay your order.");
            txtCashReceived.Text = "0";

        }
    }

    private void btnPay_Click_1(object sender, EventArgs e)
    {


        if (txtCashReceived.Text.Length > 0 && totalBill <= 
        Convert.ToInt32(txtCashReceived.Text) && Data.RowCount > 0)
        {
            int i = 0;
            foreach (var rep in ListReports)
            {
                i++;
                var report = new ModelReports();
                report.Productname = rep.Productname;
                report.TotalSales = rep.TotalSales;
                report.TotalTransactions = rep.TotalTransactions;
                report.Save();


            }
            if (i == ListReports.Count)
            {
                MessageBox.Show("Order Successfully Paid");
                txtCashReceived.Text = "0";
            }
            pnlProducts.Controls.Clear();
            pnlCategoryPanel.Visible = false;
            dataReceiptBindingSource.Clear();
            LoadTables();
            btnDone.PerformClick();
        }
        else
        {
            MessageBox.Show("Please pay your order.");
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您从main调用某些代码,则在调用结束后它将返回main。对于Form,它是从main开始的不同线程上处理的。在这种情况下,线程将永远不会返回主线程。如果您正在使用click事件来执行某些操作,并希望在发生这种情况时调用其他代码,那么您需要重新设计您的基础结构。研究SOLID开发原则和依赖项注入。 https://www.codeproject.com/Tips/1033646/SOLID-Principle-with-Csharp-Example https://simpleinjector.readthedocs.io/en/latest/windowsformsintegration.html