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;
using System.Net;
namespace KHSCALE_TP
{
public partial class UcInsertWork : Form
{
[DllImport("user32.dll")]
static extern uint keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
string BarData = "";
public bool m_HIDE = false;
U3Database u3Database = new U3Database();
private string m_ORDER_NO = "";
private string m_ORDER_LOT = "";
private string m_ORDER_PART = "";
private bool m_FirstInput = true;
// 전자 저울 변수 선언
private SerialBase m_ser = null;
public UcInsertWork()
{
InitializeComponent();
DataView grpMach = new DataView(GetMachTable());
UtilClass.SetLookup(this.lookUpEdit_Mach, grpMach, "MACH_CD", "MACH_NM", true, true);
DataView grpcenter = new DataView(GetcenterTable());
UtilClass.SetLookup(this.lookUpEdit_center, grpcenter, "WORKCENTER", "CENTER_NAME", true, true);
string localIP = "Not available, please check your network seetings!";
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
localIP = ip.ToString();
txt_ip.Text = localIP;
}
SetScale();
}
public void Search()
{
try
{
DataTable dt = null;
dt = u3Database.OpenSQL("select * from T_KH_SAL_WORK_D a where a.ORDER_NO = '" + txt_orderno.Text + "' and a.PLOT_NO = '" + txt_lot.Text + "'");
// 기존에 저장된 데이터가 있는지 확인하여 있으면 기존에 저장된 데이터를 불러옴(자재만)
if (dt.Rows.Count == 0)
{
gridControl_Main.DataSource = null;
//OnInitButtonClicked();
DataTable resultComp3 = u3Database.OpenSQL("EXEC KHERP.KHC_MFG.dbo.usp_pop_khc_m104 '" + txt_orderno.Text + "', '" + txt_lot.Text + "'");
gridControl_Main.DataSource = resultComp3;
barcode.SelectAll();
}
else if (dt.Rows.Count != 0)
{
gridControl_Main.DataSource = null;
//OnInitButtonClicked();
//DataTable dt1 = null;
//쿼리 수정 필
//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 = '" + txt_orderno.Text + "' and a.lot = '" + txt_lot.Text + "'");
DataTable resultComp3 = u3Database.OpenSQL("EXEC KHJPARTINDATA '" + txt_orderno.Text + "', '" + txt_lot.Text + "'");
gridControl_Main.DataSource = resultComp3;
}
}
catch (Exception ex)
{
this.ActiveControl = barcode;
barcode.SelectAll();
XtraMessageBox.Show(ex.Message);
}
}
//전자저울 셋팅
private void SetScale()
{
//CAS 501/600
if (txt_ip.Text == "192.168.1.121" || txt_ip.Text == "192.168.1.124")
{
m_ser = new ComCasCi501();
m_ser.Init("COM1", 9600, 0, 8, 1);
}
//ICS9000
else if (txt_ip.Text == "192.168.1.125")
{
m_ser = new ComIcs9000();
m_ser.Init("COM1", 9600, 0, 8, 1);
}
//FS-1020C
else if (txt_ip.Text == "192.168.1.126" || txt_ip.Text == "192.168.1.127" || txt_ip.Text == "192.168.1.128" || txt_ip.Text == "192.168.1.122" || txt_ip.Text == "192.168.1.123")
{
m_ser = new ComFs1020c();
m_ser.Init("COM1", 9600, 0, 8, 1);
}
else if (txt_ip.Text == "192.168.1.129")
{
m_ser = new ComFs1020c();
// 구리스는 COM2 / 그 외는 COM1
m_ser.Init("COM2", 9600, 0, 8, 1);
}
}
private DataTable GetMachTable()
{
try
{
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' and a.MACH_TYPE = '04' and a.MACH_NM like '%' + 'PV' + '%' order by a.MACH_CD");
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
return null;
}
private DataTable GetcenterTable()
{
try
{
return u3Database.OpenSQL("select 'N' as SEL_FIELD, a.WORKCENTER, a.CENTER_NAME from dbo.T_STD_CENTER a where a.COMP_CD = '" + ConstClass._COMP_CD + "'");
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
return null;
}
public void SetData(string ORDER_NO, string ORDER_LOT, string PART_NO)
{
m_ORDER_NO = ORDER_NO;
m_ORDER_LOT = ORDER_LOT;
m_ORDER_PART = PART_NO;
txt_orderno.Text = m_ORDER_NO;
txt_lot.Text = m_ORDER_LOT;
txt_partno.Text = m_ORDER_PART;
Search();
}
private void UcInsertWork_Load(object sender, EventArgs e)
{
//timer1.Interval = 1000;
//timer1.Enabled = true;
// 저울의 현재 값 받기
//float value = m_ser.GetValue();
}
public void barcode_search(string BarData)
{
try
{
OnInitButtonClicked();
string[] arValues = barcode.Text.Trim().Split(' ');
string jp = arValues[0];
string l = arValues[1];
string jp1 = jp.Substring(1, 8);
txt_jpartno.Text = jp1;
txt_jlot.Text = l;
DataTable dt1 = u3Database.OpenSQL("select a.[description] from T_KH_SAL_ORDER a where a.order_no = '" + txt_orderno.Text + "' and a.lot = '" + txt_lot.Text + "' and a.resource_used = '" + jp1.ToString() + "'");
txt_jpartnm.Text = dt1.Rows[0]["description"].ToString();
barcode.SelectAll();
}
catch (Exception ex)
{
this.ActiveControl = barcode;
barcode.SelectAll();
XtraMessageBox.Show(ex.Message);
}
m_FirstInput = true;
}
private void OnInitButtonClicked()
{
//barcode.Text = "";
txt_jpartno.Text = "";
txt_jpartnm.Text = "";
txt_jlot.Text = "";
txt_qty.Text = "";
txt_tqty.Text = "";
}
private void Input()
{
try
{
this.Cursor = Cursors.WaitCursor;
txt_qty.Text = txt_qty.Text == "" ? "0" : txt_qty.Text;
int in_qty = Convert.ToInt32(txt_qty.Text);
u3Database.ExcuteSql("INSERT INTO T_KH_SAL_WORK_D (ORDER_NO, PPART_NO, PLOT_NO, JPART_NO, JLOT_NO, QTY, REG_ID, REG_DT, UP_ID, UP_DT) VALUES (" +
" '" + txt_orderno.Text + "'" +
" ,'" + txt_partno.Text + "'" +
" ,'" + txt_lot.Text + "'" +
" ,'" + txt_jpartno.Text + "'" +
" ,'" + txt_jlot.Text + "'" +
" ,'" + in_qty + "'" +
" ,'" + 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 Start()
{
}
private void simpleButton_CANCEL_Click(object sender, EventArgs e)
{
//m_ser.Close();
this.Close();
m_HIDE = true;
}
private void simpleButton_INPUT_Click(object sender, EventArgs e)
{
//작업지시에 대한 원자재 투입 실적 저장
Input();
}
private void barcode_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
barcode_search(BarData);
}
else
{
}
}
private void simpleButton_Backspace_Click(object sender, EventArgs e)
{
txt_qty.Text = txt_qty.Text.Substring(0, txt_qty.Text.Length - 1);
}
private void simpleButton_Number_Click(object sender, EventArgs e)
{
if (m_FirstInput)
{
txt_qty.Text = "";
m_FirstInput = false;
}
txt_qty.Text += ((SimpleButton)sender).Text;
}
private void simpleButton_X_Click(object sender, EventArgs e)
{
txt_qty.Text = "";
}
private void lookUpEdit_Mach_EditValueChanged(object sender, EventArgs e)
{
try
{
if (lookUpEdit_Mach.EditValue.ToString() != String.Empty || lookUpEdit_Mach.EditValue.ToString() != "")
{
this.Cursor = Cursors.WaitCursor;
//string sDate = this.dateEdit_ORDER_DT.DateTime.ToString("yyyy-MM-dd");
string sDate = DateTime.Now.ToString("yyyy-MM-dd");
string mc = lookUpEdit_Mach.EditValue.ToString();
DataTable resultData = null;
resultData = u3Database.OpenSQL("select ISNULL(a.REAL_DATA,'0') as REAL_DATA, b.REMARK01, b.REMARK02 from T_HT_REAL_DATA a inner join T_STD_MACH b on a.MACH_CD = b.MACH_CD where a.COMP_CD = '0001' and a.MACH_CD = '" + mc.ToString() + "' and SUBSTRING(CONVERT(varchar(20),a.REG_DT,23),0,11) = '" + sDate + "'");
//resultData = u3Database.OpenSQL("select ISNULL(a.REAL_DATA,'0') as REAL_DATA, b.REMARK01, b.REMARK02 from T_HT_REAL_DATA a inner join T_STD_MACH b on a.MACH_CD = b.MACH_CD where a.COMP_CD = '0001' and a.MACH_CD = '" + mc.ToString() + "'");
string pv = resultData.Rows[0]["REAL_DATA"].ToString();
double pvs = Convert.ToDouble(pv);
txt_qty.Text = pvs.ToString();
txt_jpartno.Text = resultData.Rows[0]["REMARK01"].ToString();
txt_jpartnm.Text = resultData.Rows[0]["REMARK02"].ToString();
txt_jlot.Text = sDate;
this.Cursor = Cursors.Arrow;
}
else
{
return;
}
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
MessageBox.Show(ex.Message);
}
}
private void gridView_Main_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView View = sender as DevExpress.XtraGrid.Views.Grid.GridView;
try
{
DataRow dr = View.GetDataRow(e.RowHandle);
if (Convert.ToDouble(dr["QTY"]) > 0)
{
e.Appearance.BackColor = System.Drawing.Color.DeepSkyBlue;
e.HighPriority = true;
}
}
catch
{
}
}
private void simpleButton1_s_Click(object sender, EventArgs e)
{
txt_s.Text = "";
txt_e.Text = "";
txt_ip.Text = "";
float value = m_ser.GetValue();
txt_s.Text = value.ToString();
if(txt_s.Text!="")
{
simpleButton1_s.LookAndFeel.SkinMaskColor = Color.Black;
simpleButton_Reset.Visible = true;
}
}
private void simpleButton1_e_Click(object sender, EventArgs e)
{
float value = m_ser.GetValue();
txt_e.Text = value.ToString();
string s = txt_s.Text;
string e1= txt_e.Text;
double ss = Convert.ToDouble(s);
double ee = Convert.ToDouble(e1);
txt_qty.Text = Convert.ToString(ss - ee);
}
private void simpleButton_Reset_Click(object sender, EventArgs e)
{
txt_s.Text = "";
txt_e.Text = "";
txt_ip.Text = "";
simpleButton1_s.LookAndFeel.SkinMaskColor = Color.Lime;
simpleButton_Reset.Visible = false;
}
}
}