/*******************************************************************************
* 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.Basics.Library;
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 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.txtVBELN.Focus();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存按钮事件
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
// 验证信息是否完整
bool validResult = IsValidData();
if (validResult)
{
this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "F_PM_2302";
cre.Name = "SaveOrder";
OrderEntity order = GetOrderEntity();
cre.Request = JsonHelper.ToJson(order);
ServiceResultEntity sre = (ServiceResultEntity)DoAsync(() =>
{
return PMModuleProxyNew.Service.HandleRequest(cre);
});
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
if (Convert.ToInt32(sre.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 (!string.IsNullOrEmpty(sre.Message))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007, sre.Message),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "生产订单", "保存"),
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 void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 订单号拼接事件
///
///
///
private void txtVBELN_TextChanged(object sender, EventArgs e)
{
txtOrderNo.Text = txtVBELN.Text.Trim() + "/" + txtPOSNR.Text.Trim() + "#" + txtSummary.Text.Trim();
}
/////
///// 获取组织机构结果集
/////
/////
//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 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"]);
txtVBELN.Text = orderRow["VBELN"].ToString();
txtPOSNR.Text = orderRow["POSNR"].ToString();
txtSummary.Text = orderRow["Summary"].ToString();
//// 条码串
//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.txtVBELN.Focus();
return false;
}
// 如果不是hegii开头的订单,必须天订单号和行号
if (!txtOrderNo.Text.StartsWith("HEGII"))
{
// SAP销售订单号不能为空
if (string.IsNullOrEmpty(this.txtVBELN.Text.Trim()))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "SAP销售订单号"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtVBELN.Focus();
return false;
}
// 行号不能为空
if (string.IsNullOrEmpty(this.txtPOSNR.Text.Trim()))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "行号"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtPOSNR.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);
// sap销售订单号
order.VBELN = this.txtVBELN.Text.Trim();
// 行号
order.POSNR = this.txtPOSNR.Text.Trim();
// 描述
order.Summary = this.txtSummary.Text.Trim();
//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;
txtVBELN.Text = string.Empty;
txtPOSNR.Text = string.Empty;
txtSummary.Text = string.Empty;
this.txtOrderNo.Text = string.Empty;
this.dtpOrderDateFrom.Value = DateTime.Now;
this.txtRemarks.Text = string.Empty;
this.txtVBELN.Focus();
}
#endregion
}
}