/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PM_2101.cs
* 2.功能描述:在产盘点一览
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/05/13 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.DockPanel;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels.PMModule;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
namespace Dongke.IBOSS.PRD.Client.PMModule
{
///
/// 在产盘点一览
///
public partial class F_PM_2101 : DockPanelBase
{
#region 成员变量
// 窗体的单例模式
private static F_PM_2101 _instance;
// 当前选择的行
private int _selectedRowIndex;
#endregion
#region 构造函数
public F_PM_2101()
{
InitializeComponent();
this.Text = "在产盘点";//FormTitles.F_PM_2101;
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
this.tsbtnClearData.Text = ButtonText.TSBTN_CLEARDATAINCHECKED;
this.tsbtnAll.Text = ButtonText.TSBTN_ALL;
this.tsbtnUnAll.Text = ButtonText.TSBTN_UNALL;
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
}
///
/// 单例模式,防止重复创建窗体
///
public static F_PM_2101 Instance
{
get
{
if (_instance == null)
{
_instance = new F_PM_2101();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 新建按钮事件
///
///
///
private void tsbtnAdd_Click(object sender, EventArgs e)
{
try
{
F_PM_2102 frmPM2102 = new F_PM_2102();
DialogResult dialogResult = frmPM2102.ShowDialog();
// 重新加载GridView
if (dialogResult == DialogResult.OK)
{
// 数据量大时,查询明细会卡顿。
//InCheckedEntity requestEntity = CreatesearchInCheckedRequestEntity();
//DataSet dtInChecked = (DataSet)DoAsync(new AsyncMethod(() =>
//{
// return PMModuleProxy.Service.GetAllInChecked(requestEntity);
//}));
//if (dtInChecked != null && dtInChecked.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
//{
// this.dgvInChecked.DataSource = null;
// this.dgvInChecked.DataSource = dtInChecked.Tables[0];
// this.dgvInChecked.Rows[this.dgvInChecked.CurrentCell.RowIndex].Selected = true;
// this.dgvInChecked.CurrentCell = this.dgvInChecked.Rows[this.dgvInChecked.CurrentCell.RowIndex].Cells["InCheckedNo"];
// // 设置ToolStripButton按钮状态
// this.tsbtnInChecked.Enabled = true;
// this.tsbtnDisable.Enabled = true;
// this.dgvInChecked.ReadOnly = true;
// //btnSearch_Click(null, null);
//}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 盘点按钮事件
///
///
///
private void tsbtnInChecked_Click(object sender, EventArgs e)
{
try
{
F_PM_2103 frmPM2103 = null;
if (this.dgvInChecked.CurrentCell != null)
{
int InCheckedID = Convert.ToInt32(
this.dgvInChecked.Rows[this._selectedRowIndex].Cells["InCheckedID"].Value);
string InCheckedNO =
this.dgvInChecked.Rows[this._selectedRowIndex].Cells["InCheckedNo"].Value.ToString();
frmPM2103 = new F_PM_2103(InCheckedID, InCheckedNO);
DialogResult dialogResult = frmPM2103.ShowDialog();
// 重新加载GridView
if (dialogResult == DialogResult.OK)
{
//btnSearch_Click(sender, e);
dgvInChecked_SelectionChanged(null, null);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 停用按钮事件
///
///
///
private void tsbtnDisable_Click(object sender, EventArgs e)
{
try
{
if (this.dgvInChecked.CurrentCell != null)
{
DialogResult dialogResult
= MessageBox.Show(string.Format(Messages.MSG_CMN_Q002, "盘点单", "停用"),
this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult.Equals(DialogResult.No))
{
return;
}
int InCheckedID = Convert.ToInt32(
this.dgvInChecked.Rows[this._selectedRowIndex].Cells["InCheckedID"].Value);
// 停用
int result = (int)DoAsync(() =>
{
return PMModuleProxy.Service.DisableInChecked(InCheckedID);
});
if (result > Constant.INT_IS_ZERO)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "盘点单", "停用"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
// 刷新窗口数据
this.btnSearch_Click(sender, e);
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "盘点单", "停用"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体加载事件
///
///
///
private void F_PM_2101_Load(object sender, EventArgs e)
{
try
{
// 绑定权限
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
this.dgvInChecked.AutoGenerateColumns = false;
this.dgvInCheckedNoDetail.AutoGenerateColumns = false;
this.dgvInCheckededDetail.AutoGenerateColumns = false;
this.dgvInCheckedWinDetail.AutoGenerateColumns = false;
this.dgvInCheckedNoDetail.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
// 初始化时间控件为当前日期
this.dtpStartTime.Value = DateTime.Now.Date;
this.dtpEndTime.Value = DateTime.Now.Date;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体关闭事件
///
///
///
private void F_PM_2101_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 清空按钮事件
///
///
///
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtInCheckedNo.Clear();
this.txtCheckedName.Clear();
// 初始化时间控件为当前日期
this.dtpStartTime.Value = DateTime.Now.Date;
this.dtpEndTime.Value = DateTime.Now.Date;
}
///
/// 选定项改变事件
///
///
///
private void dgvInChecked_SelectionChanged(object sender, EventArgs e)
{
try
{
// 在绑定总表时 不查询明细
if (!Convert.ToBoolean(this.Tag)
|| this.dgvInChecked.CurrentCell == null)
{
return;
}
// 选中行时查询明细
else
{
if (this.txtInCheckedNo.ReadOnly)
{
return;
}
this.dgvInChecked.Enabled = false;
this._selectedRowIndex = this.dgvInChecked.CurrentCell.RowIndex;
this.dgvInCheckedNoDetail.DataSource = null;
this.dgvInCheckededDetail.DataSource = null;
this.dgvInCheckedWinDetail.DataSource = null;
this.dgvFunctionUsers.DataSource = null;
int InCheckedID = Convert.ToInt32(this.dgvInChecked.Rows[_selectedRowIndex].Cells["InCheckedID"].Value.ToString());
DataSet dsProductionDefect = (DataSet)DoAsync(new AsyncMethod(() =>
{
return PMModuleProxy.Service.GetAllInCheckedDetail(InCheckedID);
}));
if (dsProductionDefect != null && dsProductionDefect.Tables.Count > Constant.INT_IS_ZERO)
{
//DataRow[] drInCheckedNo = dsProductionDefect.Tables[0].Select("InCheckedFlag=" + Constant.InCheckedFlag.InCheckedNo.GetHashCode());
//if (drInCheckedNo.Length > 0)
//{
// this.dgvInCheckedNoDetail.DataSource = drInCheckedNo.CopyToDataTable();
//}
//DataRow[] drInCheckeded = dsProductionDefect.Tables[0].Select("InCheckedFlag=" + Constant.InCheckedFlag.InCheckeded.GetHashCode());
//if (drInCheckeded.Length > 0)
//{
// this.dgvInCheckededDetail.DataSource = drInCheckeded.CopyToDataTable();
//}
//DataRow[] drInCheckedWin = dsProductionDefect.Tables[0].Select("InCheckedFlag=" + Constant.InCheckedFlag.InCheckedWin.GetHashCode());
//if (drInCheckedWin.Length > 0)
//{
// this.dgvInCheckedWinDetail.DataSource = drInCheckedWin.CopyToDataTable();
//}
//if(dsProductionDefect.Tables[1].Rows.Count>0)
//{
// this.dgvFunctionUsers.DataSource = dsProductionDefect.Tables[1];
//}
this.dgvInCheckedNoDetail.DataSource = dsProductionDefect.Tables[0];
this.dgvInCheckededDetail.DataSource = dsProductionDefect.Tables[1];
this.dgvInCheckedWinDetail.DataSource = dsProductionDefect.Tables[2];
this.dgvFunctionUsers.DataSource = dsProductionDefect.Tables[3];
this.dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
finally
{
this.dgvInChecked.Enabled = true;
this.dgvInChecked.Focus();
}
}
///
/// 搜索按钮事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
// 记录当前选中行
int selectRowIndex = this._selectedRowIndex;
// 控制明细不查询
this.Tag = false;
// 异步处理
this.btnSearch.Enabled = false;
this.btnClearCondition.Enabled = false;
this.dgvInChecked.DataSource = null;
this.dgvFunctionUsers.DataSource = null;
this.dgvInCheckededDetail.DataSource = null;
this.dgvInCheckedNoDetail.DataSource = null;
this.dgvInCheckedWinDetail.DataSource = null;
InCheckedEntity requestEntity = CreatesearchInCheckedRequestEntity();
DataSet dsInChecked = (DataSet)DoAsync(new AsyncMethod(() =>
{
return PMModuleProxy.Service.GetAllInChecked(requestEntity);
}));
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
if (dsInChecked != null)
{
base.DataSource = dsInChecked;
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
tsbtnInChecked.Enabled = true;
tsbtnDisable.Enabled = true;
this.dgvInChecked.DataSource = this.DataSource.Tables[0];
selectRowIndex = 0;
if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
{
tsbtnInChecked.Enabled = false;
tsbtnDisable.Enabled = false;
this.dgvInCheckedNoDetail.DataSource = null;
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (selectRowIndex >= Constant.INT_IS_ZERO)
{
//if (selectRowIndex >= dsInChecked.Tables[0].Rows.Count)
//{
// this.dgvInChecked.Rows[this.dgvInChecked.Rows.Count - 1].Selected = true;
// this.dgvInChecked.CurrentCell = this.dgvInChecked.Rows[this.dgvInChecked.Rows.Count - 1].Cells["InCheckedNo"];
//}
//else
//{
// this.dgvInChecked.Rows[selectRowIndex].Selected = true;
// this.dgvInChecked.CurrentCell = this.dgvInChecked.Rows[selectRowIndex].Cells["InCheckedNo"];
//}
this.Tag = true;
dgvInChecked_SelectionChanged(null, null);
}
}
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
finally
{
this.tsrOperate.Enabled = true;
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
// 控制明细不查询
this.Tag = true;
}
}
///
/// 关闭按钮事件
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 自动适应列宽
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvInChecked.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
this.dgvInCheckedNoDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
this.dgvInCheckededDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
this.dgvInCheckedWinDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
this.dgvFunctionUsers.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
#endregion
#region 私有方法
///
/// 搜索条件
///
///
private InCheckedEntity CreatesearchInCheckedRequestEntity()
{
InCheckedEntity result = new InCheckedEntity();
result.InCheckedNo = this.txtInCheckedNo.Text.Trim();
result.InCheckedName = this.txtCheckedName.Text.Trim();
result.BeginDate = this.dtpStartTime.Value;
result.EndDate = this.dtpEndTime.Value.AddDays(1);
return result;
}
#endregion
///
/// 清除未盘点数据按钮事件
///
///
///
private void tsbtnClearData_Click(object sender, EventArgs e)
{
bool hasSearch = false;
try
{
DataTable dt = this.dgvInCheckedNoDetail.DataSource as DataTable;
if (dt == null)
{
MessageBox.Show("没有未盘点的数据",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
dt.AcceptChanges();
DataRow[] dr = dt.Select("Sel=1");
if (dr.Length == 0)
{
if (this.dgvInChecked.CurrentCell != null)
{
int InCheckedID = Convert.ToInt32(this.dgvInChecked.Rows[this.dgvInChecked.CurrentCell.RowIndex].Cells["InCheckedID"].Value);
string InCheckedNo = this.dgvInChecked.Rows[this.dgvInChecked.CurrentCell.RowIndex].Cells["InCheckedNo"].Value.ToString();
F_PM_2117 frmPM2117 = new F_PM_2117(InCheckedID, InCheckedNo);
DialogResult dialogResult2 = frmPM2117.ShowDialog();
// 重新加载GridView
if (dialogResult2 == DialogResult.OK)
{
//btnSearch_Click(sender, e);
dgvInChecked_SelectionChanged(null, null);
}
}
return;
}
DialogResult dialogResult
= MessageBox.Show("是否清除选择未盘点产品?",
this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult.Equals(DialogResult.No))
{
return;
}
int incheckID = Convert.ToInt32(dr[0]["InCheckedID"]);
string barcodes = "";
foreach (DataRow r in dr)
{
barcodes += r["barcode"].ToString() + ",";
}
barcodes = barcodes.TrimEnd(',');
// 清除
int result = (int)DoAsync(() =>
{
return PMModuleProxy.Service.SaveClearInChecked(incheckID, barcodes);
});
if (result > Constant.INT_IS_ZERO)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "盘点产品", "清除数据"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
// 刷新窗口数据
this.btnSearch_Click(sender, e);
hasSearch = true;
}
else if (result == -Constant.INT_IS_ONE)
{
MessageBox.Show("返工产品不允许清除",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (result == -Constant.INT_IS_TWO)
{
MessageBox.Show("报损待审产品不允许清除",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "盘点产品", "清除数据"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
finally
{
if (!hasSearch)
{
this.dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
}
}
}
private void dgvInCheckedNoDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
try
{
if (this.dgvInCheckedNoDetail.CurrentRow != null && this.dgvInCheckedNoDetail.IsCurrentCellDirty)
{
if ("Sel".Equals(this.dgvInCheckedNoDetail.Columns
[this.dgvInCheckedNoDetail.CurrentCell.ColumnIndex].Name))
{
this.dgvInCheckedNoDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void tsbtnAll_Click(object sender, EventArgs e)
{
DataTable returnData = (DataTable)this.dgvInCheckedNoDetail.DataSource;
if (returnData != null)
{
//for (int i = 0; i < returnData.Rows.Count; i++)
//{
// returnData.Rows[i]["Sel"] = 1;
//}
for (int i = 0; i < returnData.DefaultView.Count; i++)
{
returnData.DefaultView[i]["Sel"] = 1;
returnData.DefaultView[i].EndEdit();
}
}
}
private void tsbtnUnAll_Click(object sender, EventArgs e)
{
DataTable returnData = (DataTable)this.dgvInCheckedNoDetail.DataSource;
if (returnData != null)
{
for (int i = 0; i < returnData.Rows.Count; i++)
{
returnData.Rows[i]["Sel"] = 0;
returnData.Rows[i].EndEdit();
}
}
}
private void tsbtnEdit_Click(object sender, EventArgs e)
{
try
{
DataGridViewRow currentRow = this.dgvInChecked.CurrentRow;
if (currentRow != null)
{
int InCheckedID = Convert.ToInt32(currentRow.Cells["InCheckedID"].Value);
F_PM_2102 frm2102 = new F_PM_2102(InCheckedID, currentRow.Cells["Remarks"].Value.ToString(), currentRow.Cells["Incheckname"].Value.ToString());
DialogResult dialogresult = frm2102.ShowDialog();
if (dialogresult.Equals(DialogResult.OK))
{
btnSearch_Click(sender, e);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvInChecked_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (-1 < e.RowIndex && -1 < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
{
this.tsbtnEdit_Click(sender, e);
}
}
private void dgvInCheckedNoDetail_Sorted(object sender, EventArgs e)
{
this.dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
}
private void tsbtnCheckData_Click(object sender, EventArgs e)
{
bool hasSearch = false;
try
{
DataTable dt = this.dgvInCheckedNoDetail.DataSource as DataTable;
if (dt == null)
{
MessageBox.Show("没有未盘点的数据。",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
dt.AcceptChanges();
DataRow[] dr = dt.Select("Sel=1");
if (dr.Length == 0)
{
if (this.dgvInChecked.CurrentCell != null)
{
int inCheckedID = Convert.ToInt32(this.dgvInChecked.Rows[this.dgvInChecked.CurrentCell.RowIndex].Cells["InCheckedID"].Value);
DialogResult dialogResultAll = MessageBox.Show("是否盘点所有未盘点产品?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (dialogResultAll == System.Windows.Forms.DialogResult.Yes)
{
ServiceResultEntity resultAll = (ServiceResultEntity)DoAsync(() =>
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "InChecked";
cre.Name = "CheckBarcodes";
cre.Properties["CheckedID"] = inCheckedID;
return PMModuleProxyNew.Service.HandleRequest(cre);
});
this.dgvInChecked_SelectionChanged(null, null);
}
}
return;
}
DialogResult dialogResult = MessageBox.Show("是否盘点选中的产品?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (dialogResult == System.Windows.Forms.DialogResult.No)
{
return;
}
int incheckID = Convert.ToInt32(dr[0]["InCheckedID"]);
string barcodes = "";
foreach (DataRow r in dr)
{
barcodes += r["barcode"].ToString() + ",";
}
barcodes = barcodes.TrimEnd(',');
ServiceResultEntity result = (ServiceResultEntity)DoAsync(() =>
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "InChecked";
cre.Name = "CheckBarcodes";
cre.Properties["CheckedID"] = incheckID;
cre.Properties["Barcodes"] = barcodes;
return PMModuleProxyNew.Service.HandleRequest(cre);
});
this.dgvInChecked_SelectionChanged(null, null);
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
finally
{
if (!hasSearch)
{
this.dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
}
}
}
}
}