Files
zszq-trs/Tools/YLTestTool/Forms/FormEodSettleV2.cs
T
2024-05-09 14:06:26 +08:00

101 lines
3.4 KiB
C#

using YLErp.DBModels;
using YLErp.Modules.EodModule.SettlementModule;
namespace YLErp.Forms
{
public partial class FormEodSettleV2 : Form
{
readonly System.Threading.Timer _timer;
readonly Action<string> _LogAction;
public FormEodSettleV2()
{
InitializeComponent();
_timer = new System.Threading.Timer(Logout, null, 2000, 2000);
_LogAction = text => richTextBox1.Text = DateTime.Now.ToString() + ": " + text + Environment.NewLine;
}
private void btnExecute_Click(object sender, EventArgs e)
{
var date = dateTimePicker1.Value.Date;
btnExecute.Enabled = false;
var task = new EodTask
{
CreateTime = DateTime.Now,
CreatorId = 0,
CreatorName = "",
EndDate = date,
StartDate = date,
PriceType = comboBox2.SelectedIndex == 0 ? EodSettlePriceType.ClosePrice : EodSettlePriceType.SettlePrice,
VolTypes = comboBox1.SelectedItem.ToString()
};
EodTaskRunner.ExecuteDebugAsync(task).ContinueWith(t =>
{
this.Invoke(new Action(() =>
{
btnExecute.Enabled = true;
}));
MessageBox.Show("执行完成");
});
}
private void Logout(object state)
{
var datas = new EodTaskQueryService(OptUserInfo.UnitTestUser).GetEodTasksToShow(true);
if (datas == null || !datas.Any())
{
richTextBox1.Invoke(_LogAction, "没有找到任务");
return;
}
var item = datas.First();
if (item.Details != null && item.Details.Any())
{
var lastDetail = item.Details.LastOrDefault();
foreach (var detail in item.Details)
{
var str = $"收盘日期:{detail.ValueDate.OtcFormatDate()},";
if (detail != lastDetail || item.TaskState == EodTaskState.completed)
{
var seconds = detail.ElapsedMilliseconds / 1000d;
str += $"已完成,&nbsp; 用时{seconds:F3}秒";
}
else if (item.TaskState == EodTaskState.running)
{
str += $"执行中,开始时间:{detail.StartTime.ToString(ConsGlobal.DateTimeFormat)}";
}
else
{
str += $"{EodTaskHelper.GetEodTaskStateDesc(item.TaskState)}:{item.TaskResult}";
}
richTextBox1.Invoke(_LogAction, str);
}
}
else
{
var str = $"{EodTaskHelper.GetEodTaskStateDesc(item.TaskState)}:{item.TaskResult}";
richTextBox1.Invoke(_LogAction, str);
}
}
private void FormEodSettleV2_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
comboBox2.SelectedIndex = 0;
this.FormClosing += (s1, e1) =>
{
_timer.Change(Timeout.Infinite, Timeout.Infinite);
};
this.Shown += (s1, e1) =>
{
_timer.Change(2000, 2000);
};
}
}
}