using Cksoft.Unity; using DllEapEntity; using DllPubInfo; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace DllXqManager { public partial class MacStatusQuery : Form { private List CurrDs = null; public delegate void SelRow(List rows,int seltype); public event SelRow eventSelRow = null; private int CurrType = 1;//1为维护机台,2为选择机台 private int CurrSelType = 1;//选择模式,1为启动模式,2为标准模式 private string CurrCondition = ""; public MacStatusQuery() { InitializeComponent(); } public MacStatusQuery(string condition) { InitializeComponent(); CurrSelType = 1; CurrCondition = condition; SetForm(2); } private void SetForm(int ftype) { CurrType = ftype; if (ftype == 2) { button3.Visible = true; button4.Visible = false; } } private string GetCondition() { StringBuilder sqlstr = new StringBuilder(100); if(edit代码.Text.Trim()!="") { sqlstr.AppendFormat(" and a.fcode like '%{0}%'", edit代码.Text.Trim()); } if (edit名称.Text.Trim() != "") { sqlstr.AppendFormat(" and a.fname like '%{0}%'", edit名称.Text.Trim()); } sqlstr.AppendFormat(CurrCondition); return sqlstr.ToString(); } private void Filldgvmain(string condition) { try { Cursor = Cursors.WaitCursor; string errorinfo = ""; CurrDs = PubInfo.SelectForCondition(condition, ref errorinfo).ToList(); if (CurrDs == null) { MessageBox.Show(errorinfo); return; } Binddgvmain(); foreach (DataGridViewColumn dgvc in dgvmain.Columns) { dgvc.ReadOnly = true; } dgvmain.Columns["选择"].ReadOnly = false; if (CurrType == 1) { //dgvmain.Columns[nameof(OrderMst.MacFCode)].Visible = false; //dgvmain.Columns[nameof(OrderMst.MacFName)].Visible = false; //dgvmain.Columns["机台指令类别"].Visible = false; //dgvmain.Columns["机台指令类别ID"].Visible = false; } } catch (Exception ex) { MessageBox.Show("操作发生错误,错误信息为:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; } //dgvmain.Columns["选择"].ReadOnly = false; } private BindingSource currbs = null; private void Binddgvmain() { currbs = new BindingSource(); var cols = CurrDs.Where(t => t.EntityStatusID >= 0).ToList(); currbs.DataSource = cols; bindingNavigator2.BindingSource = currbs; dgvmain.DataSource = currbs; PubInfo.InitDataGridView(dgvmain); //dgvmain.Columns[nameof(BaseEntity.IsSelected)].Visible = false; //dgvColDetail.Rows[0].Visible = false; } private void button1_Click(object sender, EventArgs e) { Filldgvmain(GetCondition()); } private Form CurrForm = null; public void CloseCurrForm() { CurrForm =null; } private void ShowBase(MacStatus id) { if (CurrForm != null) { (CurrForm as MacStatusBase).SetCurrID(id); } else { CurrForm = new MacStatusBase(id); (CurrForm as MacStatusBase).eventaddrow += AddRow; (CurrForm as MacStatusBase).eventcloseform += CloseCurrForm; CurrForm.Owner = this; CurrForm.Show(); } //MacStatusBase temp = new MacStatusBase(id); //temp.ShowDialog(); } private void AddRow(MacStatus id) { //throw new NotImplementedException(); List templist = CurrDs.Where(t => t.ID == id.ID).ToList(); if(templist.Count>0) { EntityHelper.CopyPropertyValue(id, templist[0]); } else { CurrDs.Add(id); } Binddgvmain(); } private void ShowBaseFor(MacStatus id) { //if(CurrForm != null) //{ // (CurrForm as TLcdBase).SetCurrID(id); //} //else //{ // CurrForm = new TLcdBase(id); // (CurrForm as TLcdBase).eventaddrow += AddRow; // (CurrForm as TLcdBase).eventcloseform += CloseCurrForm; // CurrForm.Owner = this; // CurrForm.Show(); //} //MacStatusBaseFor temp = new MacStatusBaseFor(id); //temp.Show(); } private void button4_Click(object sender, EventArgs e) { ShowBase(null); } private void mmaquery_Load(object sender, EventArgs e) { Filldgvmain(GetCondition()); } private void dgvmain_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (dgvmain.CurrentRow == null) return; ShowBaseFor(dgvmain.CurrentRow.DataBoundItem as MacStatus); } private void dgvmain_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { dgvmain.CurrentCell = dgvmain.Rows[e.RowIndex].Cells[e.ColumnIndex]; System.Drawing.Point pointglobal = System.Windows.Forms.Control.MousePosition; cms.Show(pointglobal); } } } private void toolStripMenuItem3_Click(object sender, EventArgs e) { foreach(var temprow in CurrDs) { temprow.IsSelected = 1; } dgvmain.Refresh(); } private void toolStripMenuItem4_Click(object sender, EventArgs e) { foreach (var temprow in CurrDs) { temprow.IsSelected = 0; } dgvmain.Refresh(); } private void button2_Click(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { dgvmain.EndEdit(); edit代码.Focus(); List rows = CurrDs.Where(t => t.IsSelected == 1).ToList();//.Tables[0].Select("选择=1"); if(rows.Count<=0) { MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } eventSelRow?.Invoke(rows,CurrSelType); this.Close(); } private MacStatus DelMacStatus(List entitys) { try { Hashtable tempds = new Hashtable(); string str = JsonConvert.SerializeObject(entitys); tempds.Add(nameof(MacStatus), str); Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "DelMacStatus", tempds); if (reds == null) return null; MacStatus reentity = JsonConvert.DeserializeObject(reds[nameof(MacStatus)].ToString()); return reentity; } catch (Exception e) { MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } } private void toolStripMenuItem2_Click(object sender, EventArgs e) { List rows = CurrDs.Where(t => t.IsSelected == 1).ToList();//.Tables[CurrTableName].Select("选择=1"); if (rows.Count <= 0) { MessageBox.Show("您没有选择数据,请选择。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("您确定要执行此操作吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel) return; MacStatus result = DelMacStatus(rows); if (result != null) { MessageBox.Show("操作成功。"); foreach (var temprow in rows) CurrDs.Remove(temprow); Binddgvmain(); } } private void mcaquery_FormClosed(object sender, FormClosedEventArgs e) { } private void cms_Opening(object sender, CancelEventArgs e) { dgvmain.EndEdit(); edit代码.Focus(); } private void 编辑位置ToolStripMenuItem_Click(object sender, EventArgs e) { if (dgvmain.CurrentRow == null) return; MacStatus mst = dgvmain.CurrentRow.DataBoundItem as MacStatus; //MacStatusBase temp = new MacStatusBase(mst); //temp.Show(); } } }