private void button3_Click(object sender, EventArgs e) //订单校准 { string begin_date = textBox4.Text + " 00:00:00"; string end_date = textBox5.Text + " 23:59:59"; if (DateTime.Compare(Convert.ToDateTime(end_date), Convert.ToDateTime(begin_date)) > 0) { sqlConn = "Server=172.20.24.196;DataBase=ICCSPayDB_develop;uid=sa;pwd=`123qwer"; string sqlStr = "select * from StationOrder where ((OrderStatus <> '5') and PaymentVendor in ('1001','1002','0001','0002') and PayEndTime >= '" + begin_date + "' and PayEndTime <= '" + end_date + "')"; SqlConnection Conn = new SqlConnection(sqlConn); Conn.Open(); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(sqlStr, Conn); da.SelectCommand = cmd; da.SelectCommand.ExecuteNonQuery(); da.Fill(ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { ICCSPayAPIResultVO payResultVo = null; ICCSPayAPIHandle ap = new ICCSPayAPIHandle(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //orderStatus = ds.Tables[0].Rows[i]["OrderStatus"].ToString(); //step = ds.Tables[0].Rows[i]["Step"].ToString(); payResultVo = ap.ICCSPay_Orderquery(ds.Tables[0].Rows[i]["PaymentVendor"].ToString(), ds.Tables[0].Rows[i]["TradeNo"].ToString()); if ((ds.Tables[0].Rows[i]["OrderStatus"].ToString() == "1" || ds.Tables[0].Rows[i]["OrderStatus"].ToString() == "4") && (payResultVo != null && payResultVo.is_success && payResultVo.ActualFee > 100) && ((paymentVendor == "0001" && payResultVo.result_code == "SUCCESS") || (paymentVendor == "1001" && payResultVo.result_code == "TRADE_SUCCESS") || (paymentVendor == "1002" && payResultVo.result_code == "OK"))) { } } } Conn.Close(); } }
private void button2_Click(object sender, EventArgs e) { if (isRefundable) { ICCSPayAPIResultVO payResultVo = null; ICCSPayAPIHandle ap = new ICCSPayAPIHandle(); payResultVo = ap.ICCSPay_Orderquery(paymentVendor, orderNo); string s = payResultVo.toPrint(); if ((payResultVo != null && payResultVo.is_success && payResultVo.ActualFee > 100) && ((paymentVendor == "0001" && payResultVo.result_code == "SUCCESS") || (paymentVendor == "1001" && payResultVo.result_code == "TRADE_SUCCESS") || (paymentVendor == "1002" && payResultVo.result_code == "OK"))) { //确定订单已支付,后续可开展退款 ICCSPayAPIResultVO refundVo = ap.ICCSPay_Refund(paymentVendor, payResultVo.transactionId, orderNo, payResultVo.ActualFee, payResultVo.ActualFee); if (refundVo.is_success) { //更新订单记录 SqlConnection Conn1 = new SqlConnection(sqlConn); string updateSql = ""; if (orderNo.StartsWith("A")) { updateSql = "Update " + sqlTable + " set TransactionId='" + payResultVo.transactionId + "',BankType='" + payResultVo.BankType + "',PayEndTime='" + payResultVo.returnEndTime + "',PayEndTimeRaw='" + payResultVo.returnEndTimeRaw + "',ActualFee='" + payResultVo.ActualFee + "',OrderStatus='8',Step='7' where orderNo = '" + orderNo + "'"; } else { updateSql = "Update " + sqlTable + " set TransactionId='" + payResultVo.transactionId + "',BankType='" + payResultVo.BankType + "',PayEndTime='" + payResultVo.returnEndTime + "',PayEndTimeRaw='" + payResultVo.returnEndTimeRaw + "',ActualFee='" + payResultVo.ActualFee + "',OrderStatus='8',Step='7' where tradeNo = '" + orderNo + "'"; } SqlCommand cmd1 = new SqlCommand(updateSql, Conn1); try { Conn1.Open(); cmd1.ExecuteNonQuery(); Conn1.Close(); textBox3.Text = "订单 " + orderNo + " 已退款!"; _log.Info("订单 " + orderNo + " 已于" + DateTime.Now.ToString() + "申请退款成功,退款金额 :" + refundVo.ActualFee + "分,且已更新订单表订单状态。"); } catch (Exception ex) { MessageBox.Show(ex.Message); } //增加退款表信息 SqlConnection Conn2 = new SqlConnection(sqlConn); string insertSql = "insert into WebOrderRefund (WebOrderRefundId ,WebOrderId ,TradeNo,ExternalTradeNo,RefundTradeNo" + ",RefundReason,PaymentVendor,RefundFee,TotalFee,BankType" + ",RequestTime,IsRequestSuccess,RequestErrCodeDes ,IsRespondSuccess" + ",RespondTime ,RespondErrCodeDes ,OrderStatus) VALUES " + "('" + Guid.NewGuid() + "','" + Guid.NewGuid() + "','" + orderNo + "','" + Guid.NewGuid() + "','" + payResultVo.transactionId + "','" + "申请退款" + "','" + paymentVendor + "','" + payResultVo.ActualFee + "','" + payResultVo.ActualFee + "','" + payResultVo.BankType + "','" + DateTime.Now + "','0','" + "" + "','0','" + refundVo.returnEndTime + "','" + "" + "','8')"; SqlCommand cmd2 = new SqlCommand(insertSql, Conn2); try { Conn2.Open(); cmd2.ExecuteNonQuery(); Conn2.Close(); _log.Info("订单 " + orderNo + " 已申请退款,并将订单退款记录写入退款表。"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { textBox3.Text = "订单 " + orderNo + " 未支付,不可申请退款!"; } } else { textBox3.Text = "订单 " + orderNo + " 不可申请退款!"; } }