/*******************************************************************************
* Copyright(c) 2017 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PM_2302.cs
* 2.功能描述:生产订单新建/编辑界面
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2017/02/07 1.00 新建
*******************************************************************************/
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using System;
using System.Data;
using System.Windows.Forms;
namespace Dongke.IBOSS.PRD.Client.PMModule
{
public partial class F_PM_2302 : FormBase
{
#region 成员变量
// 存储窗口的编辑状态
private Constant.FormMode _editStatus;
// 修改生产订单时存储上个窗口传过来的ID
private int _orderID;
private OrderEntity _orderEntity = new OrderEntity();
#endregion
#region 构造函数
///
/// 构造函数
///
public F_PM_2302()
: this(Constant.FormMode.Add)
{
}
///
/// 构造函数
///
public F_PM_2302(Constant.FormMode editStatus)
: this(editStatus, 0)
{
}
///
/// 构造函数
///
public F_PM_2302(Constant.FormMode editStatus, int orderID)
{
InitializeComponent();
this._editStatus = editStatus;
// 根据新建、编辑状态为标题赋值
if (editStatus == Constant.FormMode.Add)
{
this.Text = FormTitles.F_PM_2302_ADD;
}
else
{
this.Text = FormTitles.F_PM_2302_EDIT;
// 存储上个窗口传过来的生产订单ID
this._orderID = orderID;
}
// 按钮文本
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
#endregion
#region 事件
///
/// 关闭按钮事件
///
///
///
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 保存按钮事件
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
// 验证信息是否完整
bool validResult = IsValidData();
if (validResult)
{
this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
ServiceResultEntity result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(this.SaveOrder));//保存按钮方法
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
if (Convert.ToInt32(result.Result) > Constant.INT_IS_ZERO)//保存成功
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "生产订单", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
//this._organizationIDList.Add(Convert.ToInt32(result));
this.DialogResult = DialogResult.OK;
}
else if (Convert.ToInt32(result.Result)==-1)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007, result.Message),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (this._editStatus == Constant.FormMode.Edit)
{
this.Close();
}
else
{
// 重置窗口数据
this.ResetFormData();
}
}
}
catch (Exception ex)
{
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 获取组织机构结果集
///
///
private DataSet GetOrganizationDataSource()
{
try
{
OrganizationEntity organization = new OrganizationEntity();
//// 票号开头字母
//organization.LetterMarket = this.LetterMarket.Text.Trim();
//// 联系电话
//organization.Telephone = this.txtTelephone.Text.Trim();
//// 地址
//organization.Address = this.txtAddress.Text;
//// 备注
//organization.Remarks = this.txtRemarks.Text;
//// 正常标识
//organization.ValueFlags = null;
//organization.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
//organization.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
//this._organization = organization;
return SystemModuleProxy.Service.SelectOrganizationData(organization);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 窗体加载事件
///
///
///
private void F_PM_2302_Load(object sender, EventArgs e)
{
try
{
this.dgvOrderDetail.AutoGenerateColumns = false;
this.dgvOrderDetail.IsSetInputColumnsColor = true;
this.dtpOrderDateFrom.Value = DateTime.Now.Date;
// 若状态是添加,则有效标志为可用并且不显示
if (this._editStatus == Constant.FormMode.Edit)
{
this.SetOrganizationData();
txtOrderNo.ReadOnly = true;
}
else
{
DataTable dt = new DataTable("OrderDetail");
dt.Columns.Add("materialcode");
dgvOrderDetail.DataSource = dt;
}
this.txtOrderNo.Focus();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 物料编码改变事件
///
///
///
private void scbSAPCode1_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e)
{
dgvOrderDetail.DataSource = scbSAPCode1.CheckedData;
}
#endregion
#region 私有方法
///
/// 为窗体各个控赋值
///
private void SetOrganizationData()
{
try
{
// 获取生产订单信息
this._orderEntity = new OrderEntity();
this._orderEntity.OrderID = this._orderID;
DataSet result = (DataSet)DoAsync(new BaseAsyncMethod(this.GetOrderList));
if (result != null && result.Tables.Count > Constant.INT_IS_ZERO && result.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
DataRow orderRow = result.Tables[0].Rows[0];
// 生产号
this.txtOrderNo.Text = orderRow["OrderNo"].ToString();
// 订单日期
this.dtpOrderDateFrom.Value = Convert.ToDateTime(orderRow["OrderDate"]);
// 备注
this.txtRemarks.Text = orderRow["Remarks"].ToString();
this.txtDisplayNo.DataValue = Convert.ToInt32(orderRow["DisplayNo"]);
//// 条码串
//string[] arr = result.Tables[1].AsEnumerable().Select(d => d.Field("guid")).ToArray();
//string guids = string.Join(",", arr);
//arr = result.Tables[1].AsEnumerable().Select(d => d.Field("materialcode")).ToArray();
//string materialcodes = string.Join(",", arr);
//scbSAPCode1.Text = materialcodes;
scbSAPCode1.CheckedData = result.Tables[1];
dgvOrderDetail.DataSource = result.Tables[1];
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取生产订单数据
///
///
private DataSet GetOrderList()
{
try
{
return PMModuleProxy.Service.GetOrderList(this._orderEntity);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 验证输入是否完整
///
///
private bool IsValidData()
{
try
{
// 订单号不能为空
if (string.IsNullOrEmpty(this.txtOrderNo.Text.Trim()))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "订单号"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtOrderNo.Focus();
return false;
}
return true;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存组织机构
///
/// 影响的行数
private ServiceResultEntity SaveOrder()
{
try
{
OrderEntity order = GetOrderEntity();
return PMModuleProxy.Service.SaveOrder(order);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 给订单体类传值
///
///
private OrderEntity GetOrderEntity()
{
OrderEntity order = new OrderEntity();
// 生产订单ID
order.OrderID = this._orderID;
// 生产订单号
order.OrderNo = this.txtOrderNo.Text.Trim();
// 生产订单日期
order.OrderDate = this.dtpOrderDateFrom.Value;
// 备注
order.Remarks = this.txtRemarks.Text.Trim();
order.ValueFlag = 1;
order.DisplayNo = (int)(this.txtDisplayNo.DataValue ?? 0);
DataTable dt = dgvOrderDetail.DataSource as DataTable;
if (dt != null)
{
dt.AcceptChanges();
DataView dv = new DataView(dt);
order.OrderDetail = dv.ToTable(true, new string[] { "materialcode" });
}
return order;
}
///
/// 重置窗口数据
///
private void ResetFormData()
{
this._orderID = Constant.INT_IS_ZERO;
this.txtOrderNo.Text = string.Empty;
this.dtpOrderDateFrom.Value = DateTime.Now;
this.txtRemarks.Text = string.Empty;
this.txtOrderNo.Focus();
}
#endregion
}
}