You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
435 lines
18 KiB
435 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.ReferForm.AppReferForm;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Frame.Data.BLL;
|
|
|
|
namespace ICSSoft.Frame.APP
|
|
{
|
|
public partial class FormICSForecastEdit : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
String guid = "";
|
|
DataSet dataSource = new DataSet();
|
|
string Version = "";
|
|
string pk_org_ForInvcode = "000110100000000005J9";
|
|
|
|
#region 构造函数
|
|
public FormICSForecastEdit()
|
|
{
|
|
InitializeComponent();
|
|
this.MaximumSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
|
|
this.WindowState = FormWindowState.Maximized;
|
|
label6.Visible = false;
|
|
txtForecastNO.Visible = false;
|
|
}
|
|
public FormICSForecastEdit(String id, string version = null)
|
|
{
|
|
InitializeComponent();
|
|
guid = id;
|
|
Version = version;
|
|
this.MaximumSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
|
|
this.WindowState = FormWindowState.Maximized;
|
|
label6.Visible = true;
|
|
txtForecastNO.Visible = true;
|
|
}
|
|
#endregion
|
|
|
|
#region 关闭 退出
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
#region 移动窗体
|
|
private const int WM_NCHITTEST = 0x84;
|
|
private const int HTCLIENT = 0x1;
|
|
private const int HTCAPTION = 0x2;
|
|
//首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
|
|
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
|
|
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
|
|
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
|
|
|
|
//重写窗体,使窗体可以不通过自带标题栏实现移动
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
//当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
|
|
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
|
|
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
|
|
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
|
|
switch (m.Msg)
|
|
{
|
|
case WM_NCHITTEST:
|
|
base.WndProc(ref m);
|
|
if ((int)m.Result == HTCLIENT)
|
|
m.Result = (IntPtr)HTCAPTION;
|
|
return;
|
|
}
|
|
//拦截双击标题栏、移动窗体的系统消息
|
|
if (m.Msg != 0xA3)
|
|
{
|
|
base.WndProc(ref m);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 新增 修改
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (dataSource == null || dataSource.Tables.Count != 2)
|
|
{
|
|
return;
|
|
}
|
|
if (txtCustomer.EditValue == null || string.IsNullOrWhiteSpace(txtCustomer.EditValue.ToString()))
|
|
{
|
|
throw new Exception("请选择客户!");
|
|
}
|
|
DataTable dt = dataSource.Tables[1];
|
|
DataRow[] drs = dt.Select("InvCode=''");
|
|
if (drs != null && drs.Length > 0)
|
|
throw new Exception("物料编码不能为空!");
|
|
|
|
var InvCodes = (from DataRow dr in dt.Rows
|
|
group dr by (string)dr["InvCode"] into g
|
|
select new
|
|
{
|
|
InvCode = g.Key,
|
|
Count = g.Count()
|
|
}).Where(a => a.Count > 1).Select(a => a.InvCode);
|
|
if (InvCodes != null && InvCodes.Count() > 0)
|
|
{
|
|
string invcodes = string.Join(",", InvCodes);
|
|
throw new Exception("物料编码不能重复:" + invcodes);
|
|
}
|
|
ICSForecast entity = new ICSForecast();
|
|
entity.ID = guid;
|
|
entity.ForecastNO = txtForecastNO.Text.Trim();
|
|
entity.Version = txtForecastNO.Tag.ToString();
|
|
entity.Customer = txtCustomer.EditValue.ToString();
|
|
entity.Org = txtCustomer.Text.Trim();
|
|
entity.Enable = true;
|
|
entity.MUSER = AppConfig.UserCode;
|
|
entity.MUSERName = AppConfig.UserName;
|
|
entity.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
entity.WorkPoint = AppConfig.WorkPointCode;
|
|
entity.EATTRIBUTE1 = null;
|
|
entity.CreateUser = entity.MUSER;
|
|
entity.CreateDateTime = entity.MTIME;
|
|
|
|
ICSForecastBLL.Add(entity, dt, Version, AppConfig.AppConnectString);
|
|
this.Close();
|
|
ICSBaseSimpleCode.AppshowMessageBox("操作成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 取消
|
|
private void can_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
#region 页面加载
|
|
private void FormICSINVENTORYEditAdd_Load(object sender, EventArgs e)
|
|
{
|
|
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在加载...请稍等...");
|
|
_wait.Show();
|
|
DataSet ds = new DataSet();
|
|
DataTable head = new DataTable();
|
|
DataTable body = new DataTable();
|
|
try
|
|
{
|
|
AppConfig.BindCustomDrawRowIndicator(grdDetail);
|
|
init();
|
|
ds = ICSForecastBLL.SearchInfoByID(guid, AppConfig.AppConnectString);
|
|
if (ds == null || ds.Tables.Count != 2)
|
|
{
|
|
throw new Exception("查询数据失败,请重新操作!");
|
|
}
|
|
head = ds.Tables[0].Copy();
|
|
body = ds.Tables[1].Clone();
|
|
body.Columns.Add("客户料号");
|
|
if (!string.IsNullOrEmpty(guid))
|
|
{
|
|
DataTable dtDetail = ds.Tables[1];
|
|
var query =
|
|
from row1 in dtDetail.AsEnumerable()
|
|
join row2 in dtInvInfo.AsEnumerable()
|
|
on row1.Field<string>("InvCode") equals row2.Field<string>("物料编码")
|
|
select row1.ItemArray.Concat(row2.ItemArray.Skip(3));
|
|
|
|
foreach (var obj in query)
|
|
{
|
|
DataRow _dr = body.NewRow();
|
|
_dr.ItemArray = obj.ToArray();
|
|
body.Rows.Add(_dr);
|
|
}
|
|
}
|
|
dataSource.Tables.Add(head);
|
|
dataSource.Tables.Add(body);
|
|
|
|
DataRow dr = head.Rows[0];
|
|
txtForecastNO.Text = dr["ForecastNO"].ToString();
|
|
txtForecastNO.Tag = dr["Version"].ToString();
|
|
if (string.IsNullOrWhiteSpace(guid))
|
|
{
|
|
guid = AppConfig.GetGuid();
|
|
lblTitle.Text = "预测单新增";
|
|
txtForecastNO.Properties.ReadOnly = true;
|
|
txtMUSERName.Text = AppConfig.UserName;
|
|
txtMTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
else
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Version))
|
|
lblTitle.Text = "预测单修改";
|
|
else
|
|
lblTitle.Text = "预测单变更";
|
|
txtForecastNO.Properties.ReadOnly = true;
|
|
txtCustomer.Properties.ReadOnly = true;
|
|
txtCustomer.Text = dr["Customer"].ToString();
|
|
txtMUSERName.Text = AppConfig.UserName;
|
|
txtMTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
grvDetail.DataSource = body;
|
|
grdDetail.BestFitColumns();
|
|
grdDetail.Columns["客户料号"].FieldName = "客户料号";
|
|
grdDetail.Columns["InvCode"].Caption = "物料编码";
|
|
grdDetail.Columns["InvCode"].ColumnEdit = txtINVCode;
|
|
grdDetail.Columns["客户料号"].ColumnEdit = txtmaterialmnecode;
|
|
grdDetail.Columns["客户料号"].VisibleIndex = 1;
|
|
grdDetail.Columns["安全库存数量"].VisibleIndex = 2;
|
|
grdDetail.Columns["之前欠缺数量"].VisibleIndex = 3;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
_wait.Close();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
DataTable dtInvInfo = new DataTable();
|
|
#region 初始化查询条件
|
|
private void init()
|
|
{
|
|
DataSet ds = ICSForecastBLL.GetInvInfoAndCust(pk_org_ForInvcode);
|
|
|
|
#region 存货编码
|
|
//string sql = "SELECT DISTINCT INVCODE AS [存货编码] ,INVNAME AS [存货名称] ,INVSTD AS [规格型号] FROM ICSINVENTORY WHERE WorkPoint='{0}' ORDER BY INVCODE ";
|
|
//sql = string.Format(sql, AppConfig.WorkPointCode);
|
|
//string sql = @"SELECT a.code AS [存货编码] ,a.name AS [存货名称] ,a.materialspec AS [规格型号]
|
|
// FROM bd_material a
|
|
// -- INNER JOIN org_orgs b ON a.pk_org =b.pk_org
|
|
// WHERE a.pk_org='000110100000000005J9' --b.code='Ahwit'
|
|
// ORDER BY a.code
|
|
//
|
|
// SELECT cus.code AS [客户编码],cus.name AS[客户名称] FROM bd_customer cus
|
|
// INNER JOIN org_orgs org ON cus.pk_org=org.pk_org
|
|
// --WHERE org.code='{0}'
|
|
// ORDER BY cus.code";
|
|
//DataSet ds = DBHelper.ExecuteDataset(erp, CommandType.Text, sql);
|
|
|
|
txtINVCode.ValueMember = "物料编码";
|
|
txtINVCode.DisplayMember = "物料编码";
|
|
txtINVCode.DataSource = dtInvInfo = ds.Tables[0];
|
|
txtINVCode.NullText = "";//空时的值
|
|
txtINVCode.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtINVCode.ValidateOnEnterKey = true;//回车确认
|
|
txtINVCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtINVCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtINVCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
|
|
#region 客户
|
|
// string sql1 = @"SELECT cus.code AS [客户编码],cus.name AS[客户名称] FROM bd_customer cus
|
|
// INNER JOIN org_orgs org ON cus.pk_org=org.pk_org
|
|
// --WHERE org.code='{0}'
|
|
// ORDER BY cus.code";
|
|
// sql1 = string.Format(sql1, AppConfig.WorkPointCode);
|
|
// DataTable dt1 = DBHelper.ExecuteDataset(erp, CommandType.Text, sql1).Tables[0];
|
|
txtCustomer.Properties.ValueMember = "客户编码";
|
|
txtCustomer.Properties.DisplayMember = "客户名称";
|
|
txtCustomer.Properties.DataSource = ds.Tables[1];
|
|
txtCustomer.Properties.NullText = "";//空时的值
|
|
txtCustomer.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtCustomer.Properties.ValidateOnEnterKey = true;//回车确认
|
|
txtCustomer.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtCustomer.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtCustomer.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
#region 增行
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (dataSource == null || dataSource.Tables.Count != 2)
|
|
{
|
|
return;
|
|
}
|
|
DataRow dr = dataSource.Tables[1].NewRow();
|
|
dr["InvCode"] = "";
|
|
dataSource.Tables[1].Rows.Add(dr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删行
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (dataSource == null || dataSource.Tables.Count != 2)
|
|
{
|
|
return;
|
|
}
|
|
dataSource.Tables[1].Rows.RemoveAt(grdDetail.FocusedRowHandle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 复制行
|
|
private void btnCopy_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (dataSource == null || dataSource.Tables.Count != 2)
|
|
{
|
|
return;
|
|
}
|
|
DataRow dr = dataSource.Tables[1].Rows[grdDetail.FocusedRowHandle];
|
|
dataSource.Tables[1].Rows.Add(dr.ItemArray);
|
|
int index = dataSource.Tables[1].Rows.Count;
|
|
dataSource.Tables[1].Rows[index - 1]["InvCode"] = "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void txtINVCode_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
//GridLookUpEdit edit = sender as GridLookUpEdit;
|
|
//if (e.KeyCode != Keys.Enter)
|
|
//{
|
|
// return;
|
|
//}
|
|
//try
|
|
//{
|
|
// if (edit.EditValue != null || edit.EditValue.ToString() != "" || edit.EditValue.ToString() != "nulltext")
|
|
// {
|
|
// var o = edit.Properties.GetRowByKeyValue(edit.EditValue);
|
|
// if (o is DataRowView)
|
|
// {
|
|
// DataRowView RowView = o as DataRowView;
|
|
// string InvCT = RowView.Row["客户料号"].ToString();
|
|
// grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, grdDetail.Columns["客户料号"], InvCT);
|
|
// }
|
|
// else
|
|
// {
|
|
// grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, "客户料号", "");
|
|
// }
|
|
// }
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
//}
|
|
}
|
|
|
|
private void txtINVCode_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
GridLookUpEdit edit = sender as GridLookUpEdit;
|
|
try
|
|
{
|
|
if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext")
|
|
{
|
|
var o = edit.Properties.GetRowByKeyValue(edit.EditValue);
|
|
if (o is DataRowView)
|
|
{
|
|
DataRowView RowView = o as DataRowView;
|
|
string InvCT = RowView.Row["客户料号"].ToString();
|
|
grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, grdDetail.Columns["客户料号"], InvCT);
|
|
}
|
|
else
|
|
{
|
|
grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, "客户料号", "");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, "客户料号", "");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void txtmaterialmnecode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ButtonEdit btn = (ButtonEdit)sender;
|
|
if (string.IsNullOrWhiteSpace(btn.Text))
|
|
throw new Exception("请输入客户料号!");
|
|
|
|
FormDataRefer reForm = new FormDataRefer();
|
|
reForm.FormTitle = "物料信息";
|
|
DataTable menuData = dtInvInfo.Copy();
|
|
reForm.DataSource = menuData;
|
|
reForm.MSelectFlag = false;
|
|
reForm.RowIndexWidth = 35;
|
|
//reForm.HideCols.Add("ID");
|
|
//reForm.FormWidth = 500;
|
|
//reForm.FormHeight = 500;
|
|
reForm.FilterKey = btn.Text;
|
|
if (reForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
DataTable retData = reForm.ReturnData;
|
|
foreach (DataRow dr in retData.Rows)
|
|
{
|
|
grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, grdDetail.Columns["客户料号"], dr["客户料号"].ToString());
|
|
grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, grdDetail.Columns["InvCode"], dr["物料编码"].ToString());
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|