/*******************************************************************************
* Copyright(c) 2017 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PM_2301.cs
* 2.功能描述:生产订单一览
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2017/2/7 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.DockPanel;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.PMModule
{
public partial class F_PM_2301 : DockPanelBase
{
#region 成员变量
// 单例模式
private static F_PM_2301 _instance;
// 存储查询条件
private OrderEntity _orderEntity = new OrderEntity();
// 最后选择行
private int _selecedRow;
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_PM_2301 Instance
{
get
{
if (_instance == null)
{
_instance = new F_PM_2301();
}
return _instance;
}
}
#endregion
#region 构造函数
public F_PM_2301()
{
InitializeComponent();
//正常标识数据源
this.chkValueFlag.Items.Add("正常", true);
this.chkValueFlag.Items.Add("停用");
//窗体标题
this.Text = FormTitles.F_PM_2301;
//新建
this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
//编辑
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
//自适应列宽
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
// 停用
this.tsbtnValueFlag.Text = ButtonText.TSBTN_DISABLE;
//关闭
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
//查询
this.btnSearch.Text = ButtonText.BTN_SEARCH;
//清空条件
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
//查询条件
this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
}
#endregion
#region 事件
///
/// 清空条件按钮事件
///
///
///
private void btnClearCondition_Click(object sender, EventArgs e)
{
// 订单号
this.txtOrderNo.Clear();
// 订单日期
this.dtpOrderDateFrom.Value = DateTime.Now;
this.dtpOrderDateTo.Value = DateTime.Now;
this.dtpOrderDateFrom.Enabled = false;
this.dtpOrderDateTo.Enabled = false;
this.chkDateTime.Checked = false;
// 备注
this.txtRemarks.Clear();
this.chkValueFlag.SelectedValues = new object[] { Constant.INT_IS_ONE };
}
///
/// 查询按钮点击事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
// 根据页面设定订单实体值
this.GetOrderEntityFromLayout();
// 记录当前选中行
int selectRowIndex = this._selecedRow;
// 异步处理
this.dgvOrder.DataSource = null;
this.btnSearch.Enabled = false;
this.btnClearCondition.Enabled = false;
DataSet userDataSet = (DataSet)DoAsync(new AsyncMethod(this.SearchOrderNoData));
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
if (userDataSet != null)
{
base.DataSource = (DataSet)userDataSet;
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
this.dgvOrder.DataSource = this.DataSource.Tables[0];
if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
{
this.tsbtnEdit.Enabled = false;
this.tsbtnValueFlag.Enabled = false;
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (selectRowIndex >= Constant.INT_IS_ZERO)
{
if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
{
this.dgvOrder.Rows[this.dgvOrder.Rows.Count - 1].Selected = true;
this.dgvOrder.CurrentCell = this.dgvOrder.Rows[this.dgvOrder.Rows.Count - 1].Cells["OrderNo"];
}
else
{
this.dgvOrder.Rows[selectRowIndex].Selected = true;
this.dgvOrder.CurrentCell = this.dgvOrder.Rows[selectRowIndex].Cells["OrderNo"];
}
}
}
}
}
else
{
this.tsbtnEdit.Enabled = false;
this.tsbtnValueFlag.Enabled = false;
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 画面加载
///
///
///
private void FrmOrganization_Load(object sender, EventArgs e)
{
try
{
// 加载权限
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
this.dgvOrder.AutoGenerateColumns = false;
DataTable dt = new DataTable();
dt.Columns.Add("ValidFlagID");
dt.Columns.Add("ValidFlagName");
DataRow dr = dt.NewRow();
dr[0] = "1";
dr[1] = "正常";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "0";
dr[1] = "停用";
dt.Rows.Add(dr);
this.chkValueFlag.DataSource = dt;
object[] checkValueFlags = new object[1];
checkValueFlags[0] = 1;
this.chkValueFlag.SelectedValues = checkValueFlags;
this.tsbtnValueFlag.Enabled = false;
this.dtpOrderDateFrom.Value = DateTime.Now;
this.dtpOrderDateTo.Value = DateTime.Now;
this.dtpOrderDateFrom.Enabled = false;
this.dtpOrderDateTo.Enabled = false;
this.dgvOrderDetail.AutoGenerateColumns = false;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 释放成员变量
///
///
///
private void FrmOrganization_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 关闭按钮
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 自适应列宽按钮事件
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvOrder.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
this.dgvOrderDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
///
/// 编辑按钮事件
///
///
///
private void tsbtnEdit_Click(object sender, EventArgs e)
{
try
{
DataGridViewRow currentRow = this.dgvOrder.CurrentRow;
if (currentRow != null)
// 获取相应节点数据
{
F_PM_2302 frmPM2302 = new F_PM_2302(Constant.FormMode.Edit,
Convert.ToInt32(currentRow.Cells["OrderID"].Value));
DialogResult dialogresult = frmPM2302.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 tsbtnAdd_Click(object sender, EventArgs e)
{
try
{
F_PM_2302 frmPM2302 = new F_PM_2302(Constant.FormMode.Add, 0);
DialogResult dialogResult = frmPM2302.ShowDialog();
// 重新加载GridView
if (dialogResult == DialogResult.OK)
{
btnSearch_Click(sender, e);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 双击进入编辑页面
///
///
///
private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
// 判断是否是双击列头,如果是双击列头的话,不弹出编辑画面
if (-Constant.INT_IS_ONE < e.RowIndex && -Constant.INT_IS_ONE < e.ColumnIndex && tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
{
tsbtnEdit_Click(sender, e);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 选定项改变事件
///
///
///
private void dgvOrder_SelectionChanged(object sender, EventArgs e)
{
if (this.dgvOrder.CurrentCell == null)
{
this.tsbtnEdit.Enabled = false;
this.tsbtnValueFlag.Enabled = false;
}
else
{
string ValueFlag = this.dgvOrder.Rows[dgvOrder.CurrentCell.RowIndex].Cells["ValueFlag"].Value.ToString();
if (ValueFlag == "1")
{
this.tsbtnValueFlag.Text = "停用(&S)";
}
else
{
this.tsbtnValueFlag.Text = "启用(&S)";
}
this.tsbtnEdit.Enabled = true;
this.tsbtnValueFlag.Enabled = true;
// 异步处理
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "F_PM_2301";
cre.Name = "GetOrderDetail";
cre.Properties["OrderID"] = dgvOrder.CurrentRow.Cells["OrderID"].Value.ToNullableInt32();
ServiceResultEntity sre = (ServiceResultEntity)DoAsync(()
=> { return PMModuleProxyNew.Service.HandleRequest(cre); });
if (sre.Status == Constant.ServiceResultStatus.Success
&& sre.Data != null && sre.Data.Tables.Count > 0)
{
dgvOrderDetail.DataSource = sre.Data.Tables[0];
}
}
}
///
/// 更改标识按钮事件
///
///
///
private void tsbtnValueFlag_Click(object sender, EventArgs e)
{
try
{
string displayTitle = this.tsbtnValueFlag.Text.Contains("停用") ? "停用" : "启用";
// 提示用户确认更改
DialogResult msgBoxResult = MessageBox.Show(
"是否对该订单进行" + displayTitle + "操作?", this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (msgBoxResult == DialogResult.Yes)
{
ServiceResultEntity result = (ServiceResultEntity)DoAsync(new AsyncMethod(this.ChangeOrderFlag));
if (Convert.ToInt32(result.Result) > Constant.INT_IS_ZERO)
{
// 提示信息
MessageBox.Show(displayTitle + "成功",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
// 重新加载数据
this.btnSearch_Click(sender, e);
}
else
{
// 提示信息
MessageBox.Show(displayTitle + "失败",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 获取输入的订单信息
///
///
private OrderEntity GetOrderEntityFromLayout()
{
this._orderEntity = new OrderEntity();
// 订单号
this._orderEntity.OrderNo = this.txtOrderNo.Text.Trim();
if (chkDateTime.Checked)
{
// 订单日期
this._orderEntity.OrderFromDate = this.dtpOrderDateFrom.Value.Date;
this._orderEntity.OrderToDate = this.dtpOrderDateTo.Value.Date.AddDays(1).AddMinutes(-1);
}
// 备注
this._orderEntity.Remarks = this.txtRemarks.Text.Trim();
// 正常标识
string sqlStringValueFlags = string.Empty;
for (int i = 0; i < this.chkValueFlag.SelectedValues.Length; i++)
{
sqlStringValueFlags += this.chkValueFlag.SelectedValues[i].ToString() + ",";
}
this._orderEntity.ValueFlagList = sqlStringValueFlags.TrimEnd(',');
return _orderEntity;
}
///
/// 获取订单列表
///
///
private DataSet SearchOrderNoData()
{
try
{
return PMModuleProxy.Service.GetOrderList(this._orderEntity);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 启用/停用方法
///
/// 影响的行数
private ServiceResultEntity ChangeOrderFlag()
{
try
{
OrderEntity order = new OrderEntity();
order.ValueFlag = Convert.ToInt32(this.dgvOrder.CurrentRow.Cells["ValueFlag"].Value) == 0 ? 1 : 0;
order.OrderID = Convert.ToInt32(this.dgvOrder.CurrentRow.Cells["OrderID"].Value);
return PMModuleProxy.Service.ChangeOrderFlag(order);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
private void chkDateTime_CheckedChanged(object sender, EventArgs e)
{
this.dtpOrderDateFrom.Enabled = chkDateTime.Checked;
this.dtpOrderDateTo.Enabled = chkDateTime.Checked;
}
}
}