You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
319 lines
12 KiB
C#
319 lines
12 KiB
C#
using Rs.Controls;
|
|
using Rs.DataAccess;
|
|
using Rs.Framework;
|
|
using Rs.MotionPlat.Commom;
|
|
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.SysConfig
|
|
{
|
|
public partial class BinFrm : BaseForm
|
|
{
|
|
SqliteHelper db = new SqliteHelper();
|
|
public BinFrm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
string trayName = string.Empty;
|
|
if(rbtnOk.Checked)
|
|
{
|
|
trayName = ETrayType.Ok.ToString();
|
|
}
|
|
else if(rbtnNg.Checked)
|
|
{
|
|
trayName= ETrayType.Ng.ToString();
|
|
}
|
|
string lotName=cboxLotName.Text;
|
|
if(string.IsNullOrEmpty(lotName))
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, "please select lotname");
|
|
}
|
|
else
|
|
{
|
|
string binName = txtBinName.Text;
|
|
if (string.IsNullOrEmpty(binName))
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, "please input binName");
|
|
}
|
|
else
|
|
{
|
|
string selectSql = $"select * from bininfo where trayname='{trayName}' and lotname='{lotName}' and binname='{binName}'";
|
|
DataTable dt = db.GetDataTable(selectSql);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, "input binname existing,please input different binname");
|
|
}
|
|
else
|
|
{
|
|
List<int> usedSlots = new List<int>();
|
|
//查询所有的已经被占用的穴位
|
|
string querySql = $"select * from bininfo where trayname='{trayName}' and lotname='{lotName}'";
|
|
dt = db.GetDataTable(querySql);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
foreach (string s in row["bininfo"].ToString().Split(','))
|
|
{
|
|
usedSlots.Add(int.Parse(s));
|
|
}
|
|
}
|
|
}
|
|
List<TraySlot> slots = rsTray1.GetDrawSlots();
|
|
if (slots != null && slots.Count > 0)
|
|
{
|
|
List<int> drawSlots = new List<int>();
|
|
string binInfo = string.Join(",", slots.Select(s => s.Index).ToList());
|
|
foreach (string s in binInfo.Split(','))
|
|
{
|
|
drawSlots.Add(int.Parse(s));
|
|
}
|
|
IEnumerable<int> comSlots = drawSlots.Intersect<int>(usedSlots.ToArray());
|
|
if (comSlots != null && comSlots.Count() > 0)
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, $"Intersection with the divided area:{string.Join(",", comSlots)}");
|
|
rsTray1.Refresh();
|
|
bind();
|
|
}
|
|
else
|
|
{
|
|
string insertSql = $"insert into bininfo(trayname,lotname,binname,bininfo) values('{trayName}','{lotName}','{binName}','{binInfo}')";
|
|
db.ExecuteNonQuery(insertSql);
|
|
rsTray1.Refresh();
|
|
bind();
|
|
BinManager.Load();
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, $"please draw area to place {binName}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void bind()
|
|
{
|
|
rsTray1.ChangeStatus(ESlotStatus.NotHave);
|
|
string trayName = string.Empty;
|
|
if (rbtnOk.Checked)
|
|
{
|
|
trayName = ETrayType.Ok.ToString();
|
|
}
|
|
else if (rbtnNg.Checked)
|
|
{
|
|
trayName = ETrayType.Ng.ToString();
|
|
}
|
|
string lotName = cboxLotName.Text;
|
|
string querySql = $"select * from bininfo where trayname='{trayName}' and lotname='{lotName}'";
|
|
DataTable dt= db.GetDataTable(querySql);
|
|
dataGridView1.DataSource = dt;
|
|
if(dt!=null && dt.Rows.Count>0)
|
|
{
|
|
for(int row=0; row<dt.Rows.Count;row++)
|
|
{
|
|
string slots = dataGridView1.Rows[row].Cells["Slots"].Value.ToString();
|
|
foreach (var item in slots.Split(','))
|
|
{
|
|
rsTray1.ChangeStatus(int.Parse(item), ESlotStatus.Disable);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void BinFrm_Load(object sender, EventArgs e)
|
|
{
|
|
dataGridView1.AutoGenerateColumns = false;
|
|
dataGridView2.AutoGenerateColumns = false;
|
|
bindLotName();
|
|
BindBin();
|
|
}
|
|
|
|
void bindLotName()
|
|
{
|
|
cboxLotName.Items.Clear();
|
|
//cboxLotName.Text = string.Empty;
|
|
//cboxLotName.Items.Clear();
|
|
//string trayName = string.Empty;
|
|
//if (rbtnOk.Checked)
|
|
//{
|
|
// trayName = ETrayType.Ok.ToString();
|
|
//}
|
|
//else if (rbtnNg.Checked)
|
|
//{
|
|
// trayName = ETrayType.Ng.ToString();
|
|
//}
|
|
//string querySql = $"select distinct lotname from bininfo where trayname='{trayName}'";
|
|
string querySql = $"select distinct lotname from bininfo";
|
|
DataTable dt= db.GetDataTable(querySql);
|
|
dataGridView2.DataSource = dt;
|
|
foreach (DataRow dataRow in dt.Rows)
|
|
{
|
|
cboxLotName.Items.Add(dataRow["lotname"].ToString());
|
|
}
|
|
dataGridView1.DataSource = null;
|
|
}
|
|
|
|
private void cboxLotName_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
bind();
|
|
}
|
|
|
|
|
|
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
rsTray1.ChangeStatus(ESlotStatus.NotHave);
|
|
for (int row=0;row<dataGridView1.Rows.Count;row++)
|
|
{
|
|
if (row == e.RowIndex)
|
|
{
|
|
string slots = dataGridView1.Rows[row].Cells["Slots"].Value.ToString();
|
|
foreach (var item in slots.Split(','))
|
|
{
|
|
rsTray1.ChangeStatus(int.Parse(item), ESlotStatus.Have);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string slots = dataGridView1.Rows[row].Cells["Slots"].Value.ToString();
|
|
foreach (var item in slots.Split(','))
|
|
{
|
|
rsTray1.ChangeStatus(int.Parse(item), ESlotStatus.Disable);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
|
|
{
|
|
if(e.RowIndex>=0 && e.Button== MouseButtons.Right)
|
|
{
|
|
dataGridView1.Rows[e.RowIndex].Selected = true;
|
|
contextMenuStrip1.Show(MousePosition.X,MousePosition.Y);
|
|
}
|
|
}
|
|
|
|
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DataGridViewSelectedRowCollection selectedRows = dataGridView1.SelectedRows;
|
|
if(selectedRows!=null&& selectedRows.Count>0)
|
|
{
|
|
if(int.TryParse(selectedRows[0].Cells["ID"].Value.ToString(), out int id))
|
|
{
|
|
EButtonType btn = Msgbox.ShowTipDialog(EButtonType.Ok | EButtonType.Cancel, "Are you sure to delete?","tip");
|
|
if(btn== EButtonType.Ok)
|
|
{
|
|
string deleteSql = $"delete from bininfo where id={id}";
|
|
if(db.ExecuteNonQuery(deleteSql)>0)
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, "delete ok","tip");
|
|
bind();
|
|
BinManager.Load();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void rbtnOk_Click(object sender, EventArgs e)
|
|
{
|
|
bind();
|
|
}
|
|
|
|
private void rbtnNg_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
bind();
|
|
}
|
|
|
|
private void dataGridView2_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
|
|
{
|
|
if (e.RowIndex >= 0 && e.Button == MouseButtons.Right)
|
|
{
|
|
dataGridView2.Rows[e.RowIndex].Selected = true;
|
|
contextMenuStrip2.Show(MousePosition.X, MousePosition.Y);
|
|
}
|
|
}
|
|
|
|
private void deleteToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
DataGridViewSelectedRowCollection selectedRows = dataGridView2.SelectedRows;
|
|
if (selectedRows != null && selectedRows.Count > 0)
|
|
{
|
|
string lotname = selectedRows[0].Cells[0].Value.ToString();
|
|
EButtonType btn = Msgbox.ShowTipDialog(EButtonType.Ok | EButtonType.Cancel, $"Are you sure to delete {lotname}?", "tip");
|
|
if (btn == EButtonType.Ok)
|
|
{
|
|
string deleteSql = $"delete from bininfo where lotname='{lotname}'";
|
|
if (db.ExecuteNonQuery(deleteSql) > 0)
|
|
{
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, "delete ok", "tip");
|
|
bindLotName();
|
|
bind();
|
|
BinManager.Load();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void setCurrentToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DataGridViewSelectedRowCollection selectedRows = dataGridView2.SelectedRows;
|
|
if (selectedRows != null && selectedRows.Count > 0)
|
|
{
|
|
string lotname = selectedRows[0].Cells[0].Value.ToString();
|
|
EButtonType btn = Msgbox.ShowTipDialog(EButtonType.Ok | EButtonType.Cancel, $"Are you sure to set {lotname} to current run bin ?", "tip");
|
|
if (btn == EButtonType.Ok)
|
|
{
|
|
SysConfigParam.Update("CurrentUsedBin", lotname);
|
|
SysConfigParam.Init();
|
|
BindBin();
|
|
}
|
|
}
|
|
}
|
|
|
|
void BindBin()
|
|
{
|
|
cboxEnableBin.Checked = GlobalVar.EnableBin;
|
|
cboxEnableFullAlarm.Checked=GlobalVar.EnableFullAlarm;
|
|
if (!string.IsNullOrEmpty(GlobalVar.CurrentUsedBin))
|
|
{
|
|
lblCurrentUsedBin.Text = GlobalVar.CurrentUsedBin;
|
|
}
|
|
txtBinToGrr.Text = GlobalVar.BinToGrr;
|
|
}
|
|
|
|
private void txtBinToGrr_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
SysConfigParam.Update("BinToGrr", txtBinToGrr.Text);
|
|
SysConfigParam.Init();
|
|
}
|
|
|
|
private void cboxEnableBin_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SysConfigParam.Update("EnableBin", cboxEnableBin.Checked.ToString());
|
|
SysConfigParam.Init();
|
|
}
|
|
|
|
private void cboxEnableFullAlarm_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SysConfigParam.Update("EnableFullAlarm", cboxEnableFullAlarm.Checked.ToString());
|
|
SysConfigParam.Init();
|
|
}
|
|
}
|
|
}
|