Пример #1
0
        private void do_settlement()
        {
            if (MessageBox.Show("确定结算?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                DB db = new DB();

                int trace_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE state = 's' AND (trans_name = 'payment' OR trans_name =  'deposit' OR trans_name = 'points_payment' OR trans_name = 'points_deposit')");
                if (trace_count == 0)
                {
                    MessageBox.Show("无交易流水");
                    return;
                }

                int payment_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                int deposit_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                int points_payment_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                int points_deposit_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");

                int payment_amount = 0;
                int deposit_amount= 0;
                int points_payment_amount = 0;
                int points_deposit_amount = 0;

                if (payment_count > 0)
                {
                    payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                }
                if (deposit_count > 0)
                {
                    deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                }
                if (points_payment_count > 0)
                {
                    points_payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                }
                if (points_deposit_count > 0)
                {
                    points_deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");
                }

                MainForm.trans.init();
                MainForm.trans.Action = "settlement";
                MainForm.trans.Batch_No = Utils.getBatchNum();
                MainForm.trans.Trace_No = Utils.getTraceNum();
                MainForm.trans.Payment_Count = payment_count.ToString();
                MainForm.trans.Payment_Amount = payment_amount.ToString();
                MainForm.trans.Deposit_Count = deposit_count.ToString();
                MainForm.trans.Deposit_Amount = deposit_amount.ToString();
                MainForm.trans.Points_Payment_Count = points_payment_count.ToString();
                MainForm.trans.Points_Payment_Amount = points_payment_amount.ToString();
                MainForm.trans.Points_Deposit_Count = points_deposit_count.ToString();
                MainForm.trans.Points_Deposit_Amount = points_deposit_amount.ToString();

                MainForm.send_trans(MainForm.trans);

            }
        }
Пример #2
0
        private void do_settlement()
        {
            if (MessageBox.Show("确定结算?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                DB db = new DB();

                int trace_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE state = 's' AND (trans_name = 'payment' OR trans_name =  'deposit' OR trans_name = 'points_payment' OR trans_name = 'points_deposit')");
                if (trace_count == 0)
                {
                    MessageBox.Show("无交易流水");
                    return;
                }

                int payment_count        = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                int deposit_count        = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                int points_payment_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                int points_deposit_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");

                int payment_amount        = 0;
                int deposit_amount        = 0;
                int points_payment_amount = 0;
                int points_deposit_amount = 0;

                if (payment_count > 0)
                {
                    payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                }
                if (deposit_count > 0)
                {
                    deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                }
                if (points_payment_count > 0)
                {
                    points_payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                }
                if (points_deposit_count > 0)
                {
                    points_deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");
                }

                MainForm.trans.init();
                MainForm.trans.Action                = "settlement";
                MainForm.trans.Batch_No              = Utils.getBatchNum();
                MainForm.trans.Trace_No              = Utils.getTraceNum();
                MainForm.trans.Payment_Count         = payment_count.ToString();
                MainForm.trans.Payment_Amount        = payment_amount.ToString();
                MainForm.trans.Deposit_Count         = deposit_count.ToString();
                MainForm.trans.Deposit_Amount        = deposit_amount.ToString();
                MainForm.trans.Points_Payment_Count  = points_payment_count.ToString();
                MainForm.trans.Points_Payment_Amount = points_payment_amount.ToString();
                MainForm.trans.Points_Deposit_Count  = points_deposit_count.ToString();
                MainForm.trans.Points_Deposit_Amount = points_deposit_amount.ToString();

                MainForm.send_trans(MainForm.trans);
            }
        }
Пример #3
0
        public static void send_trans(CoolCard.MessagePackage.CardTrans trans)
        {
            // 上送交易前要先添加本地交易流水
            DB db = new DB();
            String guid = Guid.NewGuid().ToString();
            db.AddTrans(guid, trans.Card_No, trans.Action, trans.Batch_No, trans.Trace_No, trans.Amount, current_operator);
            db.ExecuteNoReturnSQL("UPDATE settings SET val = val + 1 WHERE setting = 'current_trace_no'");

            // 上送交易
            string dataPackage = trans.Build_Trans_String();
            MySocket mSocket = new MySocket();
            string rtnString = mSocket.Send(dataPackage);
            // 处理返回结果
            Hashtable hashTable = new Hashtable();
            hashTable = trans.GetReturnPackage(rtnString);
            // 如果返回成功,则更新本地数据表中的交易记录状态为"s"
            string action = "";
            string shop_no = "";
            string terminal_no = "";
            string trans_date = "";
            string trans_time = "";
            string batch_no = "";
            string trace_no = "";
            string result_code = "";
            foreach (DictionaryEntry de in hashTable)
            {
                if (de.Key.ToString().Trim() == "action")
                {
                    action = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "shop_no")
                {
                    shop_no = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "terminal_no")
                {
                    terminal_no = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "result_code")
                {
                    result_code = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "trans_date")
                {
                    trans_date = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "trans_time")
                {
                    trans_time = de.Value.ToString().Trim();
                }
                if(de.Key.ToString().Trim() == "batch_no")
                {
                    batch_no = de.Value.ToString().Trim();
                }
                if(de.Key.ToString().Trim() == "trace_no")
                {
                    trace_no = de.Value.ToString().Trim();
                }
            }
            if (action != "settlement")
            {
                if (result_code == "0")
                {
                    db.UpdateTrans(guid, trans_date, trans_time, batch_no, trace_no, "s");
                    PrintTicket(hashTable);
                }
                else
                {
                    MessageBox.Show(result_code.ToString() + ":" + CoolCard.Config.GetConfig("ERRORCODE", result_code), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    db.UpdateTrans(guid, trans_date, trans_time, batch_no, trace_no, "f");
                }
            }
            else
            {
                if (result_code == "0" || result_code == "29")
                {
                    if (result_code == "29")
                    {
                        MessageBox.Show("账不平");
                    }

                    int payment_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                    int deposit_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                    int points_payment_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                    int points_deposit_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");

                    int payment_amount = 0;
                    int deposit_amount = 0;
                    int points_payment_amount = 0;
                    int points_deposit_amount = 0;

                    if (payment_count > 0)
                    {
                        payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                    }
                    if (deposit_count > 0)
                    {
                        deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                    }
                    if (points_payment_count > 0)
                    {
                        points_payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                    }
                    if (points_deposit_count > 0)
                    {
                        points_deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");
                    }

                    StreamReader sr = new StreamReader(Environment.CurrentDirectory + "/settlement.tpl");
                    string printString = "";
                    printString = sr.ReadToEnd();
                    sr.Close();
                    String settlement_data = "";
                    settlement_data += "消费\t" + payment_count.ToString() + "\t" + payment_amount.ToString() + "\t\n";
                    settlement_data += "充值\t" + deposit_count.ToString() + "\t" + deposit_amount.ToString() + "\t\n";

                    printString = printString.Replace("{shop_num}", shop_no);
                    printString = printString.Replace("{terminal_num}", terminal_no);
                    printString = printString.Replace("{date}", trans_date);
                    printString = printString.Replace("{time}", trans_time);
                    printString = printString.Replace("{settlement_data}", settlement_data);

                    db.ExecuteNoReturnSQL("DELETE FROM trans");
                    db.ExecuteNoReturnSQL("UPDATE settings SET val = val + 1 WHERE setting = 'current_batch_no'");
                    db.ExecuteNoReturnSQL("UPDATE settings SET val = '1' WHERE setting = 'current_trace_no'");

                    MessageBox.Show(printString);
                    //TicketsPrinter ticketsPrinter = new TicketsPrinter();
                    //ticketsPrinter.PrintString = printString;
                    //ticketsPrinter.printTicket();
                }
                else
                {
                    MessageBox.Show(result_code.ToString() + ":" + CoolCard.Config.GetConfig("ERRORCODE", result_code), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #4
0
        public static void send_trans(CoolCard.MessagePackage.CardTrans trans)
        {
            // 上送交易前要先添加本地交易流水
            DB     db   = new DB();
            String guid = Guid.NewGuid().ToString();

            db.AddTrans(guid, trans.Card_No, trans.Action, trans.Batch_No, trans.Trace_No, trans.Amount, current_operator);
            db.ExecuteNoReturnSQL("UPDATE settings SET val = val + 1 WHERE setting = 'current_trace_no'");

            // 上送交易
            string   dataPackage = trans.Build_Trans_String();
            MySocket mSocket     = new MySocket();
            string   rtnString   = mSocket.Send(dataPackage);
            // 处理返回结果
            Hashtable hashTable = new Hashtable();

            hashTable = trans.GetReturnPackage(rtnString);
            // 如果返回成功,则更新本地数据表中的交易记录状态为"s"
            string action      = "";
            string shop_no     = "";
            string terminal_no = "";
            string trans_date  = "";
            string trans_time  = "";
            string batch_no    = "";
            string trace_no    = "";
            string result_code = "";

            foreach (DictionaryEntry de in hashTable)
            {
                if (de.Key.ToString().Trim() == "action")
                {
                    action = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "shop_no")
                {
                    shop_no = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "terminal_no")
                {
                    terminal_no = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "result_code")
                {
                    result_code = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "trans_date")
                {
                    trans_date = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "trans_time")
                {
                    trans_time = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "batch_no")
                {
                    batch_no = de.Value.ToString().Trim();
                }
                if (de.Key.ToString().Trim() == "trace_no")
                {
                    trace_no = de.Value.ToString().Trim();
                }
            }
            if (action != "settlement")
            {
                if (result_code == "0")
                {
                    db.UpdateTrans(guid, trans_date, trans_time, batch_no, trace_no, "s");
                    PrintTicket(hashTable);
                }
                else
                {
                    MessageBox.Show(result_code.ToString() + ":" + CoolCard.Config.GetConfig("ERRORCODE", result_code), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    db.UpdateTrans(guid, trans_date, trans_time, batch_no, trace_no, "f");
                }
            }
            else
            {
                if (result_code == "0" || result_code == "29")
                {
                    if (result_code == "29")
                    {
                        MessageBox.Show("账不平");
                    }

                    int payment_count        = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                    int deposit_count        = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                    int points_payment_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                    int points_deposit_count = db.GetCount("SELECT COUNT(*) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");

                    int payment_amount        = 0;
                    int deposit_amount        = 0;
                    int points_payment_amount = 0;
                    int points_deposit_amount = 0;

                    if (payment_count > 0)
                    {
                        payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'payment' AND state = 's'");
                    }
                    if (deposit_count > 0)
                    {
                        deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'deposit' AND state = 's'");
                    }
                    if (points_payment_count > 0)
                    {
                        points_payment_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_payment' AND state = 's'");
                    }
                    if (points_deposit_count > 0)
                    {
                        points_deposit_amount = db.GetCount("SELECT SUM(amount) FROM trans WHERE trans_name = 'points_deposit' AND state = 's'");
                    }

                    StreamReader sr          = new StreamReader(Environment.CurrentDirectory + "/settlement.tpl");
                    string       printString = "";
                    printString = sr.ReadToEnd();
                    sr.Close();
                    String settlement_data = "";
                    settlement_data += "消费\t" + payment_count.ToString() + "\t" + payment_amount.ToString() + "\t\n";
                    settlement_data += "充值\t" + deposit_count.ToString() + "\t" + deposit_amount.ToString() + "\t\n";

                    printString = printString.Replace("{shop_num}", shop_no);
                    printString = printString.Replace("{terminal_num}", terminal_no);
                    printString = printString.Replace("{date}", trans_date);
                    printString = printString.Replace("{time}", trans_time);
                    printString = printString.Replace("{settlement_data}", settlement_data);

                    db.ExecuteNoReturnSQL("DELETE FROM trans");
                    db.ExecuteNoReturnSQL("UPDATE settings SET val = val + 1 WHERE setting = 'current_batch_no'");
                    db.ExecuteNoReturnSQL("UPDATE settings SET val = '1' WHERE setting = 'current_trace_no'");

                    MessageBox.Show(printString);
                    //TicketsPrinter ticketsPrinter = new TicketsPrinter();
                    //ticketsPrinter.PrintString = printString;
                    //ticketsPrinter.printTicket();
                }
                else
                {
                    MessageBox.Show(result_code.ToString() + ":" + CoolCard.Config.GetConfig("ERRORCODE", result_code), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }