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;
using WMS.Frm.Base;
using WMS.Model.Stock;
using WMS.Common;
using WMS.Ctrl;
using WMS.Model.Base;
using WMS.Frm;
using WMS.FrmBaseData;
using WMS.Business.Stock;
using WMS.Business;
namespace WMS.FrmStock
{
public partial class FrmCountingDet : FormBase
{
///
/// 盘点任务MODEL
///
CountingModel countingModel = new CountingModel();
///
/// 盘点任务MODEL集合
///
List countList = new List();
///
/// 盘点任务MODEL
///
CountingInfoModel countingInfoModel = new CountingInfoModel();
///
/// 盘点任务MODEL集合
///
List infoList = new List();
///
/// 盘点单号
///
public string pdsheet = string.Empty;
///
/// 业务类型
///
int workflag = 3;//0 增加 1 修改 2 删除 ;
public FrmCountingDet()
{
InitializeComponent();
}
///
/// 页面加载
///
///
///
public void FrmCountingDet_Load(object sender, EventArgs e)
{
try
{
FrmSelectModle = new CountingModel();
DateTime dt = DateTime.Now;
if (string.IsNullOrEmpty(pdsheet))
{
BSCountingTab.DataSource = new CountingModel() { PLAN_DATE_STAR = dt.AddDays(1 - dt.Day), PLAN_DATE_END = dt.AddDays(1 - dt.Day).AddMonths(1).AddDays(-1) };
PageInfo.PageEnabled = false;
bindCountGrid();
}
else
{
CountingModel strmodel = new CountingModel()
{
COUNT_ID = pdsheet
};
countList = IBussFactory.Instance().GetCountingList(strmodel);
if (countList != null)
{
GCCounting.DataSource = countList;
GVCounting.RefreshData();
bindCountInfoGrid(new CountingInfoModel() { COUNT_ID = pdsheet });
if (countList.Count > 0)
{
DateCount.EditValue = countList[0].COUNT_DATE;
noteData1.SelectedValue = countList[0].REMARK;
DicCountMan.TextBoxFlag = countList[0].COUNT_MAN;
DicCountMan.TextBoxValue = countList[0].COUNT_MAN_NAME;
}
xtraTabInfo.SelectedTabPage = PageCount;
}
}
frmButtonItem["Save"].Enabled = false;
}catch(Exception ex)
{ }
}
///
/// 通用查询
///
///
public override void LoadListData(DataTable table)
{
countList = ConvertHelper.ConvertToList(table);
GCCounting.DataSource = countList;
GVCounting.RefreshData();
}
///
/// 绑定盘点任务
///
private void bindCountGrid()
{
BSCountingTab.EndEdit();
CountingModel smodel = BSCountingTab.DataSource as CountingModel;
smodel.COUNT_STATUS = "1";
try
{
// = Newtonsoft.Json.JsonConvert.DeserializeObject>(strlist);
countList = IBussFactory.Instance().GetCountingList(smodel);
if(countList!=null)
{
GCCounting.DataSource = countList;
GVCounting.RefreshData();
}
}
catch (Exception e)
{
SystemCommon.ShowErrorMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
}
///
/// 绑定明细
///
///
private void bindCountInfoGrid(CountingInfoModel model)
{
try
{
infoList = IBussFactory.Instance().GetList(model);
if (infoList != null)
{
GCCountInfo.DataSource = infoList.OrderBy(r => r.STO_SEAT);
GVCountInfo.RefreshData();
}
}
catch(Exception e)
{
SystemCommon.ShowErrorMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
}
///
/// 盘点单双击
///
///
///
private void GCCounting_DoubleClick(object sender, EventArgs e)
{
if (GVCounting.FocusedRowHandle < 0)
{
return;
}
countingModel = GVCounting.GetFocusedRow() as CountingModel;
countingInfoModel.COUNT_ID = countingModel.COUNT_ID;
bindCountInfoGrid(countingInfoModel);
PageInfo.PageEnabled = true;
xtraTabInfo.SelectedTabPage = PageInfo;
DateCount.EditValue = DateTime.Now;
DicCountMan.TextBoxFlag = userData.USER_ID;
DicCountMan.TextBoxValue = userData.NAME;
if (!string.IsNullOrEmpty(countingModel.COUNT_MAN))
{
DicCountMan.TextBoxFlag = countingModel.COUNT_MAN;
}
else
{
DicCountMan.TextBoxFlag = userData.USER_ID;
}
if (countingModel.COUNT_DATE.ToString("yyyyMMdd") != "00010101")
{
DateCount.EditValue = countingModel.COUNT_DATE;
}
else
{
DateCount.EditValue = DateTime.Now;
}
}
///
/// 盘点任务显示转换
///
///
///
private void GVCounting_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (e.Value == null || e.Value == DBNull.Value)
{
return;
}
if (e.Column.FieldName == "COUNT_TYPE")
{
switch (e.Value.ToString().Trim())
{
case "0":
e.DisplayText = "全盘";
break;
case "1":
e.DisplayText = "动盘";
break;
case "2":
e.DisplayText = "自定义";
break;
default:
e.DisplayText = "其它";
break;
}
}
else if (e.Column.FieldName == "COUNT_STATUS")
{
switch (e.Value.ToString().Trim())
{
case "0":
e.DisplayText = "未确认";
break;
case "1":
e.DisplayText = "已确认";
break;
case "2":
e.DisplayText = "已盘点";
break;
case "3":
e.DisplayText = "已复核";
break;
default:
e.DisplayText = "其它";
break;
}
}
}
#region 以下是继承的按钮事件
///
/// 新增按钮
///
public void Add()
{
workflag = 0;
frmButtonItem["Save"].Enabled = true;
frmButtonItem["Edit"].Enabled = false;
GCCounting_DoubleClick(null, null);
}
///
/// 保存按钮
///
public void Save()
{
FrmOperator(workflag);
}
///
/// 删除按钮
///
public void Del()
{
}
///
/// 修改按钮
///
public void Edit()
{
if (countingModel.COUNT_STATUS != "2")
{
SystemCommon.ShowInfoMessageBox("该盘点单不能修改!");
return;
}
workflag = 1;
frmButtonItem["Save"].Enabled = true;
}
///
/// 刷新按钮
///
public void RefreshDataButton()
{
}
///
/// 确定按钮
///
public void Confirm()
{
}
///
/// 查询按钮
///
public void Search()
{
FrmSelect frm = new FrmSelect(FrmSelectModle);
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.LoadListData(frm.SelectData);
}
}
///
/// 导出按钮
///
public void ExportDataButton()
{
}
///
/// 打印按钮
///
public void PrintDataButton()
{
}
///
/// 备注
///
protected new void NoteDataButton(FormBase fBase)
{
}
///
/// 审核
///
public void AuditDataButton()
{
}
///
/// 反审核
///
public void ReturnAuditDataButton()
{
}
#endregion
#region 操作(增、改、删)
///
/// 操作(增、改、删)
///
/// 0 新增 1修改 2删除 3停用 4启用/param>
private void FrmOperator(int flag)
{
try
{
GVCountInfo.CloseEditor();
GVCountInfo.UpdateCurrentRow();
string err = "";
countingModel.COUNT_MAN = DicCountMan.TextBoxFlag;
countingModel.COUNT_DATE = Convert.ToDateTime(DateCount.EditValue);
if (!string.IsNullOrEmpty(countingModel.REMARK))
{
countingModel.REMARK += ";" + noteData1.Text;
}
countingModel.COUNT_STATUS = "2";
if (flag == 0)
{
if (infoList.Count == 0)
{
SystemCommon.ShowInfoMessageBox("请先完善盘点信息!");
return;
}
bool back = true;
foreach (CountingInfoModel cim in infoList)
{
if (cim.STATUS != "0")
{
back = false;
}
}
if (back)
{
countingModel.COUNT_BACK = "0";
}
else
{
countingModel.COUNT_BACK = "1";
}
err = IBussFactory.Instance().UpdateAndInfo(countingModel, infoList);
}
else if (flag == 1)
{
if (infoList.Count == 0)
{
SystemCommon.ShowInfoMessageBox("请先完善盘点信息!");
return;
}
bool back = true;
foreach (CountingInfoModel cim in infoList)
{
if (cim.STATUS != "0")
{
back = false;
}
}
if (back)
{
countingModel.COUNT_BACK = "0";
}
else
{
countingModel.COUNT_BACK = "1";
}
err = IBussFactory.Instance().UpdateAndInfo(countingModel, infoList);
}
if (!string.IsNullOrEmpty(err))
{
SystemCommon.ShowErrorMessageBox(err);
}
else
{
SystemCommon.ShowInfoMessageBox("操作成功!");
frmButtonItem["Save"].Enabled = false;
}
}
catch (Exception e)
{
SystemCommon.ShowInfoMessageBox("您的操作出错:" + Environment.NewLine + e.Message);
}
}
#endregion
///
/// GRID修改完成时
///
///
///
private void GVCountInfo_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (e.Column.Name == "colSTO_NUM")
{
decimal num = 0;
try
{
num = Convert.ToDecimal(e.Value);
}
catch
{
SystemCommon.ShowInfoMessageBox("请输入有效数量!");
return;
}
CountingInfoModel model = GVCountInfo.GetFocusedRow() as CountingInfoModel;
if (num == model.BOOK_NUM)
{
model.STATUS = "0";
}
else if (num > model.BOOK_NUM)
{
model.STATUS = "1";
}
else
{
model.STATUS = "2";
}
model.DIFF_NUM = (num - model.BOOK_NUM);
}
}
///
/// 超链接点击
///
///
///
private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e)
{
CountingInfoModel model = GVCountInfo.GetFocusedRow() as CountingInfoModel;
if (model != null && !string.IsNullOrEmpty(model.GOODS_ID))
{
FrmGoodsInfoDet.IFlag = 2;
FrmGoodsInfoDet.StrGoodsID = model.GOODS_ID;
LoadForm load = new LoadForm();
DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 0);
DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在读取商品信息....");
FrmGoodsInfoDet.GetInstance().Show();
}
}
}
}