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.

305 lines
11 KiB
C#

9 months ago
using JwKdsV.Component;
using JwKdsV.Core;
using JwKdsV.Core.Utils;
using JwKdsV.Entity.Product;
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 JwKdsV
{
public partial class SaleClearModify : BaseForm
{
/// <summary>
/// 商品信息
/// </summary>
private ProductExt _product = null;
/// <summary>
/// 当前操作的沽清数据,如果为空表示新增
/// </summary>
private SaleClear _saleClear = null;
private SaleClear _oldValue = null;
public SaleClearModify(ProductExt product, SaleClear saleClear = null)
{
InitializeComponent();
this.Name = "SaleClearModify";
this._product = product;
this._saleClear = saleClear;
this.Text = this._saleClear == null ? "新增沽清设置" : "修改沽清设置";
this.txtTotalQuantity.Multiline = false;
this.txtTotalQuantity.GotFocus += OnGotFocus;
this.txtTotalQuantity.MouseDown += OnInputMouseDown;
this.txtNotifyQuantity.Multiline = false;
this.txtNotifyQuantity.GotFocus += OnGotFocus;
this.txtNotifyQuantity.MouseDown += OnInputMouseDown;
this.txtAddQuantity.Multiline = false;
this.txtAddQuantity.Text = "0";
this.txtAddQuantity.GotFocus += OnGotFocus;
this.txtAddQuantity.MouseDown += OnInputMouseDown;
if (this._saleClear == null)
{
this._saleClear = new SaleClear();
this._saleClear.Id = IdWorkerUtils.Instance.NextId();
this._saleClear.TenantId = Global.Instance.StoreInfo.TenantId;
this._saleClear.StoreNo = Global.Instance.StoreInfo.StoreNo;
this._saleClear.PosNo = Global.Instance.StoreInfo.PosNo;
this._saleClear.BrandId = this._product.BrandId;
this._saleClear.TypeId = this._product.TypeId;
this._saleClear.TypeName = this._product.TypeName;
this._saleClear.ProductId = this._product.Id;
this._saleClear.ProductNo = this._product.No;
this._saleClear.ProductName = this._product.Name;
this._saleClear.UnitId = this._product.UnitId;
this._saleClear.UnitName = this._product.UnitName;
this._saleClear.SpecId = this._product.SpecId;
this._saleClear.SpecName = this._product.SpecName;
this._saleClear.TotalQuantity = 0;
this._saleClear.NotifyQuantity = 0;
this._saleClear.SaleQuantity = 0;
this._saleClear.Quantity = 0;
this._saleClear.StopFlag = 0;
this._saleClear.SuitFlag = this._product.SuitFlag;
this._saleClear.StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
this._saleClear.EndTime = DateTime.Now.ToString("yyyy-MM-dd 23:59:00");
this._saleClear.CreateUser = Global.Instance.Worker.No;
this._saleClear.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
this._oldValue = ObjectUtils.Copy<SaleClear>(this._saleClear);
}
}
private void OnInputMouseDown(object sender, MouseEventArgs e)
{
if (sender is NumericTextBox)
{
var item = sender as NumericTextBox;
//如果鼠标左键操作并且标记存在,则执行全选
if (e.Button == MouseButtons.Left && (bool)item.Tag == true)
{
item.SelectAll();
}
//取消全选标记
item.Tag = false;
}
}
private void OnGotFocus(object sender, EventArgs e)
{
if (sender is NumericTextBox)
{
var item = sender as NumericTextBox;
item.Tag = true; //设置标记
item.SelectAll(); //注意
}
}
private bool ValidateInputValue()
{
if (string.IsNullOrEmpty(this.txtTotalQuantity.Text.Trim()))
{
this.ShowMessage(this.lblInfo, "沽清数量不能为空,请输入...", true);
this.txtTotalQuantity.Focus();
this.txtTotalQuantity.SelectAll();
return false;
}
if (this.txtTotalQuantity.DecimalValue < this.txtSaleQuantity.DecimalValue)
{
this.ShowMessage(this.lblInfo, "沽清数量不能小于已售数量,请输入...", true);
this.txtTotalQuantity.Focus();
this.txtTotalQuantity.SelectAll();
return false;
}
if (this.txtNotifyQuantity.DecimalValue > this.txtTotalQuantity.DecimalValue)
{
this.ShowMessage(this.lblInfo, "提醒数量不能大于沽清数量,请输入...", true);
this.txtNotifyQuantity.Focus();
this.txtNotifyQuantity.SelectAll();
return false;
}
if (this.txtTotalQuantity.DecimalValue != this.txtSaleQuantity.DecimalValue + this.txtQuantity.DecimalValue)
{
this.ShowMessage(this.lblInfo, "沽清数量、已售数量和剩余数量不匹配...", true);
this.txtTotalQuantity.Focus();
this.txtTotalQuantity.SelectAll();
return false;
}
//沽清时间
TimeSpan timespan = this.endTime.Value - this.startTime.Value;
if (timespan.Minutes < 0)
{
this.ShowMessage(this.lblInfo, "结束时间不能小于沽清时间...", true);
this.startTime.Focus();
return false;
}
this.ShowMessage(this.lblInfo, "单品沽清存储中...", false);
return true;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this.SetStyle(ControlStyles.Selectable, true);
//单品名称
this.lblProductName.Text = string.Format(this.lblProductName.Tag.ToString(), this._product.Name);
//销售单位
this.lblProductUnit.Text = string.Format(this.lblProductUnit.Tag.ToString(), this._product.UnitName);
//沽清数量
this.txtTotalQuantity.Text = this._saleClear.TotalQuantity.ToString();
//提醒数量
this.txtNotifyQuantity.Text = this._saleClear.NotifyQuantity.ToString();
//已售数量
this.txtSaleQuantity.Text = this._saleClear.SaleQuantity.ToString();
//剩余数量
this.txtQuantity.Text = this._saleClear.Quantity.ToString();
//沽清时间
var startTime = DateTime.Now;
DateTime.TryParse(this._saleClear.StartTime, out startTime);
this.startTime.Value = startTime;
//结束时间
var endTime = DateTime.Now;
DateTime.TryParse(this._saleClear.EndTime, out endTime);
this.endTime.Value = endTime;
//中途取消
this.chkStopFlag.Checked = (this._saleClear.StopFlag == 1);
this.ActiveControl = this.txtTotalQuantity;
this.txtTotalQuantity.Focus();
this.txtSaleQuantity.SelectAll();
}
private void OnTouchClick(object sender, Component.TouchEventArgs e)
{
switch (e.Value)
{
case "clear":
{
//如果当前焦点控件是输入框
if (this.ActiveControl is NumericTextBox)
{
var activeControl = this.ActiveControl as NumericTextBox;
activeControl.Text = string.Empty;
}
}
break;
case "close":
{
this.OnCancelClick(sender, EventArgs.Empty);
}
break;
case "accept":
{
var valid = ValidateInputValue();
if (valid)
{
bool isException = false;
try
{
this._saleClear.TotalQuantity = this.txtTotalQuantity.DecimalValue + this.txtAddQuantity.DecimalValue;
this._saleClear.NotifyQuantity = this.txtNotifyQuantity.DecimalValue;
this._saleClear.SaleQuantity = this.txtSaleQuantity.DecimalValue;
//变更剩余数量
this._saleClear.Quantity = this._saleClear.TotalQuantity - this._saleClear.SaleQuantity;
this._saleClear.StopFlag = this.chkStopFlag.Checked ? 1 : 0;
if (this._saleClear.StopFlag == 1)
{
this._saleClear.StopUser = Global.Instance.Worker.No;
this._saleClear.StopTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
//沽清时间
this._saleClear.StartTime = this.startTime.Value.ToString("yyyy-MM-dd HH:mm:00");
//结束时间
this._saleClear.EndTime = this.endTime.Value.ToString("yyyy-MM-dd HH:mm:59");
}
catch (Exception ex)
{
isException = true;
logger.Error(ex, "保存沽清数据异常");
}
finally
{
if (!isException)
{
//服务中心共享沽清
MessageCenterUtils.Instance.ChangeSaleClear(this._saleClear);
this.OnAcceptButtonClick(new TransparentEventArgs(TransparentAction.Accept, "accept", this._saleClear));
this.OnCancelClick(sender, EventArgs.Empty);
}
}
}
}
break;
default:
InputSimulatorUtils.SendKey(KeyCodes.Map[e.Value]);
break;
}
}
private void OnCancelClick(object sender, EventArgs e)
{
this.Close();
}
private void OnTotalQuantityValueChanged(object sender, EnterEventArg e)
{
var item = sender as NumericTextBox;
this.txtQuantity.Text = (item.DecimalValue - this.txtSaleQuantity.DecimalValue).ToString();
}
}
}