Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string password = this.txtOldPassword.Text.Trim();          // 原密码
            string newPassword = this.txtNewPassword.Text.Trim();       // 新密码
            string reNewPassword = this.txtReNewPassword.Text.Trim();   // 重复新密码

            if (newPassword != reNewPassword)  // 检查两次输入的新密码是否一致
            {
                MessageBox.Show("两次输入的新密码不一致!");
                return;
            }

            DB db = new DB();
            DataTable dt = new DataTable();
            dt = db.ExecuteReturnSQL("SELECT password FROM operators WHERE operator_no = '" + MainForm.current_operator + "'");
            if (dt.Rows.Count > 0)
            {
                if (password == dt.Rows[0][0].ToString().Trim())
                {
                    db.ExecuteNoReturnSQL("UPDATE operators SET password = '******' WHERE operator_no = '" + MainForm.current_operator + "'");
                }
                else
                {
                    MessageBox.Show("原密码不正确!");
                }
            }
            else
            {
                MessageBox.Show("操作员不存在!");
            }
        }
Example #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);

            }
        }
Example #3
0
 public static String getTraceNum()
 {
     DB db = new DB();
     DataTable traceData = db.ExecuteReturnSQL("SELECT val FROM settings WHERE setting = 'current_trace_no'");
     if (traceData.Rows.Count > 0)
     {
         String traceNum = traceData.Rows[0][0].ToString() ;
         return Convert.ToString(traceNum);
     }
     else
     {
         return "1";
     }
 }
Example #4
0
 public static String getBatchNum()
 {
     DB db = new DB();
     DataTable batchData = db.ExecuteReturnSQL("SELECT val FROM settings WHERE setting = 'current_batch_no'");
     if (batchData.Rows.Count > 0)
     {
         String batchNum = batchData.Rows[0][0].ToString();
         return Convert.ToString(batchNum);
     }
     else
     {
         return "1";
     }
 }
Example #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string operatorNo = this.txtOperatorNo.Text.Trim();
            string password = this.txtPassword.Text.Trim();
            string rePassword = this.txtRePassword.Text.Trim();

            if (operatorNo == "")
            {
                MessageBox.Show("操作员号不能为空!");
                return;
            }

            if (password != rePassword)
            {
                MessageBox.Show("两次输入的密码不一致!");
                return;
            }


            DB db = new DB();
            DataTable dt = new DataTable();
            dt = db.ExecuteReturnSQL("SELECT * FROM operators WHERE operator_no = '" + operatorNo + "'");
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("此操作员已存在!");
            }
            else
            {
                if (db.ExecuteNoReturnSQL("INSERT INTO operators (operator_no, password) VALUES ('" + operatorNo + "', '" + password + "')"))
                {
                    MessageBox.Show("添加操作员成功!");
                }
                else
                {
                    MessageBox.Show("添加操作员失败!");
                }
            }

        }
Example #6
0
        /*
         *  冲正交易
         */
        private void do_reversal(int reversal_times)
        {
            DB db = new DB();
            DataTable dt = new DataTable();
            dt = db.ExecuteReturnSQL("SELECT id, card_no, batch_no, trace_no FROM trans WHERE state='p' AND trans_name IN ('payment', 'deposit', 'cancel_trans', 'points_payment', 'points_deposit')");
            if (dt.Rows.Count > 0)
            {
                this.statusTransText.Text = "冲正";
                this.Refresh();

                String id = dt.Rows[0]["id"].ToString();
                String card_no = dt.Rows[0]["card_no"].ToString();
                String old_batch_no = dt.Rows[0]["batch_no"].ToString();
                String old_trace_no = dt.Rows[0]["trace_no"].ToString();

                trans.init();
                trans.Action = "reversal";
                trans.Old_Batch_No = old_batch_no;
                trans.Old_Trace_No = old_trace_no;
                trans.Card_No = card_no;

                trans.Batch_No = Utils.getBatchNum();
                trans.Trace_No = Utils.getTraceNum();

                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 result_code = "";
                foreach (DictionaryEntry de in hashTable)
                {
                    if (de.Key.ToString().Trim() == "result_code")
                    {
                        result_code = de.Value.ToString().Trim();
                    }
                }

                if (result_code == "1")
                {
                    db.ExecuteNoReturnSQL(String.Format("UPDATE trans SET state='s' WHERE id='{0}'", id));
                }

                this.statusTransText.Text = "";
                this.Refresh();
            }
            else
            {
                return;
            }
        }
Example #7
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);
                }
            }
        }
Example #8
0
        private void SignInForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                String operator_no = this.textBox_operator_no.Text.Trim();
                String operator_password = this.textBox_operator_password.Text.Trim();
                if (operator_password == "")
                {
                    this.textBox_operator_password.Focus();
                    return;
                }
                if (operator_no == "")
                {
                    this.textBox_operator_no.Focus();
                    return;
                }

            //                DB db = new DB();
            //                String sql = "SELECT * FROM operators WHERE operator_no ='" + operator_no + "' AND password = '******'";
            //                SQLiteDataReader dr = db.ExecuteReturnSQL(sql);
            //                if (dr == null)
            //                {
            //                    MessageBox.Show("未知错误,请联系软件提供商");
            //                    return;
            //                }
            //                if (dr.HasRows == true)
            //                {
                    //签到交易包

                    MainForm.trans.init();
                    Config cfg = new Config();

                    MainForm.trans.Action = "singin";
                    MainForm.trans.Operator_Account = operator_no;
                    MainForm.trans.Operator_Password = CoolCard.Security.MD5Encrypt(operator_password);
                    string transString = MainForm.trans.Build_Trans_String();

                    MySocket mSocket = new MySocket();
                    string rtnString = mSocket.Send(transString);

                    //处理返回结果
                    rtnString = rtnString.Replace(@"""", "").Replace("'", "").Replace("{", "").Replace("}", "");
                    string[] tmp_arr1 = rtnString.Split(',');
                    string[] tmp_arr2;
                    Hashtable hashTable = new Hashtable();
                    for (int i = 0; i < tmp_arr1.Length; i++)
                    {
                        tmp_arr2 = tmp_arr1[i].ToString().Split(':');
                        hashTable.Add(tmp_arr2[0].ToString(), tmp_arr2[1].ToString());
                    }
                    //如果返回成功,则更新本地数据表中的交易记录状态为"s"
                    string trans_date = "";
                    string trans_time = "";
                    string result_code = "";
                    int batch_no = 0;
                    int tracte_no = 0;
                    foreach (DictionaryEntry de in hashTable)
                    {
                        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 = Convert.ToInt32(de.Value.ToString());
                        }
                        if(de.Key.ToString().Trim() == "trace_no")
                        {
                            tracte_no = Convert.ToInt32(de.Value.ToString());
                        }
                    }

                    if (result_code == "0")
                    {
                        MainForm.login = true;
                        MainForm.current_operator = operator_no;
                        DB db = new DB();
                        db.ExecuteNoReturnSQL(String.Format("UPDATE settings SET val = '{0}' WHERE setting = 'current_batch_no'", batch_no.ToString()));
                        db.ExecuteNoReturnSQL(String.Format("UPDATE settings SET val = '{0}' WHERE setting = 'current_trace_no'", tracte_no.ToString()));
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(result_code.ToString() + ":" + CoolCard .Config .GetConfig ("ERRORCODE", result_code, ""), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
            //                }
            //                else
            //                {
            //                    MessageBox.Show("操作员不存在或密码错");
            //                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                MainForm.loginCanceled = true;
                MainForm.login = true;
                this.Close();
            }
        }