コード例 #1
0
        private void b_Print_Click(object sender, EventArgs e)
        {
            if (t_Paid.Text == "")
            {
                MessageBox.Show("Please Enter a Payment Amount");
            }

            else if (int.Parse(t_Paid.Text) < int.Parse(t_Tpay.Text))
            {
                MessageBox.Show("Payment Amount is LOW !");
            }
            else if (checkBox_bKash.CheckState == CheckState.Checked && checkBox_Cash.CheckState == CheckState.Checked)
            {
                MessageBox.Show("Select a paymnet method");
            }

            else
            {
                List <Receipt> rcpt = new List <Receipt>();
                rcpt.Clear();
                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    Receipt receipt = new Receipt
                    {
                        Id       = int.Parse(dataGridView2.Rows[i].Cells[0].Value.ToString()),
                        Name     = dataGridView2.Rows[i].Cells[1].Value.ToString(),
                        Price    = float.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString()),
                        Quantity = int.Parse(dataGridView2.Rows[i].Cells[3].Value.ToString()),
                        Total    = float.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString())
                    };
                    rcpt.Add(receipt);
                }
                rs.Name  = "DataSet1";
                rs.Value = rcpt;
                ReceiptForm frm = new ReceiptForm(rcpt, t_PayTotal.Text, t_v.Text, t_Vat.Text, t_Around.Text, t_Tpay.Text, t_Paid.Text, t_Return.Text, textBox2.Text, DateTime.Now.ToString("dd-MMM-yyyy"), DateTime.Now.ToString("hh:mm tt"));

                frm.reportViewer1.LocalReport.DataSources.Clear();
                frm.reportViewer1.LocalReport.DataSources.Add(rs);
                frm.reportViewer1.LocalReport.ReportEmbeddedResource = "App.rptReceipt.rdlc";

                PosService posService = new PosService();
                for (int j = 0; j < dataGridView2.Rows.Count; j++)
                {
                    if (checkBox_bKash.CheckState == CheckState.Checked)
                    {
                        payType = "bKash";
                    }
                    if (checkBox_Cash.CheckState == CheckState.Checked)
                    {
                        payType = "Cash";
                    }
                    price    = int.Parse(dataGridView2.Rows[j].Cells[4].Value.ToString());
                    vat      = Convert.ToSingle((price * 0.1) + price);
                    totalPay = (int)Math.Round(vat);
                    if (textBox7.Text == string.Empty)
                    {
                        cId = 0;
                    }
                    else
                    {
                        cId = int.Parse(textBox7.Text);
                    }
                    result = posService.Insert(new Pos {
                        ItemId = int.Parse(dataGridView2.Rows[j].Cells[0].Value.ToString()), Name = dataGridView2.Rows[j].Cells[1].Value.ToString(), Price = float.Parse(dataGridView2.Rows[j].Cells[2].Value.ToString()), Quantity = int.Parse(dataGridView2.Rows[j].Cells[3].Value.ToString()), TotalAmount = totalPay, PaymentType = payType, SaleDate = Convert.ToDateTime(DateTime.Now.ToString("dd-MMM-yyyy")), CustomerId = cId, CashierName = textBox2.Text
                    });
                }
                if (result > 0)
                {
                    result = 0;
                    MessageBox.Show("Sales added.");
                }
                else
                {
                    MessageBox.Show("Error");
                }
                dataGridView2.Rows.Clear();
                t_PayTotal.Text = t_v.Text = t_Vat.Text = t_Around.Text = t_Tpay.Text = t_Paid.Text = t_Return.Text = string.Empty;
                frm.ShowDialog();
            }
        }