using ComponentFactory.Krypton.Toolkit;
using NXWMS.Client.Code.Extends;
using NXWMS.Client.Model.AppModels.Condition.Base;
using NXWMS.Client.Model.AppModels.Result;
using NXWMS.Client.Model.AppModels.Result.Base;
using NXWMS.Client.Model.CoreModels;
using NXWMS.Client.String.Enums;
using NXWMS.Commons;
using NXWMS.Services;
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 NXWMS.Forms.Base
{
public partial class frmBin : KryptonForm
{
///
/// 界面最后执行操作
///
private EnumOperation _LastOperation;
///
/// 窗体类名
///
private string _CrrentClassName;
///
/// 客户端字段排序列表
///
private List _clientFieldOrderList;
///
/// 库区列表
///
private List _regionList;
///
/// 仓库列表
///
private List _warehouseList;
///
/// 区域列表
///
private List _areaList;
//private int _pageSize;
//private int _pageIndex;
//private int _totalCount;
private int _selectIndex;
private int _selectId;
private string _selectWarehouseCode;
private string _selectAreaCode;
private string _selectRegionCode;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
public frmBin()
{
InitializeComponent();
_CrrentClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
InitData();
InitControl();
}
//private void cmbRegionCode_SelectedIndexChanged(object sender, EventArgs e)
//{
// if (cmbRegionCode.SelectedValue != null)
// {
// var regionInfo = _regionList.Where(s => s.REGION_CODE == cmbRegionCode.SelectedValue.ToString()).FirstOrDefault();
// if (regionInfo != null)
// {
// _selectAreaCode = regionInfo.AREA_CODE;
// _selectWarehouseCode = regionInfo.WAREHOUSE_CODE;
// lbWarehouse.Text = regionInfo.AREA_NAME;
// _selectRegionCode = regionInfo.REGION_CODE;
// lbRegion.Text = regionInfo.AREA_NAME;
// }
// }
//}
///
/// 数据初始化
///
private void InitData()
{
var regionResult = BaseServices.regionService.GetList(new RegionSearchCondition { IsUsed = true, ItemSQL = "REGION_CODE,REGION_NAME,AREA_NAME,AREA_CODE,WAREHOUSE_CODE,WAREHOUSE_NAME" });
if (regionResult.Status == OperateStatus.Success)
{
_regionList = regionResult.Data.RowData.ToList();
}
var warehouseResult = BaseServices.warehouseService.GetList(new WarehouseSearchCondition { IsUsed = true, ItemSQL = "WAREHOUSE_CODE,WAREHOUSE_NAME" });
if (warehouseResult.Status == OperateStatus.Success)
{
_warehouseList = warehouseResult.Data.RowData.ToList();
}
var areaResult = BaseServices.areaService.GetList(new AreaSearchCondition { IsUsed = true, ItemSQL = "AREA_CODE,AREA_NAME" });
if (areaResult.Status == OperateStatus.Success)
{
_areaList = areaResult.Data.RowData.ToList();
}
_clientFieldOrderList = new List();
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "AREA_NAME", FieldDesc = "区域" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WAREHOUSE_NAME", FieldDesc = "仓库" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "REGION_NAME", FieldDesc = "库区" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TUNNEL", FieldDesc = "巷道" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_CODE", FieldDesc = "库位编码" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BinTypeName", FieldDesc = "库位类型" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_ROW", FieldDesc = "排" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_COLUMN", FieldDesc = "列" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_LAYER", FieldDesc = "层" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "LENGTH", FieldDesc = "长(M)" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WIDE", FieldDesc = "宽(M)" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "HEIGHT", FieldDesc = "高(M)" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PUT_SHELF_ORDER", FieldDesc = "上架顺序" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DOWN_SHELF_ORDER", FieldDesc = "下架顺序" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "VOLUME_LIMIT", FieldDesc = "体积限制" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WEIGHT_LIMIT", FieldDesc = "重量限制(KG)" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "NUMBER_LIMIT", FieldDesc = "数量限制" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TRAR_LIMIT", FieldDesc = "托盘限制" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BLEND_PRODUCT_FLAG", FieldDesc = "允许混放产品" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BLEND_BATCH_FLAG", FieldDesc = "允许混放批次" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == 0)
{
if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
{
if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
{
_CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
}
this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
}
else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
{
if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
{
_CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
}
this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
}
else
{
if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
{
_CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
}
this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
}
}
}
///
/// 选择行主键列表
///
private List _CheckRowIdList = new List();
///
/// 当前页面操作的主键
///
private string _PrimaryKey = "BIN_ID";
private void btnRemove_Click(object sender, EventArgs e)
{
if (_CheckRowIdList.Count == 0)
{
return;
}
if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
_LastOperation = EnumOperation.Remove;
var editResult = BaseServices.binService.Deleted(new BinCondition
{
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
Ids = string.Join(",", _CheckRowIdList)
});
if (editResult.Status == OperateStatus.Success)
{
KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
//groupOperation.Visible = false;
btnSearch_Click(null, null);
}
}
}
///
/// 控件初始化
///
private void InitControl()
{
CheckForIllegalCrossThreadCalls = false;
//groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
//cmbRegionCode.DataSource = _regionList;
//cmbRegionCode.DisplayMember = "REGION_NAME";
//cmbRegionCode.ValueMember = "REGION_CODE";
//cmbRegionCode.SelectedIndex = -1;
cmbSearchRegionCode.DataSource = _regionList;
cmbSearchRegionCode.DisplayMember = "REGION_NAME";
cmbSearchRegionCode.ValueMember = "REGION_CODE";
cmbSearchRegionCode.SelectedIndex = -1;
var fieldList = new List().GetFieldValueCodeList();
cmbSearchBinType.DataSource = fieldList;
cmbSearchBinType.DisplayMember = "Name";
cmbSearchBinType.ValueMember = "Code";
cmbSearchBinType.SelectedIndex = -1;
//cmbBinType.DataSource = fieldList;
//cmbBinType.DisplayMember = "Name";
//cmbBinType.ValueMember = "Code";
//cmbBinType.SelectedIndex = -1;
////TODO 这是一个字典表,需要改
//fieldList = new List();
//fieldList.Add(new FieldValue { Code = "Common", Name = "临时货架排" });
//cmbShelf.DataSource = fieldList;
//cmbShelf.DisplayMember = "Name";
//cmbShelf.ValueMember = "Code";
//cmbShelf.SelectedIndex = -1;
//_pageIndex = 1;
//_pageSize = 20;
}
private void groupOperation_GostFocus(object sender, EventArgs e)
{
//groupOperation.Values.Heading = _LastOperation.Display();
////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
//groupOperation.Text = $"{ _LastOperation.Display()}数据";
//lbStatusMessage.Visible = true;
}
private void btnSearch_Click(object sender, EventArgs e)
{
// _pageIndex = 1;
var loadfrm = new frmLoading();
loadfrm.Show();
// pageTool.Initialize(LoadSearch, 0, _pageSize);
var message = loadfrm.EventCalExec(LoadSearch, pageTool.PageIndex, pageTool.PageSize);
if (!string.IsNullOrWhiteSpace(message))
{
KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private string LoadSearch(int pageIndex, int pageSize)
{
var result = BaseServices.binService.GetList(new BinSearchCondition
{
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
BinCode = txtSearchBinCode.Text,
RegionCode = cmbSearchRegionCode.SelectedValue.GetObjectToString(),
BinColumn = Convert.ToInt32(numSearchBinColumn.Value),
BinRow = Convert.ToInt32(numSearchBinRow.Value),
BinType = cmbSearchBinType.SelectedValue.GetObjectToString(),
IsUsed = chkSearchUse.Checked,
PageIndex = pageIndex,
PageSize = pageSize
});
if (result.Status == OperateStatus.Success)
{
pageTool.DataCount = result.Data.TotalCount;
if (result.Data.RowData.Any())
{
dataGridView.Columns.Clear();
dataGridView.DataSource = result.Data.RowData.ToList();
dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
}
else
{
if (dataGridView.DataSource != null)
{
dataGridView.DataSource = new List();
}
dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
}
return string.Empty;
}
else
{
return result.Message;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
var frm = new ChildFrm.FrmBinEdit();
frm.RegionList = this._regionList;
frm.Operation = EnumOperation.Add;
frm.InitControl();
if (frm.ShowDialog() == DialogResult.OK)
{
btnSearch_Click(null, null);
dataGridView.ClearSelection();
}
//if (!groupOperation.Visible)
//{
// _selectId = 0;
// _selectRegionCode = "";
// _selectWarehouseCode = "";
// _selectAreaCode = "";
// lbWarehouse.Text = ".";
// lbRegion.Text = ".";
// tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
// richDescibe.Text = "";
// _LastOperation = EnumOperation.Add;
// txtBinCode.Enabled = true;
// groupOperation.Visible = true;
// groupOperation.Focus();
//}
}
private void btnEdit_Click(object sender, EventArgs e)
{
dataGridView_CellDoubleClick(null, null);
}
private void SelectInit()
{
_selectIndex = dataGridView.SelectedRows.Count > 0 ? dataGridView.SelectedRows[0].Index : -1;
if (_selectIndex >= 0)
{
_selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
}
}
private void btnSearchExport_Click(object sender, EventArgs e)
{
this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
}
private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
SelectInit();
if (_selectIndex >= 0)
{
var frm = new ChildFrm.FrmBinEdit();
frm.Operation = EnumOperation.Edit;
frm.RegionList = this._regionList;
frm.Id = this._selectId;
frm.InitControl();
frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
if (frm.ShowDialog() == DialogResult.OK)
{
this.btnSearch_Click(null, null);
dataGridView.ClearSelection();
}
//richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
// dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
//txtBinCode.Enabled = false;
//groupOperation.Visible = true;
//groupOperation.Focus();
}
}
private Point mouse_offset;
private void groupOperation_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void groupOperation_MouseMove(object sender, MouseEventArgs e)
{
((Control)sender).Cursor = Cursors.Arrow;
if (e.Button == MouseButtons.Left)
{
Point mousePos = MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
Application.DoEvents();
}
}
private void btnExit_Click(object sender, EventArgs e)
{
if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//groupOperation.Visible = false;
}
else
{
//groupOperation.Visible = true;
//groupOperation.Focus();
}
}
private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
e.Row.HeaderCell.Value = string.Format("{0}", (this.pageTool.PageIndex - 1) * this.pageTool.PageSize + e.Row.Index + 1);
}
private void pageTool_OnPageChange(int PageIndex, int PageSzie)
{
this.btnSearch_Click(null, null);
}
private void chkSearchUse_CheckedChanged(object sender, EventArgs e)
{
}
private void btnSearchImport_Click(object sender, EventArgs e)
{
var SyncResult = BaseServices.binService.SyncERP();
if (SyncResult.Status == OperateStatus.Success)
{
this.btnSearch_Click(null, null);
}
else
{
KryptonMessageBox.Show($"操作失败!\r\n{SyncResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}