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.

516 lines
20 KiB
C#

9 months ago
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.SuperGrid;
using POSV.Card;
using POSV.Component;
using POSV.Entity;
using POSV.Helper;
using POSV.Template;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace POSV.Stock
{
public partial class StoreStockCheckForm : BusinessForm
{
private List<StoreStorage> storageList = new List<StoreStorage>();
private string storageId = null;
private List<StockUncheckTicketDetailResponse> details = new List<StockUncheckTicketDetailResponse>();//盘点列表
public StoreStockCheckForm()
{
InitializeComponent();
this.controlBox1.Text = "门店库存盘点";
this.controlBox1.ShowApplicationVersion = false;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this.Focus();
this.noTextBox.Focus();
this.noTextBox.SelectAll();
this.ActiveControl = this.noTextBox;
//仓库列表
InitStorageMenu();
//可编辑cell颜色特殊标注
var panel = this.stockListTable.PrimaryGrid;
Color bgColor = ColorTranslator.FromHtml("193,255,192");
panel.Columns["checkAmount"].CellStyles.Default.Background.Color1 = bgColor;
panel.Columns["description"].CellStyles.Default.Background.Color1 = bgColor;
Color textColor = ColorTranslator.FromHtml("255,0,0");
panel.Columns["operation"].CellStyles.Default.TextColor = textColor;
//默认查询未审核的单据
ProductStockQuery();
}
private void InitStorageMenu()
{
StoreStorage storeStorage = new StoreStorage();
storeStorage.Id = "";
storeStorage.No = "";
storeStorage.Name = "全部仓库";
storageList.Add(storeStorage);
try
{
using (var db = Global.Instance.OpenDataBase)
{
StringBuilder sqlBuf = new StringBuilder();
sqlBuf.Append(" select id,no,name from pos_store_storage ;");
storageList.AddRange(db.Fetch<StoreStorage>(sqlBuf.ToString()));
}
}
catch (Exception ex)
{
LOGGER.Error(ex);
}
RefreshMain();
}
private void RefreshMain()
{
this.comboBoxEx1.DisplayMember = "name";
this.comboBoxEx1.ValueMember = "id";
this.comboBoxEx1.DataSource = storageList;
this.comboBoxEx1.SelectedIndexChanged += OnStorageSelectedIndexChanged;
}
private void OnStorageSelectedIndexChanged(object sender, EventArgs e)
{
var obj = sender as ComboBoxEx;
storageId = StringUtils.GetString(obj.SelectedValue);
}
private void OnCloseTouchClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void OnControlBoxKeyboardClick(object sender, EventArgs e)
{
}
private void exitClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void queryClick(object sender, EventArgs e)
{
ProductStockQuery();
}
private void OnDataBindingComplete(object sender, DevComponents.DotNetBar.SuperGrid.GridDataBindingCompleteEventArgs e)
{
var rows = e.GridPanel.Rows;
foreach (GridRow row in rows)
{
row.Cells["sysPrice"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["sysPrice"].Value));
row.Cells["checkAmount"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["checkAmount"].Value));
row.Cells["checkMoney"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["checkMoney"].Value));
}
}
public void ProductStockQuery()
{
try
{
var request = new StockUncheckTicketDetailRequest();
request.StoreId = Global.Instance.Authc.StoreId;
request.StorageId = storageId;
request.TypeId = "";
request.Keyword = this.noTextBox.Text;
var response = StockUtils.StockUncheckTicketDetail(request);
//成功
if (response.Item1)
{
details = response.Item3.List;
foreach (var ticketDetail in details) {
ticketDetail.Operation = "删除";
}
stockListTable.PrimaryGrid.DataSource = details;
}
else
{
details = new List<StockUncheckTicketDetailResponse>();
stockListTable.PrimaryGrid.DataSource = details;
this.ShowToastNotify(this, response.Item2);
}
}
catch (Exception ex)
{
this.ShowToastNotify(this, "未审核的盘点明细列表查询异常");
LOGGER.Error(ex, "未审核的盘点明细列表查询异常");
}
}
/// <summary>
/// 新增盘点单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddClick(object sender, EventArgs e)
{
var addForm = new StoreStockCheckAddForm();
addForm.OnTicktQuery += Form_OnTicktQuery;
TransparentForm trans = new TransparentForm(this, addForm);
trans.Show(this);
}
private void Form_OnTicktQuery(object sender)
{
ProductStockQuery();
}
/// <summary>
/// 盘点审核
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ApplyClick(object sender, EventArgs e)
{
if (details != null && details.Count > 0)
{
//打开提示界面
var form = new StoreStockCheckApplyForm(1);
form.OnApplyClick += Form_OnApplyClick;
form.ShowDialog(this);
}
else {
this.ShowToastNotify(this, "请先盘点");
}
}
private void Form_OnApplyClick(object sender, NotifyEventArgs e)
{
try
{
this.ShowToastNotify(this, "正在进行盘点审核,请勿关闭....", 100000);
StockCheckTicketStatusUpdateRequest request = new StockCheckTicketStatusUpdateRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
request.StorageId = this.storageId;
request.Status = 1;
request.CheckMan = Global.Instance.BusinessPlanLog.WorkerNo;
var response = StockUtils.StockCheckTicketStatusUpdate(request);
//成功
if (response.Item1)
{
this.ShowToastNotify(this, response.Item2);
ProductStockQuery();
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
catch (Exception ex)
{
this.ShowToastNotify(this, "盘点单审核异常");
LOGGER.Error(ex, "盘点单审核异常");
}
}
/// <summary>
/// 盘点作废
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CancelClick(object sender, EventArgs e)
{
if (details != null && details.Count > 0)
{
//打开提示界面
var form = new StoreStockCheckApplyForm(2);
form.OnCancelClick += Form_OnCancelClick;
form.ShowDialog(this);
}
else
{
this.ShowToastNotify(this, "请先盘点");
}
}
private void Form_OnCancelClick(object sender, NotifyEventArgs e)
{
try
{
StockCheckTicketStatusUpdateRequest request = new StockCheckTicketStatusUpdateRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
request.StorageId = this.storageId;
request.Status = 2;
request.CheckMan = Global.Instance.BusinessPlanLog.WorkerNo;
var response = StockUtils.StockCheckTicketStatusUpdate(request);
//成功
if (response.Item1)
{
this.ShowToastNotify(this, response.Item2);
ProductStockQuery();
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
catch (Exception ex)
{
this.ShowToastNotify(this, "盘点单审核异常");
LOGGER.Error(ex, "盘点单审核异常");
}
}
/// <summary>
/// 保存盘点明细
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveClick(object sender, EventArgs e)
{
this.buttonX2.Focus();
try
{
if (details.Count <= 0)
{
this.ShowToastNotify(this, "没有盘点明细要提交");
return;
}
StockUncheckTicketDetailUpdateRequest request = new StockUncheckTicketDetailUpdateRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
request.WorkerNo = Global.Instance.BusinessPlanLog.WorkerNo;
//便利获取原料信息
var rows = this.stockListTable.PrimaryGrid.Rows;
List<StockUncheckTicketDetailUpdate> addDetail = new List<StockUncheckTicketDetailUpdate>();
if (rows.Count > 0)
{
foreach (var temRow in rows)
{
GridRow row = temRow as GridRow;
var productName = StringUtils.GetString(row.Cells["productName"].Value);
var id = StringUtils.GetString(row.Cells["id"].Value);
var ticketId = StringUtils.GetString(row.Cells["ticketId"].Value);
var ticketNo = StringUtils.GetString(row.Cells["ticketNo"].Value);
var sysPrice = StringUtils.GetDecimal(row.Cells["sysPrice"].Value);
var sysAmount = StringUtils.GetDecimal(row.Cells["sysAmount"].Value);
var checkAmount = StringUtils.GetDecimal(row.Cells["checkAmount"].Value);
if (checkAmount < 0)
{
var dialog = new DialogForm("错误提示", string.Format("<{0}>盘点数量<{1}>,请调整", productName, checkAmount), MessageBoxIcon.Error, MessageBoxButtons.OK);
dialog.ShowDialog(this);
row.IsSelected = true;
return;
}
var differenceAmount = StringUtils.GetDecimal(row.Cells["differenceAmount"].Value);
var sysMoney = StringUtils.GetDecimal(row.Cells["sysMoney"].Value);
var checkMoney = StringUtils.GetDecimal(row.Cells["checkMoney"].Value);
var differenceMoney = StringUtils.GetDecimal(row.Cells["differenceMoney"].Value);
var Description = StringUtils.GetString(row.Cells["description"].Value);
StockUncheckTicketDetailUpdate stockUncheckTicketDetailUpdate = new StockUncheckTicketDetailUpdate();
stockUncheckTicketDetailUpdate.Id = id;
stockUncheckTicketDetailUpdate.TicketId = ticketId;
stockUncheckTicketDetailUpdate.TicketNo = ticketNo;
stockUncheckTicketDetailUpdate.SysPrice = sysPrice;
stockUncheckTicketDetailUpdate.SysAmount = sysAmount;
stockUncheckTicketDetailUpdate.CheckAmount = checkAmount;
stockUncheckTicketDetailUpdate.DifferenceAmount = differenceAmount;
stockUncheckTicketDetailUpdate.SysMoney = sysMoney;
stockUncheckTicketDetailUpdate.CheckMoney = checkMoney;
stockUncheckTicketDetailUpdate.DifferenceMoney = differenceMoney;
stockUncheckTicketDetailUpdate.Description = Description;
addDetail.Add(stockUncheckTicketDetailUpdate);
}
}
request.DetailList = addDetail;
var response = StockUtils.StockUncheckTicketDetailUpdate(request);
//成功
if (response.Item1)
{
this.ShowToastNotify(this, response.Item2);
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
catch (Exception ex)
{
this.ShowToastNotify(this, "盘点单保存异常");
LOGGER.Error(ex, "盘点单保存异常");
}
}
private void OnBeginEdit(object sender, GridEditEventArgs e)
{
var cell = e.GridCell;
var cellPoint = this.stockListTable.PointToScreen(cell.LocationRelative);
if (cell.GridColumn.Name == "checkAmount")
{
cellPoint.Y -= this.stockListTable.VScrollOffset;
var p = NumericKeyboard.CalculateLocation(cellPoint, cell.GridColumn.Width);
NumericKeyboard.ShowKeyboard(this, p);
}
else
{
var txtForm = new TxtKeyboardForm(StringUtils.GetString(cell.Value));
txtForm.NotifyChanged += (o, args) =>
{
cell.Value = args.Data;
};
var trans = new TransparentForm(this, .5, txtForm);
trans.Show(this);
}
}
private void OnCellValueChanged(object sender, GridCellValueChangedEventArgs e)
{
var cell = e.GridCell;
if (cell.GridColumn.Name == "checkAmount")
{
var row = cell.GridRow;
var sysPrice = StringUtils.GetDecimal(row.Cells["sysPrice"].Value);
var checkAmount = StringUtils.GetDecimal(row.Cells["checkAmount"].Value);
var sysAmount = StringUtils.GetDecimal(row.Cells["sysAmount"].Value);
var sysMoney = StringUtils.GetDecimal(row.Cells["sysMoney"].Value);
if (checkAmount < 0)
{
this.ShowToastNotify(this, "数量非法");
row.Cells["checkAmount"].Value = 0;
checkAmount = 0;
}
var checkMoney = sysPrice * checkAmount;
row.Cells["checkMoney"].Value = checkMoney;
row.Cells["differenceAmount"].Value = checkAmount- sysAmount;
row.Cells["differenceMoney"].Value = checkMoney- sysMoney;
}
}
private void OnCloseEdit(object sender, GridCloseEditEventArgs e)
{
NumericKeyboard.CloseKeyboard();
}
private void OnMinimizedClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void OnTxtMemoCustomClick(object sender, EventArgs e)
{
var obj = sender as NormalTextBox;
var txtForm = new TxtKeyboardForm(StringUtils.GetString(obj.Text));
txtForm.NotifyChanged += (o, args) =>
{
obj.Text = args.Data.ToString();
};
var trans = new TransparentForm(this, .5, txtForm);
trans.Show(this);
}
private void OnOrderItemCellClick(object sender, GridCellClickEventArgs e)
{
if ("operation" == e.GridCell.GridColumn.Name)
{
GridRow selectRow = (GridRow)this.stockListTable.PrimaryGrid.ActiveRow;
if (selectRow != null)
{
var detailId = StringUtils.GetString(selectRow.Cells["id"].Value);
try
{
StockCheckTicketDetailDelRequest request = new StockCheckTicketDetailDelRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
request.DetailIds = detailId;
var response = StockUtils.StockCheckTicketDetailDel(request);
//成功
if (response.Item1)
{
this.ShowToastNotify(this, response.Item2);
this.stockListTable.PrimaryGrid.Rows.Remove(selectRow);
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
catch (Exception ex)
{
this.ShowToastNotify(this, "盘点明细删除失败");
LOGGER.Error(ex, "盘点明细删除失败");
}
}
}
}
/// <summary>
/// 打印盘点单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnPrint(object sender, EventArgs e)
{
if (details != null && details.Count > 0)
{
this.ShowToastNotify(this, "开始打印");
//构建收银小票模版参数
var vars = StockHelper.BuilderCheckVariable(details);
Tuple<bool, string> result = StockHelper.PrinterTicket("库存盘点_通用模版", vars, true, false);
this.ShowToastNotify(this, string.Format("{0}", result.Item2));
}
else
{
this.ShowToastNotify(this, "请先盘点");
}
}
private void BtnCheckSummary(object sender, EventArgs e)
{
var SummaryForm = new StoreStockCheckSummaryForm();
TransparentForm trans = new TransparentForm(this, SummaryForm);
trans.Show(this);
}
/// <summary>
/// 盘点历史
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnHistory(object sender, EventArgs e)
{
var stockCheckTicketForm = new StockCheckTicketForm();
TransparentForm trans = new TransparentForm(this, stockCheckTicketForm);
trans.Show(this);
}
}
}