/* * 冲正交易 */ 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; } }
/* * 结算 */ private void do_settlement() { if (MessageBox.Show("确定结算?", "", MessageBoxButtons.OKCancel) == DialogResult.OK) { MainForm.trans.init(); MainForm.trans.Action = "settlement"; string dataPackage = MainForm.trans.Build_Trans_String(); // 上送交易 MySocket mSocket = new MySocket(); string rtnString = mSocket.Send(dataPackage); // 打印统计单 } }
/* * 结算 */ private void do_settlement() { if (MessageBox.Show("确定结算?", "", MessageBoxButtons.OKCancel) == DialogResult.OK) { MainForm.trans.init(); MainForm .trans.Action = "settlement"; string dataPackage = MainForm.trans.Build_Trans_String(); // 上送交易 MySocket mSocket = new MySocket(); string rtnString = mSocket.Send(dataPackage); // 打印统计单 } }
private void btnAddMember_Click(object sender, EventArgs e) { if (this.txtMemberName.Text.Trim() == "") { MessageBox.Show("会员名称不能为空!"); return; } if (this.txtCellNumber.Text.Trim() == "") { MessageBox.Show("电话号码不能为空!"); return; } if (this.txtCardNumber.Text.Trim() == "") { MessageBox.Show("卡号不能为空!"); return; } Member member = new Member(); member.Action = "bind_member"; member.Member_Card_Number = this.txtCardNumber.Text.Trim(); member.Member_Cell_Number = this.txtCellNumber.Text.Trim(); member.Member_Name = this.txtMemberName.Text.Trim(); member.Member_Id_Number = this.txtIdNumber.Text.Trim(); member.Member_Remark = this.txtRemark.Text.Trim(); member.Member_Sex = this.comboBoxSex.Text.Trim(); string trans_string = member.Build_String(); MySocket ms = new MySocket(); string rst = ms.Send(trans_string); MessageBox.Show(CoolCard.Config.GetConfig("ERRORCODE", rst, "未找到消息配置")); }
private void btnAddMember_Click(object sender, EventArgs e) { if (this.txtMemberName.Text.Trim() == "") { MessageBox.Show("会员名称不能为空!"); return; } if (this.txtCellNumber.Text.Trim() == "") { MessageBox.Show("电话号码不能为空!"); return; } if (this.txtCardNumber.Text.Trim() == "") { MessageBox.Show("卡号不能为空!"); return; } Member member = new Member(); member.Action = "bind_member"; member.Member_Card_Number = this.txtCardNumber.Text.Trim(); member.Member_Cell_Number = this.txtCellNumber.Text.Trim(); member.Member_Name = this.txtMemberName.Text.Trim(); member.Member_Id_Number = this.txtIdNumber.Text.Trim(); member.Member_Remark = this.txtRemark.Text.Trim(); member.Member_Sex = this.comboBoxSex.Text.Trim(); string trans_string = member.Build_String(); MySocket ms = new MySocket(); string rst = ms.Send(trans_string); MessageBox.Show(CoolCard.Config .GetConfig ("ERRORCODE", rst, "未找到消息配置")); }
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); } } }
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(); } }
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); } } }
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(); } }