|
|
|
|
using DevComponents.DotNetBar.SuperGrid;
|
|
|
|
|
using POSV.Card;
|
|
|
|
|
using POSV.Entity;
|
|
|
|
|
using POSV.Report;
|
|
|
|
|
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 StoreStorageInAddForm : BusinessForm
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private List<string> _ids = new List<string>();
|
|
|
|
|
|
|
|
|
|
private string _oldId;
|
|
|
|
|
|
|
|
|
|
private OperateType _OperateType;
|
|
|
|
|
|
|
|
|
|
public StoreStorageInAddForm(OperateType type, string id)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
_OperateType = type;
|
|
|
|
|
|
|
|
|
|
if (type == OperateType.ADD)
|
|
|
|
|
{
|
|
|
|
|
this.controlBox1.Text = "新增入库单";
|
|
|
|
|
this.txtStatus.Text = "新建";
|
|
|
|
|
}
|
|
|
|
|
else if(type == OperateType.EDIT)
|
|
|
|
|
{
|
|
|
|
|
this.controlBox1.Text = "修改入库单";
|
|
|
|
|
_oldId = id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
BuilderOrderGrid();
|
|
|
|
|
|
|
|
|
|
InstallStorage();
|
|
|
|
|
|
|
|
|
|
Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
InstallInType();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//单据编号
|
|
|
|
|
if(_OperateType == OperateType.ADD)
|
|
|
|
|
{
|
|
|
|
|
this.txtBusNo.Text = string.Format("{0}{1}{2}", "SI", Global.Instance.Authc.PosNo, DateTime.Now.ToString("yyyyMMddHHmmss"));
|
|
|
|
|
this.txtSetMan.Text = Global.Instance.Worker.Name;
|
|
|
|
|
this.txtSetDate.Text = DateTimeUtils.GetNowFormat();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InstallEditInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载修改的订单信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InstallEditInfo()
|
|
|
|
|
{
|
|
|
|
|
Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
var res = StockUtils.QueryStoreStorageInTicketList(null, "id", _oldId, 1, 1, null, null, null);
|
|
|
|
|
if (res.Item1 && res.Item3.List != null && res.Item3.List.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//获取单据成功
|
|
|
|
|
//获取单据明细
|
|
|
|
|
var detailRes = StockUtils.QueryStoreStorageInTicketDetailList(_oldId, 1, 500);
|
|
|
|
|
|
|
|
|
|
if (detailRes.Item1)
|
|
|
|
|
{
|
|
|
|
|
return new Tuple<StoreStorageInTicket, List<StoreStorageInDetail>>(res.Item3.List[0], detailRes.Item3.List);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, detailRes.Item2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, res.Item2);
|
|
|
|
|
}
|
|
|
|
|
return new Tuple<StoreStorageInTicket, List<StoreStorageInDetail>>(null, null);
|
|
|
|
|
}).ContinueWith(task =>
|
|
|
|
|
{
|
|
|
|
|
if (task.IsFaulted)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.Error(task.Exception.GetBaseException(), "加载入库单异常");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = task.Result;
|
|
|
|
|
if(res.Item1 != null && res.Item2 != null)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsDisposed || !this.IsHandleCreated) return;
|
|
|
|
|
this.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
var order = res.Item1;
|
|
|
|
|
this.txtBusNo.Text = order.No;
|
|
|
|
|
this.boxType.Text = order.TypeName;
|
|
|
|
|
this.txtStatus.Text = order.StatusStr;
|
|
|
|
|
this.boxStorage.Text = order.StorageName;
|
|
|
|
|
this.txtMemo.Text = order.Description;
|
|
|
|
|
this.txtSetMan.Text = order.SetMan;
|
|
|
|
|
this.txtSetDate.Text = order.SetDate;
|
|
|
|
|
|
|
|
|
|
var detailList = res.Item2;
|
|
|
|
|
|
|
|
|
|
List<GridRow> gridList = new List<GridRow>();
|
|
|
|
|
foreach(var detail in detailList)
|
|
|
|
|
{
|
|
|
|
|
GridRow row = new GridRow("", detail.ProductId, detail.ProductNo, detail.ProductName, detail.SpecId, detail.SpecName, detail.ProductDescription, detail.StockUnitId, detail.StockUnitName, detail.Amount, detail.Price, StringUtils.FormatDataTwoDigit(detail.Money), detail.Description);
|
|
|
|
|
gridList.Add(row);
|
|
|
|
|
}
|
|
|
|
|
this.detailGrid.PrimaryGrid.Rows.AddRange(gridList);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InstallStorage()
|
|
|
|
|
{
|
|
|
|
|
List<StoreStorage> storeList = null;
|
|
|
|
|
using(var db = Global.Instance.OpenDataBase)
|
|
|
|
|
{
|
|
|
|
|
storeList = db.Query<StoreStorage>("order by no").ToList();
|
|
|
|
|
}
|
|
|
|
|
this.boxStorage.DataSource = storeList;
|
|
|
|
|
this.boxStorage.DisplayMember = "Name";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InstallInType()
|
|
|
|
|
{
|
|
|
|
|
var res = StockUtils.QueryStoreStorageTicketType("1");
|
|
|
|
|
if (res.Item1)
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsHandleCreated || this.IsDisposed) return;
|
|
|
|
|
this.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsHandleCreated || this.IsDisposed) return;
|
|
|
|
|
this.boxType.DataSource = res.Item3;
|
|
|
|
|
this.boxType.DisplayMember = "Description";
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, res.Item2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BuilderOrderGrid()
|
|
|
|
|
{
|
|
|
|
|
var panel = detailGrid.PrimaryGrid;
|
|
|
|
|
|
|
|
|
|
panel.DefaultRowHeight = 40;
|
|
|
|
|
panel.RowHeaderIndexOffset = 1;
|
|
|
|
|
|
|
|
|
|
var cols = ReportUtils.GetGridObject("POSV.Stock.", "StoreStorageInAddTicketDetail.json");
|
|
|
|
|
if (cols != null)
|
|
|
|
|
{
|
|
|
|
|
Assembly asmb = Assembly.LoadFrom("DevComponents.DotNetBar.SuperGrid.dll");
|
|
|
|
|
foreach (var col in cols)
|
|
|
|
|
{
|
|
|
|
|
panel.Columns.Add(new DevComponents.DotNetBar.SuperGrid.GridColumn()
|
|
|
|
|
{
|
|
|
|
|
Name = col.Name,
|
|
|
|
|
HeaderText = col.HeaderText,
|
|
|
|
|
DataPropertyName = col.DataPropertyName,
|
|
|
|
|
Visible = col.Display,
|
|
|
|
|
Width = col.Width,
|
|
|
|
|
AllowEdit = col.AllowEdit,
|
|
|
|
|
EditorType = asmb.GetType(col.EditorType, true)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//可编辑cell颜色特殊标注
|
|
|
|
|
Color bgColor = ColorTranslator.FromHtml("193,255,192");
|
|
|
|
|
panel.Columns["amount"].CellStyles.Default.Background.Color1 = bgColor;
|
|
|
|
|
panel.Columns["price"].CellStyles.Default.Background.Color1 = bgColor;
|
|
|
|
|
panel.Columns["description"].CellStyles.Default.Background.Color1 = bgColor;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
panel.NoRowsText = "加载报表错误,请联系管理员";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选择商品
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void OnSelectProductClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_ids = new List<string>();
|
|
|
|
|
foreach(GridRow row in detailGrid.PrimaryGrid.Rows)
|
|
|
|
|
{
|
|
|
|
|
_ids.Add(row.Cells["specId"].Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var form = new SelectProductForm(_ids, null);
|
|
|
|
|
form.OnProductClick += Form_OnProductClick; ;
|
|
|
|
|
TransparentForm trans = new TransparentForm(this, form);
|
|
|
|
|
trans.ShowDialog(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Form_OnProductClick(object sender, MaterialDetailEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var product = e.Detail;
|
|
|
|
|
var rows = this.detailGrid.PrimaryGrid.Rows;
|
|
|
|
|
bool isExist = false;
|
|
|
|
|
if(rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach(GridRow row in rows)
|
|
|
|
|
{
|
|
|
|
|
if (product.SpecId.Equals(StringUtils.GetString(row["specId"])))
|
|
|
|
|
{
|
|
|
|
|
isExist = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isExist)
|
|
|
|
|
{
|
|
|
|
|
GridRow row = new GridRow("", product.ProductId, product.ProductNo, product.ProductName, product.SpecId, product.SpecName, product.Memo, product.PackUnitId, product.PackUnitName, 0.00, product.Price, 0.00, "");
|
|
|
|
|
rows.Add(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void OnCloseClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(this.Owner != null)
|
|
|
|
|
{
|
|
|
|
|
this.Owner.Close();
|
|
|
|
|
}
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnExistClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnCloseClick(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBeginEdit(object sender, GridEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var cell = e.GridCell;
|
|
|
|
|
var cellPoint = this.detailGrid.PointToScreen(cell.LocationRelative);
|
|
|
|
|
if(cell.GridColumn.Name == "amount" || cell.GridColumn.Name == "price")
|
|
|
|
|
{
|
|
|
|
|
cellPoint.Y -= this.detailGrid.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 OnCloseEdit(object sender, GridCloseEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
NumericKeyboard.CloseKeyboard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCellValueChanged(object sender, GridCellValueChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var cell = e.GridCell;
|
|
|
|
|
if (cell.GridColumn.Name == "amount" || cell.GridColumn.Name == "price")
|
|
|
|
|
{
|
|
|
|
|
var row = cell.GridRow;
|
|
|
|
|
var amount = StringUtils.GetDecimal(row.Cells["amount"].Value);
|
|
|
|
|
if (amount < 0)
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, "数量非法");
|
|
|
|
|
row.Cells["amount"].Value = 0;
|
|
|
|
|
amount = 0;
|
|
|
|
|
}
|
|
|
|
|
var price = StringUtils.GetDecimal(row.Cells["price"].Value);
|
|
|
|
|
var money = StringUtils.FormatDataTwoDigit(amount * price);
|
|
|
|
|
row.Cells["money"].Value = money;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMemoClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var txtForm = new TxtKeyboardForm(StringUtils.GetString(this.txtMemo.Text));
|
|
|
|
|
txtForm.NotifyChanged += (o, args) =>
|
|
|
|
|
{
|
|
|
|
|
this.txtMemo.Text = args.Data.ToString();
|
|
|
|
|
};
|
|
|
|
|
var trans = new TransparentForm(this, .5, txtForm);
|
|
|
|
|
trans.Show(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSaveClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.buttonX4.Focus();
|
|
|
|
|
StoreStorageInTicketAndDetail ticket = new StoreStorageInTicketAndDetail();
|
|
|
|
|
if(_OperateType == OperateType.EDIT)
|
|
|
|
|
{
|
|
|
|
|
ticket.Id = _oldId;
|
|
|
|
|
}
|
|
|
|
|
ticket.No = this.txtBusNo.Text;
|
|
|
|
|
var type = this.boxType.SelectedValue as StoreStorageTicketType;
|
|
|
|
|
if(type == null)
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, "请选择入库类型");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ticket.Type = type.Sign;
|
|
|
|
|
var storage = this.boxStorage.SelectedValue as StoreStorage;
|
|
|
|
|
if(storage == null)
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, "请选择入库仓库");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ticket.StorageId = storage.Id;
|
|
|
|
|
ticket.StorageName = storage.Name;
|
|
|
|
|
|
|
|
|
|
ticket.Description = this.txtMemo.Text;
|
|
|
|
|
ticket.SetMan = Global.Instance.Worker.Name;
|
|
|
|
|
ticket.SetDate = this.txtSetDate.Text;
|
|
|
|
|
|
|
|
|
|
List<StoreStorageInDetail> detailList = new List<StoreStorageInDetail>();
|
|
|
|
|
var rows = detailGrid.PrimaryGrid.Rows;
|
|
|
|
|
if(rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (GridRow row in rows)
|
|
|
|
|
{
|
|
|
|
|
StoreStorageInDetail detail = new StoreStorageInDetail();
|
|
|
|
|
detail.ProductId = StringUtils.GetString(row.Cells["productId"].Value);
|
|
|
|
|
detail.ProductNo = StringUtils.GetString(row.Cells["productNo"].Value);
|
|
|
|
|
detail.ProductName = StringUtils.GetString(row.Cells["productName"].Value);
|
|
|
|
|
detail.SpecId = StringUtils.GetString(row.Cells["specId"].Value);
|
|
|
|
|
detail.SpecName = StringUtils.GetString(row.Cells["specName"].Value);
|
|
|
|
|
detail.ProductDescription = StringUtils.GetString(row.Cells["productDescription"].Value);
|
|
|
|
|
detail.StockUnitId = StringUtils.GetString(row.Cells["stockUnitId"].Value);
|
|
|
|
|
detail.StockUnitName = StringUtils.GetString(row.Cells["stockUnitName"].Value);
|
|
|
|
|
detail.Amount = StringUtils.GetDecimal(row.Cells["amount"].Value);
|
|
|
|
|
detail.Price = StringUtils.GetDecimal(row.Cells["price"].Value);
|
|
|
|
|
detail.Money = StringUtils.GetDecimal(row.Cells["money"].Value);
|
|
|
|
|
detail.Description = StringUtils.GetString(row.Cells["description"].Value);
|
|
|
|
|
|
|
|
|
|
if(detail.Amount <= 0)
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, string.Format("<{0}>入库数量<{1}>不合法", detail.ProductName, detail.Amount));
|
|
|
|
|
row.IsSelected = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
detailList.Add(detail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ticket.DetailList = detailList;
|
|
|
|
|
|
|
|
|
|
Tuple<bool, string, string> res = null;
|
|
|
|
|
if (_OperateType == OperateType.ADD)
|
|
|
|
|
{
|
|
|
|
|
res = StockUtils.AddStoreStorageTicket(ticket);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res = StockUtils.ModifyStoreStorageTicket(ticket);
|
|
|
|
|
}
|
|
|
|
|
if (res.Item1)
|
|
|
|
|
{
|
|
|
|
|
DialogForm dialog = new DialogForm("提示","入库单保存成功", MessageBoxIcon.Warning, MessageBoxButtons.OK);
|
|
|
|
|
dialog.ShowDialog(this);
|
|
|
|
|
NotifyParent();
|
|
|
|
|
OnCloseClick(sender, e);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, res.Item2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, "请选择入库商品");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void NotifyParent()
|
|
|
|
|
{
|
|
|
|
|
OnSaveSuccess?.Invoke(this, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public delegate void EventHandler(object sender, EventArgs e);
|
|
|
|
|
|
|
|
|
|
public event EventHandler OnSaveSuccess;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void OnDeleteItemClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GridRow row = this.detailGrid.PrimaryGrid.ActiveRow as GridRow;
|
|
|
|
|
if(row == null)
|
|
|
|
|
{
|
|
|
|
|
this.ShowToastNotify(this, "请选择删除的明细");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.detailGrid.PrimaryGrid.Rows.Remove(row);
|
|
|
|
|
_ids.Remove(row.Cells["specId"].Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void detailGrid_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|