using Rs.Controls; using Rs.DataAccess; using Rs.Framework; using Rs.MotionPlat.AuxiliaryEquipment; using Rs.MotionPlat.Commom; using Rs.MotionPlat.Flow; using Rs.MotionPlat.Flow.SubFlow; 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; namespace Rs.MotionPlat.Recipe { public partial class TurnoverTrayCheckHeight : BaseForm { SqliteHelper db = new SqliteHelper(); DataTable dt = new DataTable(); TraySlot selectedSlot; public TurnoverTrayCheckHeight() { InitializeComponent(); } private void btnCreateMatrix_Click(object sender, EventArgs e) { string deleteSql = $"delete from traypoints where recipename='{GlobalVar.CurRecipe}' and trayname='{dt.Rows[0]["trayname"]}'"; db.ExecuteNonQuery(deleteSql); int rowNum = 4; int colNum = 8; int index = 1; for (int i = 0; i < rowNum; i++) { for (int j = 0; j < colNum; j++) { double xRun = double.Parse(dt.Rows[0]["MarkX1"].ToString()) + (j * double.Parse(dt.Rows[0]["SlotOffsetDistX"].ToString())); double yRun = double.Parse(dt.Rows[0]["MarkY1"].ToString()) + (i * double.Parse(dt.Rows[0]["SlotOffsetDistY"].ToString())); string insertRunSql = $"insert into TrayPoints(trayid,recipename,trayname,slotindex,x,y) values({dt.Rows[0]["id"]},'{GlobalVar.CurRecipe}', '{dt.Rows[0]["TrayName"]}',{index},{xRun},{yRun})"; db.ExecuteNonQuery(insertRunSql); index++; } } BindPoints(); } private void BindPoints() { string querySql = $"select * from normaltray where recipename='{GlobalVar.CurRecipe}' and trayname='CheckHeightTurnover'"; dt = db.GetDataTable(querySql); if (ObjectHelper.IsNotNullorEmpty(dt)) { txtMarkX1.Text = dt.Rows[0]["MarkX1"].ToString(); txtMarkY1.Text = dt.Rows[0]["MarkY1"].ToString(); } querySql = $"select * from TrayPoints where trayname='{dt.Rows[0]["TrayName"]}'"; DataTable dtRunPoints = db.GetDataTable(querySql); if (ObjectHelper.IsNotNullorEmpty(dtRunPoints)) { dgvRunPoints.DataSource = dtRunPoints; } } private void TurnoverTrayCheckHeight_Load(object sender, EventArgs e) { PositionHelper.BindPosition(groupBox4); dgvRunPoints.AutoGenerateColumns = false; BindPoints(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { } private void Teach_Click(object sender, EventArgs e) { Button btnTeach = (Button)sender; string name = btnTeach.Name.Replace("btnTeach", ""); Control txt = ControlManager.FindControl(groupBox1, "txt" + name); if (txt != null) { double pos = Ops.GetCurPosition(txt.Tag.ToString()); txt.Text = pos.ToString("0.000"); if (ObjectHelper.IsNotNullorEmpty(dt)) { string updateSql = $"update NormalTray set {txt.Name.Replace("txt", "")}={pos} where recipename='{GlobalVar.CurRecipe}' and trayname='{dt.Rows[0]["trayname"]}'"; if (db.ExecuteNonQuery(updateSql) > 0) { BindPoints(); Msg.ShowInfo("teach point ok!"); } } } } private void rsTray1_SlotClickEvent(Controls.TraySlot arg1, MouseEventArgs arg2) { selectedSlot = arg1; contextMenuStrip1.Show(MousePosition.X, MousePosition.Y); } private void moveToolStripMenuItem_Click(object sender, EventArgs e) { if (selectedSlot != null) { string querySql = $"select * from TrayPoints where trayid={dt.Rows[0]["id"]} and slotindex={selectedSlot.Index}"; DataTable dtGoPosition = db.GetDataTable(querySql); if (ObjectHelper.IsNotNullorEmpty(dtGoPosition)) { double targetX = double.Parse(dtGoPosition.Rows[0]["X"].ToString()); double targetY = double.Parse(dtGoPosition.Rows[0]["Y"].ToString()); DialogResult dr = Msg.ShowQuestion($"Are you sure to move turnoverx to {targetX},turnovery to {targetY}?"); if (dr == DialogResult.OK) { Motion.ErrorCode errCode = AxisControl.GetAxis("TurnoverX").MovePos(targetX, 4); if (errCode > Motion.ErrorCode.Ok) { Msg.ShowError($"axis TurnoverX move fail,ret={errCode}"); return; } errCode = AxisControl.GetAxis("TurnoverY").MovePos(targetY, 4); if (errCode > Motion.ErrorCode.Ok) { Msg.ShowError($"axis TurnoverY move fail,ret={errCode}"); return; } } } } } private void txtTurnoverCheckBaseHeight_KeyUp(object sender, KeyEventArgs e) { UpdateSysParam(txtTurnoverTrayOffsetHeight); } private void button6_Click(object sender, EventArgs e) { double val = DeviceFactory.checkHeightDev.Read(); if (val != AlarmConstID.NG) { lblTestValue.Text = DeviceFactory.checkHeightDev.Read().ToString("0.000"); //lblSubValue.Text = (double.Parse(lblTestValue.Text) - double.Parse(txtTurnoverTrayOffsetHeight.Text)).ToString("0.000"); } else { Msg.ShowError("测高失败"); } } private void txtTurnoverTrayTestHeightOffsetX_KeyUp(object sender, KeyEventArgs e) { UpdateSysParam(txtTurnoverTrayTestHeightOffsetX); } private void testHeightToolStripMenuItem_Click(object sender, EventArgs e) { if (selectedSlot != null) { TestHeightResult thr = LaserFlow.Instance.HasProduct(ETrayType.Turnover, selectedSlot.Index); if (thr != null && thr.HasProduct) { Msg.ShowInfo("has product"); } else { Msg.ShowInfo("hasn't product"); } } } } }