File name
Commit message
Commit date
File name
Commit message
Commit date
using ClientLib;
using ClientLib.CommonService2;
using DevExpress.XtraEditors;
using PublicLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
namespace KHSCALE_TP
{
public partial class UcWork : UserControl
{
[DllImport("user32.dll")]
static extern uint keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
string BarData = "";
U3Database u3Database = new U3Database();
U3Config u3Config = new U3Config();
private string m_ORDER_CD = "";
private string m_ORDER_G_CD = "";
public UcWork()
{
InitializeComponent();
u3Database.SetSqlServer();
//DataView grpMach = new DataView(GetMachTable());
//UtilClass.SetLookup(this.lookUpEdit_Mach, grpMach, "MACH_CD", "MACH_NM", true, true);
dateEdit_ORDER_DT.DateTime = DateTime.Now;
//searchProc();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
OnInitButtonClicked();
}
public string ReceivedData = "";
public string orderno = "";
public string lot = "";
public void searchProc()
{
try
{
this.Cursor = Cursors.WaitCursor;
gridControl_Main.DataSource = null;
string sDate = this.dateEdit_ORDER_DT.DateTime.ToString("yyyy-MM-dd");
DataTable resultData = null;
gridControl_Main.DataSource = resultData;
this.Cursor = Cursors.Arrow;
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
MessageBox.Show(ex.Message);
}
}
public void barcode_search(string BarData)
{
try
{
string[] arValues = barcode.Text.Trim().Split(' ');
//if (arValues.Length != 4 && arValues[0] != "P")
// throw new Exception("정상적인 바코드가 아닙니다");
if (arValues.Length == 2) //작업지시바코드일경우
{
DataTable dt = null;
dt = u3Database.OpenSQL("select * from T_KH_SAL_WORK_D a where a.ORDER_NO = '" + arValues[0].ToString().Substring(1) + "' and a.PLOT_NO = '" + arValues[1].ToString() + "'");
// 기존에 저장된 데이터가 있는지 확인하여 있으면 기존에 저장된 데이터를 불러옴(자재만)
if (dt.Rows.Count == 0)
{
gridControl_P.DataSource = null;
gridControl_B.DataSource = null;
gridControl_Main.DataSource = null;
OnInitButtonClicked();
txt_workno.Text = arValues[0].Substring(1);
txt_lotno.Text = arValues[1];
DataTable dt1 = null;
//dt1 = u3Database.OpenSQL("select a.resource_no, a.resource_name, a.order_qty, a.demand_status_desc from T_KH_SAL_ORDER a where a.order_no = '" + arValues[0].ToString().Substring(1) + "' and a.lot = '" + arValues[1].ToString() + "'");
dt1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m101 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
txt_partno.Text = dt1.Rows[0]["resource_no"].ToString();
txt_partnm.Text = dt1.Rows[0]["resource_name"].ToString();
txt_qty.Text = dt1.Rows[0]["order_qty"].ToString();
txt_state.Text = dt1.Rows[0]["demand_status_desc"].ToString();
DataTable resultComp1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m103 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
gridControl_P.DataSource = resultComp1;
DataTable resultComp2 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m102 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
gridControl_B.DataSource = resultComp2;
DataTable resultComp3 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m104 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
gridControl_Main.DataSource = resultComp3;
barcode.SelectAll();
}
else if (dt.Rows.Count != 0)
{
gridControl_P.DataSource = null;
gridControl_B.DataSource = null;
gridControl_Main.DataSource = null;
OnInitButtonClicked();
txt_workno.Text = arValues[0].Substring(1);
txt_lotno.Text = arValues[1];
DataTable dt1 = null;
dt1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m101 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
txt_partno.Text = dt1.Rows[0]["resource_no"].ToString();
txt_partnm.Text = dt1.Rows[0]["resource_name"].ToString();
txt_qty.Text = dt1.Rows[0]["order_qty"].ToString();
txt_state.Text = dt1.Rows[0]["demand_status_desc"].ToString();
DataTable resultComp1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m103 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
gridControl_P.DataSource = resultComp1;
DataTable resultComp2 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m102 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
gridControl_B.DataSource = resultComp2;
DataTable resultComp3 = u3Database.OpenSQL("EXEC KHJPARTINDATA1 '" + txt_workno.Text + "', '" + txt_lotno.Text + "'");
gridControl_Main.DataSource = resultComp3;
DataTable resultComp4 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m105 '" + arValues[0].ToString().Substring(1) + "', '" + arValues[1].ToString() + "'");
gridControl_note.DataSource = resultComp4;
barcode.SelectAll();
}
}
}
catch (Exception ex)
{
this.ActiveControl = barcode;
barcode.SelectAll();
XtraMessageBox.Show(ex.Message);
}
}
public void barcode_search2(string order_no, string lot)
{
try
{
DataTable dt = null;
dt = u3Database.OpenSQL("select * from T_KH_SAL_WORK_D a where a.ORDER_NO = '" + order_no + "' and a.PLOT_NO = '" + lot + "'");
if (dt.Rows.Count == 0)
{
string a = order_no.Replace(" ", string.Empty);
string b = lot.Replace(" ", string.Empty);
//barcode.Text = a + " " + b;
txt_workno.Text = a;
txt_lotno.Text = b;
DataTable dt1 = null;
dt1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m101 '" + a + "', '" + b + "'");
txt_partno.Text = dt1.Rows[0]["resource_no"].ToString();
txt_partnm.Text = dt1.Rows[0]["resource_name"].ToString();
txt_qty.Text = dt1.Rows[0]["order_qty"].ToString();
txt_state.Text = dt1.Rows[0]["demand_status_desc"].ToString();
DataTable resultComp1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m103 '" + a + "', '" + b + "'");
gridControl_P.DataSource = resultComp1;
DataTable resultComp2 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m102 '" + a + "', '" + b + "'");
gridControl_B.DataSource = resultComp2;
DataTable resultComp3 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m104 '" + a + "', '" + b + "'");
gridControl_Main.DataSource = resultComp3;
DataTable resultComp4 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m105 '" + a + "', '" + b + "'");
gridControl_note.DataSource = resultComp4;
}
else if (dt.Rows.Count != 0)
{
string a = order_no.Replace(" ", string.Empty);
string b = lot.Replace(" ", string.Empty);
//barcode.Text = a + " " + b;
txt_workno.Text = a;
txt_lotno.Text = b;
DataTable dt1 = null;
dt1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m101 '" + a + "', '" + b + "'");
txt_partno.Text = dt1.Rows[0]["resource_no"].ToString();
txt_partnm.Text = dt1.Rows[0]["resource_name"].ToString();
txt_qty.Text = dt1.Rows[0]["order_qty"].ToString();
txt_state.Text = dt1.Rows[0]["demand_status_desc"].ToString();
DataTable resultComp1 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m103 '" + a + "', '" + b + "'");
gridControl_P.DataSource = resultComp1;
DataTable resultComp2 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m102 '" + a + "', '" + b + "'");
gridControl_B.DataSource = resultComp2;
//DataTable resultComp3 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m104 '" + a + "', '" + b + "'");
DataTable resultComp3 = u3Database.OpenSQL("select a.process_key, a.note, a.resource_used, a.[description], b.QTY as in_qty, a.uom2 as uom, a.qty_total from T_KH_SAL_ORDER a left join T_KH_SAL_WORK_D b on a.order_no = b.ORDER_NO and a.lot = b.PLOT_NO and a.resource_used = b.JPART_NO where a.order_no = '" + order_no + "' and a.lot = '" + lot + "'");
gridControl_Main.DataSource = resultComp3;
DataTable resultComp4 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m105 '" + a + "', '" + b + "'");
gridControl_note.DataSource = resultComp4;
}
}
catch (Exception ex)
{
this.ActiveControl = barcode;
barcode.SelectAll();
XtraMessageBox.Show(ex.Message);
}
}
private DataTable GetMachTable()
{
try
{
this.Cursor = Cursors.WaitCursor;
return u3Database.OpenSQL("select 'N' as SEL_FIELD, a.MACH_CD, a.MACH_NO, a.MACH_NM from dbo.T_STD_MACH a where a.COMP_CD = '" + ConstClass._COMP_CD + "' and isnull(a.DEL_YN,'N') = 'N' order by a.MACH_CD");
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
XtraMessageBox.Show(ex.Message);
}
return null;
}
private void simpleButton_Pre_Click(object sender, EventArgs e)
{
try
{
dateEdit_ORDER_DT.DateTime = dateEdit_ORDER_DT.DateTime.AddDays(-1);
//searchProc();
}
catch (Exception ex)
{
}
}
private void simpleButton_Next_Click(object sender, EventArgs e)
{
try
{
dateEdit_ORDER_DT.DateTime = dateEdit_ORDER_DT.DateTime.AddDays(1);
//searchProc();
}
catch (Exception ex)
{
}
}
private void lookUpEdit_Mach_EditValueChanged(object sender, EventArgs e)
{
searchProc();
}
private void simpleButton_ReFresh_Click(object sender, EventArgs e)
{
OnInitButtonClicked();
}
private void OnInitButtonClicked()
{
txt_workno.Text = "";
txt_lotno.Text = "";
txt_partno.Text = "";
txt_partnm.Text = "";
txt_qty.Text = "";
txt_state.Text = "";
gridControl_P.DataSource = null;
gridControl_B.DataSource = null;
gridControl_Main.DataSource = null;
}
private void simpleButton_Search_Click(object sender, EventArgs e)
{
UcOrderList ol = new UcOrderList();
if (ol.ShowDialog() != DialogResult.Yes)
{
return;
}
this.barcode_search2(ol.orderno, ol.lot);
//txt_workno.Text = ol.orderno;
//txt_lotno.Text = ol.lot;
}
private void simpleButton_Work_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
string sDate = this.dateEdit_ORDER_DT.DateTime.ToString("yyyy-MM-dd");
DataTable dt1 = null;
dt1 = u3Database.OpenSQL("select SUM(a.QTY) as QTY from T_KH_SAL_WORK_D a where a.ORDER_NO = '" + txt_workno.Text + "' and a.PLOT_NO = '" + txt_lotno.Text + "'");
try
{
u3Database.ExcuteSql("INSERT INTO T_KH_SAL_WORK_M (COMP_CD, ORDER_NO, LOT_NO, PART_NO, RECORD_DT, TRUE_QTY, RED_ID, REG_DT, UP_ID, UP_DT) VALUES (" +
" '" + ConstClass._COMP_CD + "'" +
" ,'" + txt_workno.Text + "'" +
" ,'" + txt_lotno.Text + "'" +
" ,'" + txt_partno.Text + "'" +
" ,'" + sDate + "'" +
" ,'" + dt1.Rows[0]["QTY"].ToString() + "'" +
" ,'" + ConstClass._USR_ID + "'" +
" ,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'" +
" ,'" + ConstClass._USR_ID + "'" +
" ,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'" +
")");
XtraMessageBox.Show("생산실적을 저장하였습니다.");
OnInitButtonClicked();
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
XtraMessageBox.Show(ex.Message);
}
this.Cursor = Cursors.Arrow;
}
private void barcode_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
barcode_search(BarData);
}
else
{
}
}
private void gridControl_Main_DoubleClick(object sender, EventArgs e)
{
DataRow row = gridView_Main.GetFocusedDataRow();
if (row == null)
{
return;
}
UcInsertWork iw = new UcInsertWork();
iw.SetData(txt_workno.Text, txt_lotno.Text, txt_partno.Text);
if (iw.ShowDialog() == DialogResult.Yes)
{
searchProc();
}
}
}
}