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

612 lines
25 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;
using System.Data.SqlClient;
namespace ICSSoft.Frame.APP
{
public partial class FormICSTuiKuAdd : DevExpress.XtraEditors.XtraForm
{
private int flag = 0;
private string Qty = "";
private string StorageCode = "";
private string TransNo = "";
#region 构造函数
public FormICSTuiKuAdd()
{
InitializeComponent();
txtmuser.Text = AppConfig.UserName;
flag = 0;
}
//#region 审核
//public FormICSTuiKuAdd(string TransferNO, string TransLine, string INVCode, string INVName, int status)
// {
// if (status == 0)
// {
// DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存请稍等...");
// try
// {
// string sql = @"update ICSTransferNOBack set Status = '审核' where 1=1 and TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
// sql = string.Format(sql);
// DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
// _wait.Close();
// }
// catch (Exception ex)
// {
// _wait.Close();
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
// }
// }
// else if (status == 1)
// {
// DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在审核请稍等...");
// try
// {
// string sql = @"update ICSTransferNOBack set Status = '已审核', Approver = '{0}' where 1=1 and TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
// sql = string.Format(sql, AppConfig.UserName);
// DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
// _wait.Close();
// }
// catch (Exception ex)
// {
// _wait.Close();
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
// }
// }
// else if (status == 2)
// {
// DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在审核请稍等...");
// try
// {
// string sql = @"update ICSTransferNOBack set Status = '反审核', Approver = '{0}' where 1=1 and TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
// sql = string.Format(sql, AppConfig.UserName);
// DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
// _wait.Close();
// }
// catch (Exception ex)
// {
// _wait.Close();
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
// }
// }
// }
//#endregion
#region 删除
public FormICSTuiKuAdd(string TransferNO, string INVCode, string TransLine, string WHCode, string Qty)
{
try
{
SqlConnection conn = new SqlConnection(AppConfig.AppConnectString);
conn.Open();
SqlCommand cmd = new SqlCommand();
SqlTransaction trans = conn.BeginTransaction();
cmd.Transaction = trans;
cmd.Connection = conn;
try
{
string sqls = @"delete ICSMaterialPick where VouchCode = '" + TransferNO + "' and VouchRow = '" + TransLine + "' and SubInvCode = '" + INVCode + "' and WHCode = '" + WHCode + "'and Quantity = '" + Qty + "' ";
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqls;
cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
#endregion
public FormICSTuiKuAdd(string TransferNO, string TransLine, string INVCode, string StorageCode,string qty, string muser)
{
InitializeComponent();
this.txtSubInvCode.Enabled = false;
this.txtTransferNO.Enabled = false;
this.txtNO.Enabled = false;
this.txtVouchRow.Enabled = false;
this.txtTransferNO.Text = TransferNO.Substring(0, 8);
this.txtNO.Text = TransferNO.Substring(TransferNO.Length - (TransferNO.Length - 8), TransferNO.Length - 8);
this.txtVouchRow.Text = TransLine;
this.txtSubInvCode.Text = INVCode;
this.txtStorageCode.Text = StorageCode;
this.SearchINVCodeInfo(INVCode);
this.StorageCodeInfo();
this.txtmuser.Text = muser;
Qty = qty;
flag = 1;
}
#endregion
#region 存货名称
private void SearchINVCodeInfo(string INVCode)
{
string sql = @"select INVName from ICSINVENTORY where 1=1 and INVCode='" + INVCode + "' order by MTIME";
sql = string.Format(sql);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
this.txtInvName.Text = dr["INVName"].ToString();
}
if (txtInvName.Text == "")
{
ICSBaseSimpleCode.AppshowMessageBox("物料号对应的存货名称为空,请确认");
return;
}
else
{
this.txtQuantity.Enabled = true;
this.txtQuantity.Focus();
}
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("未查询到物料号对应的存货名称");
return;
}
}
#endregion
public void StorageCodeInfo()
{
string sql = @"SELECT StorageCode FROM ICSStorage where 1=1";
sql = string.Format(sql);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
this.txtStorageCode.Items.Add(dr["StorageCode"].ToString());
}
}
}
public void SearchINVCodeInfo()
{
string sql = @"select DISTINCT TOP 10 INVCode from ICSINVENTORY where 1=1 order by INVCode";
sql = string.Format(sql);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
this.txtSubInvCode.Items.Add(dr["INVCode"].ToString());
}
}
}
#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)
{
Decimal qty = new Decimal();
TransNo = this.txtTransferNO.Text + this.txtNO.Text;
if (flag == 0)
{
try
{
#region 判断是否为空
if (txtStorageCode.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("仓库不能为空");
return;
}
if (txtQuantity.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("数量不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtQuantity.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数量");
this.txtQuantity.Text = "";
return;
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtQuantity.Text = "";
return;
}
}
#endregion
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在新增请稍等...");
try
{
SqlConnection conn = new SqlConnection(AppConfig.AppConnectString);
SqlCommand com = conn.CreateCommand();
SqlTransaction tran;
conn.Open();
tran = conn.BeginTransaction();
com.Transaction = tran;
try
{
string sql = @"insert into ICSMaterialPick (VouchCode, VouchRow, SubInvCode, InvCode, Quantity, MTIME, MUSER, MUSERName, MoveType,WorkPoint, MOCode, MORow, WBS, DemandQuantity, SupplyQuantity, BackQuantity, HasQuantity,Sign,WHCode,ComUnitCode,BomNo,LotNo,DeleteStatus,VoucherNO,Year,VoucherDate,Status,Writeback)
values (@VouchCode, @VouchRow, @SubInvCode, '', @Quantity, @MTIME, @MUSER, @MUSERName, '退料',@WorkPoint,'','','',0,0,0,0,'',@WHCode,'','','','','','','','','')";
com.CommandText = sql;
com.Parameters.Clear();
com.Parameters.AddWithValue("@VouchCode", TransNo);
com.Parameters.AddWithValue("@VouchRow", txtVouchRow.Text.Trim());
com.Parameters.AddWithValue("@SubInvCode", txtSubInvCode.Text.Trim());
com.Parameters.AddWithValue("@WHCode", txtStorageCode.Text.Trim());
com.Parameters.AddWithValue("@Quantity", qty);
com.Parameters.AddWithValue("@Mtime", DateTime.Now.ToString());
com.Parameters.AddWithValue("@Muser", AppConfig.UserName);
com.Parameters.AddWithValue("@MUSERName", AppConfig.UserName);
com.Parameters.AddWithValue("@WorkPoint",AppConfig.WorkPointCode);
com.ExecuteNonQuery();
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
throw ex;
}
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox("新增成功");
}
catch (Exception ex)
{
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
if (flag == 1)
{
try
{
#region 判断是否为空
StorageCode =txtStorageCode.Text.Trim();
if (txtQuantity.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("数量不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtQuantity.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数量");
this.txtQuantity.Text = "";
return;
}
else
{
if (qty == Decimal.Parse(Qty))
{
ICSBaseSimpleCode.AppshowMessageBox("输入数量与原先相同,请确认");
this.txtQuantity.Text = "";
return;
}
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtQuantity.Text = "";
return;
}
}
#endregion
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在修改请稍等...");
try
{
string sql = @"update ICSMaterialPick set Quantity = {0} ,WHCode={1}where 1=1 and VouchCode = '" + TransNo + "' and VouchRow = '" + this.txtVouchRow.Text + "' and SubInvCode = '" + this.txtSubInvCode.Text + "' ";
sql = string.Format(sql, qty, StorageCode);
DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox("修改成功");
}
catch (Exception ex)
{
_wait.Close();
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
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 FormICSChuKuAdd_Load(object sender, EventArgs e)
{
if (flag == 0)
{
this.txtTransferNO.Text = "T2" + DateTime.Now.ToString("yyyyMMddHHmmss").Substring(2, 6);
this.SearchINVCodeInfo();
this.StorageCodeInfo();
}
this.txtNO.Focus();
}
#region 判断是否为空
private void cBINVCode_SelectedIndexChanged(object sender, EventArgs e)
{
if (txtSubInvCode.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("物料号不能为空");
return;
}
this.SearchINVCodeInfo(this.txtSubInvCode.Text.Trim());
}
#endregion
#region 存货编码
private void cBINVCode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string sql = @"select DISTINCT INVCode from ICSINVENTORY where 1=1 and INVCode like '%" + this.txtSubInvCode.Text + "%' order by INVCode";
sql = string.Format(sql);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt.Rows.Count > 1)
{
this.txtSubInvCode.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
this.txtSubInvCode.Items.Add(dr["INVCode"].ToString());
}
}
else if (dt.Rows.Count == 1)
{
this.txtSubInvCode.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
this.txtSubInvCode.Items.Add(dr["INVCode"].ToString());
this.txtSubInvCode.Text = dr["INVCode"].ToString();
}
cBINVCode_SelectedIndexChanged(sender, e);
}
}
}
#endregion
#region 判断是否为空
private void ICSStorageCode_SelectedIndexChanged(object sender, EventArgs e)
{
if (txtStorageCode.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("仓库编码不能为空");
return;
}
}
#endregion
//#region 仓库
//private void ICSStorageCode_KeyDown(object sender, KeyEventArgs e)
//{
// if (e.KeyCode == Keys.Enter)
// {
// string sql = @"SELECT StorageCode FROM ICSStorage where 1=1";
// sql = string.Format(sql);
// DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
// if (dt.Rows.Count > 1)
// {
// this.txtStorageCode.Items.Clear();
// foreach (DataRow dr in dt.Rows)
// {
// this.txtStorageCode.Items.Add(dr["StorageCode"].ToString());
// }
// }
// else if (dt.Rows.Count == 1)
// {
// this.txtStorageCode.Items.Clear();
// foreach (DataRow dr in dt.Rows)
// {
// this.txtStorageCode.Items.Add(dr["WHCode"].ToString());
// this.txtStorageCode.Text = dr["WHCode"].ToString();
// }
// cBINVCode_SelectedIndexChanged(sender, e);
// }
// }
//}
//#endregion
#region 单号
private void txtNO_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Decimal qty = new Decimal();
if (txtNO.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("数字不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtNO.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数字");
this.txtNO.Text = "";
return;
}
if (this.txtNO.Text.Length == 2)
{
TransNo = txtTransferNO.Text.Trim() + txtNO.Text.Trim();
string sql = @"SELECT MAX(A.VouchRow) AS LINE FROM ICSMaterialPick A WHERE A.VouchCode = '{0}'";
sql = string.Format(sql, TransNo);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt.Rows.Count <= 0)
{
this.txtVouchRow.Text = "001";
this.txtSubInvCode.Focus();
this.txtSubInvCode.SelectAll();
}
else
{
string Line = "";
foreach (DataRow dr in dt.Rows)
{
Line = dr["LINE"].ToString();
}
if (Line == "" || Line == null)
{
this.txtVouchRow.Text = "001";
this.txtSubInvCode.Focus();
this.txtSubInvCode.SelectAll();
}
else
{
this.txtVouchRow.Text = (Convert.ToInt32(Line) + 1).ToString().PadLeft(3, '0');
this.txtSubInvCode.Focus();
this.txtSubInvCode.SelectAll();
}
}
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的位数,为2位");
this.txtNO.Text = "";
return;
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtNO.Text = "";
return;
}
}
}
}
#endregion
#region 行号
private void txtTransLine_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Decimal qty = new Decimal();
if (txtVouchRow.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("行号不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtVouchRow.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的行号");
this.txtVouchRow.Text = "";
return;
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtVouchRow.Text = "";
return;
}
}
}
}
#endregion
}
}