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

534 lines
22 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 FormICSChuKuAdd : DevExpress.XtraEditors.XtraForm
{
private int flag = 0;
private string Qty = "";
private string TransNo = "";
#region 构造函数
public FormICSChuKuAdd()
{
InitializeComponent();
txtmuser.Text = AppConfig.UserName;
flag = 0;
}
public FormICSChuKuAdd(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 ICSTransferNO 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 ICSTransferNO 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 ICSTransferNO 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);
}
}
}
public FormICSChuKuAdd(string TransferNO, string TransLine, string INVCode, string INVName)
{
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 ICSTransferNO where TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
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);
}
}
public FormICSChuKuAdd(string TransferNO, string TransLine, string INVCode, string INVName, string qty, string muser)
{
InitializeComponent();
this.cBINVCode.Enabled = false;
this.txtTransferNO.Enabled = false;
this.txtNO.Enabled = false;
this.txtTransLine.Enabled = false;
this.txtTransferNO.Text = TransferNO.Substring(0, 8);
this.txtNO.Text = TransferNO.Substring(TransferNO.Length - (TransferNO.Length - 8), TransferNO.Length - 8);
this.txtTransLine.Text = TransLine;
this.cBINVCode.Text = INVCode;
this.txtINVName.Text = INVName;
this.txtmuser.Text = muser;
Qty = qty;
flag = 1;
}
#endregion
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.txtQty.Enabled = true;
this.txtQty.Focus();
}
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("未查询到物料号对应的存货名称");
return;
}
}
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.cBINVCode.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 (txtQty.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("数量不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtQty.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数量");
this.txtQty.Text = "";
return;
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtQty.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 ICSTransferNO (TransferNO, TransLine, INVCode, INVName, QTY, MTIME, MUSER, MUSERName, Status)
values (@TransferNO, @TransLine, @INVCode, @INVName, @QTY, @MTIME, @MUSER, @MUSERName, '开立')";
com.CommandText = sql;
com.Parameters.Clear();
com.Parameters.AddWithValue("@TransferNO", TransNo);
com.Parameters.AddWithValue("@TransLine", txtTransLine.Text.Trim());
com.Parameters.AddWithValue("@INVCode", cBINVCode.Text.Trim());
com.Parameters.AddWithValue("@INVName", txtINVName.Text.Trim());
com.Parameters.AddWithValue("@QTY", qty);
com.Parameters.AddWithValue("@Mtime", DateTime.Now.ToString());
com.Parameters.AddWithValue("@Muser", AppConfig.UserName);
com.Parameters.AddWithValue("@MUSERName", AppConfig.UserName);
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 判断是否为空
if (txtQty.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("数量不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtQty.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数量");
this.txtQty.Text = "";
return;
}
else
{
if (qty == Decimal.Parse(Qty))
{
ICSBaseSimpleCode.AppshowMessageBox("输入数量与原先相同,请确认");
this.txtQty.Text = "";
return;
}
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtQty.Text = "";
return;
}
}
#endregion
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在修改请稍等...");
try
{
string sql = @"update ICSTransferNO set QTY = {0} where 1=1 and TransferNO = '" + TransNo + "' and TransLine = '" + this.txtTransLine.Text + "' and INVCode = '" + this.cBINVCode.Text + "' and INVName = '" + this.txtINVName.Text + "'";
sql = string.Format(sql, qty);
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.txtNO.Focus();
}
private void cBINVCode_SelectedIndexChanged(object sender, EventArgs e)
{
#region 判断是否为空
if (cBINVCode.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("物料号不能为空");
return;
}
#endregion
this.SearchINVCodeInfo(this.cBINVCode.Text.Trim());
}
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.cBINVCode.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.cBINVCode.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
this.cBINVCode.Items.Add(dr["INVCode"].ToString());
}
}
else if (dt.Rows.Count == 1)
{
this.cBINVCode.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
this.cBINVCode.Items.Add(dr["INVCode"].ToString());
this.cBINVCode.Text = dr["INVCode"].ToString();
}
cBINVCode_SelectedIndexChanged(sender, e);
}
}
}
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.TransLine) AS LINE FROM ICSTransferNO A WHERE A.TransferNO = '{0}'";
sql = string.Format(sql, TransNo);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt.Rows.Count <= 0)
{
this.txtTransLine.Text = "001";
this.cBINVCode.Focus();
this.cBINVCode.SelectAll();
}
else
{
string Line = "";
foreach (DataRow dr in dt.Rows)
{
Line = dr["LINE"].ToString();
}
if (Line == "" || Line == null)
{
this.txtTransLine.Text = "001";
this.cBINVCode.Focus();
this.cBINVCode.SelectAll();
}
else
{
this.txtTransLine.Text = (Convert.ToInt32(Line) + 1).ToString().PadLeft(2, '0');
this.cBINVCode.Focus();
this.cBINVCode.SelectAll();
}
}
#region
//this.txtTransLine.Enabled = true;
//this.txtTransLine.Focus();
//this.txtTransLine.SelectAll();
#endregion
}
else
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的位数,为2位");
this.txtNO.Text = "";
return;
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtNO.Text = "";
return;
}
}
}
}
private void txtTransLine_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Decimal qty = new Decimal();
if (txtTransLine.Text.Trim() == "")
{
ICSBaseSimpleCode.AppshowMessageBox("行号不能为空");
return;
}
else
{
try
{
qty = Decimal.Parse(this.txtTransLine.Text);
if (qty <= 0)
{
ICSBaseSimpleCode.AppshowMessageBox("请输入正确的行号");
this.txtTransLine.Text = "";
return;
}
}
catch
{
ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
this.txtTransLine.Text = "";
return;
}
}
}
}
}
}