Esempio n. 1
0
        private void PrintTicket(int flag)
        {
            try
            {
                setWaitCursor(true);
                string retailer = "";
                string docid    = "";
                string tourist  = "";
                string purchase = "";
                string token    = "";
                if (Constants.PRINTER_SELECT == "OPOS Printer")
                {
                    if (Constants.PRINTER_OPOS_TYPE != null)
                    {
                        JObject json = new JObject();
                        json.Add("retailer_name", txt_StoreName.Text);
                        json.Add("gst_no", txt_GSTNo.Text);
                        json.Add("doc_id", txt_DocId.Text);
                        json.Add("issue_date", txt_IssueDate.Text);
                        json.Add("passport_number", txt_PassportNo.Text);
                        json.Add("country_code", txt_CountryCode.Text);

                        JArray jsonArrary = new JArray();

                        int nRow = GRD_RECEIPT.RowCount;
                        for (int i = 0; i < nRow; i++)
                        {
                            JObject jsonReceipt = new JObject();

                            jsonReceipt.Add("number", GRD_RECEIPT.Rows[i].Cells["No"].Value.ToString());
                            jsonReceipt.Add("receipt_number", GRD_RECEIPT.Rows[i].Cells["ReceiptNumber"].Value.ToString());
                            jsonReceipt.Add("receipt_date", GRD_RECEIPT.Rows[i].Cells["PurchaseDate"].Value.ToString());
                            jsonReceipt.Add("gross_amount", GRD_RECEIPT.Rows[i].Cells["PurchaseAmount"].Value.ToString());
                            jsonReceipt.Add("quantity", GRD_RECEIPT.Rows[i].Cells["Quantity"].Value.ToString());
                            jsonReceipt.Add("description", GRD_RECEIPT.Rows[i].Cells["PurchaseItem"].Value.ToString());

                            jsonArrary.Add(jsonReceipt);
                        }

                        json.Add("purchase_list", jsonArrary.ToString());

                        json.Add("sales_amt", txt_SalesAmt.Text);
                        json.Add("gst_amt", txt_GSTAmt.Text);
                        json.Add("service_amt", txt_ServiceAmt.Text);
                        json.Add("refund_amt", txt_RefundAmt.Text);

                        if (txt_TokenType.Text.Trim().Equals(""))
                        {
                            json.Add("token_type", txt_TokenType.Text);
                            json.Add("token_display", txt_TokenDisplay.Text);
                        }
                        else
                        {
                            json.Add("token_type", "");
                            json.Add("token_display", "");
                        }

                        BixolonPrinterUtil printer = new BixolonPrinterUtil();

                        if (txt_StatusCode.Text.Equals("01"))       // Issued
                        {
                            printer.PrintOPOS(Constants.PRINTER_OPOS_TYPE, json.ToString(), flag);
                        }
                        else if (txt_StatusCode.Text.Equals("03"))   // Void
                        {
                            printer.PrintOPOS(Constants.PRINTER_OPOS_TYPE, json.ToString(), flag);
                        }
                        else
                        {
                            MessageBox.Show("Ticket not valid");
                        }
                    }
                }
                else
                {
                    if (Constants.PRINTER_TYPE != null)
                    {
                        retailer = txt_StoreName.Text + "|" + txt_GSTNo.Text + "|" + txt_ADDR.Text;

                        docid = txt_DocId.Text + "|" + Utils.FormatConvertDateSG(txt_IssueDate.Text);

                        tourist = txt_PassportNo.Text + "|" + txt_CountryCode.Text;

                        JArray jsonArrary = new JArray();

                        int nRow = GRD_RECEIPT.RowCount;
                        purchase += nRow + "|";
                        for (int i = 0; i < nRow; i++)
                        {
                            purchase += i + "|";
                            purchase += Utils.FormatConvertDateSG(GRD_RECEIPT.Rows[i].Cells["PurchaseDate"].Value.ToString()) + "|";
                            purchase += GRD_RECEIPT.Rows[i].Cells["PurchaseAmount"].Value.ToString() + "|";
                            purchase += GRD_RECEIPT.Rows[i].Cells["ReceiptNumber"].Value.ToString() + "|";
                        }
                        purchase += txt_SalesAmt.Text + "|" + txt_GSTAmt.Text + "|" + txt_ServiceAmt.Text + "|" + txt_RefundAmt.Text;

                        if (!token_type.Equals(""))
                        {
                            token  = token_type + "|";
                            token += txt_TokenDisplay.Text;
                        }
                        else
                        {
                            token  = "" + "|";
                            token += "";
                        }
                    }

                    WindowPrinterUtil printer = new WindowPrinterUtil();
                    if (txt_StatusCode.Text.Equals("01"))
                    {
                        printer.PrintTicket(retailer, docid, tourist, purchase, token, "02");
                    }
                    else if (txt_StatusCode.Text.Equals("03"))
                    {
                        printer.PrintTicket(retailer, docid, tourist, purchase, token, "03");
                    }
                    else
                    {
                        MessageBox.Show("Ticket not valid");
                    }
                }
            }
            finally
            {
                setWaitCursor(false);
            }
        }
        private void PrintTicket(JObject jsonRes)
        {
            try
            {
                setWaitCursor(true);

                string retailer = "";
                string docid    = "";
                string tourist  = "";
                string purchase = "";
                string token    = "";
                if (Constants.PRINTER_SELECT == "OPOS Printer")
                {
                    if (Constants.PRINTER_OPOS_TYPE != null)
                    {
                        JObject json = new JObject();
                        json.Add("retailer_name", jsonRes["retailer_name"].ToString());
                        json.Add("gst_no", jsonRes["retailer_gstno"].ToString());
                        json.Add("doc_id", jsonRes["formatted_docid"].ToString());

                        string issue_date = Utils.FormatDate(jsonRes["date_of_issue"].ToString()) + " " + Utils.FormatTime(jsonRes["time_of_issue"].ToString());

                        json.Add("issue_date", issue_date);

                        if (jsonRes["passport_number"] != null)
                        {
                            json.Add("passport_number", jsonRes["passport_number"].ToString());
                        }
                        else
                        {
                            json.Add("passport_number", "");
                        }

                        if (jsonRes["country_code"] != null)
                        {
                            json.Add("country_code", jsonRes["country_code"].ToString());
                        }
                        else
                        {
                            json.Add("country_code", "");
                        }

                        JArray jsonArrary = new JArray();

                        JArray tmp_arr = JArray.Parse(jsonRes["purchase_list"].ToString());

                        int i = 0;
                        foreach (JObject tmp_obj in tmp_arr.Children <JObject>())
                        {
                            i++;
                            JObject jsonReceipt = new JObject();

                            jsonReceipt.Add("number", i);
                            jsonReceipt.Add("receipt_number", tmp_obj["receipt_number"].ToString());
                            jsonReceipt.Add("receipt_date", Utils.FormatDate(tmp_obj["receipt_date"].ToString()));
                            jsonReceipt.Add("gross_amount", tmp_obj["gross_amount"].ToString());
                            jsonReceipt.Add("quantity", tmp_obj["quantity"].ToString());
                            jsonReceipt.Add("description", tmp_obj["description"].ToString());
                            jsonArrary.Add(jsonReceipt);
                        }

                        json.Add("purchase_list", jsonArrary.ToString());

                        json.Add("sales_amt", jsonRes["sales_amount"].ToString());
                        json.Add("gst_amt", jsonRes["gst_amount"].ToString());
                        json.Add("service_amt", jsonRes["service_amount"].ToString());
                        json.Add("refund_amt", jsonRes["refund_amount"].ToString());

                        if (jsonRes["token_type"] != null)
                        {
                            json.Add("token_type", jsonRes["token_type"].ToString());
                        }

                        if (jsonRes["token_display"] != null)
                        {
                            if (jsonRes["token_type"].ToString().Equals("C"))
                            {
                                String[] token_text = jsonRes["token_display"].ToString().Split(new String[] { "****" }, StringSplitOptions.RemoveEmptyEntries);
                                json.Add("token_display", "****-****-****-" + token_text[token_text.Length - 1].ToString());
                            }
                            else
                            {
                                json.Add("token_display", jsonRes["token_display"].ToString());
                            }
                        }


                        BixolonPrinterUtil printer = new BixolonPrinterUtil();

                        printer.PrintOPOS(Constants.PRINTER_OPOS_TYPE, json.ToString(), 1);
                    }
                }
                else
                {
                    if (Constants.PRINTER_TYPE != null)
                    {
                        retailer = jsonRes["retailer_name"].ToString() + "|" + jsonRes["retailer_gstno"].ToString() + "|" + jsonRes["retailer_addr"].ToString();

                        docid = jsonRes["formatted_docid"].ToString() + "|" + Utils.FormatDate(jsonRes["date_of_issue"].ToString()) + " " + Utils.FormatTime(jsonRes["time_of_issue"].ToString());

                        tourist = jsonRes["passport_number"].ToString() + "|" + jsonRes["country_code"].ToString();

                        JArray jsonArrary = new JArray();

                        JArray tmp_arr = JArray.Parse(jsonRes["purchase_list"].ToString());

                        int i = 0;

                        purchase += tmp_arr.Count + "|";
                        foreach (JObject tmp_obj in tmp_arr.Children <JObject>())
                        {
                            i++;
                            JObject jsonReceipt = new JObject();

                            purchase += i + "|";
                            purchase += Utils.FormatDate(tmp_obj["receipt_date"].ToString()) + "|";
                            purchase += tmp_obj["gross_amount"].ToString() + "|";
                            purchase += tmp_obj["receipt_number"].ToString() + "|";
                            purchase += jsonRes["sales_amount"].ToString() + "|" + jsonRes["gst_amount"].ToString() + "|" + jsonRes["service_amount"].ToString() + "|" + jsonRes["refund_amount"].ToString();
                        }

                        if (jsonRes["token_type"] != null)
                        {
                            token = jsonRes["token_type"].ToString() + "|";
                        }

                        if (jsonRes["token_display"] != null)
                        {
                            if (jsonRes["token_type"].ToString().Equals("C"))
                            {
                                String[] token_text = jsonRes["token_display"].ToString().Split(new String[] { "****" }, StringSplitOptions.RemoveEmptyEntries);
                                token += "****-****-****-" + token_text[token_text.Length - 1].ToString();
                            }
                            else
                            {
                                token += jsonRes["token_display"].ToString();
                            }
                        }
                    }

                    WindowPrinterUtil printer = new WindowPrinterUtil();
                    printer.PrintTicket(retailer, docid, tourist, purchase, token, "01");
                }
            }
            catch (Exception ex)
            {
                Constants.LOGGER_MAIN.Error(ex.StackTrace);
                //MessageBox.Show(ex.StackTrace);
            }
            finally
            {
                setWaitCursor(false);
            }
        }