/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PC_1101.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_PC_1101 : DockPanelBase
{
#region 成员变量
// 窗体的单例模式
private static F_PC_1101 _instance;
#endregion
#region 构造函数
public F_PC_1101()
{
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_PC_1101 Instance
{
get
{
if (_instance == null)
{
_instance = new F_PC_1101();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 新建按钮事件
///
///
///
private void tsbtnAdd_Click(object sender, EventArgs e)
{
try
{
F_PC_1102 frmPM2102 = new F_PC_1102();
DialogResult dialogResult = frmPM2102.ShowDialog();
// 重新加载GridView
if (dialogResult == DialogResult.OK)
{
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 盘点按钮事件
///
///
///
private void tsbtnInChecked_Click(object sender, EventArgs e)
{
try
{
if (this.dgvInChecked.CurrentCell != null)
{
int checkedID = Convert.ToInt32(
this.dgvInChecked.CurrentRow.Cells["CheckedID"].Value);
string checkedNO =
this.dgvInChecked.CurrentRow.Cells["CheckedNo"].Value.ToString();
F_PC_1103 frmPM2603 = new F_PC_1103(checkedID, checkedNO);
DialogResult dialogResult = frmPM2603.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.OKCancel, MessageBoxIcon.Question);
if (dialogResult != DialogResult.OK)
{
return;
}
int checkedID = Convert.ToInt32(
this.dgvInChecked.CurrentRow.Cells["CheckedID"].Value);
// 停用
ServiceResultEntity result = (ServiceResultEntity)DoAsync(() =>
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1101";
cre.Name = "DisableMouldChecked";
cre.Properties["CheckedID"] = checkedID;
return PCModuleProxyNew.Service.HandleRequest(cre);
});
if (result.Status == Constant.ServiceResultStatus.Success)
{
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.dgvLossDetail.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)
{
// 在绑定总表时 不查询明细
if (!Convert.ToBoolean(this.Tag)
|| this.dgvInChecked.CurrentCell == null)
{
return;
}
try
{
// 选中行时查询明细
if (this.txtInCheckedNo.ReadOnly)
{
return;
}
this.dgvInChecked.Enabled = false;
this.dgvInCheckedNoDetail.DataSource = null;
this.dgvInCheckededDetail.DataSource = null;
this.dgvInCheckedWinDetail.DataSource = null;
this.dgvLossDetail.DataSource = null;
this.dgvFunctionUsers.DataSource = null;
int checkedID = Convert.ToInt32(this.dgvInChecked.CurrentRow.Cells["CheckedID"].Value.ToString());
ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new AsyncMethod(() =>
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1101";
cre.Name = "GetAllMouldCheckDetail";
cre.Properties["CheckedID"] = checkedID;
return PCModuleProxyNew.Service.HandleRequest(cre);
}));
if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
{
this.dgvFunctionUsers.DataSource = sre.Data.Tables[0];
this.dgvInCheckedNoDetail.DataSource = sre.Data.Tables[1];
this.dgvInCheckededDetail.DataSource = sre.Data.Tables[2];
this.dgvInCheckedWinDetail.DataSource = sre.Data.Tables[3];
this.dgvLossDetail.DataSource = sre.Data.Tables[4];
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
{
// 控制明细不查询
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;
this.dgvLossDetail.DataSource = null;
ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new AsyncMethod(() =>
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1101";
cre.Name = "GetAllMouldCheckList";
cre.Properties["datebegin"] = this.dtpStartTime.Value;
cre.Properties["dateend"] = this.dtpEndTime.Value.AddDays(1).AddSeconds(-1);
cre.Properties["checkedno"] = this.txtInCheckedNo.Text.Trim();
cre.Properties["checkname"] = this.txtCheckedName.Text.Trim();
return PCModuleProxyNew.Service.HandleRequest(cre);
}));
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
if (sre != null && sre.Status == Constant.ServiceResultStatus.Success)
{
base.DataSource = sre.Data;
if (this.DataSource != null && this.DataSource.Tables.Count > 0)
{
tsbtnInChecked.Enabled = true;
tsbtnDisable.Enabled = true;
this.dgvInChecked.DataSource = this.DataSource.Tables[0];
if (this.DataSource.Tables[0].Rows.Count == 0)
{
tsbtnInChecked.Enabled = false;
tsbtnDisable.Enabled = false;
this.dgvInCheckedNoDetail.DataSource = null;
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
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.dgvLossDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
this.dgvFunctionUsers.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
#endregion
#region 私有方法
#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)
{
MessageBox.Show("没有选择任何未盘点的模具",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
DialogResult dialogResult
= MessageBox.Show("是否报损选择的未盘点模具?",
this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult != DialogResult.Yes)
{
return;
}
int checkID = Convert.ToInt32(dr[0]["CheckedID"]);
string barcodes = "";
foreach (DataRow r in dr)
{
barcodes += r["mouldbarcode"].ToString() + ",";
}
barcodes = barcodes.TrimEnd(',');
// 清除
ServiceResultEntity result = (ServiceResultEntity)DoAsync(() =>
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1101";
cre.Name = "SaveClearMouldChecked";
cre.Properties["CheckedID"] = checkID;
cre.Properties["Barcodes"] = barcodes;
cre.Properties["BarcodeCount"] = dr.Length;
return PCModuleProxyNew.Service.HandleRequest(cre);
});
if (result != null)
{
if (result.Status == Constant.ServiceResultStatus.Success)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "未盘点模具", "报损"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.btnSearch_Click(sender, e);
}
else if (!string.IsNullOrEmpty(result.Message))
{
MessageBox.Show(result.Message,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.btnSearch_Click(sender, e);
}
}
hasSearch = true;
}
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 checkedID = Convert.ToInt32(currentRow.Cells["CheckedID"].Value);
F_PC_1102 frm2602 = new F_PC_1102(checkedID);
DialogResult dialogresult = frm2602.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)
{
dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
}
}
}