257 lines
8.2 KiB
C#
257 lines
8.2 KiB
C#
using AllBase;
|
|
using AllBase.Extension;
|
|
using AllBase.Model.Result;
|
|
using AllBase.Model.Result.PDDResult;
|
|
using AllBase.Model.Result.WXResult;
|
|
using NaiBa.Util;
|
|
using NaiBa.Util.Extension;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.BaseForms;
|
|
using TemuKJD.Extension;
|
|
using Work;
|
|
|
|
namespace TemuKJD.WXForms.AdminForms
|
|
{
|
|
public partial class WXAdminOemWithdrawal : BaseForms.BaseGeneralForm
|
|
{
|
|
private BindingList<WXOemWithdrawalInfo> dataList = new BindingList<WXOemWithdrawalInfo>();
|
|
|
|
public WXAdminOemWithdrawal()
|
|
{
|
|
InitializeComponent();
|
|
InitBindingDataGridView();
|
|
|
|
}
|
|
private void InitBindingDataGridView()
|
|
{
|
|
this.dgvExpress.AutoGenerateColumns = false;
|
|
|
|
this.Column1.DataPropertyName = nameof(WXOemWithdrawalInfo.withdrawal_no);
|
|
this.Column2.DataPropertyName = nameof(WXOemWithdrawalInfo.amount);
|
|
this.Column3.DataPropertyName = nameof(WXOemWithdrawalInfo.withdrawal_type_string);
|
|
this.Column4.DataPropertyName = nameof(WXOemWithdrawalInfo.account_no);
|
|
this.Column5.DataPropertyName = nameof(WXOemWithdrawalInfo.status_string);
|
|
this.Column6.DataPropertyName = nameof(WXOemWithdrawalInfo.created_at);
|
|
this.Column7.DataPropertyName = nameof(WXOemWithdrawalInfo.audit_remark);
|
|
this.Column8.DataPropertyName = nameof(WXOemWithdrawalInfo.audit_time);
|
|
this.Column9.DataPropertyName = nameof(WXOemWithdrawalInfo.pay_trade_no);
|
|
this.Column10.DataPropertyName = nameof(WXOemWithdrawalInfo.oem_name);
|
|
// 2. 设置列样式
|
|
// 时间列格式化
|
|
this.Column6.DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";
|
|
this.Column8.DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
// 金额列右对齐
|
|
this.Column2.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
|
|
this.Column11.Text = "审核";
|
|
// 操作列:允许每行单独显示 审核/查看(已审核完毕的行展示审核内容)
|
|
this.Column11.UseColumnTextForLinkValue = false;
|
|
|
|
// 3. 注册金额格式化事件(分→元)
|
|
this.dgvExpress.CellFormatting += DgvExpress_CellFormatting;
|
|
|
|
this.dgvExpress.DataSource = dataList;
|
|
this.dgvExpress.CellContentClick += DgvExpress_CellContentClick;
|
|
}
|
|
|
|
private void DgvExpress_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex < 0) return;
|
|
var header = this.dgvExpress.Columns[e.ColumnIndex];
|
|
if (header.HeaderText == "审核")
|
|
{
|
|
var data = this.dgvExpress.Rows[e.RowIndex].DataBoundItem as WXOemWithdrawalInfo;
|
|
if (data == null) return;
|
|
// 待审核 → 可修改提交;已审核完毕(status!=0) → 仅展示审核内容,不允许二次修改和提交
|
|
WXAdminOemWithdrawalAuditForm auditForm = new WXAdminOemWithdrawalAuditForm(data);
|
|
if (auditForm.ShowDialog(this) == DialogResult.OK)
|
|
{
|
|
// 审核成功,刷新列表
|
|
GetDeliveryAndWaybill(this.ucSplitPage1.CurrentPage);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DgvExpress_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
// 操作列:待审核显示"审核",已审核完毕显示"查看"
|
|
if (e.ColumnIndex == this.Column11.Index && e.RowIndex >= 0)
|
|
{
|
|
var data = this.dgvExpress.Rows[e.RowIndex].DataBoundItem as WXOemWithdrawalInfo;
|
|
if (data != null)
|
|
{
|
|
e.Value = data.status == 0 ? "审核" : "查看";
|
|
e.FormattingApplied = true;
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 金额列:将分转换为元
|
|
if (e.ColumnIndex == this.Column2.Index && e.Value != null && e.Value != DBNull.Value)
|
|
{
|
|
if (long.TryParse(e.Value.ToString(), out long amountInFen))
|
|
{
|
|
e.Value = (amountInFen / 100m).ToString("F2");
|
|
e.FormattingApplied = true;
|
|
}
|
|
}
|
|
}
|
|
private void WXWaybillManageForm_Load(object sender, EventArgs e)
|
|
{
|
|
this.dgvExpress.AddSelectorColumn("colSelect");
|
|
|
|
// 初始化搜索条件默认值:状态默认"全部",时间默认查询全部记录
|
|
this.cmbStatus.SelectedIndex = 0;
|
|
this.dtpTimeBegin.Value = DateTime.Now.Date.AddYears(-10);
|
|
this.dtpTimeEnd.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
|
|
}
|
|
|
|
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
GetDeliveryAndWaybill();
|
|
}
|
|
|
|
/// <summary>清空搜索条件并重新加载</summary>
|
|
private void btnEmpty_Click(object sender, EventArgs e)
|
|
{
|
|
this.txtWithdrawalNo.Text = "";
|
|
this.txtOemIds.Text = "";
|
|
this.cmbStatus.SelectedIndex = 0;
|
|
this.dtpTimeBegin.Value = DateTime.Now.Date.AddYears(-10);
|
|
this.dtpTimeEnd.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
|
|
GetDeliveryAndWaybill();
|
|
}
|
|
|
|
void GetDeliveryAndWaybill()
|
|
{
|
|
if (this.ucSplitPage1.CurrentPage != 1)
|
|
this.ucSplitPage1.CurrentPage = 1;
|
|
else
|
|
GetDeliveryAndWaybill(1);
|
|
}
|
|
|
|
public void GetDeliveryAndWaybill(int page)
|
|
{
|
|
|
|
this.pbLoading.Visible = true;
|
|
this.dgvExpress.Rows.Clear();
|
|
dataList.Clear();
|
|
int pageCount;
|
|
int pageSize = 100;
|
|
decimal seconds;
|
|
pageSize = this.ucSplitPage1.PageSize;
|
|
|
|
// 在UI线程上读取搜索条件,避免跨线程访问控件
|
|
string withdrawalNo = this.txtWithdrawalNo.Text.Trim();
|
|
string oemIds = this.txtOemIds.Text.Trim();
|
|
int? status = this.cmbStatus.SelectedIndex <= 0 ? (int?)null : this.cmbStatus.SelectedIndex - 1;
|
|
string startTime = this.dtpTimeBegin.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
string endTime = this.dtpTimeEnd.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
Task.Run(() =>
|
|
{
|
|
|
|
List<WXOemWithdrawalInfo> list = GetOemWithdrawals(out pageCount, out seconds, page, pageSize, withdrawalNo, oemIds, status, startTime, endTime);
|
|
|
|
this.ucSplitPage1.TotalPage = pageCount;
|
|
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
list.ForEach(a => dataList.Add(a));
|
|
this.pbLoading.Visible = false;
|
|
this.statusBar.lblTaskStatus.Text = "运单号查询完毕";
|
|
#if DEBUG
|
|
this.statusBar.lblTaskStatus.Text += ",耗时:" + seconds;
|
|
#endif
|
|
}));
|
|
});
|
|
}
|
|
|
|
|
|
public List<WXOemWithdrawalInfo> GetOemWithdrawals(out int pageCount, out decimal seconds, int page = 1, int pageSize = 200, string withdrawalNo = "", string oemIds = "", int? status = null, string startTime = "", string endTime = "")
|
|
{
|
|
List<WXOemWithdrawalInfo> list = new List<WXOemWithdrawalInfo>();
|
|
pageCount = 1;
|
|
seconds = 0;
|
|
|
|
var url = BaseClass.BuildObjString("user/oem_withdrawals");
|
|
|
|
string data = "";
|
|
var obj = UserLogin.GetSignPostData(new
|
|
{
|
|
page = page,
|
|
page_size = pageSize,
|
|
withdrawal_no = string.IsNullOrEmpty(withdrawalNo) ? null : withdrawalNo,
|
|
oem_ids = string.IsNullOrEmpty(oemIds) ? null : oemIds,
|
|
status = status,
|
|
start_time = string.IsNullOrEmpty(startTime) ? null : startTime,
|
|
end_time = string.IsNullOrEmpty(endTime) ? null : endTime
|
|
});
|
|
|
|
// GetSignPostData 会把 null 转成空字符串,这里去掉空参数,避免后端收到 status="" 之类的空值
|
|
var expando = obj as System.Dynamic.ExpandoObject;
|
|
if (expando != null)
|
|
{
|
|
var dict = expando as IDictionary<string, object>;
|
|
var emptyKeys = dict.Where(kv => kv.Value == null || (kv.Value is string s && string.IsNullOrEmpty(s)))
|
|
.Select(kv => kv.Key).ToList();
|
|
foreach (var key in emptyKeys)
|
|
dict.Remove(key);
|
|
}
|
|
|
|
data = JsonHelper.SerializeObject(obj);
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
var ret = JsonConvert.DeserializeObject<PageResult<WXOemWithdrawalInfo>>(html);
|
|
if (ret.Code != 200)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
BaseMsgForm.ShowError("运单列表获取失败,请重试!" + ret.Msg);
|
|
}));
|
|
return list;
|
|
}
|
|
|
|
seconds = BaseRegex.GetDecimalJson(ref html, "seconds");
|
|
pageCount = Math.Ceiling(1.0 * ret.Total / pageSize).ParseToInt();
|
|
pageCount = Math.Max(pageCount, 1);
|
|
|
|
return ret.Data;
|
|
|
|
}
|
|
|
|
private void ucSplitPage1_PageChange(object obj)
|
|
{
|
|
GetDeliveryAndWaybill(ucSplitPage1.CurrentPage);
|
|
}
|
|
|
|
bool first = true;
|
|
private void WXWaybillManageForm_VisibleChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.Visible == true && first)
|
|
{
|
|
first = false;
|
|
|
|
this.pbLoading.Visible = true;
|
|
GetDeliveryAndWaybill(ucSplitPage1.CurrentPage);
|
|
}
|
|
}
|
|
|
|
public bool IsOperate = false;
|
|
}
|
|
}
|