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

473 lines
18 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 FormICSAllocation : DevExpress.XtraEditors.XtraForm
{
private DataSet ds;
//内存表
private DataTable dtzhu;
private DataTable dtone;
private DataTable dttwo;
private string sqltxt = "";
private string sqlconn = "";
String guid = AppConfig.GetGuid();
private DataTable dataSource = null;
#region 构造函数
public FormICSAllocation()
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
ds = new DataSet();
dtone = new DataTable();
}
#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(btnOutPut);
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 退出r0
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 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 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)
{
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
try
{
}
catch (Exception ex)
{
MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
_wait.Close();
}
}
#endregion
private void FormICSAllocation_Load(object sender, EventArgs e)
{
//btnFilter_Click(sender, e);
}
#region 选择转移单号
private void txtTransferNO_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
txtTransferNO.Text = "";
ButtonEdit btn = (ButtonEdit)sender;
string sql = @"select TransferNO as [调拨单号] from ICSInvTransfer";
sql = string.Format(sql);
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, 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 = 800;
reForm.FormHeight = 600;
reForm.FilterKey = btn.Text;
if (reForm.ShowDialog() == DialogResult.OK)
{
DataTable retData = reForm.ReturnData;
foreach (DataRow dr in retData.Rows)
{
txtTransferNO.Text = dr["调拨单号"].ToString();
}
Bindvalue( txtTransferNO.Text);
}
}
#endregion
#region 转移单表
public DataTable MainTable()
{
try
{
string sql = @"select cast( 0 as bit) as isSelect,
c.ID,
a.TransferNO,
a.TransferLine,
a.ITEMCODE,
b.INVNAME as ITEMNAME,
a.FROMStorageCode,
a.FROMStackCode,
a.TOStorageCode,
a.TOStackCode,
a.PLANQTY,
c.TransQTY as ACTQTY
from ICSInvTransferDetail a
left join ICSINVENTORY b on a.ITEMCODE=b.INVCODE
left join ICSITEMTrans c on a.TransferNO=c.TransNO and a.TransferLine=c.TransLine
where a.TransferNO='" + txtTransferNO.Text.Trim() + "' ";
sql = string.Format(sql);
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
return data;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
#endregion
#region 子表
public DataTable OneTable()
{
string sql = @"select ITEMTransID,
LotNO,
TransQTY
from ICSITEMTransLot";
sql = string.Format(sql);
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
return data;
}
#endregion
private void grvDetailone_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
{
//取消负号
if (e.KeyChar == '-')
{
e.Handled = true;
}
//执行回车
if (e.KeyChar == 13)
{
List<string> LineList = new List<string>();
string storage = "";
string stack = "";
for (int i = 0; i < grvDetail.RowCount; i++)
{
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "True")
{
string line = grvDetail.GetRowCellValue(i, colID).ToString();
LineList.Add(line);
storage = grvDetail.GetRowCellValue(i, colFROMStorageCode).ToString();
stack = grvDetail.GetRowCellValue(i, colFROMStackCode).ToString();
}
}
if (LineList.Count != 1)
{
ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行调拨 !!!");
return;
}
decimal snum = 0.00m;
if (txtInput.Text == "")
{
ICSBaseSimpleCode.AppshowMessageBox("批号不可为空!!!");
return;
}
string sqlall = @"select a.LotNO,a.WHCode,a.BinCode,a.INVCode,a.ReceiveDate,
a.LotQty
from ICSWareHouseLotInfo a
where a.LotNO='" + txtInput.Text + "' and a.WHCode='" + storage + "' and a.BinCode='" + stack + "'";
sqlall = string.Format(sqlall);
DataTable dataall = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlall).Tables[0];
if (dataall == null || dataall.Rows.Count == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("发货库房库位不存该改批号");
return;
}
//源库存数量
string sqlone = @"select sum(LotQty) as sourcenum
from ICSWareHouseLotInfo
where WHCode='{0}' and BinCode='{1}' and INVCode='{2}' ";
sqlone = string.Format(sqlone, dataall.Rows[0]["WHCode"].ToString(), dataall.Rows[0]["BinCode"].ToString(), dataall.Rows[0]["INVCode"].ToString());
DataTable dataone = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlone).Tables[0];
snum = Convert.ToDecimal(dataone.Rows[0]["sourcenum"].ToString().Equals("") ? "0.00" : dataone.Rows[0]["sourcenum"].ToString());
if (snum == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("无源库位数量");
return;
}
try
{
#region
FormICSITEMTransUIModel infomodel = new FormICSITEMTransUIModel();
infomodel.TransNO = txtTransferNO.Text;
infomodel.TransLine = int.Parse(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colTransferLine).ToString());
infomodel.ITEMCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colITEMCODE).ToString();
infomodel.FRMStorageCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colFROMStorageCode).ToString();
infomodel.FRMStackCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colFROMStackCode).ToString();
infomodel.TOStorageCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colTOStorageCode).ToString();
infomodel.TOStackCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colTOStackCode).ToString();
//infomodel.LotNO = txtInput.Text;
infomodel.TransQTY = decimal.Parse(dataall.Rows[0]["LotQty"].ToString().Equals("") ? "0" : dataall.Rows[0]["LotQty"].ToString());
infomodel.Memo = "";
infomodel.TransType = "";
infomodel.BusinessCode = "";
FormICSITEMTransLotUIModel lotmodel = new FormICSITEMTransLotUIModel();
lotmodel.LotNO = txtInput.Text;
lotmodel.ITEMCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colITEMCODE).ToString();
lotmodel.TransQTY = decimal.Parse(dataall.Rows[0]["LotQty"].ToString().Equals("") ? "0" : dataall.Rows[0]["LotQty"].ToString());
ICSAllocationBLL.AddJiLu(infomodel, lotmodel, AppConfig.AppConnectString);
ICSBaseSimpleCode.AppshowMessageBox("调拨成功");
Bindvalue(txtTransferNO.Text);
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
}
private void grvDetail_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
{
grvDetailone = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView;
}
private void grvDetailmin_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
private void Bindvalue(string transNo)
{
try
{
string sql = @"select a.FROMStorageCode,
b.StorageName,
a.FROMStackCode,
a.TOStorageCode,
c.StorageName,
a.TOStackCode,
a.MEMO,
a.TransferLine,
a.PLANQTY,
a.ACTQTY,
a.ITEMCODE,
d.INVNAME as ITEMNAME
from ICSInvTransferDetail a
left join ICSStorage b on a.FROMStorageCode=b.StorageCode
left join ICSStorage c on a.TOStorageCode=c.StorageCode
left join ICSINVENTORY d on a.ITEMCODE=d.INVCODE
where a.TransferNO='" + transNo + "' 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)
{
throw new Exception("调拨单信息为空");
}
DataRow transdr = data.Rows[0];
txtfromstorage.Text = transdr["FROMStorageCode"].ToString();
txttostorage.Text= transdr["TOStorageCode"].ToString();
txtMEMO.Text = transdr["MEMO"].ToString();
decimal planqty = Convert.ToDecimal(transdr["PLANQTY"].ToString().Equals("") ? "0" : transdr["PLANQTY"].ToString());
decimal actqty = Convert.ToDecimal(transdr["ACTQTY"].ToString().Equals("") ? "0" : transdr["ACTQTY"].ToString());
if (planqty > actqty)
txtISSend.Checked = true;
else
txtISSend.Checked = false;
//绑定
ds.Reset();
dtzhu = null;
dtone.Rows.Clear();
dtzhu = MainTable().Copy();
dtone = OneTable().Copy();
dtzhu.TableName = "one";
dtone.TableName = "two";
ds.Tables.Add(dtzhu);
ds.Tables.Add(dtone);
DataRelation dr = new DataRelation("Level1", new DataColumn[] { ds.Tables[0].Columns["ID"] }, new DataColumn[] { ds.Tables[1].Columns["ITEMTransID"] });
ds.Relations.Add(dr);
grdDetail.DataSource = dtzhu;
grvDetail.BestFitColumns();
grvDetailone.BestFitColumns();
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}