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.Language.Tool;
using ICSSoft.Base.UserControl.MessageControl;
using System.Data.SqlClient;
using ICSSoft.Base.Config.AppConfig;
using ICSSoft.Base.Report.Filter;
using ICSSoft.Base.Config.DBHelper;
using ICSSoft.Base.UserControl.FormControl;
using ICSSoft.Base.ReferForm.AppReferForm;
using ICSSoft.Frame.Data.DAL;
using ICSSoft.Frame.Data.BLL;
using ICSSoft.Frame.Data.Entity;
using ICSSoft.Base.Lable.PrintTool;
namespace ICSSoft.Frame.APP
{
public partial class FormICSLotSplitIn : DevExpress.XtraEditors.XtraForm
{
#region 基础参数
private string sqltxt = "";
private string sqlconn = "";
String guid = AppConfig.GetGuid();
private DataTable dataSource = null;
private string SimID = "";
private string LotNo = "";
private string MoCode = "";
private string MoSeq = "";
private decimal ngnumber = 0;
private String FPTYPE = "";
#endregion
#region 构造函数
public FormICSLotSplitIn()
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
}
#endregion
public FormICSLotSplitIn(string id,string type)
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
SimID = id;
this.FPTYPE = type;
}
#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 SystemOptition
///
/// 操作权限
///
///
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 ControlList = new List();
//ControlList.Add(btnDelLable);
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 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 btnFalsh_Click(object sender, EventArgs e)
{
FormICSLotSplitInCollection_Load(null, null);
}
#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 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 btnOutPut_Click(object sender, EventArgs e)
{
try
{
FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
foe.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//FormOutExcel foe = new FormOutExcel();
//if (foe.ShowDialog() == DialogResult.OK)
//{
// try
// {
// string outtype = foe._OutType;
// string exceltype = foe._ExcelType;
// string filename = foe._FileName;
// string url = foe._Url;
// string sheetname = foe._SheetName;
// if (outtype.ToLower() == "excel")
// {
// DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
// op.SheetName = sheetname;
// grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
// }
// else
// {
// grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
// }
// MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
// catch (Exception ex)
// {
// MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
//}
}
#endregion
private void FormICSLotSplitInCollection_Load(object sender, EventArgs e)
{
try
{
txtNowQty.Focus();
string sql = @"SELECT LOTNO,SEQ,MOCODE,LOTSEQ,LOTQTY,GOODQTY,NGQTY,LOTStatus,ITEMCODE,ROUTECODE,OPCODE,FXQTY,
RESCODE,EQPCODE,PRODUCTSTATUS,LACTION,ACTIONLIST,NGTIMES,ISCOM,ISHOLD,MOSEQ,CollectStatus
FROM ICSLOTSIMULATION WHERE ID = '{0}'";
sql = string.Format(sql, SimID);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
if(FPTYPE=="返修分批")
ngnumber= Convert.ToDecimal(dt.Rows[0]["FXQTY"].ToString());
else
ngnumber = Convert.ToDecimal(dt.Rows[0]["NGQTY"].ToString());
txtLOTNORemainQTY.Text = ngnumber.ToString();
txtNowQty.Text = txtLOTNORemainQTY.Text;
txtNowPackQty.Text = txtLOTNORemainQTY.Text;
txtNowNum.Text = "1";
LotNo = dt.Rows[0]["LOTNO"].ToString();
MoCode = dt.Rows[0]["MOCODE"].ToString();
MoSeq = dt.Rows[0]["MOSEQ"].ToString();
sql = @"SELECT DISTINCT '' isSelect,a.ID,a.MOCODE,
--b.MOSEQ,
a.LOTNO,a.ITEMCODE,c.INVNAME AS ITEMNAME,
a.ROUTECODE,d.ROUTEDESC,a.OPCODE,e.OPDESC,a.LOTQTY,a.GOODQTY,
case when a.NGQTY>0 then a.ngqty
when a.fxqty>0 then fxqty end as NGQTY
,a.MUSERName,a.MTIME
FROM ICSLOTSIMULATION a
LEFT JOIN ICSMO b ON a.MOCODE = b.MOCODE
LEFT JOIN ICSINVENTORY c ON a.ITEMCODE = c.INVCODE
LEFT JOIN ICSROUTE d ON d.ROUTECODE = a.ROUTECODE
LEFT JOIN ICSOP e ON a.OPCODE = e.OPCODE
WHERE a.LOTNO = '{0}'
--OR a.LOTNO IN (SELECT LOTNOSplit FROM ICSLotSplitINCollectionLog)
ORDER BY MTIME DESC"; //WHERE LOTNO = a.LOTNO
sql = string.Format(sql, LotNo);
dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
grdDetail.DataSource = dt;
grvDetail.BestFitColumns();
}
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
private void txtNowQty_EditValueChanged(object sender, EventArgs e)
{
decimal Qty = 0;
decimal Pack = 0;
decimal Num = 0;
decimal Sqty = 0;
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
decimal.TryParse(txtNowNum.Text, out Num);
if (Qty != 0 && Pack != 0)
{
Sqty = Math.Ceiling(Qty / Pack);
txtNowNum.Text = Sqty.ToString();
}
}
private void txtNowNum_EditValueChanged(object sender, EventArgs e)
{
decimal Qty = 0;
decimal Pack = 0;
decimal Num = 0;
decimal Sqty = 0;
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
decimal.TryParse(txtNowNum.Text, out Num);
if (Qty != 0 && Num != 0)
{
if (Num * Pack >= Pack + Qty || Num * Pack <= Qty)
{
Sqty = Math.Ceiling(Qty / Num);
txtNowPackQty.Text = Sqty.ToString();
}
else
return;
}
}
private void btnLot_Click(object sender, EventArgs e)
{
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……");
try
{
ICSITEMLOTBLL.SpliteLotNo(LotNo, ngnumber, FPTYPE, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("分批成功");
_wait.Close();
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
_wait.Close();
}
}
private void CreatLot(List Infolist)
{
bool isnew = false;
List simList = new List();
List loginfolist = new List();
ICSLOTSIMULATION lotSimulation = ICSITEMLOTBLL.GetICSLOTSIMULATION(SimID, AppConfig.AppConnectString);
List mo2UserList = new List();
if (lotSimulation == null)
{
isnew = true;
}
foreach (ICSITEMLot info in Infolist)
{
#region 获取原条码ICSLOTSIMULATION数据并扣减数量
#endregion
if (isnew == false)
{
#region ICSLOTSIMULATION
ICSLOTSIMULATION simInfo = new ICSLOTSIMULATION();
simInfo.ID = AppConfig.GetGuid();
simInfo.LOTNO = info.LotNO;
simInfo.SEQ = lotSimulation.SEQ;
simInfo.MOCODE = lotSimulation.MOCODE;
simInfo.LOTSEQ = lotSimulation.LOTSEQ + 1;
simInfo.LOTQTY = info.LOTQTY;
simInfo.GOODQTY = info.LOTQTY;
simInfo.NGQTY = 0;
simInfo.LOTStatus = lotSimulation.LOTStatus;
simInfo.MODELCODE = lotSimulation.MODELCODE;
simInfo.ITEMCODE = lotSimulation.ITEMCODE;
simInfo.FROMROUTE = lotSimulation.FROMROUTE;
simInfo.FROMOP = lotSimulation.FROMOP;
simInfo.ROUTECODE = lotSimulation.ROUTECODE;
simInfo.OPCODE = lotSimulation.OPCODE;
simInfo.RESCODE = lotSimulation.RESCODE;
simInfo.EQPCODE = lotSimulation.EQPCODE;
simInfo.CHECKLOTNO = lotSimulation.CHECKLOTNO;
simInfo.CARTONCODE = lotSimulation.CARTONCODE;
simInfo.PALLETCODE = lotSimulation.PALLETCODE;
simInfo.PRODUCTSTATUS = lotSimulation.PRODUCTSTATUS;
simInfo.LACTION = lotSimulation.LACTION;
simInfo.ACTIONLIST = lotSimulation.ACTIONLIST;
simInfo.NGTIMES = lotSimulation.NGTIMES;
simInfo.ISCOM = lotSimulation.ISCOM;
simInfo.ISHOLD = lotSimulation.ISHOLD;
simInfo.SHELFNO = lotSimulation.SHELFNO;
simInfo.MOSEQ = lotSimulation.MOSEQ;
simInfo.CollectStatus = lotSimulation.CollectStatus;
simInfo.BeginTime = lotSimulation.BeginTime;
simInfo.EndTime = lotSimulation.EndTime;
simInfo.MUSER = AppConfig.UserCode;
simInfo.MUSERName = AppConfig.UserName;
simInfo.MTIME = DateTime.Now;
simInfo.WorkPoint = AppConfig.WorkPointCode;
simList.Add(simInfo);
#endregion
}
#region ICSLotSplitINCollectionLog
ICSLotSplitINCollectionLog loginfo = new ICSLotSplitINCollectionLog();
loginfo.ID = AppConfig.GetGuid();
loginfo.LOTNO = LotNo;
loginfo.LOTNOSplit = info.LotNO;
if (isnew == false)
{
loginfo.OPCode = lotSimulation.OPCODE;
}
else
{
loginfo.OPCode = "";
}
loginfo.MUSER = AppConfig.UserCode;
loginfo.MUSERNAME = AppConfig.UserName;
loginfo.MTIME = DateTime.Now;
loginfo.WorkPoint = AppConfig.WorkPointCode;
loginfolist.Add(loginfo);
#endregion
string sql = @"SELECT ROUTECODE,OPCODE,OPSEQ FROM ICSROUTE2OP WHERE ROUTECODE = '{0}'
AND OPSEQ > (SELECT OPSEQ FROM ICSROUTE2OP WHERE ROUTECODE = '{0}' AND OPCODE = '{1}')
ORDER BY OPSEQ";
sql = string.Format(sql, lotSimulation.ROUTECODE, lotSimulation.OPCODE);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
ICSMO2User user = new ICSMO2User();
user.ID = AppConfig.GetGuid().ToString();
user.MOCODE = lotSimulation.MOCODE;
user.MOSEQ = lotSimulation.MOSEQ;
user.LOTNO = info.LotNO;
user.SEGCODE = "";
user.RouteCode = lotSimulation.ROUTECODE;
user.OPCODE = row["OPCODE"].ToString();
user.USERCODE = "";
user.USERName = "";
user.EQPCode = "";
user.EQPName = "";
user.StartPlanDate = DateTime.Now;
user.EndPlanDate = DateTime.Now;
user.MUSER = AppConfig.UserCode;
user.MUSERName = AppConfig.UserName;
user.MTIME = DateTime.Now;
user.WorkPoint = AppConfig.WorkPointCode;
mo2UserList.Add(user);
}
}
try
{
ICSITEMLOTBLL.SplitAdd(SimID, LotNo, Infolist, simList, loginfolist,mo2UserList, isnew, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("分批成功");
btnFalsh_Click(null, null);
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
private void btnPrint_Click(object sender, EventArgs e)
{
try
{
List parasList = new List();
List InfoList = new List();
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
{
PrintPara para = new PrintPara();
para.PrintKey = "LOTNO";
para.PrintValues = new object[] { grvDetail.GetRowCellValue(i, colLOTNO).ToString() };
parasList.Add(para);
}
}
if (parasList.Count == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
return;
}
//FormPrintDialog f = new FormPrintDialog("001", this.Text, parasList, false, null);
FormPrintDialog f = new FormPrintDialog("007", "ICSProduct", parasList, false, null);
f.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}