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.

300 lines
11 KiB
C#

using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.SuperGrid;
using POSV.Card;
using POSV.Component;
using POSV.Entity;
using POSV.Entity.Stock;
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.Windows.Forms;
namespace POSV.Stock
{
public partial class StoreStockCheckAddForm : BusinessForm
{
private List<string> ids = new List<string>();
private List<StoreStorage> storageList = new List<StoreStorage>();
private string storageId = null;
private string storageName = null;
private List<StockCheckDetailEntity> details = new List<StockCheckDetailEntity>();
public StoreStockCheckAddForm()
{
InitializeComponent();
this.controlBox1.Text = "门店库存盘点新增";
this.controlBox1.ShowApplicationVersion = false;
this.busNoTextBox.Text = string.Format("PD{0}{1}", Global.Instance.Authc.PosNo, DateTime.Now.ToString("yyyyMMddHHmmss"));
this.storeNameTextBox.Text = Global.Instance.Worker.StoreInfo.Name;
this.statusBox.Text = "新建";
this.setManTextBox.Text = Global.Instance.BusinessPlanLog.WorkerNo;
this.setDateTextBox.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
//仓库列表
InitStorageMenu();
//可编辑cell颜色特殊标注
var panel = this.detailListTable.PrimaryGrid;
Color textColor = ColorTranslator.FromHtml("255,0,0");
panel.Columns["operation"].CellStyles.Default.TextColor = textColor;
}
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);
storageId = ((StoreStorage)obj.SelectedItem).Id;
storageName = ((StoreStorage)obj.SelectedItem).Name;
}
private void OnCloseTouchClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void exitClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
public delegate void EventHandler(object sender);
public event EventHandler OnTicktQuery;
/// <summary>
/// 原料选择器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_selectProduct(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(storageId)) {
this.ShowToastNotify(this,"请先选择盘点仓库");
return;
}
var form = new StoreStockCheckSelectProductForm(storageId, ids, null);
form.OnProductClick += Form_OnProductClick;
TransparentForm trans = new TransparentForm(this, form);
trans.Show(this);
}
private void Form_OnProductClick(object sender, MaterialDetailEventArgs e)
{
var detail = e.Detail;
var rows = this.detailListTable.PrimaryGrid.Rows;
bool isExist = false;
//过滤已存在的原料信息
if (rows.Count > 0)
{
foreach (var temRow in rows)
{
GridRow row = temRow as GridRow;
if (detail.SpecId.Equals(row["specId"].Value.ToString()) && this.storageId.Equals(row["storageId"].Value.ToString()))
{
isExist = true;
break;
}
}
}
//如果不存在添加列
if (!isExist)
{
StockCheckDetailEntity entity = new StockCheckDetailEntity();
entity.StorageId =this.storageId;
entity.StorageName =this.storageName;
entity.ProductId = detail.ProductId;
entity.ProductNo = detail.ProductNo;
entity.ProductName = detail.ProductName;
entity.SpecId = detail.SpecId;
entity.SpecName = detail.SpecName;
entity.ProductDescription = "";
entity.StockUnitId = detail.PackUnitId;
entity.StockUnitName = detail.PackUnitName;
entity.Description = "";
entity.Operation = "删除";
GridRow row = new GridRow(entity.StorageId,entity.StorageName, entity.ProductNo, entity.ProductName, entity.SpecId, entity.SpecName, entity.ProductDescription, entity.StockUnitName, "删除");
row.Tag = entity;
rows.Add(row);
details.Add(entity);
}
}
/// <summary>
/// 保存盘点单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnSave(object sender, EventArgs e)
{
this.buttonX2.Focus();
try
{
if (details.Count <= 0)
{
this.ShowToastNotify(this, "请选择原料");
return;
}
StockCheckTicketAddRequest request = new StockCheckTicketAddRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
StockCheckTicketAdd stockCheckTicketAdd = new StockCheckTicketAdd();
stockCheckTicketAdd.No = this.busNoTextBox.Text;
stockCheckTicketAdd.Description = this.memoTextBox.Text;
stockCheckTicketAdd.SetMan = Global.Instance.BusinessPlanLog.WorkerNo;
stockCheckTicketAdd.SetDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//便利获取原料信息
List<StockCheckTicketAddDetail> addDetail = new List<StockCheckTicketAddDetail>();
foreach (var temRow in details)
{
StockCheckTicketAddDetail stockCheckTicketAddDetail = new StockCheckTicketAddDetail();
stockCheckTicketAddDetail.StorageId = temRow.StorageId;
stockCheckTicketAddDetail.StorageName = temRow.StorageName;
stockCheckTicketAddDetail.ProductId = temRow.ProductId;
stockCheckTicketAddDetail.ProductNo = temRow.ProductNo;
stockCheckTicketAddDetail.ProductName = temRow.ProductName;
stockCheckTicketAddDetail.SpecId = temRow.SpecId;
stockCheckTicketAddDetail.SpecName = temRow.SpecName;
stockCheckTicketAddDetail.ProductDescription = temRow.ProductDescription;
stockCheckTicketAddDetail.StockUnitId = temRow.StockUnitId;
stockCheckTicketAddDetail.StockUnitName = temRow.StockUnitName;
stockCheckTicketAddDetail.Description = temRow.Description;
addDetail.Add(stockCheckTicketAddDetail);
}
stockCheckTicketAdd.DetailList = addDetail;
request.StockCheckTicketAdd = stockCheckTicketAdd;
var response = StockUtils.StockCheckTicketAdd(request);
//成功
if (response.Item1)
{
OnTicktQuery?.Invoke(sender);
this.ShowToastNotify(this, response.Item2);
//保存成功关闭当前窗口
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
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 BtnSelectTemplate(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(storageId))
{
this.ShowToastNotify(this, "请先选择盘点仓库");
return;
}
var form = new StoreStockCheckTemplateForm(storageId, ids);
form.OnProductClick += Form_OnProductClick;
TransparentForm trans = new TransparentForm(this, form);
trans.Show(this);
}
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);
}
/// <summary>
/// 删除操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnOrderItemCellClick(object sender, GridCellClickEventArgs e)
{
if ("operation" == e.GridCell.GridColumn.Name)
{
GridRow selectRow = (GridRow)this.detailListTable.PrimaryGrid.ActiveRow;
if (selectRow != null)
{
var detail = selectRow.Tag as StockCheckDetailEntity;
this.detailListTable.PrimaryGrid.Rows.Remove(selectRow);
ids.Remove(string.Format("{0}-{1}", detail.StorageId, detail.SpecId));
details.Remove(detail);
}
}
}
}
}