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.
471 lines
20 KiB
471 lines
20 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Data.Linq;
|
|
using System.Linq;
|
|
using ICSSoft.Base.Language.Tool;
|
|
using System.Reflection;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.ReferForm;
|
|
using ICSSoft.Base.Report;
|
|
using ICSSoft.Base.ReferForm.AppReferForm;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Frame.Data.BLL;
|
|
|
|
namespace ICSSoft.Frame.APP
|
|
{
|
|
public partial class FormICSITEM2ROUTEAdd : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
String guid = "";
|
|
int flag;
|
|
FormICSITEM2ROUTEUIModel model;
|
|
|
|
#region 构造函数
|
|
public FormICSITEM2ROUTEAdd()
|
|
{
|
|
InitializeComponent();
|
|
flag = 0;
|
|
init();
|
|
chargeFormState("Add");
|
|
}
|
|
|
|
public FormICSITEM2ROUTEAdd(string itemCode, string routeCode)
|
|
{
|
|
InitializeComponent();
|
|
flag = 1;
|
|
init();
|
|
SearchInfo(itemCode, routeCode);
|
|
chargeFormState("Edit");
|
|
}
|
|
#endregion
|
|
|
|
private void chargeFormState(string state)
|
|
{
|
|
switch (state)
|
|
{
|
|
case "Add":
|
|
txtITEMCODE.Properties.ReadOnly = false;
|
|
txtROUTECODE.Properties.ReadOnly = false;
|
|
break;
|
|
case "Edit":
|
|
txtITEMCODE.Properties.ReadOnly = true;
|
|
txtROUTECODE.Properties.ReadOnly = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void SearchInfo(string itemCode, string routeCode)
|
|
{
|
|
model = ICSITEM2ROUTEBLL.SearchInfoByCode(itemCode, routeCode, AppConfig.AppConnectString);
|
|
//if (model.ISREF.Equals("1"))
|
|
if (model.ISREF.Equals("是"))
|
|
|
|
checkISREF.Checked = true;
|
|
else
|
|
checkISREF.Checked = false;
|
|
txtITEMCODE.Tag = model.item as FormICSINVENTORYUIModel;
|
|
txtITEMCODE.Text = model.item.INVCODE;
|
|
txtROUTECODE.Tag = model.route as FormICSROUTEUIModel;
|
|
txtROUTECODE.Text = model.route.ROUTECODE;
|
|
}
|
|
|
|
#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 save_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (txtITEMCODE.Text.Trim() == "")
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("产品不能为空");
|
|
return;
|
|
}
|
|
if (txtROUTECODE.Text.Trim() == "")
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("途程不能为空");
|
|
return;
|
|
}
|
|
|
|
#region
|
|
//if (txtITEMCODE.Tag == null)
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox("产品格式输入不正确,请重新选择!");
|
|
// return;
|
|
//}
|
|
//if(txtROUTECODE.Tag==null){
|
|
// ICSBaseSimpleCode.AppshowMessageBox("途程格式输入不正确,请重新选择!");
|
|
// return;
|
|
//}
|
|
//FormICSITEM2ROUTEUIModel test = new FormICSITEM2ROUTEUIModel();
|
|
//test.item = new FormICSINVENTORYUIModel();
|
|
//test.item = txtITEMCODE.Tag as FormICSINVENTORYUIModel;
|
|
//test.route = new FormICSROUTEUIModel();
|
|
//test.route = txtROUTECODE.Tag as FormICSROUTEUIModel;
|
|
//FormICSITEM2ROUTEUIModel test = new FormICSITEM2ROUTEUIModel();
|
|
//test.item = new FormICSINVENTORYUIModel();
|
|
#endregion
|
|
|
|
if (ICSITEM2ROUTEBLL.CheckOP(txtROUTECODE.Text, AppConfig.AppConnectString))
|
|
{
|
|
if (flag == 0)
|
|
{
|
|
//判断是否存在相同的产品和途程
|
|
//bool a = ICSITEM2ROUTEBLL.IsIncluding(test.item.INVCODE, test.route.ROUTECODE, AppConfig.AppConnectString);
|
|
bool a = ICSITEM2ROUTEBLL.IsIncluding(txtITEMCODE.Text, txtROUTECODE.Text, AppConfig.AppConnectString);
|
|
if (!a)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("存在相同的产品和途程");
|
|
return;
|
|
}
|
|
}
|
|
//判断产品是否有使用的途程
|
|
//bool b = ICSITEM2ROUTEBLL.IsIncludingISREF(test.item.INVCODE, test.route.ROUTECODE, AppConfig.AppConnectString);
|
|
bool b = ICSITEM2ROUTEBLL.IsIncludingISREF(txtITEMCODE.Text, txtROUTECODE.Text, AppConfig.AppConnectString);
|
|
if (!b)
|
|
{
|
|
if (checkISREF.Checked)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("该产品有使用的途程");
|
|
return;
|
|
}
|
|
}
|
|
FormICSITEM2ROUTEUIModel ITEM2ROUTE = new FormICSITEM2ROUTEUIModel();
|
|
ITEM2ROUTE.item = new FormICSINVENTORYUIModel();
|
|
//ITEM2ROUTE.item = txtITEMCODE.Tag as FormICSINVENTORYUIModel;
|
|
ITEM2ROUTE.item.INVCODE = txtITEMCODE.Text;
|
|
ITEM2ROUTE.item.ID = txtITEMID.Text;
|
|
ITEM2ROUTE.route = new FormICSROUTEUIModel();
|
|
//ITEM2ROUTE.route = txtROUTECODE.Tag as FormICSROUTEUIModel;
|
|
ITEM2ROUTE.route.ROUTECODE = txtROUTECODE.Text;//.Tag as FormICSROUTEUIModel;
|
|
ITEM2ROUTE.route.ID = txtROUTEID.Text;//.Tag as FormICSROUTEUIModel;
|
|
if (checkISREF.Checked)
|
|
//ITEM2ROUTE.ISREF = "1";
|
|
ITEM2ROUTE.ISREF = "是";
|
|
|
|
else
|
|
//ITEM2ROUTE.ISREF = "0";
|
|
ITEM2ROUTE.ISREF = "否";
|
|
ICSITEM2ROUTEBLL.Add(ITEM2ROUTE, AppConfig.AppConnectString);
|
|
if (flag == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("新增成功");
|
|
}
|
|
else if (flag == 1)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("修改成功");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("途程未绑定工艺路线");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
this.Close();
|
|
this.DialogResult = DialogResult.Yes;
|
|
}
|
|
#endregion
|
|
|
|
#region 取消
|
|
private void can_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
//private void txtITEMCODE_QueryPopUp(object sender, CancelEventArgs e)
|
|
//{
|
|
// txtITEMCODE.Properties.View.Columns["guid"].Visible = false; //隐藏列
|
|
//}
|
|
|
|
private void init()
|
|
{
|
|
#region 存货编码
|
|
string sql = "SELECT DISTINCT ID,INVCODE AS [存货编码],INVNAME AS [存货名称] FROM ICSINVENTORY ORDER BY INVCODE";
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
|
|
txtITEMCODE.Properties.ValueMember = "存货编码";
|
|
txtITEMCODE.Properties.DisplayMember = "存货编码";
|
|
txtITEMCODE.Properties.DataSource = dt;
|
|
txtITEMCODE.Properties.NullText = "";//空时的值
|
|
txtITEMCODE.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtITEMCODE.Properties.ValidateOnEnterKey = true;//回车确认
|
|
txtITEMCODE.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtITEMCODE.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtITEMCODE.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
|
|
#region 途程代码
|
|
string _sql = "select ID,[ROUTECODE] as 途程代码,[ROUTEDESC] as 途程名称 from [ICSROUTE]";
|
|
DataTable _dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, _sql).Tables[0];
|
|
txtROUTECODE.Properties.ValueMember = "途程代码";
|
|
txtROUTECODE.Properties.DisplayMember = "途程代码";
|
|
txtROUTECODE.Properties.DataSource = _dt;
|
|
txtROUTECODE.Properties.NullText = "";//空时的值
|
|
txtROUTECODE.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtROUTECODE.Properties.ValidateOnEnterKey = true;//回车确认
|
|
txtROUTECODE.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtROUTECODE.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtROUTECODE.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
}
|
|
|
|
//private void txtITEMCODE_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
|
//{
|
|
// if (flag == 0)
|
|
// {
|
|
// ButtonEdit btn = (ButtonEdit)sender;
|
|
// DataTable dt = ICSITEM2ROUTEBLL.SearchItemInfoList(AppConfig.AppConnectString,btn.Text);
|
|
// FormDataRefer reForm = new FormDataRefer();
|
|
// reForm.FormTitle = "产品";
|
|
// reForm.DataSource = dt;
|
|
// reForm.MSelectFlag = false;
|
|
// reForm.RowIndexWidth = 35;
|
|
// reForm.HideCols.Add("guid");
|
|
// reForm.FormWidth = 500;
|
|
// reForm.FormHeight = 500;
|
|
// //reForm.FilterKey = btn.Text;
|
|
// //reForm.FilterKey=
|
|
// if (reForm.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// DataTable retData = reForm.ReturnData;
|
|
// foreach (DataRow dr in retData.Rows)
|
|
// {
|
|
// FormICSINVENTORYUIModel Item = new FormICSINVENTORYUIModel();
|
|
// Item.ID = dr["guid"].ToString();
|
|
// Item.INVCODE = dr["存货编码"].ToString();
|
|
// Item.INVNAME = dr["存货名称"].ToString();
|
|
// Item.INVDESC = dr["规格型号"].ToString();
|
|
// txtITEMCODE.Text = Item.INVCODE;
|
|
// txtITEMCODE.Tag = Item;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
#region 存货编码按钮
|
|
private void txtITEMCODE_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
|
{
|
|
// try
|
|
// {
|
|
// List<FormICSINVENTORYUIModel> returntype = new List<FormICSINVENTORYUIModel>();
|
|
// string sql = @"select [ID],[INVCODE],[INVNAME],[INVDESC]
|
|
// from [ICSINVENTORY]
|
|
// ";
|
|
// sql = string.Format(sql, invcode);
|
|
// if (!string.IsNullOrWhiteSpace(invcode))
|
|
// {
|
|
// sql += "WHERE INVCODE LIKE '%" + invcode + "%'";
|
|
// }
|
|
// DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
// foreach (DataRow dr in dt.Rows)
|
|
// {
|
|
// FormICSINVENTORYUIModel itemmodel = new FormICSINVENTORYUIModel();
|
|
// itemmodel.ID = dr["ID"].ToString();
|
|
// itemmodel.INVCODE = dr["INVCODE"].ToString();
|
|
// itemmodel.INVNAME = dr["INVNAME"].ToString();
|
|
// itemmodel.INVDESC = dr["INVDESC"].ToString();
|
|
// if (!returntype.Contains(itemmodel))
|
|
// returntype.Add(itemmodel);
|
|
// }
|
|
// return returntype;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
ButtonEdit btn = (ButtonEdit)sender;
|
|
string sql = @" select distinct [ID] as [产品ID] ,[INVCODE] as [存货编码] ,[INVNAME] as [存货名称] ,[INVDESC] as [规格型号]
|
|
from [ICSINVENTORY] with(nolock) WHERE 1=1 ";
|
|
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
|
|
FormDataRefer reForm = new FormDataRefer();
|
|
reForm.FormTitle = "产品信息";
|
|
DataTable menuData = data;
|
|
reForm.DataSource = menuData;
|
|
reForm.MSelectFlag = false;
|
|
reForm.RowIndexWidth = 35;
|
|
reForm.HideCols.Add("产品ID");
|
|
reForm.FormWidth = 500;
|
|
reForm.FormHeight = 500;
|
|
//reForm.FilterKey = btn.Text;
|
|
//grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
|
|
if (reForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
DataTable retData = reForm.ReturnData;
|
|
foreach (DataRow dr in retData.Rows)
|
|
{
|
|
txtITEMCODE.Text = dr["存货编码"].ToString();
|
|
//itemid = dr["产品ID"].ToString();
|
|
//txtItemName.Text = dr["存货名称"].ToString();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void txtROUTECODE_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
|
{
|
|
if (flag == 0)
|
|
{
|
|
DataTable dt = ICSITEM2ROUTEBLL.SearchRouteInfoList(AppConfig.AppConnectString);
|
|
FormDataRefer reForm = new FormDataRefer();
|
|
reForm.FormTitle = "途程";
|
|
reForm.DataSource = dt;
|
|
reForm.MSelectFlag = false;
|
|
reForm.RowIndexWidth = 35;
|
|
reForm.HideCols.Add("guid");
|
|
reForm.FormWidth = 500;
|
|
reForm.FormHeight = 500;
|
|
if (reForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
DataTable retData = reForm.ReturnData;
|
|
foreach (DataRow dr in retData.Rows)
|
|
{
|
|
FormICSROUTEUIModel Route = new FormICSROUTEUIModel();
|
|
Route.ID = dr["guid"].ToString();
|
|
Route.ROUTECODE = dr["途程代码"].ToString();
|
|
Route.ROUTEDESC = dr["途程描述"].ToString();
|
|
txtROUTECODE.Text = Route.ROUTEDESC;
|
|
txtROUTECODE.Tag = Route;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void txtITEMCODE_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
//if (e.KeyChar != (char)Keys.Back)
|
|
//{
|
|
// e.Handled = true;
|
|
//}
|
|
}
|
|
|
|
private void txtROUTECODE_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
//if (e.KeyChar != (char)Keys.Back)
|
|
//{
|
|
// e.Handled = true;
|
|
//}
|
|
}
|
|
|
|
private void txtITEMCODE_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
//this.txtITEMCODE.Text = "";
|
|
//this.txtITEMCODE.Tag = null;
|
|
}
|
|
|
|
private void txtROUTECODE_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
//this.txtROUTECODE.Text = "";
|
|
//this.txtROUTECODE.Tag = null;
|
|
}
|
|
|
|
private void txtITEMCODE_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
var o = txtITEMCODE.Properties.GetRowByKeyValue(txtITEMCODE.EditValue);
|
|
if (o is DataRowView)
|
|
{
|
|
DataRowView RowView = o as DataRowView;
|
|
if (RowView != null && RowView.DataView.Count > 0)
|
|
{
|
|
txtITEMCODE.Text = RowView.Row["存货编码"].ToString();
|
|
txtITEMID.Text = RowView.Row["ID"].ToString();
|
|
}
|
|
}
|
|
//init3();
|
|
}
|
|
|
|
private void txtROUTECODE_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
var o = txtROUTECODE.Properties.GetRowByKeyValue(txtROUTECODE.EditValue);
|
|
if (o is DataRowView)
|
|
{
|
|
DataRowView RowView = o as DataRowView;
|
|
if (RowView != null && RowView.DataView.Count > 0)
|
|
{
|
|
txtROUTECODE.Text = RowView.Row["途程代码"].ToString();
|
|
txtROUTEID.Text = RowView.Row["ID"].ToString();
|
|
}
|
|
}
|
|
LoadOP(txtROUTECODE.Text);
|
|
}
|
|
|
|
private void LoadOP(string routCode)
|
|
{
|
|
string sql = @"SELECT DISTINCT D.OPCODE, D.OPDESC FROM ICSROUTE2OP E LEFT JOIN ICSOP D ON E.OPID = D.ID
|
|
WHERE 1 = 1 AND E.WorkPoint = '{0}' AND E.ROUTECODE = '{1}' ORDER BY D.OPCODE ASC ";
|
|
sql = string.Format(sql, AppConfig.WorkPointCode, routCode);
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
|
|
string OPText = string.Empty;
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow item in dt.Rows)
|
|
{
|
|
OPText += item["OPCODE"].ToString() + " " + item["OPDESC"].ToString() + "\r\n";
|
|
}
|
|
}
|
|
this.txtOPCode.Text = OPText;
|
|
//System.Windows.Forms.Control
|
|
}
|
|
|
|
private void txtITEMCODE_QueryPopUp(object sender, CancelEventArgs e)
|
|
{
|
|
txtITEMCODE.Properties.View.Columns["ID"].Visible = false; //隐藏列
|
|
}
|
|
|
|
private void txtROUTECODE_QueryPopUp(object sender, CancelEventArgs e)
|
|
{
|
|
txtROUTECODE.Properties.View.Columns["ID"].Visible = false; //隐藏列
|
|
}
|
|
}
|
|
}
|