Exemple #1
0
        public OrderPaymentPrint(List <OrderReceipt> dataSource, Dictionary <string, string> item_list)
        {
            InitializeComponent();

            DateTime dateTime = DateTime.UtcNow.Date;

            reportViewer.LocalReport.DataSources.Clear();
            Microsoft.Reporting.WinForms.ReportParameter[] parameters = new Microsoft.Reporting.WinForms.ReportParameter[]
            {
                new Microsoft.Reporting.WinForms.ReportParameter("pTotal", item_list["total"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pDiscount", item_list["discount"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pOrderNo", item_list["order_id"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pOrderType", item_list["order_type"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pBarCode", item_list["barcode_image"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pPaymentReceived", item_list["payment_received"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pCashBack", item_list["cash_back"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pSumQty", item_list["sum_qty"]),
                new Microsoft.Reporting.WinForms.ReportParameter("pDate", dateTime.ToString("f"))
            };
            reportViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("ds", OrderPaymentPrint.ToDataTable(dataSource)));
            this.reportViewer.LocalReport.SetParameters(parameters);
            this.reportViewer.RefreshReport();
        }
        private void btn_print_Click(object sender, EventArgs e)
        {
            if (orderDetail.Rows.Count > 0)
            {
                List <OrderReceipt> list = new List <OrderReceipt>();

                int sum_qty = 0;

                foreach (DataRow row in orderDetail.Rows)
                {
                    sum_qty += Convert.ToInt16(row["item_qty"].ToString());
                    list.Add(new OrderReceipt()
                    {
                        item_id       = row["item_id"].ToString(),
                        item_name     = row["item_name"].ToString(),
                        item_discount = row["item_discount"].ToString(),
                        item_total    = row["total1"].ToString(),
                        item_qty      = row["item_qty"].ToString(),
                        price         = row["item_price"].ToString()
                    }
                             );
                }

                Code128BarcodeDraw barcode = BarcodeDrawFactory.Code128WithChecksum;
                Image image = new Bitmap(barcode.Draw(orderDetail.Rows[0]["id"].ToString(), 100));

                string barCodeImage = this.ImageToBase64(image, System.Drawing.Imaging.ImageFormat.Jpeg);


                //this.orders = new Orders();
                //this.orderStatus = new OrderStatus();
                //string order_status_id = this.orderStatus.getOrderStatus("completed");

                //if (this.isPayByCash)
                //{
                //    this.orders.Id = orderDetail.Rows[0]["id"].ToString();
                //    this.orders.Order_status_id = order_status_id;
                //    this.orders.Payment_method = "cash";
                //    this.orders.Payment_recieved = Convert.ToString(this.payment_received);
                //    this.orders.Amount_returned = Convert.ToString(this.cash_back);
                //    this.orders.completeOrder();
                //}
                //else
                //{
                //    this.orders.Id = orderDetail.Rows[0]["id"].ToString();
                //    this.orders.Order_status_id = order_status_id;
                //    this.orders.Payment_method = "debit_card";
                //    this.orders.completeOrder(false);
                //}


                Dictionary <string, string> item = new Dictionary <string, string>();
                item.Add("total", this.total);
                item.Add("discount", this.discount);
                item.Add("payment_received", Convert.ToString(this.payment_received));
                item.Add("cash_back", Convert.ToString(this.cash_back));
                item.Add("order_type", this.order_type);
                item.Add("order_id", orderDetail.Rows[0]["id"].ToString());
                item.Add("barcode_image", barCodeImage);
                item.Add("sum_qty", Convert.ToString(sum_qty));

                using (OrderPaymentPrint orderPrePayment = new OrderPaymentPrint(list, item))
                {
                    if (orderPrePayment.ShowDialog() != DialogResult.OK)
                    {
                        // do some thing
                    }
                }
            }
        }