锐腾搅拌上料功能
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.

1367 lines
55 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid;
using System.IO;
using System.Threading;
using ICSSoft.Base.Language.Tool;
using ICSSoft.Base.Config.AppConfig;
using ICSSoft.Base.UserControl.MessageControl;
using ICSSoft.Base.Config.DBHelper;
using ICSSoft.Base.Report.Filter;
using ICSSoft.Base.UserControl.FormControl;
using ICSSoft.Base.Report.GridReport;
using ICSSoft.Base.ReferForm.AppReferForm;
using ICSSoft.Frame.Data.BLL;
using ICSSoft.Frame.Data.Entity;
namespace ICSSoft.Frame.APP
{
public partial class FormICSMO : DevExpress.XtraEditors.XtraForm
{
private string sqltxt = "";
private string sqlconn = "";
String guid = AppConfig.GetGuid();
private DataTable dataSource = null;
#region 构造函数
public FormICSMO()
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns)
{
col.OptionsColumn.AllowEdit = col.Name == colSerial.Name;
// col.OptionsColumn.ReadOnly = true;
}
}
#endregion
#region 操作权限
public DataTable RightOfExute()
{
DataTable rData = new DataTable();
rData.Columns.Add("BtnName");
rData.Columns.Add("ActionName");
//查看权限(必须有)
DataRow seeRow = rData.NewRow();
seeRow["BtnName"] = "see";
seeRow["ActionName"] = "查看";
rData.Rows.Add(seeRow);
List<Control> ControlList = new List<Control>();
ControlList.Add(btnModify);
ControlList.Add(btnOutPut);
ControlList.Add(btnBatchOne2One);
ControlList.Add(btnCancelAll);
ControlList.Add(btnRefresh);
ControlList.Add(txtsend);
ControlList.Add(txtcancelSend);
ControlList.Add(btnBatch);
ControlList.Add(btnExit);
//ControlList.Add(btnDel);
//ControlList.Add(txtstop);
//ControlList.Add(txtcancelStop);
//ControlList.Add(txtcloseDan);
//ControlList.Add(btnCreate);
foreach (Control ctr in ControlList)
{
if (ctr.GetType() == typeof(SimpleButton))
{
DataRow dr = rData.NewRow();
dr["BtnName"] = ctr.Name;
dr["ActionName"] = ctr.Text;
rData.Rows.Add(dr);
}
}
rData.AcceptChanges();
return rData;
}
public DataTable RightOfData()// 数据权限
{
DataTable rData = new DataTable();
rData.Columns.Add("BodyName");
rData.Columns.Add("ControlName");
rData.Columns.Add("ControlCaption");
rData.AcceptChanges();
return rData;
}
#endregion
#region 退出
private void btnClose_Click(object sender, EventArgs e)
{
AppConfig.CloseFormShow(this.Text);
this.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
AppConfig.CloseFormShow(this.Text);
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 grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
#endregion
#region 过滤
private string tempTableName = "";
private void btnFilter_Click(object sender, EventArgs e)
{
FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
filter.OldTempTableName = tempTableName;
if (filter.ShowDialog() == DialogResult.OK)
{
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
try
{
_wait.Show();
tempTableName = filter.NewTempTableName;
sqltxt = filter.SqlText;
sqlconn = filter.FilterConnectString;
dataSource = filter.FilterData.Tables[0];
grdDetail.DataSource = dataSource;
grvDetail.BestFitColumns();
rptPage.RecordNum = dataSource.Rows.Count;
rptPage.PageSize = 499;
rptPage.PageIndex = 1;
rptPage.ReLoad();
rptPage.PageSize = 500;
rptPage.PageIndex = 1;
rptPage.ReLoad();
_wait.Close();
}
catch (Exception ex)
{
MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
_wait.Close();
}
}
}
#endregion
#region 绑定数据源
private void btnConfig_Click(object sender, EventArgs e)
{
if (AppConfig.UserCode.ToLower() != "demo")
{
ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
return;
}
FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
fdata.ShowDialog();
}
#endregion
#region 分页
private void rptPage_PageIndexChanged(object Sender, EventArgs e)
{
DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
//DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
grdDetail.DataSource = data;
}
#endregion
#region 过滤方法
private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
{
AppConfig.DropTemTable(tempTableName);
}
#endregion
#region 全选
private void btnSelectAll_Click(object sender, EventArgs e)
{
grvDetail.PostEditor();
this.Validate();
for (int i = 0; i < grvDetail.RowCount; i++)
{
grvDetail.SetRowCellValue(i, colisSelect, "Y");
}
}
#endregion
#region 全消
private void btnCancelAll_Click(object sender, EventArgs e)
{
grvDetail.PostEditor();
this.Validate();
for (int i = 0; i < grvDetail.RowCount; i++)
{
grvDetail.SetRowCellValue(i, colisSelect, "");
}
}
#endregion
#region 双击
private void grvDetail_DoubleClick(object sender, EventArgs e)
{
if (grvDetail.FocusedRowHandle < 0)
{
return;
}
if (grvDetail.FocusedColumn == colisSelect)
{
if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
{
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
}
else
{
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
}
}
}
#endregion
#region 删除
private void btnDel_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
List<string> moidList = new List<string>();
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
string moid;
if (grvDetail.GetRowCellValue(i, colMOTYPE).ToString() == "1")
{
moidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("非返程工单,不能删除!!!");
return;
}
}
}
if (moidList.Count == 0 || moidList == null)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
return;
}
if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除工单吗?删除后无法恢复,确定吗?") != DialogResult.OK)
{
btnCancelAll_Click(sender, e);
return;
}
try
{
ICSMOBLL.deleteInfo(moidList, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("删除成功");
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
btnRefresh_Click(null, null);
}
#endregion
#region 导出
private void btnOutPut_Click(object sender, EventArgs e)
{
FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
foe.ShowDialog();
}
#endregion
#region 刷新
private void btnRefresh_Click(object sender, EventArgs e)
{
string tip = "正在查找...请稍等...";
if (sender == null)
{
tip = "正在刷新界面...";
}
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm(tip);
try
{
_wait.Show();
FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
filter.OldTempTableName = tempTableName;
//tempTableName = filter.NewTempTableName;
//DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
if (!string.IsNullOrWhiteSpace(sqlconn))
{
dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
grdDetail.DataSource = dataSource;
grvDetail.BestFitColumns();
rptPage.RecordNum = dataSource.Rows.Count;
rptPage.PageIndex = 1;
rptPage.ReLoad();
}
_wait.Close();
}
catch (Exception ex)
{
MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
_wait.Close();
}
}
#endregion
#region 新增
private void btnCreate_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
FormICSMOAdd add = new FormICSMOAdd();
add.ShowDialog();
btnRefresh_Click(null, null);
}
#endregion
#region 修改
private void btnModify_Click(object sender, EventArgs e)
{
//已经分批的不能修改途程20190717ZM
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
int count = 0;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
count++;
}
}
if (count != 1)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
return;
}
try
{
string moid;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
moid = grvDetail.GetRowCellValue(i, colID).ToString();
bool issplit = ChechIsSplit(moid);
if (issplit)
{
ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改");
return;
}
else
{
FormICSMOAdd add = new FormICSMOAdd(moid);
add.ShowDialog();
}
//}
//else
//{
// ICSBaseSimpleCode.AppshowMessageBox("非返程工单,不能修改!!!");
// return;
//}
}
}
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
//throw ex;
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
#endregion
private bool ChechIsSplit(string moid)
{
bool isSplit = false;
string mocode = string.Empty; ;
string MOSEQ = string.Empty;
string sql = @" SELECT MOCODE,MOSEQ FROM ICSMO WHERE ID='" + moid + "' ";
sql = string.Format(sql);
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (data != null && data.Rows.Count > 0)
{
mocode = data.Rows[0][0].ToString();
MOSEQ = data.Rows[0][1].ToString();
}
string _sql = @"
SELECT COUNT(*) AS num FROM
ICSITEMLot b
WHERE b.TransNO='" + mocode + "' AND B.TransLine='" + MOSEQ + "' ";
_sql = string.Format(_sql);
DataTable _data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, _sql).Tables[0];
if (_data != null || _data.Rows.Count > 0)
{
int a = Int32.Parse(_data.Rows[0][0].ToString());
if (a > 0)
{
isSplit = true;
}
}
return isSplit;
//if (isSplit)
//{
// ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改");
// return;
//}
}
private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
{
AppConfig.DropTemTable(tempTableName);
}
private void FormICSMO_Load(object sender, EventArgs e)
{
btnFilter_Click(sender, e);
}
private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
{
//e.DisplayText = FormatHelper.
e.CellValue = "cccc";
}
}
//生成序列号
private void newRcard_Click(object sender, EventArgs e)
{
//SimpleButton btntemp = (SimpleButton)sender;
//if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
//{
// ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
// return;
//}
//int count = 0;
//for (int i = 0; i < grvDetail.RowCount; i++)
//{
// if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
// {
// count++;
// }
//}
//if (count != 1)
//{
// ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
// return;
//}
//try
//{
// string moID;
// string moCode;
// decimal qty = 0.00m;
// for (int i = 0; i < grvDetail.RowCount; i++)
// {
// if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
// {
// moID = grvDetail.GetRowCellValue(i, colID).ToString();
// moCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
// qty = decimal.Parse(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
// FormICSMO2RCARDAdd rec = new FormICSMO2RCARDAdd(moID, moCode, qty);
// rec.ShowDialog();
// }
// }
// btnRefresh_Click(null, null);
//}
//catch (Exception ex)
//{
// //throw ex;
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
//}
}
private void repSerialButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
try
{
string moID;
string moCode;
decimal qty = 0.00m;
moID = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString();
moCode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colMOCODE).ToString();
qty = Convert.ToDecimal(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colMOPLANQTY).ToString());
FormICSMO2RCARDAdd rec = new FormICSMO2RCARDAdd(moID, moCode, qty);
rec.ShowDialog();
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
throw ex;
}
}
//下发
private void txtsend_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
List<ICSMO> list = new List<ICSMO>();
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
string state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
if (state != "初始")
{
grvDetail.SetRowCellValue(i, colisSelect, "");
Application.DoEvents();
continue;
}
ICSMO mo = new ICSMO();
mo.MOCODE = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
mo.MOSEQ = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
mo.WorkPoint = AppConfig.WorkPointCode;
list.Add(mo);
}
}
if (list.Count == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择状态为'初始'的工单行进行下发!");
return;
}
btntemp.Enabled = false;
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("开始下发...");
try
{
_wait.Show();
int u = ICSMOBLL.Send(list, AppConfig.AppConnectString);
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox("下发成功 " + u.ToString() + " 条");
btnRefresh_Click(null, null);
#region old
// string mocode = "";
// string moseq = "";
// string state = "";
// for (int i = 0; i < grvDetail.RowCount; i++)
// {
// if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
// {
// mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
// state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
// moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
// }
// }
// string sendSql = @"SELECT * FROM ICSITEMLot WHERE TransNO='" + mocode + "' ";
// sendSql = string.Format(sendSql);
// DataTable sendData = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sendSql).Tables[0];
// if (sendData == null || sendData.Rows.Count < 1)
// {
// ICSBaseSimpleCode.AppshowMessageBox("只有分完批次才能下发!");
// return;
// }
// string _sql = @"
//SELECT
// c.ROUTECODE
//FROM
// ICSMO a
//LEFT JOIN ICSMO2ROUTE c ON a.ID = c.MOID AND a.WorkPoint=c.WorkPoint
//LEFT JOIN (
// SELECT
// b.MOCODE,
// CONVERT (INT, b.MOSEQ) AS MOSEQ,
// b.ITEMCODE,
// COUNT (*) AS IsUse
// FROM
// ICSMOPickLog a
// INNER JOIN ICSMO b ON (a.MOCode = b.MOCODE AND b.MOSEQ = a.MOSEQ AND a.ITEMCODE = b.ITEMCODE AND b.WorkPoint=a.WorkPoint)
// WHERE a.WorkPoint='"+AppConfig.WorkPointCode+@"'
// GROUP BY b.MOCODE, b.MOSEQ,b.ITEMCODE
//) d ON (d.MOCODE = a.MOCODE AND d.MOSEQ = a.MOSEQ AND d.ITEMCODE = a.ITEMCODE)
//WHERE
// 1 = 1
//AND a.MOCODE = '" + mocode + "' AND a.MOSEQ =" + moseq + " AND a.WorkPoint='"+AppConfig.WorkPointCode+"' ORDER BY a.MOCODE, CONVERT (INT, a.MOSEQ)";
// _sql = string.Format(_sql);
// DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, _sql).Tables[0];
// string _ROUTECODE = string.Empty;
// if (data != null && data.Rows.Count > 0)
// {
// _ROUTECODE = data.Rows[0][0].ToString();
// }
// else
// {
// ICSBaseSimpleCode.AppshowMessageBox("工单尚未绑定工艺路线不能下发!");
// return;
// }
// if (string.IsNullOrWhiteSpace(_ROUTECODE))
// {
// ICSBaseSimpleCode.AppshowMessageBox("工单尚未绑定工艺路线不能下发!");
// return;
// }
// //判断是否是初始状态
// if (state.Equals("初始"))
// {
// ////判断是否在工单首检记录表中
// //if (ICSMOBLL.isInFirstCheck(mocode, AppConfig.AppConnectString))
// //{
// ////判断(最近的时间)是否合格
// //if (ICSMOBLL.isQualified(mocode, AppConfig.AppConnectString))
// //{
// ICSMOBLL.Send(mocode, moseq, AppConfig.AppConnectString);
// ICSBaseSimpleCode.AppshowMessageBox("下发成功");
// //}
// //else
// //{
// // ICSBaseSimpleCode.AppshowMessageBox("不合格,不能下发");
// // return;
// // //}
// // }
// //else
// // {
// // ICSBaseSimpleCode.AppshowMessageBox("不存在工单首检记录中");
// // return;
// // }
// }
// else
// {
// ICSBaseSimpleCode.AppshowMessageBox("不是初始状态,不能下发");
// return;
// }
//btnRefresh_Click(null, null);
#endregion
}
catch (Exception ex)
{
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
finally
{
btntemp.Enabled = true;
}
}
//取消下发
private void txtcancelSend_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
List<ICSMO> list = new List<ICSMO>();
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
string state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
if (state != "下发")
{
grvDetail.SetRowCellValue(i, colisSelect, "");
Application.DoEvents();
continue;
}
ICSMO mo = new ICSMO();
mo.MOCODE = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
mo.MOSEQ = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
mo.WorkPoint = AppConfig.WorkPointCode;
list.Add(mo);
}
}
if (list.Count == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择状态为'下发'的工单行进行[取消下发]操作!");
return;
}
btntemp.Enabled = false;
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("开始下发...");
try
{
_wait.Show();
int u = ICSMOBLL.CancelSend(list, AppConfig.AppConnectString);
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox("取消下发成功 " + u.ToString() + " 条");
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
finally
{
btntemp.Enabled = true;
}
#region old
//int count = 0;
//for (int i = 0; i < grvDetail.RowCount; i++)
//{
// if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
// {
// count++;
// }
//}
//if (count != 1)
//{
// ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
// return;
//}
//try
//{
// string mocode = "";
// string state = "";
// string moseq = "";
// for (int i = 0; i < grvDetail.RowCount; i++)
// {
// if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
// {
// mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
// state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
// moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
// }
// }
// //1.
// DataTable dt = ICSMO2UserBLL.SelectMO2USER(mocode, moseq, AppConfig.AppConnectString, AppConfig.WorkPointCode);
// if (dt.Rows.Count != 0)
// {
// string msg = "";
// foreach (DataRow dr in dt.Rows)
// {
// msg += ("跟踪单:" + dr["LOTNO"].ToString() + "工序:" + dr["OPCODE"].ToString() + "\r\n");
// }
// throw new Exception("已有派工记录,不可取消下发\r\n" + msg);
// }
// //2.判断是否是下发状态
// if (state.Equals("下发"))
// {
// ICSMOBLL.cancelSend(mocode, moseq, AppConfig.AppConnectString);
// ICSBaseSimpleCode.AppshowMessageBox("取消下发成功");
// }
// else
// {
// ICSBaseSimpleCode.AppshowMessageBox("不是下发状态,不能取消下发");
// return;
// }
// btnRefresh_Click(null, null);
//}
//catch (Exception ex)
//{
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
//}
#endregion
}
//暂停
private void txtstop_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
int count = 0;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
count++;
}
}
if (count != 1)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
return;
}
try
{
string mocode = "";
string state = "";
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
}
}
//判断是否是生产中状态
if (state.Equals("生产中"))
{
ICSMOBLL.stop(mocode, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("暂停成功");
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("不是生产中状态,不能暂停");
return;
}
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
//取消暂停
private void txtcancelStop_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
int count = 0;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
count++;
}
}
if (count != 1)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
return;
}
try
{
string mocode = "";
string state = "";
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
}
}
//判断是否是暂停状态
if (state.Equals("暂停"))
{
ICSMOBLL.cancelStop(mocode, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("取消暂停成功");
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("不是暂停状态,不能取消暂停");
return;
}
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
//关单
private void txtcloseDan_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
int count = 0;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
count++;
}
}
if (count != 1)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
return;
}
try
{
string mocode = "";
string state = "";
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
}
}
//判断是否是关单状态
if (!(state.Equals("关单")))
{
ICSMOBLL.closeDan(mocode, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("关单成功");
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("已经是关单状态");
return;
}
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
//批次信息
private void btnBatch_Click(object sender, EventArgs e)
{
//SimpleButton btntemp = (SimpleButton)sender;
//if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
//{
// ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
// return;
//}
//FormICSMO2Lot add = new FormICSMO2Lot();
//add.ShowDialog();
//btnRefresh_Click(null, null);
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
int count = 0;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
count++;
}
}
if (count != 1)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
return;
}
try
{
string id;
string code;
int Qty = 0;
string itemcode;
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
id = grvDetail.GetRowCellValue(i, colID).ToString();
code = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
Qty = (int)Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
itemcode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
FormICSMO2Lot add = new FormICSMO2Lot(id, code, Qty, itemcode, moseq);
add.ShowDialog();
//btnRefresh_Click(null, null);
}
}
//判断是否是关单状态
//if (!(state.Equals("关单")))
//{
//}
//else
//{
// ICSBaseSimpleCode.AppshowMessageBox("已经是关单状态");
// return;
//}
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
private void btnBatchOne2One_Click(object sender, EventArgs e)
{
SimpleButton btntemp = (SimpleButton)sender;
if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
{
ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
return;
}
List<string> listId = new List<string>();
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
listId.Add(grvDetail.GetRowCellValue(i, colID).ToString());
}
}
if (listId.Count() == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据!!!");
return;
}
if (MessageBox.Show("每个工单行只分批成一个跟踪单,确定分批吗?", "提示", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在执行,请稍等...");
try
{
_wait.Show();
string res = "";
string msg11 = "";
string ID = "";
string MOCODE = "";
string MOSEQ = "";
string ITEMCODE = "";
string MOVER = "";
decimal MOPLANQTY = 0;
DateTime mtime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
List<ICSITEMLot> listItemLot = new List<ICSITEMLot>();
List<ICSITEMROUTE2OPLot> listItemRouteOpLot = new List<ICSITEMROUTE2OPLot>();
#region 1是否已分批.2 生成ICSITEMLot
DataTable dt = ICSMO2LotBLL.GetMO2LotInfo(listId, AppConfig.WorkPointCode, AppConfig.AppConnectString);
foreach (DataRow dr in dt.Rows)
{
ID = dr["ID"].ToString();
MOCODE = dr["MOCODE"].ToString();
MOSEQ = dr["MOSEQ"].ToString();
MOVER = dr["MOVER"].ToString();
MOPLANQTY = Convert.ToDecimal(dr["MOPLANQTY"]);
ITEMCODE = dr["ITEMCODE"].ToString();
int FP = Convert.ToInt32(dr["FP"].ToString());
if (listId.Contains(ID) && FP > 0)
{
if (msg11 == "")
{
msg11 = "以下工单行已分批\r\n";
}
msg11 += ("工单:" + MOCODE + "行:" + MOSEQ + "\r\n");
listId.Remove(ID);
continue;
}
#region ItemLot
ICSITEMLot itemlot = new ICSITEMLot();
itemlot.ID = Guid.NewGuid().ToString();
itemlot.LotNO = MOCODE + MOSEQ + "0001";
itemlot.ItemCode = ITEMCODE;
itemlot.LOTQTY = MOPLANQTY;
itemlot.TransNO = MOCODE;
itemlot.TransLine = MOSEQ;
itemlot.TYPE = "工单";
itemlot.VenderLotNO = MOVER;
itemlot.MUSER = AppConfig.UserId;
itemlot.MUSERName = AppConfig.UserName;
itemlot.Exdate = Convert.ToDateTime("2999-12-31 00:00:00.000");
itemlot.PRODUCTDATE = itemlot.MTIME = mtime;
itemlot.WorkPoint = AppConfig.WorkPointCode;
itemlot.ACTIVE = "Y";
listItemLot.Add(itemlot);
#endregion
}
if (listItemLot.Count == 0)
{
throw new Exception("没有符合条件的工单行," + msg11);
}
if (msg11 != "")
{
DialogResult dResult1 = MessageBox.Show(msg11, "是否跳过?", MessageBoxButtons.YesNo);
if (dResult1 != DialogResult.Yes)
{
throw new Exception("取消分批");
}
}
#endregion
#region 关联工单的默认途程
// string isref = "";
// string routeid = "";
// //查找工单--产品途程
// string sql1 = @"select ROUTEID,ISREF from ICSITEM2ROUTE where ITEMCODE='" + itemcode + "' and ISREF = '是' and WorkPoint='" + AppConfig.WorkPointCode + "'";
// sql1 = string.Format(sql1);
// DataTable data1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql1).Tables[0];
// if (data1 != null && data1.Rows.Count > 0)
// {
// routeid = data1.Rows[0]["ROUTEID"].ToString();
// isref = data1.Rows[0]["ISREF"].ToString();
// ICSMOBLL.addRoute(moid, routeid, itemcode, isref, AppConfig.AppConnectString);
// }
// else
// {
// string sql = @"select a.ROUTEID,
// a.ISREF
// from ICSMODEL2ROUTE a
// left join Base_Inventory b on a.MODELCODE=b.ItemMainCategoryCode
// where b.ItemCode='" + itemcode + "' and a.ISREF = '是' and a.WorkPoint='" + AppConfig.WorkPointCode + "'";
// sql = string.Format(sql);
// DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
// if (data != null && data.Rows.Count > 0)
// {
// routeid = data.Rows[0]["ROUTEID"].ToString();
// isref = data.Rows[0]["ISREF"].ToString();
// ICSMOBLL.addRoute(moid, routeid, itemcode, isref, AppConfig.AppConnectString);
// }
// else
// {
// if (ICSBaseSimpleCode.AppshowMessageBoxRepose("该工单没有默认途程,是否继续生成批次?") != DialogResult.OK)
// {
// return;
// }
// }
// }
#endregion
#region 1校验工单是否关联途程、工艺路线、工序.2生成ItemRoute2OPLot
string msg21 = "";
string msg22 = "";
string msg23 = "";
dt = ICSMO2LotBLL.GetMO2Route(listId, AppConfig.WorkPointCode, AppConfig.AppConnectString);
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
DataRow dr = dt.Rows[i];
ID = dr["ID"].ToString();
MOCODE = dr["MOCODE"].ToString();
MOSEQ = dr["MOSEQ"].ToString();
ITEMCODE = dr["ITEMCODE"].ToString();
string ROUTECODE = dr["ROUTECODE"].ToString().Trim();
string OPSEQ = dr["OPSEQ"].ToString();
string OPCODE = dr["OPCODE"].ToString().Trim();
string OPAttr = dr["OPAttr"].ToString().Trim();
string CtrlType = dr["CtrlType"].ToString().Trim();
string RouteMGR = dr["RouteMGR"].ToString().Trim();
string = dr["工时"].ToString().Trim();
if (string.IsNullOrEmpty(ROUTECODE))
{
if (msg21 == "")
{
msg21 = "以下工单行未关联工艺路线\r\n";
}
msg21 += ("工单:" + MOCODE + "行:" + MOSEQ + "\r\n");
dt.Rows.Remove(dr);
listId.Remove(ID);
listItemLot.RemoveAll(a => a.TransNO == MOCODE && a.TransLine == MOSEQ);
continue;
}
if (string.IsNullOrEmpty(OPCODE))
{
if (msg22 == "")
{
msg22 = "以下工单行,工艺路线未关联工序信息\r\n";
}
msg22 += ("工单:" + MOCODE + "行:" + MOSEQ + "工艺路线:" + ROUTECODE + "\r\n");
dt.Rows.Remove(dr);
listId.Remove(ID);
listItemLot.RemoveAll(a => a.TransNO == MOCODE && a.TransLine == MOSEQ);
continue;
}
if ( == "未维护")
{
if (msg23 == "")
{
msg23 = "以下工单行,不是所有工序都维护了工时\r\n";
}
msg23 += ("工单:" + MOCODE + "行:" + MOSEQ + "工序" + OPCODE + "\r\n");
dt.Rows.Remove(dr);
listId.Remove(ID);
listItemLot.RemoveAll(a => a.TransNO == MOCODE && a.TransLine == MOSEQ);
continue;
}
#region ItemRoute2OPLot
foreach (ICSITEMLot itemlot in listItemLot)
{
if (itemlot.TransNO == MOCODE && itemlot.TransLine == MOSEQ)
{
ICSITEMROUTE2OPLot ItemRouteOpLot = new ICSITEMROUTE2OPLot();
ItemRouteOpLot.ID = Guid.NewGuid().ToString();
ItemRouteOpLot.ITEMCODE = ITEMCODE;
ItemRouteOpLot.LotNo = itemlot.LotNO;
ItemRouteOpLot.ROUTECODE = ROUTECODE;
ItemRouteOpLot.OPCODE = OPCODE;
ItemRouteOpLot.OPSEQ = Convert.ToInt32(OPSEQ);
ItemRouteOpLot.OPCONTROL = "";
ItemRouteOpLot.OPTIONALOP = "";
ItemRouteOpLot.IDMERGETYPE = "";
ItemRouteOpLot.IDMERGERULE = 0;
ItemRouteOpLot.MUSER = AppConfig.UserId;
ItemRouteOpLot.MUSERName = AppConfig.UserName;
ItemRouteOpLot.MTIME = mtime;
ItemRouteOpLot.WorkPoint = AppConfig.WorkPointCode;
ItemRouteOpLot.CtrlType = CtrlType;
ItemRouteOpLot.OPAttr = OPAttr;
ItemRouteOpLot.RouteMGR = RouteMGR;
listItemRouteOpLot.Add(ItemRouteOpLot);
}
}
#endregion
}
if (listItemRouteOpLot.Count == 0)
{
throw new Exception("没有符合条件的工单行," + msg21 + msg22 + msg23);
}
if (msg21 != "")
{
DialogResult dResult1 = MessageBox.Show(msg21, "是否跳过?", MessageBoxButtons.YesNo);
if (dResult1 != DialogResult.Yes)
{
throw new Exception("取消分批");
}
}
if (msg22 != "")
{
DialogResult dResult1 = MessageBox.Show(msg22, "是否跳过?", MessageBoxButtons.YesNo);
if (dResult1 != DialogResult.Yes)
{
throw new Exception("取消分批");
}
}
if (msg23 != "")
{
DialogResult dResult1 = MessageBox.Show(msg22, "是否跳过?", MessageBoxButtons.YesNo);
if (dResult1 != DialogResult.Yes)
{
throw new Exception("取消分批");
}
}
#endregion
//批次汇入
ICSMO2LotBLL.Mo2LotOne2One(listItemLot, listItemRouteOpLot, AppConfig.AppConnectString);
foreach (ICSITEMLot item in listItemLot)
{
res += ("工单:" + item.TransNO + ",行:" + item.TransLine + "\r\n");//+ ",跟踪单:" + item.LotNO
}
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox("分批成功!\r\n" + res);
btnRefresh_Click(null, null);
}
catch (Exception ex)
{
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
}
}