123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
-
- 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;
- using DllEapEntity;
- using DllPubInfo;
- using Newtonsoft.Json;
- namespace DllXqManager
- {
- public partial class TLcdQuery : Form
- {
- private List<TLcd> CurrDs = null;
- public delegate void SelRow(List<TLcd> rows,int seltype);
- public event SelRow eventSelRow = null;
- private int CurrType = 1;//1为维护机台,2为选择机台
- private int CurrSelType = 1;//选择模式,1为启动模式,2为标准模式
- private string CurrCondition = "";
- public TLcdQuery()
- {
- InitializeComponent();
- }
- public TLcdQuery(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<TLcd>(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<TLcd>(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;
- }
- public void AddRow(TLcd id)
- {
- //查询是否存在,不存在则添加
- List<TLcd> rows = CurrDs.Where(t => t.ID == id.ID).ToList();
- if(rows.Count<=0)
- {
- CurrDs.Add(id);
- }
- else
- {
- rows[0] = id;
- }
- //dgvmain.Refresh();
- Binddgvmain();
- }
- private void ShowBase(TLcd 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();
- }
- }
- 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;
- ShowBase(dgvmain.CurrentRow.DataBoundItem as TLcd);
- }
- 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<TLcd> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();
- if(rows.Count<=0)
- {
- MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- eventSelRow?.Invoke(rows,CurrSelType);
- this.Close();
- }
- private TLcd CallIUBase(List<TLcd> entitys)
- {
- try
- {
- Hashtable tempds = new Hashtable();
- string str = JsonConvert.SerializeObject(entitys);
- tempds.Add(nameof(TLcd), str);
- Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "DelTLcd", tempds);
- if (reds == null)
- return null;
- TLcd reentity = JsonConvert.DeserializeObject<TLcd>(reds[nameof(TLcd)].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)
- {
- dgvmain.EndEdit();
- edit代码.Focus();
- List<TLcd> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();
- if (rows.Count <= 0)
- {
- MessageBox.Show("您没有选择数据,请选择。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (MessageBox.Show("您确定要执行此操作吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel)
- return;
- TLcd result = CallIUBase(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();
- }
- }
- }
|