You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
7.1 KiB
C#

using DevComponents.DotNetBar;
using POS.Language.Language;
using POSV.Component;
using POSV.StoreBusiness;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace POSV.Report
{
public partial class OperationLogForm : BusinessForm
{
public OperationLogForm()
{
InitializeComponent();
this.controlBox1.Text = LangProxy.ToLang("操作监控");
this.controlBox1.ShowApplicationVersion = false;
}
/// <summary>
/// 操作记录
/// </summary>
List<StoreOperationLogEntity> logList = new List<StoreOperationLogEntity>();
/// <summary>
/// 操作汇总
/// </summary>
List<StoreOperationLogEntity> summaryLogList = new List<StoreOperationLogEntity>();
public string workerNo = "";
public int PrintType = 1;//1操作记录,2操作汇总
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
DefaultGridStyle.setDefaultGridStyle(this.logListTable);
DefaultGridStyle.setDefaultGridStyle(this.summaryListTable);
this.startPicker.Value = DateTime.Parse(Global.Instance.BusinessPlan.StartTimeSimple);
this.endPicker.Value = DateTime.Parse(Global.Instance.BusinessPlan.EndTimeSimple);
QueyTicket();
}
private void BtnTimeClick(object sender, EventArgs e)
{
var obj = sender as ButtonX;
var typeStr = obj.Tag as string;
var type = (ReportQuickDate)Enum.Parse(typeof(ReportQuickDate), typeStr);
var res = DateTimeUtils.CalculateBusinessPlanDate(type, this.startPicker.Value, this.endPicker.Value);
this.startPicker.Value = res.Item1;
this.endPicker.Value = res.Item2;
QueyTicket();
}
private void TabOnClick(object sender, EventArgs e)
{
try
{
var obj = sender as SuperTabItem;
var name = obj.Tag as string;
switch (name)
{
case "superTabItem1"://单品汇总
PrintType = 1;
break;
case "superTabItem2"://类别汇总
PrintType = 2;
break;
}
QueyTicket();
}
catch (Exception ex)
{
LOGGER.Error(ex);
}
}
private void BtnExitClick(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
private void BtnQueryClick(object sender, EventArgs e)
{
QueyTicket();
}
public void QueyTicket()
{
workerNo = StringUtils.GetString(txtWorkNo.Text);
if (!"".Equals(workerNo) && workerNo.Length < 5)
{
int length = 5 - workerNo.Length;
for (int i = 0; i < length; i++)
{
workerNo = "0" + workerNo;
}
}
switch (PrintType)
{
case 1:
logList = getOperationLogList(workerNo, this.startPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"), this.endPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"));
logListTable.PrimaryGrid.DataSource = logList;
break;
case 2:
summaryLogList = getSummaryOperationLogList(workerNo, this.startPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"), this.endPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"));
summaryListTable.PrimaryGrid.DataSource = summaryLogList;
break;
}
}
public List<StoreOperationLogEntity> getOperationLogList(string workerNo, string startTime, string endTime)
{
List<StoreOperationLogEntity> newList = new List<StoreOperationLogEntity>(); ;
try
{
using (var db = Global.Instance.OpenDataBase)
{
StringBuilder sqlBuld = new StringBuilder();
sqlBuld.Append(" select workerNo,shiftNo,shiftName,operationTime,type,typeTxt,memo ");
sqlBuld.Append(" from pos_store_operation_log ");
sqlBuld.Append(" where createDate >= '{0}' and createDate <= '{1}' ");
if (!"".Equals(workerNo))
{
sqlBuld.Append(" and workerNo = '" + workerNo + "' ");
}
sqlBuld.Append(" order by createDate desc");
string sql = string.Format(sqlBuld.ToString(), startTime, endTime);
newList = db.Query<StoreOperationLogEntity>(sql).ToList();
if (newList == null)
{
newList = new List<StoreOperationLogEntity>();
}
}
}
catch (Exception ex)
{
LOGGER.Error(ex);
}
return newList;
}
public List<StoreOperationLogEntity> getSummaryOperationLogList(string workerNo, string startTime, string endTime)
{
List<StoreOperationLogEntity> newList = new List<StoreOperationLogEntity>(); ;
try
{
using (var db = Global.Instance.OpenDataBase)
{
StringBuilder sqlBuld = new StringBuilder();
sqlBuld.Append(" select workerNo,typeTxt,count(id) as ext1 ");
sqlBuld.Append(" from pos_store_operation_log ");
sqlBuld.Append(" where createDate >= '{0}' and createDate <= '{1}' ");
if (!"".Equals(workerNo))
{
sqlBuld.Append(" and workerNo = '" + workerNo + "' ");
}
sqlBuld.Append(" group by workerNo,type ");
string sql = string.Format(sqlBuld.ToString(), startTime, endTime);
newList = db.Query<StoreOperationLogEntity>(sql).ToList();
if (newList == null)
{
newList = new List<StoreOperationLogEntity>();
}
}
}
catch (Exception ex)
{
LOGGER.Error(ex);
}
return newList;
}
private void OnControlBoxCloseClick(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
private void OnCloseTouchClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void OnControlBoxMinClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
}
}